def explicitGlyph( font, char, encoding=None ): """Return glyphName or None if there is not explicit glyph for char""" cmap = font['cmap'] if encoding is None: encoding = describe.guessEncoding( font ) table = cmap.getcmap( *encoding ) glyfName = table.cmap.get( ord(char)) return glyfName
def _generalMetadata( self ): """Load general meta-data for this font (called via withFont) Guess the appropriate encoding, query line height, and character height. """ try: self.encoding = describe.guessEncoding( self.font, self.encoding ) self.lineHeight = glyphquery.lineHeight( self.font ) self.charHeight = glyphquery.charHeight( self.font ) except Exception: log.error( """Unable to load TrueType font from %r""", self.filename) raise
def glyphName(font, char, encoding=None, warnOnFailure=1): """Retrieve the glyph name for the given character XXX Not sure what the effect of the Unicode mapping will be given the use of ord... """ glyfName = explicitGlyph(font, char, encoding) if glyfName is None: encoding = describe.guessEncoding(font) #KH cmap = font['cmap'] #KH table = cmap.getcmap(*encoding) #KH glyfName = table.cmap.get(-1) if glyfName is None: glyfName = font['glyf'].glyphOrder[0] if text_log and warnOnFailure: text_log.warn( """Unable to find glyph name for %r, in %r using first glyph in table (%r)""", char, describe.shortName(font), glyfName) return glyfName
def glyphName( font, char, encoding=None, warnOnFailure=1 ): """Retrieve the glyph name for the given character XXX Not sure what the effect of the Unicode mapping will be given the use of ord... """ glyfName = explicitGlyph( font, char, encoding ) if glyfName is None: encoding = describe.guessEncoding( font ) #KH cmap = font['cmap'] #KH table = cmap.getcmap( *encoding ) #KH glyfName = table.cmap.get( -1) if glyfName is None: glyfName = font['glyf'].glyphOrder[0] if text_log and warnOnFailure: text_log.warn( """Unable to find glyph name for %r, in %r using first glyph in table (%r)""", char, describe.shortName(font), glyfName ) return glyfName