-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[builder] allow slicing of VF with continuous ital axis #627
Labels
builder
Issues related to the gftools-builder
Comments
This is the little patch to fix these issues for now:
Feel free to edit it to make it better. |
This is @yanone script:
|
FWIW, here's an updated script that should work with almost any Italic VF. (The italicAngle is font-specific, tho). import sys
import math
from fontTools.ttLib import TTFont
font = TTFont(sys.argv[-2])
def set_name(nameID, string):
for record in font["name"].names:
if record.nameID == nameID:
old_string = record.toUnicode()
if string != old_string:
font["name"].setName(
string,
record.nameID,
record.platformID,
record.platEncID,
record.langID,
)
print(
f"Set ID {nameID} ({record.platformID},{record.platEncID},{record.langID}) to '{string}'"
)
def get_name(nameID):
for record in font["name"].names:
if record.nameID == nameID:
return record.toUnicode()
def get_axis(tag):
for i, axis in enumerate(font["STAT"].table.DesignAxisRecord.Axis):
if axis.AxisTag == tag:
return i, axis
def get_axis_value(axisTag, name):
for axisValue in font["STAT"].table.AxisValueArray.AxisValue:
if (
axisValue.AxisIndex == get_axis(axisTag)[0]
and get_name(axisValue.ValueNameID) == name
):
return axisValue
# Italic angle
font["post"].italicAngle = -11
# macStyle bit
font["head"].macStyle |= 1 << 1
# fsSelection
# Unset first
for value in [0, 5, 6]:
font["OS/2"].fsSelection &= ~(1 << value)
# Then set Italic
font["OS/2"].fsSelection |= 1 << 0
# Set subfamilyname
set_name(2, "Italic")
# Change ID 4 (PostScript Name)
if get_name(4).endswith("Regular"):
set_name(4, get_name(4).replace("Regular", "Italic"))
else:
set_name(4, get_name(4) + " Italic")
# Change ID 6 (PostScript Name)
old_postscript_name = get_name(6)
if get_name(6).endswith("Regular"):
set_name(6, get_name(6).replace("Regular", "Italic"))
else:
set_name(6, get_name(6) + "Italic")
# Change ID 3 (Unique Font ID)
set_name(3, get_name(3).replace(old_postscript_name, get_name(6)))
# Change ID 17
if get_name(17).endswith("Regular"):
set_name(17, get_name(17).replace("Regular", "Italic"))
else:
set_name(17, get_name(17) + " Italic")
# Change ID 25
set_name(25, get_name(25) + "Italic")
# Adjust fvar instance names to include "Italic"
for instance in font["fvar"].instances:
if not get_name(instance.subfamilyNameID).endswith("Italic"):
new_name = get_name(instance.subfamilyNameID) + " Italic"
if new_name == "Regular Italic":
new_name = "Italic"
set_name(instance.subfamilyNameID, new_name)
# Caret slope
font["hhea"].caretSlopeRise = font["head"].unitsPerEm
font["hhea"].caretSlopeRun = round(
math.tan(math.radians(abs(font["post"].italicAngle))) * font["head"].unitsPerEm
)
font.save(sys.argv[-1]) |
Update: In the above code snipped, the italic angle got abs()'d, so it assumes right-leaning fonts. This is correct: font["hhea"].caretSlopeRun = round(math.tan(math.radians(-font["post"].italicAngle)) * font["head"].unitsPerEm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made a 3 test cases using varLib.instancer (ITAL=-12, SLANT=-12, ITAL=1) which I link here.
Mona_tests.zip
To make it short, I think we should make builder slicing the VF when we have
ITAL=1
because it would be the easiest one to fix. This is my checklist to see if Italic style linking is correct, what is un-check should be patched/fixed by gftools:Name
Style linking bits
Design space
Explanation about the last check:
The entries in the STAT table that matches ID2 and 17, are referred as such. So when the name tables are updated for the resulting Italic fonts, we end up with the wrong value names, like this:
STAT.ttx.zip
Particularly these pieces in the
weight axis
:I should be ExtraLight instead. Value should not be
nameID 17
, it should bename ID 261 'ExtraLight'
, but it is missing from the name table.It should be Regular. Value should not be
nameID 2
, it should benameID 263 'Regular'
, but it is missing from the name table.The text was updated successfully, but these errors were encountered: