Пример #1
0
    def dumpMetrics(self):

        print
        print 'fonts scanned:', len(self.processedPostscriptNames)
        print 'fonts processed:', len(self.nonEmptyPostscriptNames)
        print 'glyphs observed:', len(self.glyphCountMap)
        maxGlyphCount = reduce(max, self.glyphCountMap.values())
        print 'Highest glyph frequency:', maxGlyphCount

        glyphs = []
        for codePoint, count in self.glyphCountMap.iteritems():
            glyph = TFSMap()
            glyph.codePoint = codePoint
            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

            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[:1000]:
#            pre = {}

            pre = {
#                    'glyphHex': hex(glyph.codePoint),
                    'glyphHex': '%04X' % glyph.codePoint,
                    'glyphName': getUnicodeLongName(glyph.codePoint,
                                                    ignoreUnknown=True,
                                                    skipValidation=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)


        glyphs.sort(lambda glyph0, glyph1:cmp(glyph0.codePoint, glyph1.codePoint))
        headerPres = []
        for glyph in glyphs[:10000]:

            minGlyphColor = 0xffafafff
            maxGlyphColor = 0xff0f0f5f
            phase = glyph.count / float(maxGlyphCount)
            from tfs.common.TFSSvg import blendArgbColors
            glyphColor = 0xffffff & blendArgbColors(minGlyphColor, maxGlyphColor, phase)

            pre = {
#                    'glyphHex': hex(glyph.codePoint),
                    'glyphHex': '%X' % glyph.codePoint,
                    'glyphName': getUnicodeLongName(glyph.codePoint,
                                                    ignoreUnknown=True,
                                                    skipValidation=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),
#                                            getUnicodeCharacterName(glyph.codePoint,
#                                                                    ignoreUnknown=True,
#                                                                    skipValidation=True),
#                                            glyph.count,
#                                            glyph.count / float(len(self.nonEmptyPostscriptNames)),
#                                            )
#            print 'pre', pre
            headerPres.append(pre)

#        tableSvg = self.getTableSvg(glyphs, maxGlyphCount)


        self.writeMustacheLog('gia_pre_template.txt',
                              'most_common_glyphs.html',
                              mustacheVars = { 'pres': pres,
                                              'headerPres': headerPres,
                                              'pageTitle': '1,000 Most Commonly Implemented Font Glyphs',
                                              'headerTitle': 'Glyph Implementation Statistics',
                                              'statsTitle': 'Statistics',
                                              'stats': (
                                                        { 'key': 'Total Fonts Scanned', 'value': locale.format("%d", len(self.processedPostscriptNames), grouping=True), },
                                                        { 'key': 'Distinct Code Points Observed', 'value': locale.format("%d", len(self.glyphCountMap), grouping=True), },
                                                        ),
                                              }
#                              replaceMap = {'<!-- SVG Graph Placeholder -->': tableSvg,
#                                            }
                              )
Пример #2
0
#        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'
Пример #3
0
#        P Punctuation
#        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)