Exemple #1
0
    def generateFont(self, mix, names, italic=False, swapSuffixes=None, stemWidth=185, kern=True):

        n = names.split("/")
        log("---------------------\n%s %s\n----------------------" % (n[0], n[1]))
        log(">> Mixing masters")
        if isinstance(mix, Mix):
            f = mix.generateFont(self.basefont)
        else:
            f = mix.copy()
        if italic == True:
            log(">> Italicizing")
            tweakAmmount = 0.085
            narrowAmmount = 0.93
            if names.find("Thin") != -1:
                tweakAmmount = 0.05
            if names.find("Condensed") != -1:
                narrowAmmount = 0.96
            i = 0
            for g in f:
                i += 1
                if i % 10 == 0:
                    print g.name

                if g.name == "uniFFFD":
                    continue

                # if i < 24:
                #     continue
                # if i > 86:
                #     for i,g in enumerate(fl.font.glyphs):
                #       fl.UpdateGlyph(i)
                #     # break
                #     assert False

                # print g.name
                # if self.thinfont != None:
                #                     narrowFLGlyph(g,self.thinfont.getGlyph(g.name),factor=narrowAmmount)

                if g.name in self.lessItalic:
                    italicizeGlyph(f, g, 9, stemWidth=stemWidth)
                elif False == (g.name in self.noItalic):
                    italicizeGlyph(f, g, 10, stemWidth=stemWidth)
                # elif g.name != ".notdef":
                #    italicizeGlyph(g, 10, stemWidth=stemWidth)
                if g.width != 0:
                    g.width += 10

        if swapSuffixes != None:
            for swap in swapSuffixes:
                swapList = [g.name for g in f if g.name.endswith(swap)]
                for gname in swapList:
                    print gname
                    swapContours(f, gname.replace(swap, ""), gname)
        for gname in self.predecompose:
            if f.has_key(gname):
                decomposeGlyph(f[gname])

        log(">> Generating glyphs")
        generateGlyphs(f, self.diacriticList, self.adobeGlyphList)
        log(">> Copying features")
        readFeatureFile(f, self.ot_classes + self.basefont.features.text)
        log(">> Decomposing")
        for gname in self.decompose:
            if f.has_key(gname):
                decomposeGlyph(f[gname])

        setNamesRF(f, n, foundry=self.config.get("main", "foundry"), version=self.config.get("main", "version"))
        cleanCurves(f)
        deleteGlyphs(f, self.deleteList)

        if kern:
            log(">> Generating kern classes")
            readFeatureFile(f, self.ot_kerningclasses)
            makeKernFeature(f, self.ot_kerningclasses)

        log(">> Generating font files")
        GenerateFeature_mark(f)
        GenerateFeature_mkmk(f)
        ufoName = self.generateOutputPath(f, "ufo")
        f.save(ufoName)

        if self.buildOTF:
            log(">> Generating OTF file")
            newFont = OpenFont(ufoName)
            otfName = self.generateOutputPath(f, "otf")
            builtSuccessfully = saveOTF(newFont, otfName, autohint=self.autohintOTF)
            if not builtSuccessfully:
                sys.exit(1)

            if self.buildTTF:
                log(">> Generating TTF file")
                import fontforge

                otFont = fontforge.open(otfName)
                otFont.generate(self.generateOutputPath(f, "ttf"))
