Getting all the different font families and styles existing in one text box

How i am wondering. Does the API have the ability to obtain all the different font families and styles that exists in one text box. For example, in this sentence “PURCHASE ADOBE XD TODAY”, the whole sentence may exist in one textbox but have different styles applied throughout its contents. In this sentence, the word “Adobe” may be bold with font-size: 18px and “XD” may be italic font-size 12px etc and the rest may be standard ‘Arial’ font-size: 8px. Is there a way to programmatically get all that information in an organized way? or at the very least, how does one just go about obtaining that information one character at a time.

any help would be good thank you

2 Likes

nevermind,
I found an example online:

2 Likes

Hi i have not been able to successfully find any property that contains ‘Font-Weight’. Im looking at the API and trying to get the font weight within a styleRange. I can see it on the right side in the panel but nothing in adobes API reference.
Screen Shot 2020-10-07 at 2.14.08 PM

1 Like

Hi @dcotto,

styleRange.fontStyle is the property you’re searching for.

There, you can then use things like 'Bold', 'Italic', etc. (depending on the font family) – it’s the equivalent to the field in your screenshot :wink:

Example Code:

node.styleRanges = [{
    length: node.text.length,
    fill: new Color("#FF0000"),
    fontSize: 24,
    fontStyle: 'bold'
}];

I hope this helps,
Best,
Pablo

2 Likes