head 1.4; access; symbols rel-1-060:1.3 rel-1-053:1.3 rel-1-052:1.3 rel-1-045:1.2 rel-1-051:1.2 rel-1-044:1.2 stable-1-04:1.2.0.2 stable-1-02:1.1.0.4 rel-1-050:1.2 rel-1-043:1.2 rel-1-042:1.1 rel-1-041:1.1 rel-1-040:1.1 rel-1-023:1.1 rel-1-031:1.1 rel-1-022:1.1 rel-1-030:1.1 rel-1-021:1.1 stable-1-0:1.1.0.2 rel-1-02:1.1 rel-1-01:1.1 rel-1-00:1.1 rel-0-92:1.1 rel-0-91:1.1 rel-0-90:1.1 rel-0-04:1.1 rel-0-03:1.1 rel-0-02:1.1 rel-0-01:1.1; locks; strict; comment @# @; 1.4 date 2008.10.05.19.59.40; author tsch; state Exp; branches; next 1.3; commitid jap73dqgVgT1Atlt; 1.3 date 2008.02.10.18.02.33; author tsch; state Exp; branches; next 1.2; commitid exEpQJuWqKTbASQs; 1.2 date 2007.09.30.12.54.32; author tsch; state Exp; branches 1.2.2.1; next 1.1; commitid PfPFbmmBLvIy9Lzs; 1.1 date 2005.07.12.20.29.47; author tsch; state Exp; branches; next ; commitid 758542d428324567; 1.2.2.1 date 2008.02.10.18.02.55; author tsch; state Exp; branches; next ; commitid rgBDU1m1GLMjASQs; desc @@ 1.4 log @In preparation of the move to SVN, use the Id keyword in place of Header. @ text @/* * Copyright (c) 2004-2005 by the cairo perl team (see the file README) * * Licensed under the LGPL, see LICENSE file for more information. * * $Id: /cvs/cairo/cairo-perl/CairoPath.xs,v 1.3 2008-02-10 18:02:33 tsch Exp $ */ #include #include "ppport.h" #define MY_MAGIC_SIG 0xCAFE /* Let's hope this is unique enough */ static MAGIC * cairo_perl_mg_find (SV *sv, int type) { if (sv) { MAGIC *mg; for (mg = SvMAGIC (sv); mg; mg = mg->mg_moremagic) { if (mg->mg_type == type && mg->mg_private == MY_MAGIC_SIG) return mg; } } return 0; } SV * newSVCairoPath (cairo_path_t * path) { AV * av; SV * tie; HV * stash; MAGIC * mg; av = newAV (); /* Create a tied reference. */ tie = newRV_noinc ((SV *) av); stash = gv_stashpv ("Cairo::Path", TRUE); sv_bless (tie, stash); sv_magic ((SV *) av, tie, PERL_MAGIC_tied, Nullch, 0); /* Associate the array with the original path via magic. */ sv_magic ((SV *) av, 0, PERL_MAGIC_ext, (const char *) path, 0); mg = mg_find ((SV *) av, PERL_MAGIC_ext); /* Mark the mg as belonging to us. */ mg->mg_private = MY_MAGIC_SIG; #if PERL_REVISION <= 5 && PERL_VERSION <= 6 /* perl 5.6.x doesn't actually set mg_ptr when namlen == 0, so do it * now. */ mg->mg_ptr = (char *) path; #endif /* 5.6.x */ return tie; } cairo_path_t * SvCairoPath (SV * sv) { MAGIC * mg; if (!sv || !SvROK (sv) || !(mg = cairo_perl_mg_find (SvRV (sv), PERL_MAGIC_ext))) return NULL; return (cairo_path_t *) mg->mg_ptr; } MODULE = Cairo::Path PACKAGE = Cairo::Path void DESTROY (SV * sv) PREINIT: cairo_path_t *path; CODE: path = SvCairoPath (sv); if (path) { #if PERL_REVISION <= 5 && PERL_VERSION <= 6 /* Unset mg_ptr to prevent perl 5.6.x from trying to free it again. */ MAGIC *mg = cairo_perl_mg_find (SvRV (sv), PERL_MAGIC_ext); mg->mg_ptr = NULL; #endif /* 5.6.x */ cairo_path_destroy (path); } IV FETCHSIZE (cairo_path_t * path) PREINIT: int i; CODE: RETVAL = 0; for (i = 0; i < path->num_data; i += path->data[i].header.length) RETVAL++; OUTPUT: RETVAL SV * FETCH (cairo_path_t * path, IV index) PREINIT: int i, counter = 0; CODE: RETVAL = &PL_sv_undef; for (i = 0; i < path->num_data; i += path->data[i].header.length) { if (counter++ == index) { cairo_path_data_t *data = &path->data[i]; HV *hash = newHV (); AV *points = newAV (), *tmp; switch (data->header.type) { case CAIRO_PATH_MOVE_TO: case CAIRO_PATH_LINE_TO: tmp = newAV (); av_store (tmp, 0, newSVnv (data[1].point.x)); av_store (tmp, 1, newSVnv (data[1].point.y)); av_store (points, 0, newRV_noinc ((SV *) tmp)); break; case CAIRO_PATH_CURVE_TO: tmp = newAV (); av_store (tmp, 0, newSVnv (data[1].point.x)); av_store (tmp, 1, newSVnv (data[1].point.y)); av_store (points, 0, newRV_noinc ((SV *) tmp)); tmp = newAV (); av_store (tmp, 0, newSVnv (data[2].point.x)); av_store (tmp, 1, newSVnv (data[2].point.y)); av_store (points, 1, newRV_noinc ((SV *) tmp)); tmp = newAV (); av_store (tmp, 0, newSVnv (data[3].point.x)); av_store (tmp, 1, newSVnv (data[3].point.y)); av_store (points, 2, newRV_noinc ((SV *) tmp)); break; case CAIRO_PATH_CLOSE_PATH: break; } hv_store (hash, "type", 4, cairo_path_data_type_to_sv (data->header.type), 0); hv_store (hash, "points", 6, newRV_noinc ((SV *) points), 0); RETVAL = newRV_noinc ((SV *) hash); break; } } OUTPUT: RETVAL @ 1.3 log @ * CairoPath.xs: Fix the tied interface for paths on perl 5.6, whose magic support was slightly broken. Also cleanup the tie code a bit. @ text @d6 1 a6 1 * $Header: /cvs/cairo/cairo-perl/CairoPath.xs,v 1.2 2007-09-30 12:54:32 tsch Exp $ @ 1.2 log @ * ppport.h * Cairo.xs * CairoPath.xs * CairoPattern.xs * CairoSurface.xs * MANIFEST * cairo-perl-private.h * cairo-perl.h: Add and use the portability header ppport.h from Devel::PPPort to hopefully fix compilation on older perls. @ text @d6 1 a6 1 * $Header: /cvs/cairo/cairo-perl/CairoPath.xs,v 1.1 2005-07-12 20:29:47 tsch Exp $ d13 15 d31 1 a31 1 AV * av, * dummy; d34 1 a36 1 dummy = newAV (); d38 2 a39 1 tie = newRV_noinc ((SV *) dummy); d42 1 d44 1 a44 4 /* Both the dummy and the real array need to have the path stored in * the ext slot. SvCairoPath looks for it in the real array. * FETCHSIZE and FETCH look for it in the dummy. */ sv_magic ((SV *) dummy, 0, PERL_MAGIC_ext, (const char *) path, 0); a45 1 sv_magic ((SV *) av, tie, PERL_MAGIC_tied, "", 0); d47 12 a58 1 return newRV_noinc ((SV *) av); d65 1 a65 1 if (!sv || !SvROK (sv) || !(mg = mg_find (SvRV (sv), PERL_MAGIC_ext))) d72 3 a74 1 void DESTROY (cairo_path_t * path) d76 9 a84 1 cairo_path_destroy (path); d86 1 a86 1 IV FETCHSIZE (cairo_path_t * path, i_do_not_care_what_this_undocumented_second_argument_is) @ 1.2.2.1 log @ * CairoPath.xs: Fix the tied interface for paths on perl 5.6, whose magic support was slightly broken. Also cleanup the tie code a bit. @ text @d6 1 a6 1 * $Header: /cvs/cairo/cairo-perl/CairoPath.xs,v 1.2 2007-09-30 12:54:32 tsch Exp $ a12 15 #define MY_MAGIC_SIG 0xCAFE /* Let's hope this is unique enough */ static MAGIC * cairo_perl_mg_find (SV *sv, int type) { if (sv) { MAGIC *mg; for (mg = SvMAGIC (sv); mg; mg = mg->mg_moremagic) { if (mg->mg_type == type && mg->mg_private == MY_MAGIC_SIG) return mg; } } return 0; } d16 1 a16 1 AV * av; a18 1 MAGIC * mg; d21 1 d23 1 a23 2 /* Create a tied reference. */ tie = newRV_noinc ((SV *) av); a25 1 sv_magic ((SV *) av, tie, PERL_MAGIC_tied, Nullch, 0); d27 4 a30 1 /* Associate the array with the original path via magic. */ d32 1 d34 1 a34 12 mg = mg_find ((SV *) av, PERL_MAGIC_ext); /* Mark the mg as belonging to us. */ mg->mg_private = MY_MAGIC_SIG; #if PERL_REVISION <= 5 && PERL_VERSION <= 6 /* perl 5.6.x doesn't actually set mg_ptr when namlen == 0, so do it * now. */ mg->mg_ptr = (char *) path; #endif /* 5.6.x */ return tie; d41 1 a41 1 if (!sv || !SvROK (sv) || !(mg = cairo_perl_mg_find (SvRV (sv), PERL_MAGIC_ext))) d48 1 a48 3 void DESTROY (SV * sv) PREINIT: cairo_path_t *path; d50 1 a50 9 path = SvCairoPath (sv); if (path) { #if PERL_REVISION <= 5 && PERL_VERSION <= 6 /* Unset mg_ptr to prevent perl 5.6.x from trying to free it again. */ MAGIC *mg = cairo_perl_mg_find (SvRV (sv), PERL_MAGIC_ext); mg->mg_ptr = NULL; #endif /* 5.6.x */ cairo_path_destroy (path); } d52 1 a52 1 IV FETCHSIZE (cairo_path_t * path) @ 1.1 log @ * Cairo.pm, Cairo.xs, t/Cairo.t: Replace the %backends hash with Cairo::HAS_PS_SURFACE, HAS_PDF_SURFACE, HAS_XLIB_SURFACE, HAS_FT_FONT and HAS_PNG_FUNCTIONS. * Cairo.pm, CairoPattern.xs, CairoSurface.xs, Makefile.PL: Implement the pattern and surface hierarchy suggested by the language bindings guidelines. * Cairo.xs: Use Cairo::Context for the namespace of cairo_t, instead of just Cairo, as suggested by the guidelines. * Cairo.xs, CairoFont.xs, CairoMatrix.xs, CairoPattern.xs, CairoSurface.xs, cairo-perl.h: Add new, remove old API. Shuffle some things around. * Cairo.xs: Convert font and text extents and glyphs to and from native Perl data structures. * Cairo.xs, cairo-perl.h, cairo-perl.typemap: Remove everything that cannot be used from Perl, like the XLib and Glitz stuff. * CairoPath.xs, t/CairoPath.t: Add support for cairo_path_t, including a nice tied interface that lets you iterate over paths as if they were normal array references. * MakeHelper.pm: Extend the typemap generator to support "const" and "_noinc" types. Change the enum handling to use the Glib convention, i.e. lowercase and hyphen instead of underscore. * Makefile.PL, README: Use ExtUtils::Depends. * examples/simple.pl, examples/png/caps_join.pl, examples/png/hering.pl, examples/png/outline.pl, examples/png/spiral.pl, examples/png/splines_tolerance.pl, examples/png/stars.pl: Update the examples to make them work again after all those API changes. * t/Cairo.t, t/CairoFont.t, CairoMatrix.t, CairoPattern.t, CairoSurface.t: Redo and/or expand the whole test suite. @ text @d6 1 a6 1 * $Header: /cvs/cairo/cairo-perl/CairoFont.xs,v 1.2 2004/11/12 03:26:34 rwmcfa1 Exp $ d11 2 @