Cairo.xs 23.2 KB
Newer Older
x-rwmcfa1's avatar
x-rwmcfa1 committed
1
/*
Brian Manning's avatar
Brian Manning committed
2
 * Copyright (c) 2004-2013 by the cairo perl team (see the file README)
x-rwmcfa1's avatar
x-rwmcfa1 committed
3 4 5
 *
 * Licensed under the LGPL, see LICENSE file for more information.
 *
6
 * $Id$
x-rwmcfa1's avatar
x-rwmcfa1 committed
7 8 9 10
 *
 */

#include <cairo-perl.h>
Torsten Schönfeld's avatar
Torsten Schönfeld committed
11
#include <cairo-perl-private.h>
x-rwmcfa1's avatar
x-rwmcfa1 committed
12

13 14 15
#define NEED_newRV_noinc_GLOBAL
#include "ppport.h"

16 17
/* ------------------------------------------------------------------------- */

Torsten Schönfeld's avatar
Torsten Schönfeld committed
18 19
static void
call_xs (pTHX_ void (*subaddr) (pTHX_ CV *), CV * cv, SV ** mark)
20 21 22 23 24 25 26
{
	dSP;
	PUSHMARK (mark);
	(*subaddr) (aTHX_ cv);
	PUTBACK;	/* forget return values */
}

27 28 29
#ifndef XS_EXTERNAL
# define XS_EXTERNAL(name) XS(name)
#endif
Torsten Schönfeld's avatar
Torsten Schönfeld committed
30 31
#define CAIRO_PERL_CALL_BOOT(name)				\
	{							\
32
		extern XS_EXTERNAL (name);			\
Torsten Schönfeld's avatar
Torsten Schönfeld committed
33 34 35
		call_xs (aTHX_ name, cv, mark);	\
	}

36
/* ------------------------------------------------------------------------- */
x-rwmcfa1's avatar
x-rwmcfa1 committed
37

38 39 40 41 42 43 44 45 46 47 48 49 50 51
/* Copied from Glib/Glib.xs. */
void *
cairo_perl_alloc_temp (int nbytes)
{
	dTHR;
	SV * s;

	if (nbytes <= 0) return NULL;

	s = sv_2mortal (NEWSV (0, nbytes));
	memset (SvPVX (s), 0, nbytes);
	return SvPVX (s);
}

52 53
/* Copied from Glib/GType.xs. */
void
54 55
cairo_perl_set_isa (const char *child_package,
                    const char *parent_package)
