Пример #1
0
    def getGlyphInfos(self):
        result = []
#        glyphIndexToNameMap = {}
        glyphToCharacterMap = self.getGlyphIndexToCharacterMap()
        if self.ftFont.has_glyph_names:
            for glyphIndex in self.getGlyphIndices():
                glyphNameBuffer = ' '*256
                error = freetype.FT_Get_Glyph_Name(self.ftFont._FT_Face,
                                                   glyphIndex,
                                                   glyphNameBuffer,
                                                   len(glyphNameBuffer) - 1)
                if error:
                    raise freetype.FT_Exception(error)

                glyphInfo = TFSMap()
                glyphInfo.glyphIndex = glyphIndex
                glyphInfo.glyphName = glyphNameBuffer.strip()[:-1]
#                print 'glyphName', glyphIndex, glyphName, len(glyphName)
                glyphInfo.characterCode = None
                if glyphIndex in glyphToCharacterMap:
                    glyphInfo.characterCode = glyphToCharacterMap[glyphIndex]
                result.append(glyphInfo)

        else:
            for glyphIndex, characterCode in glyphToCharacterMap.items():
                glyphInfo = TFSMap()
                glyphInfo.glyphIndex = glyphIndex
                glyphInfo.glyphName = getUnicodeCharacterName(characterCode)
                glyphInfo.characterCode = characterCode
#                glyphInfoMap[glyphIndex] = glyphInfo
                result.append(glyphInfo)

        return result
Пример #2
0
    def getGlyphInfos(self):
        result = []
        #        glyphIndexToNameMap = {}
        glyphToCharacterMap = self.getGlyphIndexToCharacterMap()
        if self.ftFont.has_glyph_names:
            for glyphIndex in self.getGlyphIndices():
                glyphNameBuffer = ' ' * 256
                error = freetype.FT_Get_Glyph_Name(self.ftFont._FT_Face,
                                                   glyphIndex, glyphNameBuffer,
                                                   len(glyphNameBuffer) - 1)
                if error:
                    raise freetype.FT_Exception(error)

                glyphInfo = TFSMap()
                glyphInfo.glyphIndex = glyphIndex
                glyphInfo.glyphName = glyphNameBuffer.strip()[:-1]
                #                print 'glyphName', glyphIndex, glyphName, len(glyphName)
                glyphInfo.characterCode = None
                if glyphIndex in glyphToCharacterMap:
                    glyphInfo.characterCode = glyphToCharacterMap[glyphIndex]
                result.append(glyphInfo)

        else:
            for glyphIndex, characterCode in glyphToCharacterMap.items():
                glyphInfo = TFSMap()
                glyphInfo.glyphIndex = glyphIndex
                glyphInfo.glyphName = getUnicodeCharacterName(characterCode)
                glyphInfo.characterCode = characterCode
                #                glyphInfoMap[glyphIndex] = glyphInfo
                result.append(glyphInfo)

        return result
 def getGlyphName(codePoint):
     result = getUnicodeCharacterName(codePoint,
                                      ignoreUnknown=True,
                                      skipValidation=True)
     if result is None:
         return 'Unknown'
     result = result.replace('<', '').replace('>', '')
     return result
    def dumpMetricsMap(self, kerningPairMap, htmlFilename):

        print
        print 'fonts scanned:', len(self.processedPostscriptNames)
        print 'fonts processed:', len(self.nonEmptyPostscriptNames)
        print 'glyph pairs observed:', len(kerningPairMap)
        maxGlyphPairCount = reduce(max, kerningPairMap.values())
        print 'Highest glyph pair frequency:', maxGlyphPairCount

        glyphs = []
        for (
                glyph0,
                glyph1,
        ), count in kerningPairMap.iteritems():
            glyph = TFSMap()
            glyph.glyph0 = glyph0
            glyph.glyph1 = glyph1
            glyph.count = count
            glyphs.append(glyph)

        def glyphCountSort(glyph0, glyph1):
            # Negate; we want reverse order for count.
            result = -cmp(glyph0.count, glyph1.count)
            if result != 0:
                return result

            result = cmp(glyph0.glyph0, glyph1.glyph0)
            if result != 0:
                return result

            result = cmp(glyph0.glyph1, glyph1.glyph1)
            if result != 0:
                return result

            return 0
