本文整理汇总了Python中cairo.Context.get_font_face方法的典型用法代码示例。如果您正苦于以下问题:Python Context.get_font_face方法的具体用法?Python Context.get_font_face怎么用?Python Context.get_font_face使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.get_font_face方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_cairo_font_face_for_file
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import get_font_face [as 别名]
def create_cairo_font_face_for_file(filename, faceindex=0, loadoptions=0):
"""
http://cairographics.org/freetypepython
"""
CAIRO_STATUS_SUCCESS = 0
FT_Err_Ok = 0
# find shared objects
_freetype_so = ctypes.CDLL('libfreetype.so.6')
_cairo_so = ctypes.CDLL('libcairo.so.2')
_cairo_so.cairo_ft_font_face_create_for_ft_face.restype = ctypes.c_void_p
_cairo_so.cairo_ft_font_face_create_for_ft_face.argtypes = [ ctypes.c_void_p, ctypes.c_int ]
_cairo_so.cairo_set_font_face.argtypes = [ ctypes.c_void_p, ctypes.c_void_p ]
_cairo_so.cairo_font_face_status.argtypes = [ ctypes.c_void_p ]
_cairo_so.cairo_status.argtypes = [ ctypes.c_void_p ]
# initialize freetype
_ft_lib = ctypes.c_void_p()
if FT_Err_Ok != _freetype_so.FT_Init_FreeType(ctypes.byref(_ft_lib)):
raise "Error initialising FreeType library."
class PycairoContext(ctypes.Structure):
_fields_ = [("PyObject_HEAD", ctypes.c_byte * object.__basicsize__),
("ctx", ctypes.c_void_p),
("base", ctypes.c_void_p)]
_surface = ImageSurface(FORMAT_A8, 0, 0)
# create freetype face
ft_face = ctypes.c_void_p()
cairo_ctx = Context(_surface)
cairo_t = PycairoContext.from_address(id(cairo_ctx)).ctx
_cairo_so.cairo_ft_font_face_create_for_ft_face.restype = ctypes.c_void_p
if FT_Err_Ok != _freetype_so.FT_New_Face(_ft_lib, filename, faceindex, ctypes.byref(ft_face)):
raise Exception("Error creating FreeType font face for " + filename)
# create cairo font face for freetype face
cr_face = _cairo_so.cairo_ft_font_face_create_for_ft_face(ft_face, loadoptions)
if CAIRO_STATUS_SUCCESS != _cairo_so.cairo_font_face_status(cr_face):
raise Exception("Error creating cairo font face for " + filename)
_cairo_so.cairo_set_font_face(cairo_t, cr_face)
if CAIRO_STATUS_SUCCESS != _cairo_so.cairo_status(cairo_t):
raise Exception("Error creating cairo font face for " + filename)
face = cairo_ctx.get_font_face()
return face