예제 #1
0
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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
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
예제 #5
0
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