[perl-Cairo] Implement inheritance for font faces
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Cairo] Implement inheritance for font faces
- Date: Sat, 30 Apr 2011 15:20:25 +0000 (UTC)
commit e115a692fe745196fa8e58c617961a0bef77e63b
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date: Sat Apr 30 17:16:34 2011 +0200
Implement inheritance for font faces
CairoFont.xs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
CairoFt.xs | 3 +++
cairo-perl.h | 9 +++++++++
t/CairoFt.t | 3 ++-
4 files changed, 68 insertions(+), 1 deletions(-)
---
diff --git a/CairoFont.xs b/CairoFont.xs
index 1c5dfe0..f5a060b 100644
--- a/CairoFont.xs
+++ b/CairoFont.xs
@@ -9,6 +9,53 @@
#include <cairo-perl.h>
#include <cairo-perl-private.h>
+static const char *
+get_package (cairo_font_face_t *face)
+{
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+ cairo_font_type_t type;
+ const char *package;
+
+ type = cairo_font_face_get_type (face);
+ switch (type) {
+ case CAIRO_FONT_TYPE_TOY:
+ package = "Cairo::ToyFontFace";
+ break;
+
+ case CAIRO_FONT_TYPE_FT:
+ package = "Cairo::FtFontFace";
+ break;
+
+ /* These aren't wrapped yet: */
+ case CAIRO_FONT_TYPE_WIN32:
+ case CAIRO_FONT_TYPE_QUARTZ:
+ case CAIRO_FONT_TYPE_USER:
+ package = "Cairo::FontFace";
+ break;
+
+ default:
+ warn ("unknown font face type %d encountered", type);
+ package = "Cairo::FontFace";
+ break;
+ }
+
+ return package;
+#else
+ const char *package = cairo_perl_package_table_lookup (pattern);
+ return package ? package : "Cairo::FontFace";
+#endif
+}
+
+SV *
+cairo_font_face_to_sv (cairo_font_face_t *face)
+{
+ SV *sv = newSV (0);
+ sv_setref_pv(sv, get_package (face), face);
+ return sv;
+}
+
+/* ------------------------------------------------------------------------- */
+
MODULE = Cairo::Font PACKAGE = Cairo::FontFace PREFIX = cairo_font_face_
cairo_status_t cairo_font_face_status (cairo_font_face_t * font);
@@ -25,6 +72,13 @@ void DESTROY (cairo_font_face_t * font)
# --------------------------------------------------------------------------- #
+MODULE = Cairo PACKAGE = Cairo::ToyFontFace PREFIX = cairo_toy_font_face_
+
+BOOT:
+ cairo_perl_set_isa ("Cairo::ToyFontFace", "Cairo::FontFace");
+
+# --------------------------------------------------------------------------- #
+
MODULE = Cairo::Font PACKAGE = Cairo::ScaledFont PREFIX = cairo_scaled_font_
##cairo_scaled_font_t* cairo_scaled_font_create (cairo_font_face_t *font_face, const cairo_matrix_t *font_matrix, const cairo_matrix_t *ctm, const cairo_font_options_t *options);
diff --git a/CairoFt.xs b/CairoFt.xs
index 1ce8bd1..2400cb6 100644
--- a/CairoFt.xs
+++ b/CairoFt.xs
@@ -18,6 +18,9 @@ face_destroy (void *face)
MODULE = Cairo::Ft PACKAGE = Cairo::FtFontFace PREFIX = cairo_ft_font_face_
+BOOT:
+ cairo_perl_set_isa ("Cairo::FtFontFace", "Cairo::FontFace");
+
# cairo_font_face_t * cairo_ft_font_face_create_for_ft_face (FT_Face face, int load_flags);
cairo_font_face_t_noinc *
cairo_ft_font_face_create (class, SV *face, int load_flags=0)
diff --git a/cairo-perl.h b/cairo-perl.h
index c672e69..ffa9567 100644
--- a/cairo-perl.h
+++ b/cairo-perl.h
@@ -91,4 +91,13 @@ SV * cairo_pattern_to_sv (cairo_pattern_t *surface);
#define newSVCairoPattern(object) (cairo_pattern_to_sv (cairo_pattern_reference (object)))
#define newSVCairoPattern_noinc(object) (cairo_pattern_to_sv (object))
+/*
+ * special treatment for font faces
+ */
+SV * cairo_font_face_to_sv (cairo_font_face_t *surface);
+#undef newSVCairoFontFace
+#undef newSVCairoFontFace_noinc
+#define newSVCairoFontFace(object) (cairo_font_face_to_sv (cairo_font_face_reference (object)))
+#define newSVCairoFontFace_noinc(object) (cairo_font_face_to_sv (object))
+
#endif /* _CAIRO_PERL_H_ */
diff --git a/t/CairoFt.t b/t/CairoFt.t
index 18c363f..9db59de 100644
--- a/t/CairoFt.t
+++ b/t/CairoFt.t
@@ -28,10 +28,11 @@ unless ($file) {
plan skip_all => 'can\'t find font file';
}
-plan tests => 2;
+plan tests => 3;
my $ft_face = Font::FreeType->new->face ($file);
my $cr_ft_face = Cairo::FtFontFace->create ($ft_face);
+isa_ok ($cr_ft_face, 'Cairo::FtFontFace');
isa_ok ($cr_ft_face, 'Cairo::FontFace');
is ($cr_ft_face->status, 'success');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]