Highlighted

How can set font to TextRange?

Enthusiast ,
Oct 22, 2015

Copy link to clipboard

Copied

This is my code , set font of TextRange

iFont=119, font name ="Tunga"

var oTypedValRp = new TypedVal();

oTypedValRp.valType = Constants.FT_Integer;

oTypedValRp.iVal = iFont;                                                  

oDoc.SetTextVal (oTextRange,Constants.FP_FontFamily, oTypedValRp);  

But Result :TextRange has font name ="Symbol"

Why? How can set font to TextRange?

Hi, here is some code that can set the font of a text range. When run as shown, it sets the font of the currently-selected text to "Blackoak Std", if that font exists on your system. Hope this helps.

Russ

var doc = app.ActiveDoc;

var textRange = doc.TextSelection;

applyFontToTextRange(doc, textRange, "Blackoak Std");

function applyFontToTextRange(doc, textRange, fontName)

{

    if(!doc.ObjectValid())

    {

        alert("Invalid document. Cannot continue.");

        return;

    }

   

    var fontFamilyNames = app.FontFamilyNames;

    for(var i = 0; i < fontFamilyNames.length; i++)

    {

        if(fontFamilyNames == fontName) break;

    }

    if(i == fontFamilyNames.length)

    {

        alert("Could not find the specified font, " + fontName);

        return;

    }

    props = AllocatePropVals(1);

    props[0].propIdent.num = Constants.FP_FontFamily;

    props[0].propVal.valType = Constants.FT_Integer;

    props[0].propVal.ival = i;  

   

    doc.SetTextProps(textRange, props);

}

TOPICS
Scripting

Views

403

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How can set font to TextRange?

Enthusiast ,
Oct 22, 2015

Copy link to clipboard

Copied

This is my code , set font of TextRange

iFont=119, font name ="Tunga"

var oTypedValRp = new TypedVal();

oTypedValRp.valType = Constants.FT_Integer;

oTypedValRp.iVal = iFont;                                                  

oDoc.SetTextVal (oTextRange,Constants.FP_FontFamily, oTypedValRp);  

But Result :TextRange has font name ="Symbol"

Why? How can set font to TextRange?

Hi, here is some code that can set the font of a text range. When run as shown, it sets the font of the currently-selected text to "Blackoak Std", if that font exists on your system. Hope this helps.

Russ

var doc = app.ActiveDoc;

var textRange = doc.TextSelection;

applyFontToTextRange(doc, textRange, "Blackoak Std");

function applyFontToTextRange(doc, textRange, fontName)

{

    if(!doc.ObjectValid())

    {

        alert("Invalid document. Cannot continue.");

        return;

    }

   

    var fontFamilyNames = app.FontFamilyNames;

    for(var i = 0; i < fontFamilyNames.length; i++)

    {

        if(fontFamilyNames == fontName) break;

    }

    if(i == fontFamilyNames.length)

    {

        alert("Could not find the specified font, " + fontName);

        return;

    }

    props = AllocatePropVals(1);

    props[0].propIdent.num = Constants.FP_FontFamily;

    props[0].propVal.valType = Constants.FT_Integer;

    props[0].propVal.ival = i;  

   

    doc.SetTextProps(textRange, props);

}

TOPICS
Scripting

Views

404

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 22, 2015 0
Mentor ,
Oct 22, 2015

Copy link to clipboard

Copied

Hi, here is some code that can set the font of a text range. When run as shown, it sets the font of the currently-selected text to "Blackoak Std", if that font exists on your system. Hope this helps.

Russ

var doc = app.ActiveDoc;

var textRange = doc.TextSelection;

applyFontToTextRange(doc, textRange, "Blackoak Std");

function applyFontToTextRange(doc, textRange, fontName)

{

    if(!doc.ObjectValid())

    {

        alert("Invalid document. Cannot continue.");

        return;

    }

   

    var fontFamilyNames = app.FontFamilyNames;

    for(var i = 0; i < fontFamilyNames.length; i++)

    {

        if(fontFamilyNames == fontName) break;

    }

    if(i == fontFamilyNames.length)

    {

        alert("Could not find the specified font, " + fontName);

        return;

    }

    props = AllocatePropVals(1);

    props[0].propIdent.num = Constants.FP_FontFamily;

    props[0].propVal.valType = Constants.FT_Integer;

    props[0].propVal.ival = i;  

   

    doc.SetTextProps(textRange, props);

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 22, 2015 1
Enthusiast ,
Oct 22, 2015

Copy link to clipboard

Copied

Thank you very much, it working ok.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 22, 2015 0