Exemple #2
0
    def generateFont(self, mix, names, italic=False, swapSuffixes=None, stemWidth=185, kern=True):
        
        n = names.split("/")
        log("---------------------\n%s %s\n----------------------" %(n[0],n[1]))
        log(">> Mixing masters")
        if isinstance( mix, Mix):
            f = mix.generateFont(self.basefont)
        else:
            f = mix.copy()
        if italic == True:
            log(">> Italicizing")
            tweakAmmount = .085
            narrowAmmount = .93
            if names.find("Thin") != -1:
                tweakAmmount = .05
            if names.find("Condensed") != -1:
                narrowAmmount = .96
            i = 0
            for g in f:
                i += 1
                if i % 10 == 0: print g.name
                
                if g.name == "uniFFFD":
                    continue

                removeGlyphOverlap(g)

                if g.name in self.lessItalic:
                    italicizeGlyph(f, g, 9, stemWidth=stemWidth)
                elif False == (g.name in self.noItalic):
                    italicizeGlyph(f, g, 10, stemWidth=stemWidth)
                #elif g.name != ".notdef":
                #    italicizeGlyph(g, 10, stemWidth=stemWidth)
                if g.width != 0:
                    g.width += 10

        if swapSuffixes != None:
            for swap in swapSuffixes:
                swapList = [g.name for g in f if g.name.endswith(swap)]
                for gname in swapList:
                    print gname
                    swapContours(f, gname.replace(swap,""), gname)
        for gname in self.predecompose:
            if f.has_key(gname):
                decomposeGlyph(f, gname)

        log(">> Generating glyphs")
        generateGlyphs(f, self.diacriticList, self.adobeGlyphList)
        log(">> Copying features")
        readFeatureFile(f, self.ot_classes + self.basefont.features.text)
        log(">> Decomposing")
        for gname in self.decompose:
            if f.has_key(gname):
                decomposeGlyph(f, gname)

        setNamesRF(f, n, foundry=self.config.get('main', 'foundry'),
                         version=self.config.get('main', 'version'))
        if not self.compatible:
            cleanCurves(f)
        deleteGlyphs(f, self.deleteList)

        if kern:
            log(">> Generating kern classes")
            readFeatureFile(f, self.ot_kerningclasses)

        log(">> Generating font files")
        ufoName = self.generateOutputPath(f, "ufo")
        f.save(ufoName)
        self.generatedFonts.append(ufoName)

        if self.buildOTF:
            log(">> Generating OTF file")
            newFont = OpenFont(ufoName)
            otfName = self.generateOutputPath(f, "otf")
            saveOTF(newFont, otfName)
Exemple #3
0
    def generateFont(self,
                     mix,
                     names,
                     italic=False,
                     swapSuffixes=None,
                     stemWidth=185,
                     kern=True):

        n = names.split("/")
        log("---------------------\n%s %s\n----------------------" %
            (n[0], n[1]))
        log(">> Mixing masters")
        if isinstance(mix, Mix):
            f = mix.generateFont(self.basefont)
        else:
            f = mix.copy()
        if italic == True:
            log(">> Italicizing")
            tweakAmmount = .085
            narrowAmmount = .93
            if names.find("Thin") != -1:
                tweakAmmount = .05
            if names.find("Condensed") != -1:
                narrowAmmount = .96
            i = 0
            for g in f:
                i += 1
                if i % 10 == 0: print g.name

                if g.name == "uniFFFD":
                    continue

                removeGlyphOverlap(g)

                if g.name in self.lessItalic:
                    italicizeGlyph(f, g, 9, stemWidth=stemWidth)
                elif False == (g.name in self.noItalic):
                    italicizeGlyph(f, g, 10, stemWidth=stemWidth)
                #elif g.name != ".notdef":
                #    italicizeGlyph(g, 10, stemWidth=stemWidth)
                if g.width != 0:
                    g.width += 10

        if swapSuffixes != None:
            for swap in swapSuffixes:
                swapList = [g.name for g in f if g.name.endswith(swap)]
                for gname in swapList:
                    print gname
                    swapContours(f, gname.replace(swap, ""), gname)
        for gname in self.predecompose:
            if f.has_key(gname):
                decomposeGlyph(f, gname)

        log(">> Generating glyphs")
        generateGlyphs(f, self.diacriticList, self.adobeGlyphList)
        log(">> Copying features")
        readFeatureFile(f, self.ot_classes + self.basefont.features.text)
        log(">> Decomposing")
        for gname in self.decompose:
            if f.has_key(gname):
                decomposeGlyph(f, gname)

        setNamesRF(f,
                   n,
                   foundry=self.config.get('main', 'foundry'),
                   version=self.config.get('main', 'version'))
        if not self.compatible:
            cleanCurves(f)
        deleteGlyphs(f, self.deleteList)

        if kern:
            log(">> Generating kern classes")
            readFeatureFile(f, self.ot_kerningclasses)

        log(">> Generating font files")
        ufoName = self.generateOutputPath(f, "ufo")
        f.save(ufoName)
        self.generatedFonts.append(ufoName)

        if self.buildOTF:
            log(">> Generating OTF file")
            newFont = OpenFont(ufoName)
            otfName = self.generateOutputPath(f, "otf")
            saveOTF(newFont, otfName)
