def generate_svg(src_path, svg_path):
    font = Font()
    try:
        extractUFO(src_path, font)
        convertUFOToSVGFont(font, svg_path)
    except:
        print "Failed to generate SVG."
Beispiel #2
0
def generate_svg(src_path, svg_path):
    font = Font()
    try:
        extractUFO(src_path, font)
        convertUFOToSVGFont(font, svg_path)
    except:
        print "Failed to generate SVG."
def generateSVG(source, dest):
    font = Font()
    try:
        extractUFO(source, font)
        convertUFOToSVGFont(font, dest)
    except Exception:
        return ("Failed to generate SVG.", "")
    return ("", "")
Beispiel #4
0
def check_font(filename):
    print('check %s' % filename)
    ufo = defcon.Font()
    extractor.extractUFO(filename,
                         ufo,
                         doGlyphs=True,
                         doInfo=True,
                         doKerning=True)
def generateSVG(source, dest):
    font = Font()
    try:
        extractUFO(source, font)
        convertUFOToSVGFont(font, dest)
    except:
        return ("Failed to generate SVG.", "")
    return ("", "")
Beispiel #6
0
 def extract(self, path):
     fileFormat = extractor.extractFormat(path)
     app = QApplication.instance()
     data = dict(
         font=self,
         format=fileFormat,
     )
     app.postNotification("fontWillExtract", data)
     extractor.extractUFO(path, self, fileFormat)
Beispiel #7
0
def generate_svg(src_path, svg_path):
    from ufo2svg import convertUFOToSVGFont
    from defcon import Font
    from extractor import extractUFO
    font = Font()
    try:
        extractUFO(src_path, font)
        convertUFOToSVGFont(font, svg_path)
    except:
        print "Failed to generate SVG."
Beispiel #8
0
    def extract(self, path):
        import extractor

        fileFormat = extractor.extractFormat(path)
        app = QApplication.instance()
        data = dict(font=self, format=fileFormat)
        app.postNotification("fontWillExtract", data)
        extractor.extractUFO(path, self, fileFormat)
        for glyph in self:
            glyph.dirty = False
Beispiel #9
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument("file", help="path input otf file")
    args = parser.parse_args()

    ufo = defcon.Font()
    extractor.extractUFO(args.file, ufo)
    outputfileName = args.file.replace(".otf", ".ufo")

    print("saving %s to %s\n" % (args.file, outputfileName))
    ufo.save(outputfileName)
Beispiel #10
0
def getFonts(paths):
    """Takes in paths, gives list of fonts"""
    fonts = []
    for path in paths:
        if os.path.splitext(path)[-1].lower() == ".ufo":
            font = Font(path)
        else:
            font = Font()
            extractUFO(path, font, doKerning=False)
        fonts.append(font)
    fonts.sort(key=lambda weight: font.info.openTypeOS2WeightClass)
    return fonts
Beispiel #11
0
 def import_from_binary(cls, path):
     """Import the font from a .otf/.ttf file."""
     # FIXME: Check wether the current font is saved
     import extractor
     try:
         font = cls()
         extractor.extractUFO(path, font)
     except:
         logging.error("Unable to Import the chosen file")
         return None
     else:
         return font
Beispiel #12
0
 def extract(self, path):
     import extractor
     fileFormat = extractor.extractFormat(path)
     app = QApplication.instance()
     data = dict(
         font=self,
         format=fileFormat,
     )
     app.postNotification("fontWillExtract", data)
     extractor.extractUFO(path, self, fileFormat)
     for glyph in self:
         glyph.dirty = False
     self.dirty = False
     self._binaryPath = path
Beispiel #13
0
    def sourceFont(self, source):
        if source is None:
            raise Exception('font-file argument missing')

        font_type = source.split('.')[-1].lower()
        if font_type == "ufo":
            src = Font(source)
        elif font_type in  ["otf", "ttf", "woff", "woff2", "ttx", "pfa"]:
            import extractor
            src = Font()
            extractor.extractUFO(source, src)
        else:
            raise Exception('font-file in format ' + font_type + " is not supported")
        return src
Beispiel #14
0
def ttf2ufo(ttf_fps, ufo_fp):
    ufo_fp.mkdir(parents=True, exist_ok=True)
    ufos = []
    for ttf in tqdm(ttf_fps, file=sys.stdout):
        try:
            ufo = ufo_fp / (ttf.stem + ".ufo")
            ufos.append(ufo)
            if ufo.exists(): continue
            font = defcon.Font()
            extractor.extractUFO(ttf, font)
            font.save(ufo)
        except extractor.exceptions.ExtractorError:
            with nostdout():
                print(f"ExtractorError: Unable to read {str(ttf)}")
        except UFOLibError:
            with nostdout():
                print(f"UFOLibError: Unable to create {str(ufo)}")
    return ufos