#            return cmp(glyph0.codePoint, glyph1.codePoint)

        glyphs.sort(glyphCountSort)

        print 'Most common glyph:', glyphs[0]
        print 'Least common glyph:', glyphs[-1]

        locale.setlocale(locale.LC_ALL, 'en_US')

        pres = []
        for glyph in glyphs[:5000]:
            #        for glyph in glyphs[:1000]:
            #            pre = {}

            pre = {
                #                    'glyphHex': hex(glyph.codePoint),
                'glyphHex0':
                '%04X' % glyph.glyph0,
                'glyphHex1':
                '%04X' % glyph.glyph1,
                #                    'glyphName0': getUnicodeLongName(glyph.glyph0,
                #                                                    ignoreUnknown=True,
                #                                                    skipValidation=True),
                #                    'glyphName1': getUnicodeLongName(glyph.glyph1,
                #                                                    ignoreUnknown=True,
                #                                                    skipValidation=True),
                'glyphName0':
                getUnicodeCharacterName(glyph.glyph0, ignoreUnknown=True),
                'glyphName1':
                getUnicodeCharacterName(glyph.glyph1, ignoreUnknown=True),
                'glyphCount':
                locale.format("%d", glyph.count, grouping=True),
                'glyphPercent':
                '%0.2f%%' % (100.0 * glyph.count /
                             float(len(self.nonEmptyPostscriptNames))),
                #                   'glyphColor': '%06X' % glyphColor,
            }

            #            pre['value'] = '%s %s: %d (%0.2f%%)' % ( hex(glyph.codePoint),
            #                                            getUnicodeLongName(glyph.codePoint,
            #                                                                    ignoreUnknown=True,
            #                                                                    skipValidation=True),
            #                                            glyph.count,
            #                                            glyph.count / float(len(self.nonEmptyPostscriptNames)),
            #                                            )
            #            print 'pre', pre
            pres.append(pre)

        self.writeMustacheLog(
            'kia_pre_template.txt',
            htmlFilename,
            #                              'most_common_kerning_pairs.html',
            mustacheVars={
                'pres':
                pres,
                #                                              'headerPres': headerPres,
                'pageTitle':
                '1,000 Most Common Kerning Pairs',
                'headerTitle':
                '1,000 Most Common Kerning Pairs',
                #                                              'headerTitle': 'Kerning Pairs Implementation Statistics',
                'statsTitle':
                'Statistics',
                'stats': (
                    {
                        'key':
                        'Total Fonts',
                        'value':
                        locale.format("%d",
                                      len(self.processedPostscriptNames),
                                      grouping=True),
                    },
                    {
                        'key':
                        'Fonts With Valid Kerning Table',
                        'value':
                        locale.format("%d",
                                      len(self.nonEmptyPostscriptNames),
                                      grouping=True),
                    },
                    {
                        'key':
                        'Kerning Pairs Observed',
                        'value':
                        locale.format("%d", len(kerningPairMap),
                                      grouping=True),
                    },
                ),
            }
            #                              replaceMap = {'<!-- SVG Graph Placeholder -->': tableSvg,
            #                                            }
        )
Пример #5
0
#        '''

    categoryName = 'Unknown'
    categoryMap = unicodedataCategoryMap.get(unicode_category, None)
    if categoryMap is not None:
        categoryName = categoryMap.major + ' ' + categoryMap.minor

    glyphsMaps.append({
        'glyphHex':
        '%X' % value,
        'shortName':
        getUnicodeShortName(value, ignoreUnknown=True),
        'longName':
        getUnicodeLongName(value, ignoreUnknown=True),
        'glyphName':
        getUnicodeCharacterName(value, ignoreUnknown=True),
        'unicode_category':
        unicode_category,
        'category_color':
        category_color,
        'categoryName':
        categoryName,
    })

