Skip to main content
Inspiring
Feb 26, 2019 10:40 AM UTC
Question

get FontSize of the text

Hi,

how to get the font size of the text? the following code returns empty

  var oProp = doc.GetTextPropVal( textRange.beg, Constants.FP_FontSize);

  alert(oProp.propVal.sval);

pls help

This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

Inspiring
Feb 26, 2019 11:01 AM UTC

Thank you  for your response.. i have used ival instead of sval then works fine..

now i am trying to reset the font size..

pls help how to set the font size using setTextPropVal() or is there any other method to set font size?

Translate
frameexpert
Community Expert
Community Expert
Feb 26, 2019 2:08 PM UTC

#target framemaker

var doc, textRange, prop;

doc = app.ActiveDoc;

textRange = doc.TextSelection;

prop = new PropVal ();

prop.propIdent.num = Constants.FP_FontSize;

prop.propVal.valType = Constants.FT_Metric;

prop.propVal.val = 8 * 65536;

doc.SetTextPropVal (textRange, prop);

Translate
www.frameexpert.com
Inspiring
Feb 27, 2019 5:29 AM UTC

Hi, This is sample script

var findSize  = "12";

var changeSize = "20";

var doc = app.ActiveDoc;

var pgf = doc.TextSelection.beg.obj;

main(pgf, doc);

function main (pgf, doc) {

    var end = Constants.FV_OBJ_END_OFFSET - 1, begin = 0, textRange;

    

    var textList = pgf.GetText (Constants.FTI_CharPropsChange);

    for (var i = textList.length - 1; i >= 0; i -= 1) {

        begin = textList.offset;

        if (begin !== end) {          

            textRange = new TextRange (new TextLoc (pgf, begin), new TextLoc (pgf, end));           

            var oProp = doc.GetTextPropVal(textRange.beg, Constants.FP_FontSize);

            if(oProp.propVal.ival /  65536 == Number(findSize)){

                newVal = 65536 * changeSize;    

                prop = new PropVal ();

                prop.propIdent.num = Constants.FP_FontSize;

                prop.propVal.valType = Constants.FT_Metric;

                prop.propVal.val = newVal;                  

                doc.SetTextPropVal (textRange, prop);

                }                  

            end = begin;

        }

    }

    if (end > 0) {

        textRange = new TextRange (new TextLoc (pgf,0), new TextLoc (pgf,end));

         var oProp = doc.GetTextPropVal(textRange.beg, Constants.FP_FontSize);      

         if(oProp.propVal.ival /  65536 == Number(findSize)){            

         newVal = 65536 * Number(changeSize);     

         prop = new PropVal ();

        prop.propIdent.num = Constants.FP_FontSize;

        prop.propVal.valType = Constants.FT_Metric;

        prop.propVal.val = newVal;

        doc.SetTextPropVal (textRange, prop);

        }

    }

}

The above script found text which have font size 12pt successfully.. but did not changed to the size 20pt.. i think it changed by default size..

is there any mistake in the above script?

Translate
4everJang
Legend
Feb 26, 2019 10:53 AM UTC

Use oProp.propVal.val instead. And note that all sizes in Fm are expressed in Metrics. For a full conversion table from Metrics to other measurement units, here is the page in the FDK Reference Guide you can use:

Translate
4everJang
Legend
Feb 26, 2019 11:29 AM UTC

I have always found it very hard to set individual text properties. Maybe Rick can jump in here (I am sure he will - but he is in the US so in a different time zone).

Translate