aboutsummaryrefslogtreecommitdiff
path: root/Snippets/otf2ttf.py
diff options
context:
space:
mode:
Diffstat (limited to 'Snippets/otf2ttf.py')
-rwxr-xr-xSnippets/otf2ttf.py45
1 files changed, 26 insertions, 19 deletions
diff --git a/Snippets/otf2ttf.py b/Snippets/otf2ttf.py
index b925b33c..6682458f 100755
--- a/Snippets/otf2ttf.py
+++ b/Snippets/otf2ttf.py
@@ -25,14 +25,12 @@ POST_FORMAT = 2.0
REVERSE_DIRECTION = True
-def glyphs_to_quadratic(
- glyphs, max_err=MAX_ERR, reverse_direction=REVERSE_DIRECTION):
+def glyphs_to_quadratic(glyphs, max_err=MAX_ERR, reverse_direction=REVERSE_DIRECTION):
quadGlyphs = {}
for gname in glyphs.keys():
glyph = glyphs[gname]
ttPen = TTGlyphPen(glyphs)
- cu2quPen = Cu2QuPen(ttPen, max_err,
- reverse_direction=reverse_direction)
+ cu2quPen = Cu2QuPen(ttPen, max_err, reverse_direction=reverse_direction)
glyph.draw(cu2quPen)
quadGlyphs[gname] = ttPen.glyph()
return quadGlyphs
@@ -41,7 +39,7 @@ def glyphs_to_quadratic(
def update_hmtx(ttFont, glyf):
hmtx = ttFont["hmtx"]
for glyphName, glyph in glyf.glyphs.items():
- if hasattr(glyph, 'xMin'):
+ if hasattr(glyph, "xMin"):
hmtx[glyphName] = (hmtx[glyphName][0], glyph.xMin)
@@ -69,8 +67,9 @@ def otf_to_ttf(ttFont, post_format=POST_FORMAT, **kwargs):
maxp.maxStackElements = 0
maxp.maxSizeOfInstructions = 0
maxp.maxComponentElements = max(
- len(g.components if hasattr(g, 'components') else [])
- for g in glyf.glyphs.values())
+ len(g.components if hasattr(g, "components") else [])
+ for g in glyf.glyphs.values()
+ )
maxp.compile(ttFont)
post = ttFont["post"]
@@ -91,34 +90,42 @@ def main(args=None):
configLogger(logger=log)
parser = argparse.ArgumentParser()
- parser.add_argument("input", nargs='+', metavar="INPUT")
+ parser.add_argument("input", nargs="+", metavar="INPUT")
parser.add_argument("-o", "--output")
parser.add_argument("-e", "--max-error", type=float, default=MAX_ERR)
parser.add_argument("--post-format", type=float, default=POST_FORMAT)
parser.add_argument(
- "--keep-direction", dest='reverse_direction', action='store_false')
+ "--keep-direction", dest="reverse_direction", action="store_false"
+ )
parser.add_argument("--face-index", type=int, default=0)
- parser.add_argument("--overwrite", action='store_true')
+ parser.add_argument("--overwrite", action="store_true")
options = parser.parse_args(args)
if options.output and len(options.input) > 1:
if not os.path.isdir(options.output):
- parser.error("-o/--output option must be a directory when "
- "processing multiple fonts")
+ parser.error(
+ "-o/--output option must be a directory when "
+ "processing multiple fonts"
+ )
for path in options.input:
if options.output and not os.path.isdir(options.output):
output = options.output
else:
- output = makeOutputFileName(path, outputDir=options.output,
- extension='.ttf',
- overWrite=options.overwrite)
+ output = makeOutputFileName(
+ path,
+ outputDir=options.output,
+ extension=".ttf",
+ overWrite=options.overwrite,
+ )
font = TTFont(path, fontNumber=options.face_index)
- otf_to_ttf(font,
- post_format=options.post_format,
- max_err=options.max_error,
- reverse_direction=options.reverse_direction)
+ otf_to_ttf(
+ font,
+ post_format=options.post_format,
+ max_err=options.max_error,
+ reverse_direction=options.reverse_direction,
+ )
font.save(output)