56 57 58 59
{
	char *child_isa_full;
	AV *isa;

60
	New (0, child_isa_full, strlen(child_package) + 5 + 1, char);
61 62 63
	child_isa_full = strcpy (child_isa_full, child_package);
	child_isa_full = strcat (child_isa_full, "::ISA");
	isa = get_av (child_isa_full, TRUE); /* create on demand */
64
	Safefree (child_isa_full);
65 66 67 68

	av_push (isa, newSVpv (parent_package, 0));
}

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
/* Copied from Glib/Glib.xs. */
cairo_bool_t
cairo_perl_sv_is_defined (SV *sv)
{
	/* This is adapted from PP(pp_defined) in perl's pp.c */

	if (!sv || !SvANY(sv))
		return FALSE;

	switch (SvTYPE(sv)) {
	    case SVt_PVAV:
		if (AvMAX(sv) >= 0 || SvGMAGICAL(sv)
		    || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
			return TRUE;
		break;
	    case SVt_PVHV:
		if (HvARRAY(sv) || SvGMAGICAL(sv)
		    || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
			return TRUE;
		break;
	    case SVt_PVCV:
		if (CvROOT(sv) || CvXSUB(sv))
			return TRUE;
		break;
	    default:
		if (SvGMAGICAL(sv))
			mg_get(sv);
		if (SvOK(sv))
			return TRUE;
	}

	return FALSE;
}

103 104
/* ------------------------------------------------------------------------- */

105 106 107
void *
cairo_object_from_sv (SV *sv, const char *package)
{
108
	if (!cairo_perl_sv_is_ref (sv) || !sv_derived_from (sv, package))
109
		croak("Cannot convert scalar %p to an object of type %s",
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
		      sv, package);
	return INT2PTR (void *, SvIV ((SV *) SvRV (sv)));
}

SV *
cairo_object_to_sv (void *object, const char *package)
{
	SV *sv = newSV (0);
	sv_setref_pv(sv, package, object);
	return sv;
}

/* ------------------------------------------------------------------------- */

void *
cairo_struct_from_sv (SV *sv, const char *package)
{
127
	if (!cairo_perl_sv_is_ref (sv) || !sv_derived_from (sv, package))
128
		croak("Cannot convert scalar %p to a struct of type %s",
129 130 131 132 133 134 135 136 137 138 139 140 141 142
		      sv, package);
	return INT2PTR (void *, SvIV ((SV *) SvRV (sv)));
}

SV *
cairo_struct_to_sv (void *object, const char *package)
{
	SV *sv = newSV (0);
	sv_setref_pv(sv, package, object);
	return sv;
}

/* ------------------------------------------------------------------------- */

143
SV *
144
newSVCairoFontExtents (cairo_font_extents_t *extents)
145 146 147
{
	HV *hv;
	double value;
x-rwmcfa1's avatar
x-rwmcfa1 committed
148

149 150
	if (!extents)
		return &PL_sv_undef;
x-rwmcfa1's avatar
x-rwmcfa1 committed
151

152
	hv = newHV ();
x-rwmcfa1's avatar
x-rwmcfa1 committed
153

154 155
	value = extents->ascent;
	hv_store (hv, "ascent", 6, newSVnv (value), 0);
x-rwmcfa1's avatar
x-rwmcfa1 committed
156

157 158
	value = extents->descent;
	hv_store (hv, "descent", 7, newSVnv (value), 0);
x-rwmcfa1's avatar
x-rwmcfa1 committed
159

160 161
	value = extents->height;
	hv_store (hv, "height", 6, newSVnv (value), 0);
x-rwmcfa1's avatar
x-rwmcfa1 committed
162

163 164
	value = extents->max_x_advance;
	hv_store (hv, "max_x_advance", 13, newSVnv (value), 0);
x-rwmcfa1's avatar
x-rwmcfa1 committed
165

166 167
	value = extents->max_y_advance;
	hv_store (hv, "max_y_advance", 13, newSVnv (value), 0);
x-rwmcfa1's avatar
x-rwmcfa1 committed
168

169 170
	return newRV_noinc ((SV *) hv);
}
x-rwmcfa1's avatar
x-rwmcfa1 committed
171

172
/* ------------------------------------------------------------------------- */
x-rwmcfa1's avatar
x-rwmcfa1 committed
173

174
SV *
175
newSVCairoTextExtents (cairo_text_extents_t *extents)
176 177 178
{
	HV *hv;
	double value;
x-rwmcfa1's avatar
x-rwmcfa1 committed
179

180 181
	if (!extents)
		return &PL_sv_undef;
x-rwmcfa1's avatar
x-rwmcfa1 committed
182

183
	hv = newHV ();
x-rwmcfa1's avatar
x-rwmcfa1 committed
184

185 186
	value = extents->x_bearing;
	hv_store (hv, "x_bearing", 9, newSVnv (value), 0);
x-rwmcfa1's avatar
x-rwmcfa1 committed
187

188 189
	value = extents->y_bearing;
	hv_store (hv, "y_bearing", 9, newSVnv (value), 0);
x-rwmcfa1's avatar
x-rwmcfa1 committed
190

191 192
	value = extents->width;
	hv_store (hv, "width", 5, newSVnv (value), 0);
x-rwmcfa1's avatar
x-rwmcfa1 committed
193

194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
	value = extents->height;
	hv_store (hv, "height", 6, newSVnv (value), 0);

	value = extents->x_advance;
	hv_store (hv, "x_advance", 9, newSVnv (value), 0);

	value = extents->y_advance;
	hv_store (hv, "y_advance", 9, newSVnv (value), 0);

	return newRV_noinc ((SV *) hv);
}

/* ------------------------------------------------------------------------- */

SV *
209
newSVCairoGlyph (cairo_glyph_t *glyph)
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
{
	HV *hv;
	unsigned long index;
	double value;

	if (!glyph)
		return &PL_sv_undef;

	hv = newHV ();

	index = glyph->index;
	hv_store (hv, "index", 5, newSVuv (index), 0);

	value = glyph->x;
	hv_store (hv, "x", 1, newSVnv (value), 0);

	value = glyph->y;
	hv_store (hv, "y", 1, newSVnv (value), 0);

	return newRV_noinc ((SV *) hv);
}

cairo_glyph_t *
233
SvCairoGlyph (SV *sv)
234 235 236 237 238
{
	HV *hv;
	SV **value;
	cairo_glyph_t *glyph;

239
	if (!cairo_perl_sv_is_hash_ref (sv))
240
		croak ("cairo_glyph_t must be a hash reference");
x-rwmcfa1's avatar
x-rwmcfa1 committed
241

242
	hv = (HV *) SvRV (sv);
243
	glyph = cairo_perl_alloc_temp (sizeof (cairo_glyph_t));
x-rwmcfa1's avatar
x-rwmcfa1 committed
244

245 246 247
	value = hv_fetch (hv, "index", 5, 0);
	if (value && SvOK (*value))
		glyph->index = SvUV (*value);
x-rwmcfa1's avatar
x-rwmcfa1 committed
248

249 250 251
	value = hv_fetch (hv, "x", 1, 0);
	if (value && SvOK (*value))
		glyph->x = SvNV (*value);
x-rwmcfa1's avatar
x-rwmcfa1 committed
252

253 254 255
	value = hv_fetch (hv, "y", 1, 0);
	if (value && SvOK (*value))
		glyph->y = SvNV (*value);
x-rwmcfa1's avatar
x-rwmcfa1 committed
256

257 258
	return glyph;
}
x-rwmcfa1's avatar
x-rwmcfa1 committed
259

260
/* ------------------------------------------------------------------------- */
x-rwmcfa1's avatar
x-rwmcfa1 committed
261

262
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 4, 0)
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281

SV *
newSVCairoRectangle (cairo_rectangle_t *rectangle)
{
	HV *hv;

	if (!rectangle)
		return &PL_sv_undef;

	hv = newHV ();

	hv_store (hv, "x", 1, newSVnv (rectangle->x), 0);
	hv_store (hv, "y", 1, newSVnv (rectangle->y), 0);
	hv_store (hv, "width", 5, newSVnv (rectangle->width), 0);
	hv_store (hv, "height", 6, newSVnv (rectangle->height), 0);

	return newRV_noinc ((SV *) hv);
}

282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
cairo_rectangle_t *
SvCairoRectangle (SV *sv)
{
	HV *hv;
	SV **value;
	cairo_rectangle_t *rectangle;

	if (!cairo_perl_sv_is_hash_ref (sv))
		croak ("cairo_rectangle_t must be a hash reference");

	hv = (HV *) SvRV (sv);
	rectangle = cairo_perl_alloc_temp (sizeof (cairo_rectangle_t));

	value = hv_fetchs (hv, "x", 0);
	if (value && SvOK (*value))
		rectangle->x = SvNV (*value);

	value = hv_fetchs (hv, "y", 0);
	if (value && SvOK (*value))
		rectangle->y = SvNV (*value);

	value = hv_fetchs (hv, "width", 0);
	if (value && SvOK (*value))
		rectangle->width = SvNV (*value);

	value = hv_fetchs (hv, "height", 0);
	if (value && SvOK (*value))
		rectangle->height = SvNV (*value);

	return rectangle;
}

314 315 316 317
#endif

/* ------------------------------------------------------------------------- */

Torsten Schönfeld's avatar
Torsten Schönfeld committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 10, 0)

