예제 #1
1
def convertToOTF(ttfPath, dest, report):
    temp = tempfile.mkstemp(suffix=".otf")[1]

    font = RFont(ttfPath, document=False, showInterface=False)
    font.kerning.clear()
    for attr in font.info.asDict().keys():
        if attr not in defaultFontInfoAttributes:
            setattr(font.info, attr, None)

    result = font.generate(path=temp, format="otf", decompose=False, checkOutlines=False, autohint=False, releaseMode=True, glyphOrder=font.glyphOrder)
    if not font.hasInterface():
        font.close()
    report.write(result)

    sourceFont = TTFont(temp)
    sourceFontWithTables = TTFont(ttfPath)
    for table in ["loca", "OS/2", "cmap", "name", "GSUB", "GPOS", "GDEF", "kern"]:
        if table in sourceFontWithTables:
            sourceFont[table] = sourceFontWithTables[table]

    sourceFont.save(dest)

    result = OTFAutohint(dest)
    report.writeItems(result)

    os.remove(temp)
예제 #2
1
    def run(self, destDir, progress):
        paths = self.controller.get(["ufo"])

        report = Report()

        tempDir = os.path.join(destDir, "temp")
        if not os.path.exists(tempDir):
            os.makedirs(tempDir)
        tempExportPaths = self._generateCallback(tempDir, progress, report)

        progress.update("Merging Tables...")
        report.writeTitle("Merged Fonts:")
        report.newLine()

        tableNames = [item["tableName"] for item in self.tableList if item["add"]]

        for fontIndex, path in enumerate(paths):
            font = RFont(path, document=False, showInterface=False)
            binarySourcepath = font.lib.get("com.typemytype.robofont.binarySource")
            tempExportPath = tempExportPaths[fontIndex]
            if binarySourcepath:
                binaryIs
                Type = os.path.splitext(binarySourcepath)[1].lower() in [".ttf", ".otf"]
                tempIsOpenType = os.path.splitext(tempExportPath)[1].lower() in [".ttf", ".otf"]
                if binaryIsOpenType and tempIsOpenType:
                    if os.path.exists(binarySourcepath) and os.path.exists(tempExportPath):
                        binarySource = TTFont(binarySourcepath)
                        tempFont = TTFont(tempExportPath)
                        fileName = os.path.basename(tempExportPath)
                        if not self.controller.keepFileNames():
                            fileName = "%s-%s%s" % (font.info.familyName, font.info.styleName, os.path.splitext(tempExportPath)[1])
                        path = os.path.join(destDir, fileName)
                        report.writeTitle(os.path.basename(path), "'")
                        report.write("source: %s" % tempExportPath)
                        report.write("binary source: %s" % binarySourcepath)
                        report.newLine()
                        report.indent()
                        for table in tableNames:
                            if table in binarySource:
                                report.write("merge %s table" % table)
                                tempFont[table] = binarySource[table]
                        report.write("save to %s" % path)
                        tempFont.save(path)
                        report.dedent()
                        report.newLine()
                        tempFont.close()
                        binarySource.close()
            if not font.hasInterface():
                font.close()

        reportPath = os.path.join(destDir, "Binary Merge Report.txt")
        report.save(reportPath)

        if not getDefault("Batch.Debug", False):
            if os.path.exists(tempDir):
                shutil.rmtree(tempDir)
예제 #3
0
def convertToOTF(ttfPath, dest, report):
    temp = tempfile.mkstemp(suffix=".otf")[1]

    font = RFont(ttfPath, document=False, showInterface=False)
    font.kerning.clear()
    for attr in font.info.asDict().keys():
        if attr not in defaultFontInfoAttributes:
            setattr(font.info, attr, None)

    result = font.generate(path=temp,
                           format="otf",
                           decompose=False,
                           checkOutlines=False,
                           autohint=False,
                           releaseMode=True,
                           glyphOrder=font.glyphOrder)
    if not font.hasInterface():
        font.close()
    report.write(result)

    sourceFont = TTFont(temp)
    sourceFontWithTables = TTFont(ttfPath)
    for table in [
            "loca", "OS/2", "cmap", "name", "GSUB", "GPOS", "GDEF", "kern"
    ]:
        if table in sourceFontWithTables:
            sourceFont[table] = sourceFontWithTables[table]

    sourceFont.save(dest)

    result = OTFAutohint(dest)
    report.writeItems(result)

    os.remove(temp)
예제 #4
0
def generateOTF(ufoPath, dest, report):
    font = RFont(ufoPath, document=False, showInterface=False)

    result = font.generate(path=dest, format="otf", decompose=False, checkOutlines=True, autohint=False, releaseMode=True, glyphOrder=font.glyphOrder)
    if not font.hasInterface():
        font.close()
    report.write(result)

    result = OTFAutohint(dest)
    report.writeItems(result)
예제 #5
0
def generateOTF(ufoPath, dest, report):
    font = RFont(ufoPath, document=False, showInterface=False)

    result = font.generate(path=dest,
                           format="otf",
                           decompose=False,
                           checkOutlines=True,
                           autohint=False,
                           releaseMode=True,
                           glyphOrder=font.glyphOrder)
    if not font.hasInterface():
        font.close()
    report.write(result)

    result = OTFAutohint(dest)
    report.writeItems(result)
예제 #6
0
def generateTTF(ufoPath, dest, report):
    tempDest = tempfile.mkstemp(suffix=".ttf")[1]

    font = RFont(ufoPath, document=False, showInterface=False)
    font.lib[shouldAddPointsInSplineConversionLibKey] = 1

    result = font.generate(path=tempDest, format="ttf", decompose=False, checkOutlines=True, autohint=False, releaseMode=True, glyphOrder=font.glyphOrder)
    if not font.hasInterface():
        font.close()
    report.write(result)

    autohintOptions = getExtensionDefault(settingsIdentifier, defaultOptions)
    result = TTFAutohint(tempDest, dest, autohintOptions)
    report.writeItems(result)

    os.remove(tempDest)
예제 #7
0
def convertToTTF(otfPath, dest, report):
    temp = tempfile.mkstemp(suffix=".ttf")[1]
    tempDest = tempfile.mkstemp(suffix=".ttf")[1]

    font = RFont(otfPath, document=False, showInterface=False)
    font.lib[shouldAddPointsInSplineConversionLibKey] = 1
    font.kerning.clear()

    for attr in font.info.asDict().keys():
        if attr not in defaultFontInfoAttributes:
            setattr(font.info, attr, None)

    result = font.generate(path=temp,
                           format="ttf",
                           decompose=False,
                           checkOutlines=False,
                           autohint=False,
                           releaseMode=True,
                           glyphOrder=font.glyphOrder)
    if not font.hasInterface():
        font.close()
    report.write(result)

    sourceFont = TTFont(temp)
    sourceFontWithTables = TTFont(otfPath)

    for table in [
            "loca", "OS/2", "cmap", "name", "GSUB", "GPOS", "GDEF", "kern"
    ]:
        if table in sourceFontWithTables:
            sourceFont[table] = sourceFontWithTables[table]
    fixMetrics(sourceFont)
    sourceFont.save(tempDest)

    sourceFont.close()
    del sourceFont
    sourceFontWithTables.close()
    del sourceFontWithTables

    autohintOptions = getExtensionDefault(settingsIdentifier, defaultOptions)
    result = TTFAutohint(tempDest, dest, autohintOptions)
    report.writeItems(result)

    os.remove(temp)
    os.remove(tempDest)
예제 #8
0
def generateTTF(ufoPath, dest, report):
    tempDest = tempfile.mkstemp(suffix=".ttf")[1]

    font = RFont(ufoPath, document=False, showInterface=False)
    font.lib[shouldAddPointsInSplineConversionLibKey] = 1

    result = font.generate(path=tempDest,
                           format="ttf",
                           decompose=False,
                           checkOutlines=True,
                           autohint=False,
                           releaseMode=True,
                           glyphOrder=font.glyphOrder)
    if not font.hasInterface():
        font.close()
    report.write(result)

    autohintOptions = getExtensionDefault(settingsIdentifier, defaultOptions)
    result = TTFAutohint(tempDest, dest, autohintOptions)
    report.writeItems(result)

    os.remove(tempDest)
예제 #9
0
def convertToTTF(otfPath, dest, report):
    temp = tempfile.mkstemp(suffix=".ttf")[1]
    tempDest = tempfile.mkstemp(suffix=".ttf")[1]

    font = RFont(otfPath, document=False, showInterface=False)
    font.lib[shouldAddPointsInSplineConversionLibKey] = 1
    font.kerning.clear()

    for attr in font.info.asDict().keys():
        if attr not in defaultFontInfoAttributes:
            setattr(font.info, attr, None)

    result = font.generate(path=temp, format="ttf", decompose=False, checkOutlines=False, autohint=False, releaseMode=True, glyphOrder=font.glyphOrder)
    if not font.hasInterface():
        font.close()
    report.write(result)

    sourceFont = TTFont(temp)
    sourceFontWithTables = TTFont(otfPath)

    for table in ["loca", "OS/2", "cmap", "name", "GSUB", "GPOS", "GDEF", "kern"]:
        if table in sourceFontWithTables:
            sourceFont[table] = sourceFontWithTables[table]
    fixMetrics(sourceFont)
    sourceFont.save(tempDest)

    sourceFont.close()
    del sourceFont
    sourceFontWithTables.close()
    del sourceFontWithTables

    autohintOptions = getExtensionDefault(settingsIdentifier, defaultOptions)
    result = TTFAutohint(tempDest, dest, autohintOptions)
    report.writeItems(result)

    os.remove(temp)
    os.remove(tempDest)
예제 #10
0
    def run(self, destDir, progress, report=None):
        paths = self.controller.get()

        decompose = self.decompose.get()
        removeOverlap = self.remove_overlap.get()
        autohint = self.autohint.get()
        releaseMode = self.release_mode.get()
        suffix = self.generateSuffix.get()
        suffix = time.strftime(suffix)

        formats = [i for i in doodleSupportedExportFileTypes if getattr(self, i).get()]

        if report is None:
            report = Report()
        report.writeTitle("Batch Generated Fonts:")
        report.newLine()

        progress.update("Collecting Data...")

        fonts = []
        for path in paths:
            font = RFont(path, document=False, showInterface=False)
            # check font info
            requiredFontInfo = dict(descender=-250, xHeight=500, ascender=750, capHeight=750, unitsPerEm=1000)
            for attr, value in requiredFontInfo.items():
                existingValue = getattr(font.info, attr)
                if existingValue is None:
                    setattr(font.info, attr, value)
            fonts.append(font)

        if decompose:
            report.writeTitle("Decompose:")
            report.indent()
            progress.update("Decompose...")
            progress.setTickCount(len(fonts))
            for font in fonts:
                report.write("%s %s" % (font.info.familyName, font.info.styleName))
                progress.update()
                font.decompose()
            progress.setTickCount(None)
            report.dedent()
            report.newLine()
            decompose = False

            if removeOverlap:
                report.writeTitle("Remove Overlap:")
                progress.update("Remove Overlap...")
                report.indent()
                progress.setTickCount(len(fonts))
                for font in fonts:
                    report.write("%s %s" % (font.info.familyName, font.info.styleName))
                    progress.update()
                    font.removeOverlap()
                progress.setTickCount(None)
                report.dedent()
                report.newLine()
                removeOverlap = False

        report.writeTitle("Generate:")
        exportPaths = []
        for index, font in enumerate(fonts):
            report.writeTitle((os.path.basename(paths[index])))
            report.newLine()
            report.write("source: %s" % paths[index])
            report.newLine()
            for format in formats:
                report.writeTitle("Generate %s" % format, "'")
                report.indent()
                familyName = font.info.familyName or "familyName-%s" % index
                familyName = familyName.replace(" ", "")
                styleName = font.info.styleName or "styleName-%s" % index
                styleName = styleName.replace(" ", "")
                if not self.controller.keepFileNames():
                    fileName = "%s-%s%s.%s" % (familyName, styleName, suffix, format)
                else:
                    fileName = os.path.basename(paths[index])
                    fileName, _ = os.path.splitext(fileName)
                    fileName = "%s%s.%s" % (fileName, suffix, format)
                progress.update("Generating ... %s" % fileName)
                if self.controller.exportInFolders():
                    fontDir = os.path.join(destDir, format)
                else:
                    fontDir = destDir
                buildTree(fontDir)
                path = os.path.join(fontDir, fileName)
                report.write("path: %s" % path)
                result = font.generate(path=path, format=format,
                              decompose=decompose,
                              checkOutlines=removeOverlap,
                              autohint=autohint,
                              releaseMode=releaseMode,
                              progressBar=progress,
                              glyphOrder=font.glyphOrder)
                report.indent()
                report.write(result)
                report.dedent()
                exportPaths.append(path)
                report.dedent()
                report.newLine()
            if not font.hasInterface():
                font.close()
        reportPath = os.path.join(destDir, "Batch Generate Report.txt")
        report.save(reportPath)
        return exportPaths