Skip to main content
TᴀW
Legend
February 8, 2011
Question

How can I find the left edge of a column

  • February 8, 2011
  • 1 reply
  • 1640 views

Given a textColumn, how can I know what it's lefttmost edge is? That is, I would like to know the column's horizontal offset from the textFrame or the page. Is there any way of knowing this?

Thanks,

Ariel

This topic has been closed for replies.

1 reply

Peter Kahrel
Community Expert
Community Expert
February 9, 2011

Maybe this:

leftEdge = textColumn.lines[0].insertionPoints[0].horizontalOffset;

The left side of the column's text frame you get with this line:

left = textColumn.parentTextFrames[0].geometricBounds[1];

and then you substract one from the other (haven't tried it).

Peter

TᴀW
TᴀWAuthor
Legend
February 9, 2011

Hi Peter,

It doesn't work if the first line of the column has a paragraph indent,

is centre- or right-aligned, or has otherwise been altered.

Ariel

id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators
February 9, 2011

Hi Ariel, Peter,

For an untransformed, rectangular text frame, you can try something like this:

//Where textColumn is a reference to a text column...

function findLeftEdge(textColumn){
    var textFrame = textColumn.parentTextFrames[0];
    var leftEdge = textFrame.geometricBounds[1];
    var leftIndent = textFrame.textFramePreferences.insetSpacing;
    var textColumnIndex = findTextColumnIndex(textColumn);
    if(leftIndent.length == 1){
        leftIndent = leftIndent[0];
    }
    else{
        leftIndent = leftIndent[1];
    }
    var numberOfColumns = textFrame.textFramePreferences.textColumnCount;
    var spaceBetweenColumns = textFrame.textFramePreferences.textColumnGutter;
    var textFrameWidth = textFrame.geometricBounds[3] - textFrame.geometricBounds[1];
    var textColumnWidth = textFrame.textFramePreferences.textColumnFixedWidth;
    leftEdge = leftEdge + (textColumnIndex * spaceBetweenColumns) + (textColumnWidth * textColumnIndex);
    return leftEdge;
}
function findTextColumnIndex(textColumn){
    var result = 0;
    var textFrame = textColumn.parentTextFrames[0];
    for(var counter = 0; counter < textFrame.textColumns.length; counter++){
        //The index of the text column is actually the
        //index of the first character in the text column.
        if(textFrame.textColumns.item(counter).index == textColumn.index){
            result = counter;
            break;
        }
    }
    return result;
}

Thanks,

Ole