예제 #1
0
파일: Build.py 프로젝트: ssddn/roboto
    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"))
예제 #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)
예제 #3
0
파일: Build.py 프로젝트: mbrukman/inter
    def generateFont(self,
                     mix,
                     names,
                     italic=False,
                     swapSuffixes=None,
                     stemWidth=185,
                     italicMeanYCenter=-825,
                     italicNarrowAmount=1):

        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")
            i = 0
            for g in f:
                i += 1
                if i % 10 == 0: print g.name

                if g.name == "uniFFFD":
                    continue

                decomposeGlyph(f, g)
                removeGlyphOverlap(g)

                if g.name in self.lessItalic:
                    italicizeGlyph(f,
                                   g,
                                   9,
                                   stemWidth=stemWidth,
                                   meanYCenter=italicMeanYCenter,
                                   narrowAmount=italicNarrowAmount)
                elif g.name not in self.noItalic:
                    italicizeGlyph(f,
                                   g,
                                   10,
                                   stemWidth=stemWidth,
                                   meanYCenter=italicMeanYCenter,
                                   narrowAmount=italicNarrowAmount)
                if g.width != 0:
                    g.width += 10

            # set the oblique flag in fsSelection
            f.info.openTypeOS2Selection.append(9)

        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, f[gname])

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

        copyrightHolderName = ''
        if self.config.has_option('main', 'copyrightHolderName'):
            copyrightHolderName = self.config.get('main',
                                                  'copyrightHolderName')

        def getcfg(name, fallback=''):
            if self.config.has_option('main', name):
                return self.config.get('main', name)
            else:
                return fallback

        setInfoRF(
            f, n, {
                'foundry': getcfg('foundry'),
                'foundryURL': getcfg('foundryURL'),
                'designer': getcfg('designer'),
                'copyrightHolderName': getcfg('copyrightHolderName'),
                'build': self.buildTag,
                'version': getcfg('version'),
                'license': getcfg('license'),
                'licenseURL': getcfg('licenseURL'),
            })

        if not self.compatible:
            cleanCurves(f)
        deleteGlyphs(f, self.deleteList)

        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, self.glyphOrder)
예제 #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

                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)
예제 #5
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"))