Skip to content

Commit

Permalink
Merge pull request #54 from NightFurySL2001/master
Browse files Browse the repository at this point in the history
Use fontFeatures to extract OpenType features
  • Loading branch information
benkiel committed Jun 8, 2023
2 parents c310904 + 4f6d9d1 commit 31576d4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/extractor/__init__.py
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
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
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
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
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
@@ -1,3 +1,4 @@
fonttools
defcon
ufoLib2
fontFeatures

0 comments on commit 31576d4

Please sign in to comment.