SV *
newSVCairoRectangleInt (cairo_rectangle_int_t *rectangle)
{
	HV *hv;

	if (!rectangle)
		return &PL_sv_undef;

	hv = newHV ();

	hv_store (hv, "x", 1, newSViv (rectangle->x), 0);
	hv_store (hv, "y", 1, newSViv (rectangle->y), 0);
	hv_store (hv, "width", 5, newSViv (rectangle->width), 0);
	hv_store (hv, "height", 6, newSViv (rectangle->height), 0);

	return newRV_noinc ((SV *) hv);
}

cairo_rectangle_int_t *
SvCairoRectangleInt (SV *sv)
{
	HV *hv;
	SV **value;
	cairo_rectangle_int_t *rectangle;

	if (!cairo_perl_sv_is_hash_ref (sv))
		croak ("cairo_rectangle_int_t must be a hash reference");

	hv = (HV *) SvRV (sv);
	rectangle = cairo_perl_alloc_temp (sizeof (cairo_rectangle_t));

	value = hv_fetchs (hv, "x", 0);
	if (value && SvOK (*value))
		rectangle->x = SvIV (*value);

	value = hv_fetchs (hv, "y", 0);
	if (value && SvOK (*value))
		rectangle->y = SvIV (*value);

	value = hv_fetchs (hv, "width", 0);
	if (value && SvOK (*value))
		rectangle->width = SvIV (*value);

	value = hv_fetchs (hv, "height", 0);
	if (value && SvOK (*value))
		rectangle->height = SvIV (*value);

	return rectangle;
}

#endif

/* ------------------------------------------------------------------------- */

374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 8, 0)

SV *
newSVCairoTextCluster (cairo_text_cluster_t *cluster)
{
	HV *hv;

	if (!cluster)
		return &PL_sv_undef;

	hv = newHV ();

	hv_store (hv, "num_bytes", 9, newSViv (cluster->num_bytes), 0);
	hv_store (hv, "num_glyphs", 10, newSVnv (cluster->num_glyphs), 0);

	return newRV_noinc ((SV *) hv);
}

cairo_text_cluster_t *
SvCairoTextCluster (SV *sv)
{
	HV *hv;
	SV **value;
	cairo_text_cluster_t *cluster;

	if (!cairo_perl_sv_is_hash_ref (sv))
		croak ("cairo_text_cluster_t must be a hash reference");

	hv = (HV *) SvRV (sv);
	cluster = cairo_perl_alloc_temp (sizeof (cairo_text_cluster_t));

	value = hv_fetch (hv, "num_bytes", 9, 0);
	if (value && SvOK (*value))
		cluster->num_bytes = SvIV (*value);

	value = hv_fetch (hv, "num_glyphs", 10, 0);
	if (value && SvOK (*value))
		cluster->num_glyphs = SvIV (*value);

	return cluster;
}

#endif

/* ------------------------------------------------------------------------- */

Torsten Schönfeld's avatar
Torsten Schönfeld committed
420 421
MODULE = Cairo	PACKAGE = Cairo	PREFIX = cairo_

