Created
December 1, 2021 22:46
-
-
Save arrowtype/e4e849c071aef87920790313d7f9db2c to your computer and use it in GitHub Desktop.
A snippet to determine how much horizontal shift a point should get in an italic glyph, in a UFO font.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Here’s a snippet to determine how much horizontal shift a point should get in an italic glyph. | |
In practical terms, I have just used this to shift anchors in a UFO font source, in order to prepare an oblique font. | |
Basically, how can we determine "x" below, given a height ("y") and an angle (italicAngle)? | |
x | |
• - - • | |
| / | |
| / | |
y | / | |
| / | |
|/ | |
• | |
11.31° | |
This is basic trigonometry, but it’s easy to forget! We need to use the "TOA" from "SOH CAH TOA." | |
> tan(angle) = opposite/adjacent | |
which is equivalent to... | |
> opposite = tan(angle) * adjacent | |
or, in Python... | |
> xShift = math.tan(math.radians(slant) * yPos | |
So, the below is a simplified script to do determine the x shift to add at a given y position. | |
""" | |
# import the Python math library | |
import math | |
# get the font object in some way | |
font = CurrentFont() | |
# a given y postion, e.g. a mark anchor at cap height | |
yPos = 1000 | |
# a clockwise or "forward" slant is negative, so we have to use the negative of the italic Angle | |
slant = font.info.italicAngle * -1 | |
# Use tangent to determine the xShift. Note that we must also convert the angle to radians for this to work. | |
xShift = math.tan(math.radians(slant)) * yPos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment