Saturday, February 4, 2012

Converting Font Style Names to Font Angle Index Values

If your script queries a text property such as font angle, the value you get back is a number and not a name. For example, the following code snippet asks what is the font angle at the text location (tLoc) specified. That information is returned as an integer.

textProp =  doc.GetTextPropVal(tLoc, Constants.FP_FontAngle);
angleIndex = textProp.propVal.ival; //integer value

The integer value angleIndex is an index into an array containing the possible font angle values available in the current FrameMaker session. Use the app (session) property FontAngleNames to get this array of strings.

angleNames = app.FontAngleNames;

Here is that data structure as viewed in the ExtendScript DataBrowser:

The following script converts an angle name to its corresponding index in the angleNames array.

function findAngleIndex(angleName) {
    var angleNames, index;
    angleNames = app.FontAngleNames;
    for (index = 1; index < angleNames.len; index += 1) {
        if (angleNames[index] === angleName) {
    if (index === angleNames.len) {
        index = null;
    return (index);

var index;

index = findAngleIndex("Italic");
Alert(index, Constants.FF_ALERT_CONTINUE_NOTE);

The output is as shown here:

No comments:

Post a Comment