422 423 424 425 426 427
BOOT:
#include "cairo-perl-boot.xsh"
#if CAIRO_PERL_DEBUG
	call_atexit ((ATEXIT_t) cairo_debug_reset_static_data, NULL);
#endif

428 429
# The VERSION fallback is implemented in lib/Cairo.pm.
int LIB_VERSION (...)
430
    CODE:
431
	PERL_UNUSED_VAR (items);
432 433 434 435
	RETVAL = CAIRO_VERSION;
    OUTPUT:
	RETVAL

436 437 438
int LIB_VERSION_ENCODE (...)
    ALIAS:
	VERSION_ENCODE = 1
439 440 441
    PREINIT:
	int major, minor, micro;
    CODE:
442
	PERL_UNUSED_VAR (ix);
443 444 445 446 447 448 449 450 451
	if (items == 3) {
		major = SvIV (ST (0));
		minor = SvIV (ST (1));
		micro = SvIV (ST (2));
	} else if (items == 4) {
		major = SvIV (ST (1));
		minor = SvIV (ST (2));
		micro = SvIV (ST (3));
	} else {
452
		croak ("Usage: Cairo::LIB_VERSION_ENCODE (major, minor, micro) or Cairo->LIB_VERSION_ENCODE (major, minor, micro)");
453 454 455 456 457 458
	}

	RETVAL = CAIRO_VERSION_ENCODE (major, minor, micro);
    OUTPUT:
	RETVAL

459 460
# int cairo_version ();
int cairo_version (class=NULL)
461 462
    ALIAS:
	lib_version = 1
463 464
    C_ARGS:
	/* void */
465 466
    CLEANUP:
	PERL_UNUSED_VAR (ix);
467 468 469

# const char* cairo_version_string ();
const char* cairo_version_string (class=NULL)
470 471
    ALIAS:
	lib_version_string = 1
472 473
    C_ARGS:
	/* void */
474 475
    CLEANUP:
	PERL_UNUSED_VAR (ix);
Torsten Schönfeld's avatar
Torsten Schönfeld committed
476 477 478

# ---------------------------------------------------------------------------- #

479
MODULE = Cairo	PACKAGE = Cairo::Context	PREFIX = cairo_
x-rwmcfa1's avatar
x-rwmcfa1 committed
480

481 482 483
cairo_t_noinc * cairo_create (class, cairo_surface_t * target);
    C_ARGS:
	target
x-rwmcfa1's avatar
x-rwmcfa1 committed
484

485 486 487 488 489 490 491
void DESTROY (cairo_t * cr);
    CODE:
	cairo_destroy (cr);

void cairo_save (cairo_t * cr);

void cairo_restore (cairo_t * cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
492

493 494
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)

Torsten Schönfeld's avatar
Torsten Schönfeld committed
495 496 497 498 499 500 501 502
void cairo_push_group (cairo_t *cr);

void cairo_push_group_with_content (cairo_t *cr, cairo_content_t content);

cairo_pattern_t * cairo_pop_group (cairo_t *cr);

void cairo_pop_group_to_source (cairo_t *cr);

503 504
#endif

x-rwmcfa1's avatar
x-rwmcfa1 committed
505 506
void cairo_set_operator (cairo_t * cr, cairo_operator_t op);

507
void cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue);
x-rwmcfa1's avatar
x-rwmcfa1 committed
508

509
void cairo_set_source_rgba (cairo_t *cr, double red, double green, double blue, double alpha);
x-rwmcfa1's avatar
x-rwmcfa1 committed
510

511 512 513
void cairo_set_source (cairo_t *cr, cairo_pattern_t *source);

void cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface, double x, double y);
x-rwmcfa1's avatar
x-rwmcfa1 committed
514 515 516

void cairo_set_tolerance (cairo_t * cr, double tolerance);

517 518
void cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias);

x-rwmcfa1's avatar
x-rwmcfa1 committed
519 520 521 522 523 524 525 526 527
void cairo_set_fill_rule (cairo_t * cr, cairo_fill_rule_t fill_rule);

void cairo_set_line_width (cairo_t * cr, double width);

void cairo_set_line_cap (cairo_t * cr, cairo_line_cap_t line_cap);

void cairo_set_line_join (cairo_t * cr, cairo_line_join_t line_join);

##void cairo_set_dash (cairo_t * cr, double * dashes, int ndash, double offset);
528
void cairo_set_dash (cairo_t * cr, double offset, ...)
x-rwmcfa1's avatar
x-rwmcfa1 committed
529
    PREINIT:
530 531
	int i, n;
	double *pts;
x-rwmcfa1's avatar
x-rwmcfa1 committed
532
    CODE:
533 534 535 536 537
#define FIRST 2
	n = (items - FIRST);
	if (n == 0) {
		pts = NULL;
	} else {
538
		New (0, pts, n, double);
539 540 541 542 543 544 545
		if (!pts)
			croak ("malloc failure for (%d) elements", n);
		for (i = FIRST ; i < items ; i++)
			pts[i - FIRST] = SvNV (ST (i));
	}
