import ctypes import os from ctypes.util import find_library os.environ['PATH'] += ';' + os.path.dirname( __file__ ) loader = ctypes.CDLL if os.sys.platform == 'win32': loader = ctypes.CDLL library = 'freetype6' elif os.sys.platform == 'darwin': library = 'freetype' else: library = 'freetype' freetype = loader( find_library( library ) ) class FT_Bitmap_Size( ctypes.Structure ): _fields_ = [ ( 'height', ctypes.c_short ), ( 'width', ctypes.c_short ), ( 'size', ctypes.c_long ), ( 'x_ppem', ctypes.c_long ), ( 'y_ppem', ctypes.c_long ) ] FT_Generic_Finalizer = ctypes.POINTER( ctypes.CFUNCTYPE( None, ctypes.c_void_p ) ) class FT_Generic( ctypes.Structure ): _fields_ = [ ( 'data', ctypes.c_void_p ), ( 'finalizer', FT_Generic_Finalizer ) ] class FT_BBox( ctypes.Structure ): _fields_ = [ ( 'xMin', ctypes.c_long ), ( 'yMin', ctypes.c_long ), ( 'xMax', ctypes.c_long ), ( 'yMax', ctypes.c_long ), ] class FT_Glyph_Metrics( ctypes.Structure ): _fields_ = [ ( 'width', ctypes.c_long ), ( 'height', ctypes.c_long ), ( 'horiBearingX', ctypes.c_long ), ( 'horiBearingY', ctypes.c_long ), ( 'horiAdvance', ctypes.c_long ), ( 'vertBearingX', ctypes.c_long ), ( 'vertBearingY', ctypes.c_long ), ( 'vertAdvance', ctypes.c_long ) ] class FT_Vector( ctypes.Structure ): _fields_ = [ ( 'x', ctypes.c_long ), ( 'y', ctypes.c_long ) ] class FT_Bitmap( ctypes.Structure ): _fields_ = [ ( 'rows', ctypes.c_int ), ( 'width', ctypes.c_int ), ( 'pitch', ctypes.c_int ), ( 'buffer', ctypes.POINTER( ctypes.c_ubyte ) ), ( 'num_grays', ctypes.c_short ), ( 'pixel_mode', ctypes.c_char ), ( 'palette_mode', ctypes.c_char ), ( 'palette', ctypes.c_void_p ) ] class FT_Outline( ctypes.Structure ): _fields_ = [ ( 'n_contours', ctypes.c_short ), ( 'n_points', ctypes.c_short ), ( 'points', ctypes.POINTER( FT_Vector ) ), ( 'tags', ctypes.c_char_p ), ( 'contours', ctypes.POINTER( ctypes.c_short ) ), ( 'flags', ctypes.c_int ) ] class FT_GlyphSlot( ctypes.Structure ): _fields_ = [ ( 'library', ctypes.c_void_p ), ( 'face', ctypes.c_void_p ), ( 'next', ctypes.c_void_p ), ( 'reserved', ctypes.c_uint ), ( 'generic', FT_Generic ), ( 'metrics', FT_Glyph_Metrics ), ( 'linearHoriAdvance', ctypes.c_long ), ( 'linearVertAdvance', ctypes.c_long ), ( 'advance', FT_Vector ), ( 'format', ctypes.c_int ), ( 'bitmap', FT_Bitmap ), ( 'bitmap_left', ctypes.c_int ), ( 'bitmap_top', ctypes.c_int ), ( 'outline', FT_Outline ), ( 'num_subglyphs', ctypes.c_uint ), ( 'subglyphs', ctypes.c_void_p ), ( 'control_data', ctypes.c_void_p ), ( 'control_len', ctypes.c_long ), ( 'lsb_delta', ctypes.c_long ), ( 'rsb_delta', ctypes.c_long ), ( 'other', ctypes.c_void_p ), ( 'internal', ctypes.c_void_p ) ] class FT_Size_Metrics( ctypes.Structure ): _fields_ = [ ( 'x_ppem', ctypes.c_ushort ), ( 'y_ppem', ctypes.c_ushort ), ( 'x_scale', ctypes.c_long ), ( 'y_scale', ctypes.c_long ), ( 'ascender', ctypes.c_long ), ( 'descender', ctypes.c_long ), ( 'height', ctypes.c_long ), ( 'max_advance', ctypes.c_long ) ] class FT_Size( ctypes.Structure ): _fields_ = [ ( 'face', ctypes.c_void_p ), ( 'generic',ctypes. c_void_p ), ( 'metrics', FT_Size_Metrics ), ( 'internal', ctypes.c_void_p ) ] class FT_Charmap( ctypes.Structure ): _fields_ = [ ( 'face', ctypes.c_void_p ), ( 'encoding', ctypes.c_int ), ( 'platform_id', ctypes.c_ushort ), ( 'encoding_id', ctypes.c_ushort ) ] class FT_Face( ctypes.Structure ): _fields_ = [ ( 'num_faces', ctypes.c_long ), ( 'face_index', ctypes.c_long ), ( 'face_flags', ctypes.c_long ), ( 'style_flags', ctypes.c_long ), ( 'num_glyphs', ctypes.c_long ), ( 'family_name', ctypes.c_char_p ), ( 'style_name', ctypes.c_char_p ), ( 'num_fixed_sizes', ctypes.c_int ), ( 'available_sizes', ctypes.POINTER( FT_Bitmap_Size ) ), ( 'num_charmaps', ctypes.c_int ), ( 'charmaps', ctypes.POINTER( ctypes.POINTER( FT_Charmap ) ) ), ( 'generic', FT_Generic ), ( 'bbox', FT_BBox ), ( 'units_per_EM', ctypes.c_ushort ), ( 'ascender', ctypes.c_short ), ( 'descender', ctypes.c_short ), ( 'height', ctypes.c_short ), ( 'max_advance_width', ctypes.c_short ), ( 'max_advance_height', ctypes.c_short ), ( 'underline_position', ctypes.c_short ), ( 'underline_thickness', ctypes.c_short ), ( 'glyph', ctypes.POINTER( FT_GlyphSlot ) ), ( 'size', ctypes.POINTER( FT_Size ) ), ( 'charmap', ctypes.POINTER( FT_Charmap ) ), ( 'driver', ctypes.c_void_p ), ( 'memory', ctypes.c_void_p ), ( 'stream', ctypes.c_void_p ), ( 'sizes_list_head', ctypes.c_void_p ), ( 'sizes_list_tail', ctypes.c_void_p ), ( 'autohint', FT_Generic ), ( 'extensions', ctypes.c_void_p ), ( 'internal', ctypes.c_void_p ) ] library = ctypes.c_void_p() freetype.FT_Init_FreeType( ctypes.byref( library ) ) face = ctypes.pointer( FT_Face() ) freetype.FT_New_Face( library, '/usr/share/fonts/truetype/freefont/FreeMono.ttf', 0, ctypes.byref( face ) ) print( 'start' ) freetype.FT_Set_Char_Size( face, 12 << 6, 12 << 6, 96, 96 ) print( 'pass' )