#NEWLINE# def create_cairo_font_face_for_file( filename , faceindex = 0 , loadoptions = 0 ) : #NEWLINE# #INDENT# class PycairoContext ( ctypes . Structure ) : #NEWLINE# #INDENT# _fields_ = [ ( 'PyObject_HEAD' , ( ctypes . c_byte * object . __basicsize__ ) ) , ( 'ctx' , ctypes . c_void_p ) , ( 'base' , ctypes . c_void_p ) ] #NEWLINE# #UNINDENT# global _initialized #NEWLINE# global _freetype_so #NEWLINE# global _cairo_so #NEWLINE# global _ft_lib #NEWLINE# global _surface #NEWLINE# CAIRO_STATUS_SUCCESS = 0 #NEWLINE# FT_Err_Ok = 0 #NEWLINE# if ( not _initialized ) : #NEWLINE# #INDENT# _freetype_so = ctypes . CDLL ( 'libfreetype.so.6' ) #NEWLINE# _cairo_so = ctypes . CDLL ( 'libcairo.so.2' ) #NEWLINE# _cairo_so . cairo_ft_font_face_create_for_ft_face . restype = ctypes . c_void_p #NEWLINE# _cairo_so . cairo_ft_font_face_create_for_ft_face . argtypes = [ ctypes . c_void_p , ctypes . c_int ] #NEWLINE# _cairo_so . cairo_set_font_face . argtypes = [ ctypes . c_void_p , ctypes . c_void_p ] #NEWLINE# _cairo_so . cairo_font_face_status . argtypes = [ ctypes . c_void_p ] #NEWLINE# _cairo_so . cairo_status . argtypes = [ ctypes . c_void_p ] #NEWLINE# _ft_lib = ctypes . c_void_p ( ) #NEWLINE# if ( FT_Err_Ok != _freetype_so . FT_Init_FreeType ( ctypes . byref ( _ft_lib ) ) ) : #NEWLINE# #INDENT# raise 'Error initialising FreeType library.' #NEWLINE# #UNINDENT# _surface = cairo . ImageSurface ( cairo . FORMAT_A8 , 0 , 0 ) #NEWLINE# _initialized = True #NEWLINE# #UNINDENT# ft_face = ctypes . c_void_p ( ) #NEWLINE# cairo_ctx = cairo . Context ( _surface ) #NEWLINE# cairo_t = PycairoContext . from_address ( id ( cairo_ctx ) ) . ctx #NEWLINE# if ( FT_Err_Ok != _freetype_so . FT_New_Face ( _ft_lib , filename , faceindex , ctypes . byref ( ft_face ) ) ) : #NEWLINE# #INDENT# raise Exception ( ( 'Error creating FreeType font face for ' + filename ) ) #NEWLINE# #UNINDENT# cr_face = _cairo_so . cairo_ft_font_face_create_for_ft_face ( ft_face , loadoptions ) #NEWLINE# if ( CAIRO_STATUS_SUCCESS != _cairo_so . cairo_font_face_status ( cr_face ) ) : #NEWLINE# #INDENT# raise Exception ( ( 'Error creating cairo font face for ' + filename ) ) #NEWLINE# #UNINDENT# _cairo_so . cairo_set_font_face ( cairo_t , cr_face ) #NEWLINE# if ( CAIRO_STATUS_SUCCESS != _cairo_so . cairo_status ( cairo_t ) ) : #NEWLINE# #INDENT# raise Exception ( ( 'Error creating cairo font face for ' + filename ) ) #NEWLINE# #UNINDENT# face = cairo_ctx . get_font_face ( ) #NEWLINE# return face