コード例 #1
0
 def createGlyphMap(codePoint):
     return {
                'glyphHex': '%X' % codePoint,
                'glyphName': UnicodeCharacterNames.getUnicodeCharacterName(codePoint),
             }
コード例 #2
0
    def writeCompoundHtmlLog(self, dstCodePoint, contours, baseCodePoint, diacriticalCodePoints):

        import pystache

        def getFilenamePrefix(codePoint):
            return u'fi-%s' % ( hex(codePoint), )
#            filenamePrefix = u'fi-%s' % ( unichr(dstCodePoint), )
        filenamePrefix = getFilenamePrefix(dstCodePoint)
        glyphSvg = self.renderSvgScene( filenamePrefix,
                                        pathTuples = (
                                                      ( 0x7f7faf7f, contours, ),
                                                      ),
                                       )

        import tfs.common.TFSProject as TFSProject
        mustache_template_file = os.path.abspath(os.path.join(TFSProject.findProjectRootFolder(), 'data', 'log_html_mustache.txt'))
        with open(mustache_template_file, 'rt') as f:
            mustache_template = f.read()

        def formatGlyphName(glyph):
            return hex(glyph)
#            return u'%s (%s)' % ( unichr(glyph),
#                                  hex(glyph), )

        pageTitle = u'font-interpolator Log: %s' % ( formatGlyphName(dstCodePoint), )

        linkMaps = []
        currentIndex = 0
        for index, (codePoint, _, _, _,) in enumerate(self.logData):
            if codePoint == dstCodePoint:
                currentIndex = index
            linkMaps.append({
                             'linkFilename': '%s.html' % ( getFilenamePrefix(codePoint), ),
                             'linkHex': '%X' % codePoint,
                             })

        prevCodePoint, _, _, _, = self.logData[(currentIndex + len(self.logData) - 1) % len(self.logData)]
        nextCodePoint, _, _, _, = self.logData[(currentIndex + 1) % len(self.logData)]

        import tfs.common.UnicodeCharacterNames as UnicodeCharacterNames

        def createGlyphMap(codePoint):
            return {
                       'glyphHex': '%X' % codePoint,
                       'glyphName': UnicodeCharacterNames.getUnicodeCharacterName(codePoint),
                    }

        diacriticalGlyphMaps = [createGlyphMap(codePoint) for codePoint in diacriticalCodePoints]
        mustacheMap = {
                       'pageTitle': pageTitle,
                       'glyphSvg': glyphSvg,
#                       'glyph': formatGlyphName(dstCodePoint),
#                       'glyphName': formatGlyphName(dstCodePoint),
                       'glyphHex': '%X' % dstCodePoint,
                       'glyphName': UnicodeCharacterNames.getUnicodeCharacterName(dstCodePoint),
                       'baseGlyphHex': '%X' % baseCodePoint,
                       'baseGlyphName': UnicodeCharacterNames.getUnicodeCharacterName(baseCodePoint),
                       'diacriticalGlyphs': diacriticalGlyphMaps,

                       'linkMaps': linkMaps,

                        'prevLinkFilename': '%s.html' % ( getFilenamePrefix(prevCodePoint), ),
                        'prevCodePoint': '%X' % prevCodePoint,
                        'prevGlyphName': UnicodeCharacterNames.getUnicodeCharacterName(prevCodePoint),
                        'nextLinkFilename': '%s.html' % ( getFilenamePrefix(nextCodePoint), ),
                        'nextCodePoint': '%X' % nextCodePoint,
                        'nextGlyphName': UnicodeCharacterNames.getUnicodeCharacterName(nextCodePoint),
                       }
#baseCodePoint, diacriticalCodePoints
        for key in (
                     'familyName',
                     'styleName',
                     'fullName',
                     'fontName',
                    ):
            mustacheMap[key] = getattr(self.fifont.info, key)

        logHtml = pystache.render(mustache_template, mustacheMap)

        logFilename = '%s.html' % ( filenamePrefix, )
        logFile = os.path.abspath(os.path.join(self.html_folder, logFilename))
        with open(logFile, 'wt') as f:
            # TODO: explicitly encode unicode
            f.write(logHtml)