#undef FIRST
	cairo_set_dash (cr, pts, n, offset);
x-rwmcfa1's avatar
x-rwmcfa1 committed
546
    CLEANUP:
547
	if (pts)
548
		Safefree (pts);
x-rwmcfa1's avatar
x-rwmcfa1 committed
549 550 551 552 553 554 555 556 557

void cairo_set_miter_limit (cairo_t * cr, double limit);

void cairo_translate (cairo_t * cr, double tx, double ty);

void cairo_scale (cairo_t * cr, double sx, double sy);

void cairo_rotate (cairo_t * cr, double angle);

558
void cairo_transform (cairo_t *cr, const cairo_matrix_t *matrix);
x-rwmcfa1's avatar
x-rwmcfa1 committed
559

560
void cairo_set_matrix (cairo_t * cr, const cairo_matrix_t * matrix);
x-rwmcfa1's avatar
x-rwmcfa1 committed
561 562 563

void cairo_identity_matrix (cairo_t * cr);

564
void cairo_user_to_device (cairo_t *cr, IN_OUTLIST double x, IN_OUTLIST double y);
x-rwmcfa1's avatar
x-rwmcfa1 committed
565

566
void cairo_user_to_device_distance (cairo_t *cr, IN_OUTLIST double dx, IN_OUTLIST double dy);
x-rwmcfa1's avatar
x-rwmcfa1 committed
567

568
void cairo_device_to_user (cairo_t *cr, IN_OUTLIST double x, IN_OUTLIST double y);
x-rwmcfa1's avatar
x-rwmcfa1 committed
569

570
void cairo_device_to_user_distance (cairo_t *cr, IN_OUTLIST double dx, IN_OUTLIST double dy);
x-rwmcfa1's avatar
x-rwmcfa1 committed
571 572 573

void cairo_new_path (cairo_t * cr);

574 575
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)

Torsten Schönfeld's avatar
Torsten Schönfeld committed
576 577
void cairo_new_sub_path (cairo_t *cr);

578 579
#endif

x-rwmcfa1's avatar
x-rwmcfa1 committed
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
void cairo_move_to (cairo_t * cr, double x, double y);

void cairo_line_to (cairo_t * cr, double x, double y);

void cairo_curve_to (cairo_t * cr, double x1, double y1, double x2, double y2, double x3, double y3);

void cairo_arc (cairo_t * cr, double xc, double yc, double radius, double angle1, double angle2);

void cairo_arc_negative (cairo_t * cr, double xc, double yc, double radius, double angle1, double angle2);

void cairo_rel_move_to (cairo_t * cr, double dx, double dy);

void cairo_rel_line_to (cairo_t * cr, double dx, double dy);

void cairo_rel_curve_to (cairo_t * cr, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);

void cairo_rectangle (cairo_t * cr, double x, double y, double width, double height);

void cairo_close_path (cairo_t * cr);

Torsten Schönfeld's avatar
Torsten Schönfeld committed
600
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 6, 0)
601 602 603 604 605

void cairo_path_extents (cairo_t *cr, OUTLIST double x1, OUTLIST double y1, OUTLIST double x2, OUTLIST double y2);

#endif

606 607 608 609 610 611 612 613
void cairo_paint (cairo_t *cr);

void cairo_paint_with_alpha (cairo_t *cr, double alpha);

void cairo_mask (cairo_t *cr, cairo_pattern_t *pattern);

void cairo_mask_surface (cairo_t *cr, cairo_surface_t *surface, double surface_x, double surface_y);

x-rwmcfa1's avatar
x-rwmcfa1 committed
614 615
void cairo_stroke (cairo_t * cr);

616 617
void cairo_stroke_preserve (cairo_t *cr);

x-rwmcfa1's avatar
x-rwmcfa1 committed
618 619
void cairo_fill (cairo_t * cr);

620 621
void cairo_fill_preserve (cairo_t *cr);

x-rwmcfa1's avatar
x-rwmcfa1 committed
622 623 624 625 626 627 628 629 630 631 632 633 634 635
void cairo_copy_page (cairo_t * cr);

void cairo_show_page (cairo_t * cr);

int cairo_in_stroke (cairo_t * cr, double x, double y);

int cairo_in_fill (cairo_t * cr, double x, double y);

void cairo_stroke_extents (cairo_t * cr, OUTLIST double x1, OUTLIST double y1, OUTLIST double x2, OUTLIST double y2);

void cairo_fill_extents (cairo_t * cr, OUTLIST double x1, OUTLIST double y1, OUTLIST double x2, OUTLIST double y2);

void cairo_clip (cairo_t * cr);

636
void cairo_clip_preserve (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
637

638
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 4, 0)
639

640 641
##cairo_rectangle_list_t * cairo_copy_clip_rectangle_list (cairo_t *cr);
void cairo_copy_clip_rectangle_list (cairo_t *cr)
642 643 644 645
    PREINIT:
	cairo_rectangle_list_t *list;
	int i;
    PPCODE:
