use ufoLib2 for cu2qu.cli and tests
the tests are skipped if ufoLib2 is not installed.
This commit is contained in:
parent
76cc29dda4
commit
c4aeec87dc
@ -9,7 +9,7 @@ from functools import partial
|
|||||||
import fontTools
|
import fontTools
|
||||||
from .ufo import font_to_quadratic, fonts_to_quadratic
|
from .ufo import font_to_quadratic, fonts_to_quadratic
|
||||||
|
|
||||||
import defcon
|
import ufoLib2
|
||||||
|
|
||||||
logger = logging.getLogger("fontTools.cu2qu")
|
logger = logging.getLogger("fontTools.cu2qu")
|
||||||
|
|
||||||
@ -23,12 +23,15 @@ def _cpu_count():
|
|||||||
|
|
||||||
def _font_to_quadratic(zipped_paths, **kwargs):
|
def _font_to_quadratic(zipped_paths, **kwargs):
|
||||||
input_path, output_path = zipped_paths
|
input_path, output_path = zipped_paths
|
||||||
ufo = defcon.Font(input_path)
|
ufo = ufoLib2.Font.open(input_path)
|
||||||
logger.info('Converting curves for %s', input_path)
|
logger.info('Converting curves for %s', input_path)
|
||||||
if font_to_quadratic(ufo, **kwargs):
|
if font_to_quadratic(ufo, **kwargs):
|
||||||
logger.info("Saving %s", output_path)
|
logger.info("Saving %s", output_path)
|
||||||
ufo.save(output_path)
|
if output_path:
|
||||||
else:
|
ufo.save(output_path, overwrite=True)
|
||||||
|
else:
|
||||||
|
ufo.save() # save in-place
|
||||||
|
elif output_path:
|
||||||
_copytree(input_path, output_path)
|
_copytree(input_path, output_path)
|
||||||
|
|
||||||
|
|
||||||
@ -130,7 +133,7 @@ def main(args=None):
|
|||||||
output_paths = [options.output_file]
|
output_paths = [options.output_file]
|
||||||
else:
|
else:
|
||||||
# save in-place
|
# save in-place
|
||||||
output_paths = list(options.infiles)
|
output_paths = [None] * len(options.infiles)
|
||||||
|
|
||||||
kwargs = dict(dump_stats=options.verbose > 0,
|
kwargs = dict(dump_stats=options.verbose > 0,
|
||||||
max_err_em=options.conversion_error,
|
max_err_em=options.conversion_error,
|
||||||
@ -138,14 +141,18 @@ def main(args=None):
|
|||||||
|
|
||||||
if options.interpolatable:
|
if options.interpolatable:
|
||||||
logger.info('Converting curves compatibly')
|
logger.info('Converting curves compatibly')
|
||||||
ufos = [defcon.Font(infile) for infile in options.infiles]
|
ufos = [ufoLib2.Font.open(infile) for infile in options.infiles]
|
||||||
if fonts_to_quadratic(ufos, **kwargs):
|
if fonts_to_quadratic(ufos, **kwargs):
|
||||||
for ufo, output_path in zip(ufos, output_paths):
|
for ufo, output_path in zip(ufos, output_paths):
|
||||||
logger.info("Saving %s", output_path)
|
logger.info("Saving %s", output_path)
|
||||||
ufo.save(output_path)
|
if output_path:
|
||||||
|
ufo.save(output_path, overwrite=True)
|
||||||
|
else:
|
||||||
|
ufo.save()
|
||||||
else:
|
else:
|
||||||
for input_path, output_path in zip(options.infiles, output_paths):
|
for input_path, output_path in zip(options.infiles, output_paths):
|
||||||
_copytree(input_path, output_path)
|
if output_path:
|
||||||
|
_copytree(input_path, output_path)
|
||||||
else:
|
else:
|
||||||
jobs = min(len(options.infiles),
|
jobs = min(len(options.infiles),
|
||||||
options.jobs) if options.jobs > 1 else 1
|
options.jobs) if options.jobs > 1 else 1
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import defcon
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import py
|
import py
|
||||||
|
|
||||||
|
ufoLib2 = pytest.importorskip("ufoLib2")
|
||||||
|
|
||||||
from fontTools.cu2qu.ufo import CURVE_TYPE_LIB_KEY
|
from fontTools.cu2qu.ufo import CURVE_TYPE_LIB_KEY
|
||||||
from fontTools.cu2qu.cli import main
|
from fontTools.cu2qu.cli import main
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ class MainTest(object):
|
|||||||
|
|
||||||
self.run_main(ufo_path)
|
self.run_main(ufo_path)
|
||||||
|
|
||||||
font = defcon.Font(str(ufo_path))
|
font = ufoLib2.Font.open(ufo_path)
|
||||||
assert font.lib[CURVE_TYPE_LIB_KEY] == "quadratic"
|
assert font.lib[CURVE_TYPE_LIB_KEY] == "quadratic"
|
||||||
|
|
||||||
def test_single_input_output_file(self, tmpdir):
|
def test_single_input_output_file(self, tmpdir):
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from fontTools.misc.loggingTools import CapturingLogHandler
|
from fontTools.misc.loggingTools import CapturingLogHandler
|
||||||
from defcon import Font, Glyph
|
|
||||||
from fontTools.cu2qu.ufo import (
|
from fontTools.cu2qu.ufo import (
|
||||||
fonts_to_quadratic,
|
fonts_to_quadratic,
|
||||||
font_to_quadratic,
|
font_to_quadratic,
|
||||||
@ -19,6 +18,8 @@ from fontTools.cu2qu.errors import (
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
ufoLib2 = pytest.importorskip("ufoLib2")
|
||||||
|
|
||||||
DATADIR = os.path.join(os.path.dirname(__file__), 'data')
|
DATADIR = os.path.join(os.path.dirname(__file__), 'data')
|
||||||
|
|
||||||
TEST_UFOS = [
|
TEST_UFOS = [
|
||||||
@ -29,7 +30,7 @@ TEST_UFOS = [
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fonts():
|
def fonts():
|
||||||
return [Font(ufo) for ufo in TEST_UFOS]
|
return [ufoLib2.Font.open(ufo) for ufo in TEST_UFOS]
|
||||||
|
|
||||||
|
|
||||||
class FontsToQuadraticTest(object):
|
class FontsToQuadraticTest(object):
|
||||||
@ -178,8 +179,7 @@ class GlyphsToQuadraticTest(object):
|
|||||||
def test_incompatible_glyphs(self, outlines, exception, message):
|
def test_incompatible_glyphs(self, outlines, exception, message):
|
||||||
glyphs = []
|
glyphs = []
|
||||||
for i, outline in enumerate(outlines):
|
for i, outline in enumerate(outlines):
|
||||||
glyph = Glyph()
|
glyph = ufoLib2.objects.Glyph("glyph%d" % i)
|
||||||
glyph.name = "glyph%d" % i
|
|
||||||
pen = glyph.getPen()
|
pen = glyph.getPen()
|
||||||
for operator, args in outline:
|
for operator, args in outline:
|
||||||
getattr(pen, operator)(*args)
|
getattr(pen, operator)(*args)
|
||||||
@ -189,7 +189,7 @@ class GlyphsToQuadraticTest(object):
|
|||||||
assert excinfo.match(message)
|
assert excinfo.match(message)
|
||||||
|
|
||||||
def test_incompatible_fonts(self):
|
def test_incompatible_fonts(self):
|
||||||
font1 = Font()
|
font1 = ufoLib2.Font()
|
||||||
font1.info.unitsPerEm = 1000
|
font1.info.unitsPerEm = 1000
|
||||||
glyph1 = font1.newGlyph("a")
|
glyph1 = font1.newGlyph("a")
|
||||||
pen1 = glyph1.getPen()
|
pen1 = glyph1.getPen()
|
||||||
@ -198,7 +198,7 @@ class GlyphsToQuadraticTest(object):
|
|||||||
("endPath", ())]:
|
("endPath", ())]:
|
||||||
getattr(pen1, operator)(*args)
|
getattr(pen1, operator)(*args)
|
||||||
|
|
||||||
font2 = Font()
|
font2 = ufoLib2.Font()
|
||||||
font2.info.unitsPerEm = 1000
|
font2.info.unitsPerEm = 1000
|
||||||
glyph2 = font2.newGlyph("a")
|
glyph2 = font2.newGlyph("a")
|
||||||
pen2 = glyph2.getPen()
|
pen2 = glyph2.getPen()
|
||||||
@ -217,7 +217,7 @@ class GlyphsToQuadraticTest(object):
|
|||||||
assert error.segments == {1: ["line", "curve"]}
|
assert error.segments == {1: ["line", "curve"]}
|
||||||
|
|
||||||
def test_already_quadratic(self):
|
def test_already_quadratic(self):
|
||||||
glyph = Glyph()
|
glyph = ufoLib2.objects.Glyph()
|
||||||
pen = glyph.getPen()
|
pen = glyph.getPen()
|
||||||
pen.moveTo((0, 0))
|
pen.moveTo((0, 0))
|
||||||
pen.qCurveTo((1, 1), (2, 2))
|
pen.qCurveTo((1, 1), (2, 2))
|
||||||
@ -225,7 +225,7 @@ class GlyphsToQuadraticTest(object):
|
|||||||
assert not glyph_to_quadratic(glyph)
|
assert not glyph_to_quadratic(glyph)
|
||||||
|
|
||||||
def test_open_paths(self):
|
def test_open_paths(self):
|
||||||
glyph = Glyph()
|
glyph = ufoLib2.objects.Glyph()
|
||||||
pen = glyph.getPen()
|
pen = glyph.getPen()
|
||||||
pen.moveTo((0, 0))
|
pen.moveTo((0, 0))
|
||||||
pen.lineTo((1, 1))
|
pen.lineTo((1, 1))
|
||||||
@ -236,7 +236,7 @@ class GlyphsToQuadraticTest(object):
|
|||||||
assert glyph[-1][0].segmentType == "move"
|
assert glyph[-1][0].segmentType == "move"
|
||||||
|
|
||||||
def test_ignore_components(self):
|
def test_ignore_components(self):
|
||||||
glyph = Glyph()
|
glyph = ufoLib2.objects.Glyph()
|
||||||
pen = glyph.getPen()
|
pen = glyph.getPen()
|
||||||
pen.addComponent('a', (1, 0, 0, 1, 0, 0))
|
pen.addComponent('a', (1, 0, 0, 1, 0, 0))
|
||||||
pen.moveTo((0, 0))
|
pen.moveTo((0, 0))
|
||||||
@ -247,7 +247,7 @@ class GlyphsToQuadraticTest(object):
|
|||||||
|
|
||||||
def test_overlapping_start_end_points(self):
|
def test_overlapping_start_end_points(self):
|
||||||
# https://github.com/googlefonts/fontmake/issues/572
|
# https://github.com/googlefonts/fontmake/issues/572
|
||||||
glyph1 = Glyph()
|
glyph1 = ufoLib2.objects.Glyph()
|
||||||
pen = glyph1.getPointPen()
|
pen = glyph1.getPointPen()
|
||||||
pen.beginPath()
|
pen.beginPath()
|
||||||
pen.addPoint((0, 651), segmentType="line")
|
pen.addPoint((0, 651), segmentType="line")
|
||||||
@ -256,7 +256,7 @@ class GlyphsToQuadraticTest(object):
|
|||||||
pen.addPoint((0, 651), segmentType="line")
|
pen.addPoint((0, 651), segmentType="line")
|
||||||
pen.endPath()
|
pen.endPath()
|
||||||
|
|
||||||
glyph2 = Glyph()
|
glyph2 = ufoLib2.objects.Glyph()
|
||||||
pen = glyph2.getPointPen()
|
pen = glyph2.getPointPen()
|
||||||
pen.beginPath()
|
pen.beginPath()
|
||||||
pen.addPoint((1, 651), segmentType="line")
|
pen.addPoint((1, 651), segmentType="line")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user