コード例 #1
0
ファイル: pen_test.py プロジェクト: simoncozens/glyphsLib
def test_pen_recording(datadir):
    font = classes.GSFont(str(datadir.join("PenTest.glyphs")))
    pen = fontTools.pens.recordingPen.RecordingPen()
    layer = font.glyphs["recording1"].layers[0]
    layer.draw(pen)

    assert pen.value == [
        ("moveTo", ((0, 141),)),
        ("lineTo", ((0, 0),)),
        ("lineTo", ((162, 0),)),
        ("lineTo", ((162, 141),)),
        ("closePath", ()),
        ("moveTo", ((366, 0),)),
        ("curveTo", ((413, 0), (452, 32), (452, 71))),
        ("curveTo", ((452, 109), (413, 141), (366, 141))),
        ("curveTo", ((319, 141), (280, 109), (280, 71))),
        ("curveTo", ((280, 32), (319, 0), (366, 0))),
        ("closePath", ()),
        ("moveTo", ((64, 255),)),
        ("lineTo", ((56, 419),)),
        ("lineTo", ((186, 415),)),
        ("curveTo", ((189, 387), (118, 295), (196, 331))),
        ("endPath", ()),
        ("moveTo", ((266, 285),)),
        ("lineTo", ((412, 421),)),
        ("endPath", ()),
        ("moveTo", ((462, 387),)),
        ("curveTo", ((458, 358), (514, 295), (450, 301))),
        ("endPath", ()),
        ("addComponent", ("dieresis", Transform(1, 0, 0, 1, 108, -126))),
        (
            "addComponent",
            ("adieresis", Transform(0.84572, 0.30782, -0.27362, 0.75175, 517, 308)),
        ),
    ]
コード例 #2
0
def to_glyphs_components(self, ufo_glyph, layer):
    for comp in ufo_glyph.components:
        component = self.glyphs_module.GSComponent(comp.baseGlyph)
        component.transform = Transform(*comp.transformation)
        layer.components.append(component)

    for key in ["alignment", "locked", "smartComponentValues"]:
        if _lib_key(key) not in ufo_glyph.lib:
            continue
        # FIXME: (jany) move to using component identifiers for robustness
        # "alignment" is read, but not written for source backwards compatibility.
        values = ufo_glyph.lib[_lib_key(key)]
        for component, value in zip(layer.components, values):
            if value is not None:
                setattr(component, key, value)

    if COMPONENT_INFO_KEY in ufo_glyph.lib:
        for index, component_info in enumerate(ufo_glyph.lib[COMPONENT_INFO_KEY]):
            if "index" not in component_info or "name" not in component_info:
                logger.warning(
                    "Glyph %s, layer %s: The ComponentInfo at index %s is missing "
                    "index and/or name keys. Skipping, component properties will be "
                    "lost.",
                    ufo_glyph.name,
                    layer.name,
                    index,
                )
                continue

            component_index = component_info["index"]
            try:
                component = layer.components[component_index]
            except IndexError:
                logger.warning(
                    "Glyph %s, layer %s: The ComponentInfo at index %s is referencing "
                    "a component that does not exist. Skipping, component properties "
                    "will be lost.",
                    ufo_glyph.name,
                    layer.name,
                    index,
                )
                continue

            if component.name == component_info["name"]:
                if "anchor" in component_info:
                    component.anchor = component_info["anchor"]
                if "alignment" in component_info:
                    component.alignment = component_info["alignment"]
            else:
                logger.warning(
                    "Glyph %s, layer %s: The ComponentInfo at index %s says the "
                    "component at index %s is named '%s', but it is actually named "
                    "'%s'. Skipping, component properties will be lost.",
                    ufo_glyph.name,
                    layer.name,
                    index,
                    component_index,
                    component_info["name"],
                    component.name,
                )
コード例 #3
0
ファイル: components.py プロジェクト: hugovk/glyphsLib
def to_glyphs_components(self, ufo_glyph, layer):
    for comp in ufo_glyph.components:
        component = self.glyphs_module.GSComponent(comp.baseGlyph)
        component.transform = Transform(*comp.transformation)
        layer.components.append(component)

    for key in ["alignment", "locked", "smartComponentValues"]:
        if _lib_key(key) not in ufo_glyph.lib:
            continue
        # FIXME: (jany) move to using component identifiers for robustness
        values = ufo_glyph.lib[_lib_key(key)]
        for component, value in zip(layer.components, values):
            if value is not None:
                setattr(component, key, value)

    if COMPONENT_INFO_KEY in ufo_glyph.lib:
        for component_info in ufo_glyph.lib[COMPONENT_INFO_KEY]:
            component_index = component_info["index"]
            component = layer.components[component_index]
            if component.name == component_info["name"]:
                component.anchor = component_info["anchor"]
            else:
                logger.warning(
                    "Glyph {}, layer {}: The ComponentInfo says the component at index "
                    "{} is named '{}', but it is actually named '{}'. Skipping, anchor "
                    "placement might get lost.".format(
                        ufo_glyph.name,
                        layer.name,
                        component_index,
                        component_info["name"],
                        component.name,
                    ))
コード例 #4
0
ファイル: components.py プロジェクト: shengdoushi/glyphsLib
def to_glyphs_components(self, ufo_glyph, layer):
    for comp in ufo_glyph.components:
        component = self.glyphs_module.GSComponent(comp.baseGlyph)
        component.transform = Transform(*comp.transformation)
        layer.components.append(component)

    for key in ['alignment', 'locked', 'smartComponentValues']:
        if _lib_key(key) not in ufo_glyph.lib:
            continue
        # FIXME: (jany) move to using component identifiers for robustness
        values = ufo_glyph.lib[_lib_key(key)]
        for component, value in zip(layer.components, values):
            if value is not None:
                setattr(component, key, value)
コード例 #5
0
def to_glyphs_background_image(self, ufo_glyph, layer):
    """Copy the background image from the UFO Glyph to the GSLayer."""
    ufo_image = ufo_glyph.image
    if ufo_image.fileName is None:
        return
    image = self.glyphs_module.GSBackgroundImage()
    image.path = ufo_image.fileName
    image.transform = Transform(*ufo_image.transformation)
    if CROP_KEY in ufo_glyph.lib:
        x, y, w, h = ufo_glyph.lib[CROP_KEY]
        image.crop = Rect(Point(x, y), Size(w, h))
    if LOCKED_KEY in ufo_glyph.lib:
        image.locked = ufo_glyph.lib[LOCKED_KEY]
    if ALPHA_KEY in ufo_glyph.lib:
        image.alpha = ufo_glyph.lib[ALPHA_KEY]
    layer.backgroundImage = image
コード例 #6
0
ファイル: types_test.py プロジェクト: shengdoushi/glyphsLib
 def test_value_equality(self):
     assert Transform(1, 0, 0, 1, 0, 0) == Transform(1, 0, 0, 1, 0, 0)
     assert Transform(1, 0, 0, 1, 0, 0) == Transform(1.0, 0, 0, 1.0, 0, 0)
コード例 #7
0
def _save_component(component):
    c = glyphsLib.GSComponent(component.baseGlyph)
    if component.transformation != (1, 0, 0, 1, 0, 0):
        c.transform = Transform(*component.transformation)
    return c