Exemple #4
0
    def generateFont(self,
                     mix,
                     names,
                     italic=False,
                     swapSuffixes=None,
                     stemWidth=185,
                     kern=True):

        n = names.split("/")
        log("---------------------\n%s %s\n----------------------" %
            (n[0], n[1]))
        log(">> Mixing masters")
        if isinstance(mix, Mix):
            f = mix.generateFont(self.basefont)
        else:
            f = mix.copy()
        if italic == True:
            log(">> Italicizing")
            tweakAmmount = .085
            narrowAmmount = .93
            if names.find("Thin") != -1:
                tweakAmmount = .05
            if names.find("Condensed") != -1:
                narrowAmmount = .96
            i = 0
            for g in f:
                i += 1
                if i % 10 == 0: print g.name

                if g.name == "uniFFFD":
                    continue

                # if i < 24:
                #     continue
                # if i > 86:
                #     for i,g in enumerate(fl.font.glyphs):
                #       fl.UpdateGlyph(i)
                #     # break
                #     assert False

                # print g.name
                # if self.thinfont != None:
                #                     narrowFLGlyph(g,self.thinfont.getGlyph(g.name),factor=narrowAmmount)

                if g.name in self.lessItalic:
                    italicizeGlyph(f, g, 9, stemWidth=stemWidth)
                elif False == (g.name in self.noItalic):
                    italicizeGlyph(f, g, 10, stemWidth=stemWidth)
                #elif g.name != ".notdef":
                #    italicizeGlyph(g, 10, stemWidth=stemWidth)
                if g.width != 0:
                    g.width += 10

        if swapSuffixes != None:
            for swap in swapSuffixes:
                swapList = [g.name for g in f if g.name.endswith(swap)]
                for gname in swapList:
                    print gname
                    swapContours(f, gname.replace(swap, ""), gname)
        for gname in self.predecompose:
            if f.has_key(gname):
                decomposeGlyph(f, gname)

        log(">> Generating glyphs")
        generateGlyphs(f, self.diacriticList, self.adobeGlyphList)
        log(">> Copying features")
        readFeatureFile(f, self.ot_classes + self.basefont.features.text)
        log(">> Decomposing")
        for gname in self.decompose:
            if f.has_key(gname):
                decomposeGlyph(f, gname)

        setNamesRF(f,
                   n,
                   foundry=self.config.get('main', 'foundry'),
                   version=self.config.get('main', 'version'))
        cleanCurves(f)
        deleteGlyphs(f, self.deleteList)

        if kern:
            log(">> Generating kern classes")
            readFeatureFile(f, self.ot_kerningclasses)
            makeKernFeature(f, self.ot_kerningclasses)

        log(">> Generating font files")
        GenerateFeature_mark(f)
        GenerateFeature_mkmk(f)
        ufoName = self.generateOutputPath(f, "ufo")
        f.save(ufoName)

        if self.buildOTF:
            log(">> Generating OTF file")
            newFont = OpenFont(ufoName)
            otfName = self.generateOutputPath(f, "otf")
            builtSuccessfully = saveOTF(newFont,
                                        otfName,
                                        autohint=self.autohintOTF)
            if not builtSuccessfully:
                sys.exit(1)

            if self.buildTTF:
                log(">> Generating TTF file")
                import fontforge
                otFont = fontforge.open(otfName)
                otFont.generate(self.generateOutputPath(f, "ttf"))