Example #1
0
def test_dataset(tmp_path: Path) -> None:
    font = Font()
    font.data["test.png"] = b"123"
    font.data["directory/test2.png"] = b"456"
    font_path = tmp_path / "a.ufo"
    font.save(font_path)

    font = Font.open(font_path)
    assert font.data["test.png"] == b"123"
    assert font.data["directory/test2.png"] == b"456"
Example #2
0
def test_imageset(tmp_path: Path) -> None:
    font = Font()
    font.images["test.png"] = b"\x89PNG\r\n\x1a\n123"
    font.images["test2.png"] = b"\x89PNG\r\n\x1a\n456"
    font_path = tmp_path / "a.ufo"
    font.save(font_path)

    font = Font.open(font_path)
    assert font.images["test.png"] == b"\x89PNG\r\n\x1a\n123"
    assert font.images["test2.png"] == b"\x89PNG\r\n\x1a\n456"

    with pytest.raises(ValueError, match=r".*subdirectories.*"):
        font.images["directory/test2.png"] = b"\x89PNG\r\n\x1a\n456"
    with pytest.raises(KeyError):
        font.images["directory/test2.png"]
Example #3
0
    def _preprocess(self):
        ufo = UFOFont.open(self.source, validate=False)

        if self.ren is not None:
            with open(self.ren, "r") as f:
                logger.info(f"Setting {self.name} final glyph names")
                lines = f.read().split("\n")
                lines = [l.split() for l in lines if l and not l.startswith("%")]
                ufo.lib[PSNAMES_KEY] = {l[0]: l[1] for l in lines}

        if "fstype" in self.set:
            ufo.info.openTypeOS2Type = self.set["fstype"]

        otl = TTFont(self.ttf["source"]) if "source" in self.ttf else None

        return ufo, otl
Example #4
0
def main(args=None):
    parser = ArgumentParser(description="Pre-process UFO files")
    parser.add_argument("input")
    parser.add_argument("ren")
    parser.add_argument("otl")
    parser.add_argument("output")

    options = parser.parse_args(args)

    font = Font.open(options.input, validate=False)
    font.features.text = ""
    font.kerning = {}
    font.groups = {}

    font.lib[PSNAMES_KEY] = load_names(options.ren)
    otf = TTFont(options.otl, lazy=True)
    tables = {"GDEF", "GSUB", "GPOS"}
    if "MATH" in otf:
        tables |= {"MATH", "cmap"}
    add_otl(font, otf, tables)

    font.save(options.output, validate=False, overwrite=True)