646
	list = cairo_copy_clip_rectangle_list (cr);
647 648 649 650 651 652 653 654 655 656
	CAIRO_PERL_CHECK_STATUS (list->status);
	EXTEND (sp, list->num_rectangles);
	for (i = 0; i < list->num_rectangles; i++)
		PUSHs (sv_2mortal (newSVCairoRectangle (&(list->rectangles[i]))));
	cairo_rectangle_list_destroy (list);

void cairo_clip_extents (cairo_t *cr, OUTLIST double x1, OUTLIST double y1, OUTLIST double x2, OUTLIST double y2);

#endif

Torsten Schönfeld's avatar
Torsten Schönfeld committed
657 658 659 660 661 662
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 10, 0)

cairo_bool_t cairo_in_clip (cairo_t *cr, double x, double y);

#endif

663
void cairo_reset_clip (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
664

665
void cairo_select_font_face (cairo_t *cr, const char_utf8 *family, cairo_font_slant_t slant, cairo_font_weight_t weight);
x-rwmcfa1's avatar
x-rwmcfa1 committed
666

667
void cairo_set_font_size (cairo_t *cr, double size);
x-rwmcfa1's avatar
x-rwmcfa1 committed
668

669
void cairo_set_font_matrix (cairo_t *cr, const cairo_matrix_t *matrix);
x-rwmcfa1's avatar
x-rwmcfa1 committed
670

671 672
##void cairo_get_font_matrix (cairo_t *cr, cairo_matrix_t *matrix);
cairo_matrix_t * cairo_get_font_matrix (cairo_t *cr)
Torsten Schönfeld's avatar
Torsten Schönfeld committed
673 674
    PREINIT:
	cairo_matrix_t matrix;
675
    CODE:
Torsten Schönfeld's avatar
Torsten Schönfeld committed
676
	cairo_get_font_matrix (cr, &matrix);
677
	RETVAL = cairo_perl_copy_matrix (&matrix);
678 679
    OUTPUT:
	RETVAL
x-rwmcfa1's avatar
x-rwmcfa1 committed
680

681 682 683 684 685 686 687 688 689 690
void cairo_set_font_options (cairo_t *cr, const cairo_font_options_t *options);

##void cairo_get_font_options (cairo_t *cr, cairo_font_options_t *options);
cairo_font_options_t * cairo_get_font_options (cairo_t *cr)
    CODE:
	RETVAL = cairo_font_options_create ();
	cairo_get_font_options (cr, RETVAL);
    OUTPUT:
	RETVAL

691 692
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)

Torsten Schönfeld's avatar
Torsten Schönfeld committed
693 694
void cairo_set_scaled_font (cairo_t *cr, const cairo_scaled_font_t *scaled_font);

695 696
#endif

697 698 699 700 701 702
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 4, 0)

cairo_scaled_font_t * cairo_get_scaled_font (cairo_t *cr);

#endif

703
void cairo_show_text (cairo_t * cr, const char_utf8 * utf8);
x-rwmcfa1's avatar
x-rwmcfa1 committed
704

705 706 707 708 709 710 711
##void cairo_show_glyphs (cairo_t * cr, cairo_glyph_t * glyphs, int num_glyphs);
void cairo_show_glyphs (cairo_t * cr, ...)
    PREINIT:
	cairo_glyph_t * glyphs = NULL;
	int num_glyphs, i;
    CODE:
	num_glyphs = items - 1;
712
	Newz (0, glyphs, num_glyphs, cairo_glyph_t);
713 714 715
	for (i = 1; i < items; i++)
		glyphs[i - 1] = *SvCairoGlyph (ST (i));
	cairo_show_glyphs (cr, glyphs, num_glyphs);
716
	Safefree (glyphs);
x-rwmcfa1's avatar
x-rwmcfa1 committed
717

718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 8, 0)

##void cairo_show_text_glyphs (cairo_t *cr, const char *utf8, int utf8_len, const cairo_glyph_t *glyphs, int num_glyphs, const cairo_text_cluster_t *clusters, int num_clusters, cairo_text_cluster_flags_t cluster_flags);
void
cairo_show_text_glyphs (cairo_t *cr, SV *utf8_sv, SV *glyphs_sv, SV *clusters_sv, cairo_text_cluster_flags_t cluster_flags)
    PREINIT:
	const char *utf8 = NULL;
	STRLEN utf8_len = 0;
	cairo_glyph_t * glyphs = NULL;
	cairo_text_cluster_t * clusters = NULL;
	int i, num_glyphs, num_clusters;
	AV *glyphs_av, *clusters_av;
    CODE:
	if (!cairo_perl_sv_is_array_ref (glyphs_sv))
		croak ("glyphs must be an array ref");
	if (!cairo_perl_sv_is_array_ref (clusters_sv))
		croak ("text clusters must be an array ref");

