def test_registerCustomTableClassStandardName(): registerCustomTableClass(TABLETAG, "ttFont_test") try: font = TTFont() font[TABLETAG] = newTable(TABLETAG) font[TABLETAG].numbers = [4, 5, 6] assert font[TABLETAG].compile(font) == b"\x04\x05\x06" finally: unregisterCustomTableClass(TABLETAG)
def test_registerCustomTableClass(): font = TTFont() font[TABLETAG] = newTable(TABLETAG) font[TABLETAG].data = b"\x00\x01\xff" f = io.BytesIO() font.save(f) f.seek(0) assert font[TABLETAG].data == b"\x00\x01\xff" registerCustomTableClass(TABLETAG, "ttFont_test", "CustomTableClass") try: font = TTFont(f) assert font[TABLETAG].numbers == [0, 1, 255] assert font[TABLETAG].compile(font) == b"\x00\x01\xff" finally: unregisterCustomTableClass(TABLETAG)
def buildVarC( designspacePath, ttfPath, outTTFPath, doTTX, saveWoff2, neutralOnly=False ): import pathlib registerCustomTableClass("VarC", "rcjktools.table_VarC", "table_VarC") ttfPath = pathlib.Path(ttfPath) if outTTFPath is None: outTTFPath = ttfPath.parent / (ttfPath.stem + "-varc" + ttfPath.suffix) else: outTTFPath = pathlib.Path(outTTFPath) ttf = TTFont(ttfPath) axisTags = [axis.axisTag for axis in ttf["fvar"].axes] globalAxisNames = {axisTag for axisTag in axisTags if axisTag[0] != "V"} vcFont = VarCoFont(designspacePath) vcData, allLocations, neutralGlyphNames = vcFont.extractVarCoData( globalAxisNames, neutralOnly ) if neutralGlyphNames: gvarTable = ttf["gvar"] for glyphName in neutralGlyphNames: del gvarTable.variations[glyphName] buildVarCTable(ttf, vcData, allLocations) if doTTX: outTTXPath = outTTFPath.parent / (outTTFPath.stem + "-before.ttx") ttf.saveXML(outTTXPath, tables=["VarC"]) ttf.save(outTTFPath) ttf = TTFont(outTTFPath, lazy=True) # Load from scratch if doTTX: outTTXPath = outTTFPath.parent / (outTTFPath.stem + "-after.ttx") ttf.saveXML(outTTXPath, tables=["VarC"]) if saveWoff2: outWoff2Path = outTTFPath.parent / (outTTFPath.stem + ".woff2") ttf.flavor = "woff2" ttf.save(outWoff2Path)
return self.font.glyphNames def __contains__(self, glyphName): try: self.font.ttFont.getGlyphID(glyphName, requireReal=True) except KeyError: return False return True def drawGlyph(self, pen, glyphName, location): from blackrenderer.backends.pathCollector import PathCollectorCanvas self.font.setLocation(location) canv = PathCollectorCanvas() self.font.drawGlyph(glyphName, canv) for path in canv.paths: path.replay(pen) if __name__ == "__main__": from vanilla.dialogs import getFileOrFolder registerCustomTableClass("VarC", "rcjktools.table_VarC", "table_VarC") result = getFileOrFolder( "Please select a VarCo .designspace, .ttf or .rcjk project", fileTypes=["designspace", "ttf", "rcjk"], ) if result: VarCoPreviewer(result[0])
def main(): registerCustomTableClass("VarC", "rcjktools.table_VarC", "table_VarC") sys.exit(ttx_main())
def varcFont(self): from fontTools.ttLib import registerCustomTableClass from rcjktools.ttVarCFont import TTVarCFont registerCustomTableClass("VarC", "rcjktools.table_VarC", "table_VarC") return TTVarCFont(None, ttFont=self.ttFont, hbFont=self.shaper.font)