Skip to main content
FRIdNGE
April 24, 2023
Question

Extract "underlineWeight" value …

  • April 24, 2023
  • 2 replies
  • 1146 views

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

This topic has been closed for replies.

2 replies

m1b
Community Expert
Community Expert
April 24, 2023

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

Legend
April 24, 2023

A homebrew font parser would fail on clouded fonts.

 

From SDK/source/public/interfaces/text/IPMFont.h:

 

/**
Get position for underline
 
@paramyOffset
@paramthickness
@paramxScale
@paramyScale
@paramvertical
@paramisTcy
*/
virtual void GetUnderlinePosition(PMReal *yOffset, PMReal *thickness, PMReal xScale = 1.0, PMReal yScale = 1.0, bool16 vertical = kFalse, bool16 isTcy = kFalse) const = 0;

 

Let's say the SDK has better comments on other methods. Somewhere else:

@isTCY specifies if the vertical text in question is actually "horizontal in vertical" (is text composition Y)

 

Legend
April 24, 2023

Fonts can specify an "underlineThickness", maybe the value is taken from there.

https://learn.microsoft.com/en-us/typography/opentype/spec/post

FRIdNGE
FRIdNGEAuthor
April 24, 2023

Hi Dirk,

 

OK with Myriad Pro BUT not the case on other fonts tested.

 

(^/)

 

m1b
Community Expert
Community Expert
April 24, 2023

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