Skip to content
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

Use fontFeatures to extract OpenType features #54

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def extractUFO(
doGlyphs=True,
doInfo=True,
doKerning=True,
doFeatures=True,
format=None,
customFunctions={},
):
Expand All @@ -63,6 +64,7 @@ def extractUFO(
doGlyphs=doGlyphs,
doInfo=doInfo,
doKerning=doKerning,
doFeatures=doFeatures,
customFunctions=customFunctions.get(format, []),
)
except:
Expand Down
16 changes: 16 additions & 0 deletions Lib/extractor/formats/opentype.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from extractor.exceptions import ExtractorError
from extractor.stream import InstructionStream
from extractor.tools import RelaxedInfo, copyAttr
from fontFeatures.ttLib import unparse


TRUETYPE_INSTRUCTIONS_KEY = "public.truetype.instructions"
Expand Down Expand Up @@ -40,6 +41,7 @@ def extractFontFromOpenType(
doGlyphs=True,
doInfo=True,
doKerning=True,
doFeatures=True,
customFunctions=[],
doInstructions=True,
):
Expand All @@ -56,6 +58,9 @@ def extractFontFromOpenType(
destination.groups.update(groups)
destination.kerning.clear()
destination.kerning.update(kerning)
if doFeatures:
features = extractOpenTypeFeatures(source)
destination.features.text = features
for function in customFunctions:
function(source, destination)
if doInstructions:
Expand Down Expand Up @@ -1054,3 +1059,14 @@ def _extractOpenTypeKerningFromKern(source):
# there are no minimum values.
kerning.update(subtable.kernTable)
return kerning


# -------
# Features
# -------


def extractOpenTypeFeatures(source):
return unparse(source).asFea()


5 changes: 5 additions & 0 deletions Lib/extractor/formats/ttx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extractOpenTypeInfo,
extractOpenTypeGlyphs,
extractOpenTypeKerning,
extractOpenTypeFeatures,
)


Expand All @@ -23,6 +24,7 @@ def extractFontFromTTX(
doGlyphs=True,
doInfo=True,
doKerning=True,
doFeatures=True,
customFunctions=[],
):
from fontTools.ttLib import TTFont, TTLibError
Expand All @@ -38,6 +40,9 @@ def extractFontFromTTX(
destination.groups.update(groups)
destination.kerning.clear()
destination.kerning.update(kerning)
if doFeatures:
features = extractOpenTypeFeatures(source)
destination.features.text = features
for function in customFunctions:
function(source, destination)
source.close()
4 changes: 4 additions & 0 deletions Lib/extractor/formats/type1.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def extractFontFromType1(
doGlyphs=True,
doInfo=True,
doKerning=True,
doFeatures=False,
customFunctions=[],
):
source = T1Font(pathOrFile)
Expand All @@ -39,6 +40,9 @@ def extractFontFromType1(
# in theory, it could be retried from an AFM.
# we need to find the AFM naming rules so that we can sniff for the file.
pass
if doFeatures:
# Type1 does not have OpenType features
pass
for function in customFunctions:
function(source, destination)

Expand Down
5 changes: 5 additions & 0 deletions Lib/extractor/formats/woff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
extractOpenTypeInfo,
extractOpenTypeGlyphs,
extractOpenTypeKerning,
extractOpenTypeFeatures,
)

try:
Expand Down Expand Up @@ -34,6 +35,7 @@ def extractFontFromWOFF(
doGlyphs=True,
doInfo=True,
doKerning=True,
doFeatures=True,
customFunctions=[],
):
source = TTFont(pathOrFile)
Expand All @@ -46,6 +48,9 @@ def extractFontFromWOFF(
destination.groups.update(groups)
destination.kerning.clear()
destination.kerning.update(kerning)
if doFeatures:
features = extractOpenTypeFeatures(source)
destination.features.text = features
for function in customFunctions:
function(source, destination)
source.close()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fonttools
defcon
ufoLib2
fontFeatures