736
	sv_utf8_upgrade (utf8_sv);
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
	utf8 = SvPV (utf8_sv, utf8_len);

	glyphs_av = (AV *) SvRV (glyphs_sv);
	num_glyphs = av_len (glyphs_av) + 1;
	glyphs = cairo_glyph_allocate (num_glyphs);
	for (i = 0; i < num_glyphs; i++) {
		SV **value = av_fetch (glyphs_av, i, 0);
		if (value)
			glyphs[i] = *SvCairoGlyph (*value);
	}

	clusters_av = (AV *) SvRV (clusters_sv);
	num_clusters = av_len (clusters_av) + 1;
	clusters = cairo_text_cluster_allocate (num_clusters);
	for (i = 0; i < num_clusters; i++) {
		SV **value = av_fetch (clusters_av, i, 0);
		if (value)
			clusters[i] = *SvCairoTextCluster (*value);
	}

	cairo_show_text_glyphs (cr,
	                        utf8, (int) utf8_len,
	                        glyphs, num_glyphs,
	                        clusters, num_clusters, cluster_flags);

	cairo_text_cluster_free (clusters);
	cairo_glyph_free (glyphs);

#endif

767
cairo_font_face_t * cairo_get_font_face (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
768

769 770 771 772 773 774 775 776 777
##void cairo_font_extents (cairo_t *cr, cairo_font_extents_t *extents);
cairo_font_extents_t * cairo_font_extents (cairo_t *cr)
    PREINIT:
	cairo_font_extents_t extents;
    CODE:
	cairo_font_extents (cr, &extents);
	RETVAL = &extents;
    OUTPUT:
	RETVAL
x-rwmcfa1's avatar
x-rwmcfa1 committed
778

779
void cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face);
x-rwmcfa1's avatar
x-rwmcfa1 committed
780

781 782
##void cairo_text_extents (cairo_t * cr, const char * utf8, cairo_text_extents_t * extents);
cairo_text_extents_t * cairo_text_extents (cairo_t * cr, const char_utf8 * utf8)
783 784 785 786 787 788 789
    PREINIT:
	cairo_text_extents_t extents;
    CODE:
	cairo_text_extents (cr, utf8, &extents);
	RETVAL = &extents;
    OUTPUT:
	RETVAL
x-rwmcfa1's avatar
x-rwmcfa1 committed
790

791 792 793 794 795 796 797 798
##void cairo_glyph_extents (cairo_t * cr, cairo_glyph_t * glyphs, int num_glyphs, cairo_text_extents_t * extents);
cairo_text_extents_t * cairo_glyph_extents (cairo_t * cr, ...)
    PREINIT:
	cairo_text_extents_t extents;
	cairo_glyph_t * glyphs = NULL;
	int num_glyphs, i;
    CODE:
	num_glyphs = items - 1;
799
	Newz (0, glyphs, num_glyphs, cairo_glyph_t);
800 801 802 803
	for (i = 1; i < items; i++)
		glyphs[i - 1] = *SvCairoGlyph (ST (i));
	cairo_glyph_extents (cr, glyphs, num_glyphs, &extents);
	RETVAL = &extents;
804
	Safefree (glyphs);
805 806
    OUTPUT:
	RETVAL
x-rwmcfa1's avatar
x-rwmcfa1 committed
807

808
void cairo_text_path  (cairo_t * cr, const char_utf8 * utf8);
x-rwmcfa1's avatar
x-rwmcfa1 committed
809

810 811 812 813 814 815 816
##void cairo_glyph_path (cairo_t * cr, cairo_glyph_t * glyphs, int num_glyphs);
void cairo_glyph_path (cairo_t * cr, ...)
    PREINIT:
	cairo_glyph_t * glyphs = NULL;
	int num_glyphs, i;
    CODE:
	num_glyphs = items - 1;
817
	Newz (0, glyphs, num_glyphs, cairo_glyph_t);
818 819 820
	for (i = 1; i < items; i++)
		glyphs[i - 1] = *SvCairoGlyph (ST (i));
	cairo_glyph_path (cr, glyphs, num_glyphs);
821
	Safefree (glyphs);
x-rwmcfa1's avatar
x-rwmcfa1 committed
822

