Copy link to clipboard
Copied
Hi all,
I would like to extract the "underlineWeight" value of an underlined text.
But, if by default (value between parenthesis), I only get "-9999" using:
alert(app.selection[0].underlineWeight)
Idea?
Best,
(^/) The Jedi
Copy link to clipboard
Copied
Fonts can specify an "underlineThickness", maybe the value is taken from there.
https://learn.microsoft.com/en-us/typography/opentype/spec/post
Copy link to clipboard
Copied
Hi Dirk,
OK with Myriad Pro BUT not the case on other fonts tested.
(^/)
Copy link to clipboard
Copied
It is *entirely* font-dependent. In a quick test I did here I found a font that had no "underlineThickness" value at all and Indesign gave it a hairline on the baseline. Thickness and offset were zeros. - Mark
Copy link to clipboard
Copied
Dirk is right.
Indesign gets "underlineThickness" value from the font itself. The formula it uses to derive the default value is (underlineThickness / unitsPerEm * font size).
• The underlineThickness is defined in EmSquare units.
• UnitsPerEm is defined in the font itself and is often, but not always, 1000.
Example: a font with a 100 EmUnit underlineThickness and 1000 unitsPerEm and set at 12pt font size will have an underline thickness of 1.2pts.
The offset value is also from the font: "underlinePosition" and is calculated exactly as above.
The question remains: how are you to get that value from the font? I don't think it's exposed to the scripting API. Maybe SDK?
- Mark
Copy link to clipboard
Copied
A homebrew font parser would fail on clouded fonts.
From SDK/source/public/interfaces/text/IPMFont.h:
Let's say the SDK has better comments on other methods. Somewhere else:
Copy link to clipboard
Copied
Hi Mark,
Maybe I'm not totally clear: What I try to get (in the screenshot posted) is to extract (for later manipulations) the 2 values "1.081" and "2.25".
(^/)
Copy link to clipboard
Copied
Yes, that's what I understood to be your meaning. It will be hard to get those values. They are derived like I showed. You can see that they are font-dependent just by changing fonts. Those "auto" values will change depending on the font selected—try a few weird ones and you will see most obviously.
To extract them I believe you will need to know the font's underlineThickness value and UnitsPerEm value.
See my screenshot of my quick experiment:
Left and right words "underline" use two different fonts that I have modified to have the parameters shown at the bottom. They are both set at 12pt font size. Both have 1000 unitsPerEm. And above shows Indesign "auto" values. The values are 20/1000*12 = 0.24pts on the left and 10/1000*12 = 0.12pts on the right.
Copy link to clipboard
Copied
"you will need to know the font's underlineThickness value and UnitsPerEm value."
So [stupid question] how to get these 2 values?
(^/)
Copy link to clipboard
Copied
Yeah that's the question alright. I'm afraid I don't know how to get it with ExtendScript. Dirk showed alikely route with the SDK via the IPMFont interface. I know that's probably not what you wanted to hear.
Another approach would be to take the average or perhaps mode of the values of underlineThickness from a good sampling of the fonts you care about (ignoring the unorthodox or strangely constructed fonts). This wouldn't always be correct, but would mostly be pretty close. Not very satisfying I would guess.
Another approach might be to see what you get when you export a very controlled sample of underlined text as various vector formats (SVG?) and literally measure the rectangle of the underline. Getting a bit far fetched and may not work anyway because underline is usually just a property of the text and it doesn't get outlined by createOutlines() either.
Sorry, I don't have a great answer.
- Mark
Copy link to clipboard
Copied
Mark,
In fact, it's [paradoxically] a right answer!
Weight and Offset depends on the font (name) and its size. So [samples]:
Arial Black Regular 18 pt (1.081 pt) (2.25 pt)
Arial Bold 18 pt (1.89 pt) (1.907 pt)
Arial Regular 10 pt (0.732 pt) (1.06 pt)
Arial Regular 8 pt (0.586 pt) (0,848 pt)
[Note there's a link inside a same family (the 2 last lines) where we can get the 2 last values * 80%.]
So I just need to collect a sample of each configuration through a .txt to save these data (and complete them as I come across other configurations in the future).
Just a little manual!
Best,
(^/)
Copy link to clipboard
Copied
Oh yes, good point! You can reliably do that so long as you know the font.
Also, here's an illustration I should have made earlier. If you guess that the UnitsPerEm of the font is 1000, and you set a character at 1000pt size, the underline weight in EmUnits should equal the underline weight in pts. I tried it here:
As you can see there is a rounding error (surprisingly large!) but you get the idea. The underlineThickness is 10 EmUnits and here it equals 10pts. Likewise, the underlinePosition is 120 EmUnits and here measures 120pts.