huertatipografica / HTLetterspacer

HT Letterspacer is a tool for spacing fonts
https://huertatipografica.github.io/HTLetterspacer/
GNU General Public License v3.0
73 stars 16 forks source link

Deitalicizing side-bearing values for italic fonts? #56

Closed madig closed 3 years ago

madig commented 3 years ago

I'm looking at breaking up the code and making a neat copy of the core algorithm, to make it work on UFOs and provide a better base for editor-specific scripts. I'm running into trouble with italic fonts; the final side-bearings produced by the algorithm seem to be made specifically for Glyphs.app's automatic value conversion when dealing with italic fonts.

From what I can glean, Glyphs.app (and optionally FontLab 7) measures italic side-bearings from y = xHeight / 2 with a measurement line following the italic angle instead of y = 0 and a straight-up line like in non-italic fonts.

grafik

The -11 and 10 values are what come out of HT Letterspacer. There is no such standardized italic side-bearings measuring in the UFO world, so I need to de-italicize these values to arrive at:

grafik

I think there are two options here:

  1. Deitalicize the final values
  2. Stop HT Letterspacer from italicizing the values in the first place

So far, I have failed at both. The former because I can't find a calculation that spits out what Glyphs.app does and the latter because taking out all the (slant|deSlant) calls from the code doesn't actually do much because the side-bearing computation seems to be independent of the angle anyway?!

Halp!

schriftgestalt commented 3 years ago

Glyphs is generating a NSBezierPath from the layer and then back-slants it on the half x-height. Then measures the bounding box of that NSBezierpath.

madig commented 3 years ago

"Generates a NSBezierPath" as in it applies a negative angle skew transformation with origin = xheight / 2 to the layer contents? And how does it take an italic side-bearing like 11 and transform it into -62? Back-slant, apply side-bearing, forward-slant, use new side-bearing?

schriftgestalt commented 3 years ago

It doesn't deal with the none slanted sidebearing at all. All operations work on the UI value.

madig commented 3 years ago

Ok thanks. Figured it out. Code follows once I am ready for a PR.