<s> import sys <EOL> import numpy as np <EOL> from . _vispy_fonts import _vispy_fonts , _get_vispy_font_filename <EOL> if sys . platform . startswith ( '<STR_LIT>' ) : <EOL> from ... ext . fontconfig import find_font <EOL> elif sys . platform . startswith ( '<STR_LIT>' ) : <EOL> from . _win32 import find_font <EOL> else : <EOL> raise NotImplementedError <EOL> _font_dict = { } <EOL> def _load_font ( face , bold , italic ) : <EOL> from ... ext . freetype import Face , FT_FACE_FLAG_SCALABLE <EOL> key = '<STR_LIT>' % ( face , bold , italic ) <EOL> if key in _font_dict : <EOL> return _font_dict [ key ] <EOL> if face in _vispy_fonts : <EOL> fname = _get_vispy_font_filename ( face , bold , italic ) <EOL> else : <EOL> fname = find_font ( face , bold , italic ) <EOL> font = Face ( fname ) <EOL> if ( FT_FACE_FLAG_SCALABLE & font . face_flags ) == <NUM_LIT:0> : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> % face ) <EOL> _font_dict [ key ] = font <EOL> return font <EOL> def _load_glyph ( f , char , glyphs_dict ) : <EOL> """<STR_LIT>""" <EOL> from ... ext . freetype import ( FT_LOAD_RENDER , FT_LOAD_NO_HINTING , <EOL> FT_LOAD_NO_AUTOHINT ) <EOL> flags = FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT <EOL> face = _load_font ( f [ '<STR_LIT>' ] , f [ '<STR_LIT>' ] , f [ '<STR_LIT>' ] ) <EOL> face . set_char_size ( f [ '<STR_LIT:size>' ] * <NUM_LIT:64> ) <EOL> face . load_char ( char , flags ) <EOL> bitmap = face . glyph . bitmap <EOL> width = face . glyph . bitmap . width <EOL> height = face . glyph . bitmap . rows <EOL> bitmap = np . array ( bitmap . buffer ) <EOL> w0 = bitmap . size // height if bitmap . size > <NUM_LIT:0> else <NUM_LIT:0> <EOL> bitmap . shape = ( height , w0 ) <EOL> bitmap = bitmap [ : , : width ] . astype ( np . ubyte ) <EOL> left = face . glyph . bitmap_left <EOL> top = face . glyph . bitmap_top <EOL> advance = face . glyph . advance . x / <NUM_LIT> <EOL> glyph = dict ( char = char , offset = ( left , top ) , bitmap = bitmap , <EOL> advance = advance , kerning = { } ) <EOL> glyphs_dict [ char ] = glyph <EOL> for other_char , other_glyph in glyphs_dict . items ( ) : <EOL> kerning = face . get_kerning ( other_char , char ) <EOL> glyph [ '<STR_LIT>' ] [ other_char ] = kerning . x / <NUM_LIT> <EOL> kerning = face . get_kerning ( char , other_char ) <EOL> other_glyph [ '<STR_LIT>' ] [ char ] = kerning . x / <NUM_LIT> </s>