mustacheMap = {
    'glyphsMaps': glyphsMaps,
    'pageTitle': 'Unicode Categories Chart',
}
mustacheFilename = 'gia_chart_template.txt'
dstFilename = 'glyph_categories.html'
dstFile = os.path.abspath(
    def dumpMetricsMap(self, kerningPairMap, htmlFilename):

        print
        print 'fonts scanned:', len(self.processedPostscriptNames)
        print 'fonts processed:', len(self.nonEmptyPostscriptNames)
        print 'glyph pairs observed:', len(kerningPairMap)
        maxGlyphPairCount = reduce(max, kerningPairMap.values())
        print 'Highest glyph pair frequency:', maxGlyphPairCount

        glyphs = []
        for (glyph0, glyph1,), count in kerningPairMap.iteritems():
            glyph = TFSMap()
            glyph.glyph0 = glyph0
            glyph.glyph1 = glyph1
            glyph.count = count
            glyphs.append(glyph)

        def glyphCountSort(glyph0, glyph1):
            # Negate; we want reverse order for count.
            result = -cmp(glyph0.count, glyph1.count)
            if result != 0:
                return result

            result = cmp(glyph0.glyph0, glyph1.glyph0)
            if result != 0:
                return result

            result = cmp(glyph0.glyph1, glyph1.glyph1)
            if result != 0:
                return result

            return 0
#            return cmp(glyph0.codePoint, glyph1.codePoint)

        glyphs.sort(glyphCountSort)

        print 'Most common glyph:', glyphs[0]
        print 'Least common glyph:', glyphs[-1]

        locale.setlocale(locale.LC_ALL, 'en_US')

        pres = []
        for glyph in glyphs[:5000]:
#        for glyph in glyphs[:1000]:
#            pre = {}

            pre = {
#                    'glyphHex': hex(glyph.codePoint),
                    'glyphHex0': '%04X' % glyph.glyph0,
                    'glyphHex1': '%04X' % glyph.glyph1,
#                    'glyphName0': getUnicodeLongName(glyph.glyph0,
#                                                    ignoreUnknown=True,
#                                                    skipValidation=True),
#                    'glyphName1': getUnicodeLongName(glyph.glyph1,
#                                                    ignoreUnknown=True,
#                                                    skipValidation=True),
                    'glyphName0': getUnicodeCharacterName(glyph.glyph0, ignoreUnknown=True),
                    'glyphName1': getUnicodeCharacterName(glyph.glyph1, ignoreUnknown=True),
                   'glyphCount': locale.format("%d", glyph.count, grouping=True),
                   'glyphPercent': '%0.2f%%' % (100.0 * glyph.count / float(len(self.nonEmptyPostscriptNames))),
#                   'glyphColor': '%06X' % glyphColor,
                   }

#            pre['value'] = '%s %s: %d (%0.2f%%)' % ( hex(glyph.codePoint),
#                                            getUnicodeLongName(glyph.codePoint,
#                                                                    ignoreUnknown=True,
#                                                                    skipValidation=True),
#                                            glyph.count,
#                                            glyph.count / float(len(self.nonEmptyPostscriptNames)),
#                                            )
#            print 'pre', pre
            pres.append(pre)


        self.writeMustacheLog('kia_pre_template.txt',
                              htmlFilename,
#                              'most_common_kerning_pairs.html',
                              mustacheVars={ 'pres': pres,
#                                              'headerPres': headerPres,
                                              'pageTitle': '1,000 Most Common Kerning Pairs',
                                              'headerTitle': '1,000 Most Common Kerning Pairs',
#                                              'headerTitle': 'Kerning Pairs Implementation Statistics',
                                              'statsTitle': 'Statistics',
                                              'stats': (
                                                        { 'key': 'Total Fonts', 'value': locale.format("%d", len(self.processedPostscriptNames), grouping=True), },
                                                        { 'key': 'Fonts With Valid Kerning Table', 'value': locale.format("%d", len(self.nonEmptyPostscriptNames), grouping=True), },
                                                        { 'key': 'Kerning Pairs Observed', 'value': locale.format("%d", len(kerningPairMap), grouping=True), },
                                                        ),
                                              }
#                              replaceMap = {'<!-- SVG Graph Placeholder -->': tableSvg,
#                                            }
                              )
 def getGlyphName(codePoint):
     result = getUnicodeCharacterName(codePoint, ignoreUnknown=True, skipValidation=True)
     if result is None:
         return 'Unknown'
     result = result.replace('<', '').replace('>', '')
     return result
Пример #8
0
#        Z Separator
#        S Symbol
#        C Other
#        '''

    categoryName = 'Unknown'
    categoryMap = unicodedataCategoryMap.get(unicode_category, None)
    if categoryMap is not None:
        categoryName = categoryMap.major + ' ' + categoryMap.minor


    glyphsMaps.append({
                       'glyphHex': '%X' % value,
                       'shortName': getUnicodeShortName(value, ignoreUnknown=True),
                       'longName': getUnicodeLongName(value, ignoreUnknown=True),
                       'glyphName': getUnicodeCharacterName(value, ignoreUnknown=True),
                       'unicode_category': unicode_category,
                       'category_color': category_color,
                       'categoryName': categoryName,
                       })

mustacheMap = {
               'glyphsMaps': glyphsMaps,
               'pageTitle': 'Unicode Categories Chart',
               }
mustacheFilename = 'gia_chart_template.txt'
dstFilename = 'glyph_categories.html'
dstFile = os.path.abspath(os.path.join(TFSProject.findProjectRootFolder(), 'out', dstFilename))
print 'dstFile', dstFile
writeMustacheLog(mustacheFilename, dstFile, mustacheMap)