[cairo-commit] [cairo-www] src/freetypepython.mdwn
Carl Worth
cworth at freedesktop.org
Tue Oct 23 18:47:06 PDT 2007
src/freetypepython.mdwn | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
New commits:
commit d48cdf062a9114997445bbdd08ebbf2222eb2beb
Author: Carl Worth <cworth at annarchy.freedesktop.org>
Date: Tue Oct 23 18:47:06 2007 -0700
web commit by BehdadEsfahbod: Fix bug and raise exceptions
diff --git a/src/freetypepython.mdwn b/src/freetypepython.mdwn
index 260d3a3..71e4425 100644
--- a/src/freetypepython.mdwn
+++ b/src/freetypepython.mdwn
@@ -11,14 +11,15 @@ The resulting cairo font face however is used normally with pycairo.
_initialized = False
- def create_cairo_font_face_for_file (filename, faceindex):
+ def create_cairo_font_face_for_file (filename, faceindex=0, loadoptions=0):
global _initialized
global _freetype_so
global _cairo_so
global _ft_lib
global _surface
- STATUS_SUCCESS = 0
+ CAIRO_STATUS_SUCCESS = 0
+ FT_Err_Ok = 0
if not _initialized:
@@ -28,7 +29,8 @@ The resulting cairo font face however is used normally with pycairo.
# initialize freetype
_ft_lib = ctypes.c_void_p ()
- assert 0 == _freetype_so.FT_Init_FreeType (ctypes.byref (_ft_lib))
+ 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__),
@@ -44,14 +46,17 @@ The resulting cairo font face however is used normally with pycairo.
cairo_ctx = cairo.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
- assert 0 == _freetype_so.FT_New_Face (_ft_lib, filename, faceindex, ctypes.byref(ft_face))
+ if FT_Err_Ok != _freetype_so.FT_New_Face (_ft_lib, filename, faceindex, ctypes.byref(ft_face)):
+ raise "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)
- assert STATUS_SUCCESS == _cairo_so.cairo_font_face_status (cr_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 "Error creating cairo font face for " + filename
_cairo_so.cairo_set_font_face (cairo_t, cr_face)
- assert STATUS_SUCCESS == _cairo_so.cairo_status (cairo_t)
+ if CAIRO_STATUS_SUCCESS != _cairo_so.cairo_status (cairo_t):
+ raise "Error creating cairo font face for " + filename
face = cairo_ctx.get_font_face ()
More information about the cairo-commit
mailing list