Skip to main content
Inspiring
February 26, 2019
Question

get FontSize of the text

  • February 26, 2019
  • 2 replies
  • 1609 views

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 has been closed for replies.

2 replies

Inspiring
February 26, 2019

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?

frameexpert
Community Expert
Community Expert
February 26, 2019

#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);

www.frameexpert.com
Inspiring
February 27, 2019

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?

4everJang
Legend
February 26, 2019

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:

4everJang
Legend
February 26, 2019

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).