823
cairo_operator_t cairo_get_operator (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
824

825
cairo_pattern_t * cairo_get_source (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
826

827
double cairo_get_tolerance (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
828

829 830
cairo_antialias_t cairo_get_antialias (cairo_t *cr);

Torsten Schönfeld's avatar
Torsten Schönfeld committed
831
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 6, 0)
832 833 834 835 836

cairo_bool_t cairo_has_current_point (cairo_t *cr);

#endif

837
void cairo_get_current_point (cairo_t *cr, OUTLIST double x, OUTLIST double y);
x-rwmcfa1's avatar
x-rwmcfa1 committed
838

839
cairo_fill_rule_t cairo_get_fill_rule (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
840

841
double cairo_get_line_width (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
842

843
cairo_line_cap_t cairo_get_line_cap (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
844

845
cairo_line_join_t cairo_get_line_join (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
846

847
double cairo_get_miter_limit (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
848

849
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 4, 0)
850

851 852
## int cairo_get_dash_count (cairo_t *cr);
## void cairo_get_dash (cairo_t *cr, double *dashes, double *offset);
853 854 855 856 857
void cairo_get_dash (cairo_t *cr)
    PREINIT:
	int count, i;
	double *dashes, offset;
    PPCODE:
858
	count = cairo_get_dash_count (cr);
859 860 861
	if (count == 0) {
		dashes = NULL;
	} else {
862
		New (0, dashes, count, double);
863 864 865
		if (!dashes)
			croak ("malloc failure for (%d) elements", count);
	}
866
	cairo_get_dash (cr, dashes, &offset);
867 868 869 870
	EXTEND (sp, count + 1);
	PUSHs (sv_2mortal (newSVnv (offset)));
	for (i = 0; i < count; i++)
		PUSHs (sv_2mortal (newSVnv (dashes[i])));
871
	Safefree (dashes);
872 873 874

#endif

875 876
##void cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix);
cairo_matrix_t * cairo_get_matrix (cairo_t *cr)
Torsten Schönfeld's avatar
Torsten Schönfeld committed
877 878
    PREINIT:
	cairo_matrix_t matrix;
x-rwmcfa1's avatar
x-rwmcfa1 committed
879
    CODE:
Torsten Schönfeld's avatar
Torsten Schönfeld committed
880
	cairo_get_matrix (cr, &matrix);
881
	RETVAL = cairo_perl_copy_matrix (&matrix);
x-rwmcfa1's avatar
x-rwmcfa1 committed
882 883
    OUTPUT:
	RETVAL
x-rwmcfa1's avatar
x-rwmcfa1 committed
884

885 886
cairo_surface_t * cairo_get_target (cairo_t *cr);

887 888
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)

Torsten Schönfeld's avatar
Torsten Schönfeld committed
889 890
cairo_surface_t * cairo_get_group_target (cairo_t *cr);

891 892
#endif

893
cairo_path_t * cairo_copy_path (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
894

895
cairo_path_t * cairo_copy_path_flat (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
896

897
void cairo_append_path (cairo_t *cr, cairo_path_t *path);
x-rwmcfa1's avatar
x-rwmcfa1 committed
898

899
cairo_status_t cairo_status (cairo_t *cr);
x-rwmcfa1's avatar
x-rwmcfa1 committed
900

901 902 903 904 905 906 907 908
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0)

void cairo_tag_begin (cairo_t * cr, const char_utf8 * tag_name, const char_utf8 * attributes);

void cairo_tag_end (cairo_t * cr, const char_utf8 * tag_name);

#endif

909
# --------------------------------------------------------------------------- #
x-rwmcfa1's avatar
x-rwmcfa1 committed
910

911 912 913 914
MODULE = Cairo	PACKAGE = Cairo	PREFIX = cairo_

bool
HAS_PS_SURFACE ()
x-rwmcfa1's avatar
x-rwmcfa1 committed
915
    CODE:
x-rwmcfa1's avatar
x-rwmcfa1 committed
916
#ifdef CAIRO_HAS_PS_SURFACE
917 918 919
	RETVAL = TRUE;
#else
	RETVAL = FALSE;
x-rwmcfa1's avatar
x-rwmcfa1 committed
920
#endif
921 922 923 924 925 926 927 928 929 930
    OUTPUT:
	RETVAL

bool
HAS_PDF_SURFACE ()
    CODE:
#ifdef CAIRO_HAS_PDF_SURFACE
	RETVAL = TRUE;
#else
	RETVAL = FALSE;
x-rwmcfa1's avatar
x-rwmcfa1 committed
931
#endif
932 933 934 935
    OUTPUT:
	RETVAL

bool
936
HAS_SVG_SURFACE ()
937
    CODE:
938
#ifdef CAIRO_HAS_SVG_SURFACE
939 940 941
	RETVAL = TRUE;
#else
	RETVAL = FALSE;
x-rwmcfa1's avatar
x-rwmcfa1 committed
942
#endif
943 944 945
    OUTPUT:
	RETVAL

946 947 948 949 950 951 952 953 954 955 956
bool
HAS_RECORDING_SURFACE ()
    CODE:
#ifdef CAIRO_HAS_RECORDING_SURFACE
	RETVAL = TRUE;
#else
	RETVAL = FALSE;
#endif
    OUTPUT:
	RETVAL

957 958 959 960 961 962 963 964 965 966 967
bool
HAS_FT_FONT ()
    CODE:
#ifdef CAIRO_HAS_FT_FONT
	RETVAL = TRUE;
#else
	RETVAL = FALSE;
#endif
    OUTPUT:
	RETVAL

968 969 970 971 972 973 974
bool
HAS_PNG_FUNCTIONS ()
    CODE:
#ifdef CAIRO_HAS_PNG_FUNCTIONS
	RETVAL = TRUE;
#else
	RETVAL = FALSE;
x-rwmcfa1's avatar
x-rwmcfa1 committed
975
#endif
976 977
    OUTPUT:
	RETVAL