(self, char, fullwidth)
Build a glyph for the given unicode character.
Build a glyph for the given unicode character.
Build a glyph for the given unicode character .
def _build_glyph(self, char, fullwidth):
        """Build a glyph for the given unicode character."""
        try:
            byteseq = bytearray(self._fontdict[char])
        except KeyError:
            logging.debug('No glyph for code point %r; replacing with blank.', char)
            byteseq = bytearray(self._height)
        # shape of encoded mask (8 or 16 wide; usually 8, 14 or 16 tall)
        code_height = 8 if self._height == 9 else self._height
        if len(byteseq) < code_height:
            byteseq = byteseq.ljust(code_height, b'\0')
        glyph = bytematrix.ByteMatrix.frompacked(byteseq, code_height, items_per_byte=8)
        # stretch or sqeeze if necessary
        req_width = self._width * (2 if fullwidth else 1)
        if req_width >= glyph.width * 2:
            logging.debug('Code point %r stretched to full-width.', char)
            glyph = glyph.hrepeat(2)
        elif glyph.width >= (req_width-1) * 2:
            logging.debug('Code point %r squeezed to half-width.', char)
            glyph = glyph[:, ::2]
        # repeat last rows (e.g. for 9-bit high chars)
        if self._height > glyph.height:
            glyph = _extend_height(glyph, char in self._carry_row_9_chars)
        # repeat last cols (e.g. for 9-bit wide chars)
        if req_width > glyph.width:
            glyph = _extend_width(glyph, char in self._carry_col_9_chars)
        self._glyphs[char] = glyph
def _build_glyph ( self , char , fullwidth ) : try : byteseq = bytearray ( self . _fontdict [ char ] ) except KeyError : logging . debug ( 'No glyph for code point %r; replacing with blank.' , char ) byteseq = bytearray ( self . _height ) # shape of encoded mask (8 or 16 wide; usually 8, 14 or 16 tall) code_height = 8 if self . _height == 9 else self . _height if len ( byteseq ) < code_height : byteseq = byteseq . ljust ( code_height , b'\0' ) glyph = bytematrix . ByteMatrix . frompacked ( byteseq , code_height , items_per_byte = 8 ) # stretch or sqeeze if necessary req_width = self . _width * ( 2 if fullwidth else 1 ) if req_width >= glyph . width * 2 : logging . debug ( 'Code point %r stretched to full-width.' , char ) glyph = glyph . hrepeat ( 2 ) elif glyph . width >= ( req_width - 1 ) * 2 : logging . debug ( 'Code point %r squeezed to half-width.' , char ) glyph = glyph [ : , : : 2 ] # repeat last rows (e.g. for 9-bit high chars) if self . _height > glyph . height : glyph = _extend_height ( glyph , char in self . _carry_row_9_chars ) # repeat last cols (e.g. for 9-bit wide chars) if req_width > glyph . width : glyph = _extend_width ( glyph , char in self . _carry_col_9_chars ) self . _glyphs [ char ] = glyph