Beispiel #15
0
    def extract(self, path):
        import extractor

        fileFormat = extractor.extractFormat(path)
        app = QApplication.instance()
        data = dict(font=self, format=fileFormat)
        app.postNotification("fontWillExtract", data)
        # don't bring on UndoManager just yet
        func = self.newGlyph
        try:
            self.newGlyph = types.MethodType(Font.newGlyph, self)
            extractor.extractUFO(path, self, fileFormat)
            for glyph in self:
                glyph.dirty = False
                glyph.undoManager = UndoManager(glyph)
        finally:
            self.newGlyph = func
        self.dirty = False
        self._binaryPath = path
    def test_extract_cmap_with_UVS(self, FontClass):
        ufo = FontClass()
        extractor.extractUFO(getpath("UVSTest.ttf"), ufo)

        assert {
            glyph.name: set(glyph.unicodes)
            for glyph in ufo if glyph.unicodes
        } == {
            "zero": {0x030},
            "Anegativesquared": {0x1F170},
        }

        assert ufo.lib.get("public.unicodeVariationSequences") == {
            "FE00": {
                "0030": "zero.slash"
            },
            "FE0E": {
                "1F170": "Anegativesquared.text"
            },
            "FE0F": {
                "1F170": "Anegativesquared"
            },
        }
Beispiel #17
0
# Counts the total number of glyphs of all the fonts in a directory tree

import os
from defcon import Font
from extractor import extractUFO


count = 0
fontCount = 0
employees = 11

for dirname, dirnames, filenames in os.walk(os.getcwd()):
    for fn in filenames:
        if fn.endswith('.otf') or fn.endswith('.ttf'):
            fontCount += 1
            fp = os.path.join(dirname, fn)
            font = Font()
            extractUFO(fp, font)
            count += len(font)
            print "Running total: %s glyphs in %s fonts." % (count, fontCount)
            
print """___________________________________________________
Final count: %s glyphs in %s fonts. %d glyphs per employee (gpe)""" % (count, fontCount, count/employees)
Beispiel #18
0
# Counts the total number of glyphs of all the fonts in a directory tree

import os
from defcon import Font
from extractor import extractUFO

count = 0
fontCount = 0
employees = 11

for dirname, dirnames, filenames in os.walk(os.getcwd()):
    for fn in filenames:
        if fn.endswith('.otf') or fn.endswith('.ttf'):
            fontCount += 1
            fp = os.path.join(dirname, fn)
            font = Font()
            extractUFO(fp, font)
            count += len(font)
            print "Running total: %s glyphs in %s fonts." % (count, fontCount)

print """___________________________________________________
Final count: %s glyphs in %s fonts. %d glyphs per employee (gpe)""" % (
    count, fontCount, count / employees)
Beispiel #19
0
import argparse
import defcon
import extractor

def create_arg_parser():
	parser = argparse.ArgumentParser()
	parser.add_argument("-i", help = "input filename")
	parser.add_argument("-o", help = "output filename")
	args = parser.parse_args()
	return args

if __name__ == "__main__":
	args = create_arg_parser()
	ttf_path = args.i
	ufo_path = args.o
	print('ttf_path: ', ttf_path)
	print('ufo_path:', ufo_path)
	# Make UFO
	print('Generating UFO...', ufo_path)
	ufo = defcon.Font()
	extractor.extractUFO(ttf_path, ufo)
	ufo.save(ufo_path)
	print('Done.')
Beispiel #20
0
import extractor
import defcon
# from fontTools.ttLib import TTFont
from ufo2ft import compileTTF

ufo = defcon.Font()

# Take the font generated by FL5 from the VFB and extract it to UFO
extractor.extractUFO("data/ibm_plex/IBM Plex Serif-Text-FL.ttf", ufo)

# Save the extracted UFO
ufo.save("data/ibm_plex/IBM Plex Serif-Text-FL_extracted.ufo")
ufo = defcon.Font("data/ibm_plex/IBM Plex Serif-Text-FL_extracted.ufo")

# Build a new TTF from the extracted UFO
ttf = compileTTF(ufo, reverseDirection=False)
ttf.save("data/ibm_plex/IBM Plex Serif-Text-ufo2ft.ttf")

# Force recompilation by closing and reopening the font; not needed
# ttf.close()
# ttf = TTFont("data/ibm_plex/IBM Plex Serif-Text-ufo2ft.ttf")

# Also save TTX dump
ttf.saveXML("data/ibm_plex/IBM Plex Serif-Text-ufo2ft.ttx")
ttf.saveXML("data/ibm_plex/IBM Plex Serif-Text-FL.ttx")


# ufo = defcon.Font()
# extractor.extractUFO("data/font_a/font-normal-fl.ttf", ufo)
# ufo.save("data/font_a/font-normal-fl_extracted.ufo")
# ufo = defcon.Font("data/font_a/font-normal-fl_extracted.ufo")
Beispiel #21
0
#!/usr/bin/python3

import extractor
import defcon
ufo = defcon.Font()
extractor.extractUFO("SourceCodePro-Regular.woff2", ufo)
ufo.info.postscriptFontName = "SourceCodePro"
ufo.save("SourceCodePro-Regular.ufo")
Beispiel #22
0
import defcon
import extractor
import os
import pathlib
import sys
import ufonormalizer

# The only argument is the base name of the font. No directory or extension.
fileName = sys.argv[1]

# Create a new empty defcon font object
font = defcon.Font()

# File paths
ttf = os.path.join(os.path.join("..", "fonts", "ttf"), fileName + ".ttf")
ufo = os.path.join(os.path.join("..", "sources"), fileName + ".ufo")

# Load the TrueType font data into the font object
extractor.extractUFO(ttf, font)

# Save the font object as a UFO (Unified Font Object)
font.save(ufo)

# Close the font object since we are going to normalize it next
font.close()

# Normalize the UFO without writing modification times
ufonormalizer.normalizeUFO(ufo, writeModTimes=False)