Cairo.pm 27.1 KB
Newer Older
1
#
2
# Copyright (c) 2004-2012 by the cairo perl team (see the file README)
3 4 5
#
# Licensed under the LGPL, see LICENSE file for more information.
#
6
# $Id$
7 8 9 10 11 12 13 14 15 16
#

package Cairo;

use strict;
use warnings;
use DynaLoader;

our @ISA = qw/DynaLoader/;

17
our $VERSION = '1.090';
18 19 20 21 22

sub dl_load_flags { $^O eq 'darwin' ? 0x00 : 0x01 }

Cairo->bootstrap ($VERSION);

23 24 25 26 27 28 29 30 31 32 33
# Our Cairo::VERSION used to be a simple wrapper around CAIRO_VERSION.  But a
# package's VERSION sub is supposed to do Perl version checking so that things
# like 'use Cairo 1.00' work.  To not break backwards-compatibility, we
# dispatch according to the number of arguments passed in.
sub VERSION {
  if (scalar @_ == 2) {
    shift->SUPER::VERSION (@_);
  } else {
    Cairo::LIB_VERSION (@_);
  }
}
34 35 36 37 38 39 40

1;

__END__

=head1 NAME

41
Cairo - Perl interface to the cairo 2d vector graphics library
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

=head1 SYNOPSIS

  use Cairo;

  my $surface = Cairo::ImageSurface->create ('argb32', 100, 100);
  my $cr = Cairo::Context->create ($surface);

  $cr->rectangle (10, 10, 40, 40);
  $cr->set_source_rgb (0, 0, 0);
  $cr->fill;

  $cr->rectangle (50, 50, 40, 40);
  $cr->set_source_rgb (1, 1, 1);
  $cr->fill;

  $cr->show_page;

  $surface->write_to_png ('output.png');

=head1 ABSTRACT

Cairo provides Perl bindings for the vector graphics library cairo.  It
supports multiple output targets, including PNG, PDF and SVG.  Cairo produces
identical output on all those targets.

=head1 API DOCUMENTATION

70 71
This is a listing of the API Cairo provides.  For more verbose information,
refer to the cairo manual at L<http://cairographics.org/manual/>.
72 73 74 75 76 77 78 79

=head2 Drawing

=head3 Cairo::Context -- The cairo drawing context

I<Cairo::Context> is the main object used when drawing with Cairo. To draw with
Cairo, you create a I<Cairo::Context>, set the target surface, and drawing
options for the I<Cairo::Context>, create shapes with methods like
80
C<$cr-E<gt>move_to> and C<$cr-E<gt>line_to>, and then draw shapes with
81 82 83 84 85
C<$cr-E<gt>stroke> or C<$cr-E<gt>fill>.

I<Cairo::Context>'s can be pushed to a stack via C<$cr-E<gt>save>. They may
then safely be changed, without loosing the current state. Use
C<$cr-E<gt>restore> to restore to the saved state.
86

87 88
=over

89
=item $cr = Cairo::Context->create ($surface)
90 91 92 93 94 95 96

=over

=item $surface: I<Cairo::Surface>

=back

97
=item $cr-E<gt>save
98

99
=item $cr->restore
100

101
=item $status = $cr->status
102

103
=item $surface = $cr->get_target
104

105
=item $cr->push_group [1.2]
106

107
=item $cr->push_group_with_content ($content) [1.2]
108 109 110 111 112 113 114

=over

=item $content: I<Cairo::Content>

=back

115
=item $pattern = $cr->pop_group [1.2]
116

117
=item $cr->pop_group_to_source [1.2]
118

119
=item $surface = $cr->get_group_target [1.2]
120

121
=item $cr->set_source_rgb ($red, $green, $blue)
122 123 124 125 126 127 128 129 130 131 132

=over

=item $red: double

=item $green: double

=item $blue: double

=back

133
=item $cr->set_source_rgba ($red, $green, $blue, $alpha)
134 135 136 137 138 139 140 141 142 143 144 145 146

=over

=item $red: double

=item $green: double

=item $blue: double

=item $alpha: double

=back

147
=item $cr->set_source ($source)
148 149 150 151 152 153 154

=over

=item $source: I<Cairo::Pattern>

=back

155
=item $cr->set_source_surface ($surface, $x, $y)
156 157 158 159 160 161 162 163 164 165 166

=over

=item $surface: I<Cairo::Surface>

=item $x: double

=item $y: double

=back

167
=item $source = $cr->get_source
168

169
=item $cr->set_antialias ($antialias)
170 171 172 173 174 175 176

=over

=item $antialias: I<Cairo::Antialias>

=back

177
=item $antialias = $cr->get_antialias
178

179
=item $cr->set_dash ($offset, ...)
180 181 182 183 184 185 186 187 188

=over

=item $offset: double

=item ...: list of doubles

=back

189
=item $cr->set_fill_rule ($fill_rule)
190 191 192 193 194 195 196

=over

=item $fill_rule: I<Cairo::FillRule>

=back

197
=item $fill_rule = $cr->get_fill_rule
198

199
=item $cr->set_line_cap ($line_cap)
200 201 202 203 204 205 206

=over

=item $line_cap: I<Cairo::LineCap>

=back

207
=item $line_cap = $cr->get_line_cap
208

209
=item $cr->set_line_join ($line_join)
210 211 212 213 214 215 216

=over

=item $line_join: I<Cairo::LineJoin>

=back

217
=item $line_join = $cr->get_line_join
218

219
=item $cr->set_line_width ($width)
220 221 222 223 224 225 226

=over

=item $width: double

=back

227
=item $width = $cr->get_line_width
228

229
=item $cr->set_miter_limit ($limit)
230 231 232 233 234 235 236

=over

=item $limit: double

=back

237
=item ($offset, @dashes) = $cr->get_dash [1.4]
238

239
=item $limit = $cr->get_miter_limit
240

241
=item $cr->set_operator ($op)
242 243 244 245 246 247 248

=over

=item $op: I<Cairo::Operator>

=back

249
=item $op = $cr->get_operator
250

251
=item $cr->set_tolerance ($tolerance)
252 253 254 255 256 257 258

=over

=item $tolerance: double

=back

259
=item $tolerance = $cr->get_tolerance
260

261
=item $cr->clip
262

263
=item $cr->clip_preserve
264

265
=item ($x1, $y1, $x2, $y2) = $cr->clip_extents [1.4]
266

267 268 269 270 271 272 273 274 275 276
=item $bool = $cr->in_clip ($x, $y) [1.10]

=over

=item $x: double

=item $y: double

=back

277
=item @rectangles = $cr->copy_clip_rectangle_list [1.4]
278

279
=item $cr->reset_clip
280

281
=item $cr->fill
282

283
=item $cr->fill_preserve
284

285
=item ($x1, $y1, $x2, $y2) = $cr->fill_extents
286

287
=item $bool = $cr->in_fill ($x, $y)
288 289 290 291 292 293 294 295 296

=over

=item $x: double

=item $y: double

=back

297
=item $cr->mask ($pattern)
298 299 300 301 302 303 304

=over

=item $pattern: I<Cairo::Pattern>

=back

305
=item $cr->mask_surface ($surface, $surface_x, $surface_y)
306 307 308 309 310 311 312 313 314 315 316

=over

=item $surface: I<Cairo::Surface>

=item $surface_x: double

=item $surface_y: double

=back

317
=item $cr->paint
318

319
=item $cr->paint_with_alpha ($alpha)
320 321 322 323 324 325 326

=over

=item $alpha: double

=back

327
=item $cr->stroke
328

329
=item $cr->stroke_preserve
330

331
=item ($x1, $y1, $x2, $y2) = $cr->stroke_extents
332

333
=item $bool = $cr->in_stroke ($x, $y)
334 335 336 337 338 339 340 341 342

=over

=item $x: double

=item $y: double

=back

343 344 345
=item $cr->copy_page

=item $cr->show_page
346

347
=back
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363

=cut

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

=head3 Paths -- Creating paths and manipulating path data

  $path = [
    { type => "move-to", points => [[1, 2]] },
    { type => "line-to", points => [[3, 4]] },
    { type => "curve-to", points => [[5, 6], [7, 8], [9, 10]] },
    ...
    { type => "close-path", points => [] },
  ];

I<Cairo::Path> is a data structure for holding a path. This data structure
364 365
serves as the return value for C<$cr-E<gt>copy_path> and
C<$cr-E<gt>copy_path_flat> as well the input value for
366 367 368 369 370 371 372 373 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
C<$cr-E<gt>append_path>.

I<Cairo::Path> is represented as an array reference that contains path
elements, represented by hash references with two keys: I<type> and I<points>.
The value for I<type> can be either of the following:

=over

=item C<move-to>

=item C<line-to>

=item C<curve-to>

=item C<close-path>

=back

The value for I<points> is an array reference which contains zero or more
points.  Points are represented as array references that contain two doubles:
I<x> and I<y>.  The necessary number of points depends on the I<type> of the
path element:

=over

=item C<move-to>: 1 point

=item C<line_to>: 1 point

=item C<curve-to>: 3 points

=item C<close-path>: 0 points

=back

The semantics and ordering of the coordinate values are consistent with
C<$cr-E<gt>move_to>, C<$cr-E<gt>line_to>, C<$cr-E<gt>curve_to>, and
C<$cr-E<gt>close_path>.

405 406 407 408 409 410 411 412 413 414 415 416
Note that the paths returned by Cairo are implemented as tied array references
which do B<not> support adding, removing or shuffling of path segments.  For
these operations, you need to make a shallow copy first:

  my @path_clone = @{$path};
  # now you can alter @path_clone which ever way you want

The points of a single path element can be changed directly, however, without
the need for a shallow copy:

  $path->[$i]{points} = [[3, 4], [5, 6], [7, 8]];

417 418 419
=over

=item $path = $cr->copy_path
420

421
=item $path = $cr->copy_path_flat
422

423
=item $cr->append_path ($path)
424 425 426 427 428 429 430

=over

=item $path: I<Cairo::Path>

=back

431
=item $bool = $cr->has_current_point [1.6]
432

433
=item ($x, $y) = $cr->get_current_point
434

435
=item $cr->new_path
436

437
=item $cr->new_sub_path [1.2]
438

439
=item $cr->close_path
440

441
=item ($x1, $y1, $x2, $y2) = $cr->path_extents [1.6]
442

443
=item $cr->arc ($xc, $yc, $radius, $angle1, $angle2)
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458

=over

=item $xc: double

=item $yc: double

=item $radius: double

=item $angle1: double

=item $angle2: double

=back

459
=item $cr->arc_negative ($xc, $yc, $radius, $angle1, $angle2)
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474

=over

=item $xc: double

=item $yc: double

=item $radius: double

=item $angle1: double

=item $angle2: double

=back

475
=item $cr->curve_to ($x1, $y1, $x2, $y2, $x3, $y3)
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492

=over

=item $x1: double

=item $y1: double

=item $x2: double

=item $y2: double

=item $x3: double

=item $y3: double

=back

493
=item $cr->line_to ($x, $y)
494 495 496 497 498 499 500 501 502

=over

=item $x: double

=item $y: double

=back

503
=item $cr->move_to ($x, $y)
504 505 506 507 508 509 510 511 512

=over

=item $x: double

=item $y: double

=back

513
=item $cr->rectangle ($x, $y, $width, $height)
514 515 516 517 518 519 520 521 522 523 524 525 526

=over

=item $x: double

=item $y: double

=item $width: double

=item $height: double

=back

527
=item $cr->glyph_path (...)
528 529 530 531 532 533 534

=over

=item ...: list of I<Cairo::Glyph>'s

=back

535
=item $cr->text_path ($utf8)
536 537 538 539 540 541 542

=over

=item $utf8: string in utf8 encoding

=back

543
=item $cr->rel_curve_to ($dx1, $dy1, $dx2, $dy2, $dx3, $dy3)
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560

=over

=item $dx1: double

=item $dy1: double

=item $dx2: double

=item $dy2: double

=item $dx3: double

=item $dy3: double

=back

561
=item $cr->rel_line_to ($dx, $dy)
562 563 564 565 566 567 568 569 570

=over

=item $dx: double

=item $dy: double

=back

571
=item $cr->rel_move_to ($dx, $dy)
572 573 574 575 576 577 578 579 580

=over

=item $dx: double

=item $dy: double

=back

581 582
=back

583 584 585 586 587 588
=cut

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

=head3 Patterns -- Gradients and filtered sources

589 590 591
=over

=item $status = $pattern->status
592

593
=item $type = $pattern->get_type [1.2]
594

595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
=item $pattern->set_extend ($extend)

=over

=item $extend: I<Cairo::Extend>

=back

=item $extend = $pattern->get_extend

=item $pattern->set_filter ($filter)

=over

=item $filter: I<Cairo::Filter>

=back

=item $filter = $pattern->get_filter

615
=item $pattern->set_matrix ($matrix)
616 617 618 619 620 621 622

=over

=item $matrix: I<Cairo::Matrix>

=back

623
=item $matrix = $pattern->get_matrix
624

625
=item $pattern = Cairo::SolidPattern->create_rgb ($red, $green, $blue)
626 627 628 629 630 631 632 633 634 635 636

=over

=item $red: double

=item $green: double

=item $blue: double

=back

637
=item $pattern = Cairo::SolidPattern->create_rgba ($red, $green, $blue, $alpha)
638 639 640 641 642 643 644 645 646 647 648 649 650

=over

=item $red: double

=item $green: double

=item $blue: double

=item $alpha: double

=back

651
=item ($r, $g, $b, $a) = $pattern->get_rgba [1.4]
652

653
=item $pattern = Cairo::SurfacePattern->create ($surface)
654 655 656 657 658 659 660

=over

=item $surface: I<Cairo::Surface>

=back

661
=item $surface = $pattern->get_surface [1.4]
662

663
=item $pattern = Cairo::LinearGradient->create ($x0, $y0, $x1, $y1)
664 665 666 667 668 669 670 671 672 673 674 675 676

=over

=item $x0: double

=item $y0: double

=item $x1: double

=item $y1: double

=back

677
=item ($x0, $y0, $x1, $y1) = $pattern->get_points [1.4]
678

679
=item $pattern = Cairo::RadialGradient->create ($cx0, $cy0, $radius0, $cx1, $cy1, $radius1)
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696

=over

=item $cx0: double

=item $cy0: double

=item $radius0: double

=item $cx1: double

=item $cy1: double

=item $radius1: double

=back

697
=item ($x0, $y0, $r0, $x1, $y1, $r1) = $pattern->get_circles [1.4]
698

699
=item $pattern->add_color_stop_rgb ($offset, $red, $green, $blue)
700 701 702 703 704 705 706 707 708 709 710 711 712

=over

=item $offset: double

=item $red: double

=item $green: double

=item $blue: double

=back

713
=item $pattern->add_color_stop_rgba ($offset, $red, $green, $blue, $alpha)
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728

=over

=item $offset: double

=item $red: double

=item $green: double

=item $blue: double

=item $alpha: double

=back

729
=item @stops = $pattern->get_color_stops [1.4]
730 731 732 733

A color stop is represented as an array reference with five elements: offset,
red, green, blue, and alpha.

734 735
=back

736 737 738 739
=cut

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

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 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
=head3 Regions -- Representing a pixel-aligned area

=over

=item $region = Cairo::Region->create (...) [1.10]

=over

=item ...: zero or more I<Cairo::RectangleInt>

=back

=item $status = $region->status [1.10]

=item $num = $region->num_rectangles [1.10]

=item $rect = $region->get_rectangle ($i) [1.10]

=over

=item $i: integer

=back

=item $bool = $region->is_empty [1.10]

=item $bool = $region->contains_point ($x, $y) [1.10]

=over

=item $x: integer

=item $y: integer

=back

=item $bool = $region_one->equal ($region_two) [1.10]

=over

=item $region_two: I<Cairo::Region>

=back

=item $region->translate ($dx, $dy) [1.10]

=over

=item $dx: integer

=item $dy: integer

=back

=item $status = $dst->intersect ($other) [1.10]

=item $status = $dst->intersect_rectangle ($rect) [1.10]

=item $status = $dst->subtract ($other) [1.10]

=item $status = $dst->subtract_rectangle ($rect) [1.10]

=item $status = $dst->union ($other) [1.10]

=item $status = $dst->union_rectangle ($rect) [1.10]

=item $status = $dst->xor ($other) [1.10]

=item $status = $dst->xor_rectangle ($rect) [1.10]

=over

=item $other: I<Cairo::Region>

=item $rect: I<Cairo::RectangleInt>

=back

=back

=cut

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

824 825
=head3 Transformations -- Manipulating the current transformation matrix

826 827 828
=over

=item $cr->translate ($tx, $ty)
829 830 831 832 833 834 835 836 837

=over

=item $tx: double

=item $ty: double

=back

838
=item $cr->scale ($sx, $sy)
839 840 841 842 843 844 845 846 847

=over

=item $sx: double

=item $sy: double

=back

848
=item $cr->rotate ($angle)
849 850 851 852 853 854 855

=over

=item $angle: double

=back

856
=item $cr->transform ($matrix)
857 858 859 860 861 862 863

=over

=item $matrix: I<Cairo::Matrix>

=back

864
=item $cr->set_matrix ($matrix)
865 866 867 868 869 870 871

=over

=item $matrix: I<Cairo::Matrix>

=back

872
=item $matrix = $cr->get_matrix
873

874
=item $cr->identity_matrix
875

876
=item ($x, $y) = $cr->user_to_device ($x, $y)
877 878 879 880 881 882 883 884 885

=over

=item $x: double

=item $y: double

=back

886
=item ($dx, $dy) = $cr->user_to_device_distance ($dx, $dy)
887 888 889 890 891 892 893 894 895

=over

=item $dx: double

=item $dy: double

=back

896
=item ($x, $y) = $cr->device_to_user ($x, $y)
897 898 899 900 901 902 903 904 905

=over

=item $x: double

=item $y: double

=back

906
=item ($dx, $dy) = $cr->device_to_user_distance ($dx, $dy)
907 908 909 910 911 912 913 914 915

=over

=item $dx: double

=item $dy: double

=back

916 917
=back

918 919 920 921 922 923 924 925 926 927 928 929 930
=cut

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

=head3 Text -- Rendering text and sets of glyphs

Glyphs are represented as anonymous hash references with three keys: I<index>,
I<x> and I<y>.  Example:

  my @glyphs = ({ index => 1, x => 2, y => 3 },
                { index => 2, x => 3, y => 4 },
                { index => 3, x => 4, y => 5 });

931 932 933
=over

=item $cr->select_font_face ($family, $slant, $weight)
934 935 936 937 938 939 940 941 942 943 944

=over

=item $family: string

=item $slant: I<Cairo::FontSlant>

=item $weight: I<Cairo::FontWeight>

=back

945
=item $cr->set_font_size ($size)
946 947 948 949 950 951 952

=over

=item $size: double

=back

953
=item $cr->set_font_matrix ($matrix)
954 955 956 957 958 959 960

=over

=item $matrix: I<Cairo::Matrix>

=back

961
=item $matrix = $cr->get_font_matrix
962

963
=item $cr->set_font_options ($options)
964 965 966 967 968 969 970

=over

=item $options: I<Cairo::FontOptions>

=back

971
=item $options = $cr->get_font_options
972

973
=item $cr->set_scaled_font ($scaled_font) [1.2]
974 975 976 977 978 979 980

=over

=item $scaled_font: I<Cairo::ScaledFont>

=back

981
=item $scaled_font = $cr->get_scaled_font [1.4]
982

983
=item $cr->show_text ($utf8)
984 985 986 987 988 989 990

=over

=item $utf8: string

=back

991
=item $cr->show_glyphs (...)
992 993 994 995 996 997 998

=over

=item ...: list of glyphs

=back

999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
=item $cr->show_text_glyphs ($utf8, $glyphs, $clusters, $cluster_flags) [1.8]

=over

=item $utf8: string

=item $glyphs: array ref of glyphs

=item $clusters: array ref of clusters

=item $cluster_flags: I<Cairo::TextClusterFlags>

=back

1013
=item $face = $cr->get_font_face
1014

1015
=item $extents = $cr->font_extents
1016

1017
=item $cr->set_font_face ($font_face)
1018 1019 1020 1021 1022 1023 1024

=over

=item $font_face: I<Cairo::FontFace>

=back

1025
=item $cr->set_scaled_font ($scaled_font)
1026 1027 1028 1029 1030 1031 1032

=over

=item $scaled_font: I<Cairo::ScaledFont>

=back

1033
=item $extents = $cr->text_extents ($utf8)
1034 1035 1036 1037 1038 1039 1040

=over

=item $utf8: string

=back

1041
=item $extents = $cr->glyph_extents (...)
1042 1043 1044 1045 1046 1047 1048

=over

=item ...: list of glyphs

=back

1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
=item $face = Cairo::ToyFontFace->create ($family, $slant, $weight) [1.8]

=over

=item $family: string

=item $slant: I<Cairo::FontSlant>

=item $weight: I<Cairo::FontWeight>

=back

=item $family = $face->get_family [1.8]

=item $slang = $face->get_slant [1.8]

=item $weight = $face->get_weight [1.8]

1067 1068
=back

1069 1070 1071 1072 1073 1074 1075 1076
=cut

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

=head2 Fonts

=head3 Cairo::FontFace -- Base class for fonts

1077 1078 1079 1080 1081
=over

=item $status = $font_face->status

=item $type = $font_face->get_type [1.2]
1082

1083
=back
1084 1085 1086 1087 1088 1089 1090

=cut

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

=head3 Scaled Fonts -- Caching metrics for a particular font size

1091 1092 1093
=over

=item $scaled_font = Cairo::ScaledFont->create ($font_face, $font_matrix, $ctm, $options)
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106

=over

=item $font_face: I<Cairo::FontFace>

=item $font_matrix: I<Cairo::Matrix>

=item $ctm: I<Cairo::Matrix>

=item $options: I<Cairo::FontOptions>

=back

1107
=item $status = $scaled_font->status
1108

1109
=item $extents = $scaled_font->extents
1110

1111
=item $extents = $scaled_font->text_extents ($utf8) [1.2]
1112 1113 1114 1115 1116 1117 1118

=over

=item $utf8: string

=back

1119
=item $extents = $scaled_font->glyph_extents (...)
1120 1121 1122 1123 1124 1125 1126

=over

=item ...: list of glyphs

=back

1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
=item ($status, $glyphs, $clusters, $cluster_flags) = $scaled_font->text_to_glyphs ($x, $y, $utf8) [1.8]

=over

=item $x: double

=item $y: double

=item $utf8: string

=back

1139 1140 1141
=item $font_face = $scaled_font->get_font_face [1.2]

=item $options = $scaled_font->get_font_options [1.2]
1142

1143
=item $font_matrix = $scaled_font->get_font_matrix [1.2]
1144

1145
=item $ctm = $scaled_font->get_ctm [1.2]
1146

1147 1148
=item $scale_matrix = $scaled_font->get_scale_matrix [1.8]

1149
=item $type = $scaled_font->get_type [1.2]
1150

1151
=back
1152 1153 1154 1155 1156 1157 1158

=cut

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

=head3 Font Options -- How a font should be rendered

1159 1160 1161
=over

=item $font_options = Cairo::FontOptions->create
1162

1163
=item $status = $font_options->status
1164

1165
=item $font_options->merge ($other)
1166 1167 1168 1169 1170 1171 1172

=over

=item $other: I<Cairo::FontOptions>

=back

1173
=item $hash = $font_options->hash
1174

1175
=item $bools = $font_options->equal ($other)
1176 1177 1178 1179 1180 1181 1182

=over

=item $other: I<Cairo::FontOptions>

=back

1183
=item $font_options->set_antialias ($antialias)
1184 1185 1186 1187 1188 1189 1190

=over

=item $antialias: I<Cairo::AntiAlias>

=back

1191
=item $antialias = $font_options->get_antialias
1192

1193
=item $font_options->set_subpixel_order ($subpixel_order)
1194 1195 1196 1197 1198 1199 1200

=over

=item $subpixel_order: I<Cairo::SubpixelOrder>

=back

1201
=item $subpixel_order = $font_options->get_subpixel_order
1202

1203
=item $font_options->set_hint_style ($hint_style)
1204 1205 1206 1207 1208 1209 1210

=over

=item $hint_style: I<Cairo::HintStyle>

=back

1211
=item $hint_style = $font_options->get_hint_style
1212

1213
=item $font_options->set_hint_metrics ($hint_metrics)
1214 1215 1216 1217 1218 1219 1220

=over

=item $hint_metrics: I<Cairo::HintMetrics>

=back

1221 1222 1223
=item $hint_metrics = $font_options->get_hint_metrics

=back
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235

=cut

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

=head3 FreeType Fonts -- Font support for FreeType

If your cairo library supports it, the FreeType integration allows you to load
font faces from font files.  You can query for this capability with
C<Cairo::HAS_FT_FONT>.  To actually use this, you'll need the L<Font::FreeType>
module.

1236 1237 1238
=over

=item my $face = Cairo::FtFontFace->create ($ft_face, $load_flags=0)
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255

=over

=item $ft_face: I<Font::FreeType::Face>

=item $load_flags: integer

=back

This method allows you to create a I<Cairo::FontFace> from a
I<Font::FreeType::Face>.  To obtain the latter, you can for example load it
from a file:

  my $file = '/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf';
  my $ft_face = Font::FreeType->new->face ($file);
  my $face = Cairo::FtFontFace->create ($ft_face);

1256 1257
=back

1258 1259 1260 1261 1262 1263 1264 1265
=cut

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

=head2 Surfaces

=head3 I<Cairo::Surface> -- Base class for surfaces

1266 1267
=over

1268
=item $similar = Cairo::Surface->create_similar ($other, $content, $width, $height)
1269 1270 1271

=over

1272 1273
=item $other: I<Cairo::Surface>

1274 1275 1276 1277 1278 1279 1280 1281
=item $content: I<Cairo::Content>

=item $width: integer

=item $height: integer

=back

1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
For hysterical reasons, you can also use the following syntax:

  $similar = $other->create_similar ($content, $width, $height)

=item $new = Cairo::Surface->create_for_rectangle ($target, $x, $y, $width, $height) [1.10]

=over

=item $target: I<Cairo::Surface>

=item $x: double

=item $y: double

=item $width: double

=item $height: double

=back

1302
=item $status = $surface->status
1303

1304
=item $surface->finish
1305

1306
=item $surface->flush
1307

1308
=item $font_options = $surface->get_font_options
1309

1310
=item $content = $surface->get_content [1.2]
1311

1312
=item $surface->mark_dirty
1313

1314
=item $surface->mark_dirty_rectangle ($x, $y, $width, $height)
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327

=over

=item $x: integer

=item $y: integer

=item $width: integer

=item $height: integer

=back

1328
=item $surface->set_device_offset ($x_offset, $y_offset)
1329 1330 1331 1332 1333 1334 1335 1336 1337

=over

=item $x_offset: integer

=item $y_offset: integer

=back

1338
=item ($x_offset, $y_offset) = $surface->get_device_offset [1.2]
1339

1340
=item $surface->set_fallback_resolution ($x_pixels_per_inch, $y_pixels_per_inch) [1.2]
1341 1342 1343 1344 1345 1346 1347 1348 1349

=over

=item $x_pixels_per_inch: double

=item $y_pixels_per_inch: double

=back

1350 1351
=item ($x_pixels_per_inch, $y_pixels_per_inch) = $surface->get_fallback_resolution [1.8]

1352
=item $type = $surface->get_type [1.2]
1353

1354
=item $status = $surface->copy_page [1.6]
1355 1356 1357 1358 1359 1360 1361

=over

=item $status: I<Cairo::Status>

=back

1362
=item $status = $surface->show_page [1.6]
1363 1364 1365 1366 1367 1368 1369

=over

=item $status: I<Cairo::Status>

=back

1370 1371
=item $boolean = $surface->has_show_text_glyphs [1.8]

1372 1373
=back

1374 1375 1376 1377 1378 1379
=cut

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

=head3 Image Surfaces -- Rendering to memory buffers

1380 1381 1382
=over

=item $surface = Cairo::ImageSurface->create ($format, $width, $height)
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393

=over

=item $format: I<Cairo::Format>

=item $width: integer

=item $height: integer

=back

1394
=item $surface = Cairo::ImageSurface->create_for_data ($data, $format, $width, $height, $stride)
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409

=over

=item $data: image data

=item $format: I<Cairo::Format>

=item $width: integer

=item $height: integer

=item $stride: integer

=back

1410 1411 1412
=item $data = $surface->get_data [1.2]

=item $format = $surface->get_format [1.2]
1413

1414
=item $width = $surface->get_width
1415

1416
=item $height = $surface->get_height
1417

1418
=item $stride = $surface->get_stride [1.2]
1419

1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
=item $stride = Cairo::Format::stride_for_width ($format, $width) [1.6]

=over

=item $format: I<Cairo::Format>

=item $width: integer

=back

1430
=back
1431 1432 1433 1434 1435 1436 1437

=cut

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

=head3 PDF Surfaces -- Rendering PDF documents

1438 1439 1440
=over

=item $surface = Cairo::PdfSurface->create ($filename, $width_in_points, $height_in_points) [1.2]
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451

=over

=item $filename: string

=item $width_in_points: double

=item $height_in_points: double

=back

1452
=item $surface = Cairo::PdfSurface->create_for_stream ($callback, $callback_data, $width_in_points, $height_in_points) [1.2]
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465

=over

=item $callback: L<Cairo::WriteFunc>

=item $callback_data: scalar

=item $width_in_points: double

=item $height_in_points: double

=back

1466
=item $surface->set_size ($width_in_points, $height_in_points) [1.2]
1467 1468 1469 1470 1471 1472 1473 1474 1475

=over

=item $width_in_points: double

=item $height_in_points: double

=back

1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493
=item $surface->restrict_to_version ($version) [1.10]

=over

=item $version: I<Cairo::PdfVersion>

=back

=item @versions = Cairo::PdfSurface::get_versions [1.10]

=item $string = Cairo::PdfSurface::version_to_string ($version) [1.10]

=over

=item $version: I<Cairo::PdfVersion>

=back

1494 1495
=back

1496 1497 1498 1499 1500 1501
=cut

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

=head3 PNG Support -- Reading and writing PNG images

1502 1503 1504
=over

=item $surface = Cairo::ImageSurface->create_from_png ($filename)
1505 1506 1507 1508 1509 1510 1511

=over

=item $filename: string

=back

1512
=item Cairo::ReadFunc: $data = sub { my ($callback_data, $length) = @_; }
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523

=over

=item $data: binary image data, of length $length

=item $callback_data: scalar, user data

=item $length: integer, bytes to read

=back

1524
=item $surface = Cairo::ImageSurface->create_from_png_stream ($callback, $callback_data)
1525 1526 1527 1528 1529 1530 1531 1532 1533

=over

=item $callback: L<Cairo::ReadFunc>

=item $callback_data: scalar

=back

1534
=item $status = $surface->write_to_png ($filename)
1535 1536 1537 1538 1539 1540 1541

=over

=item $filename: string

=back

1542
=item Cairo::WriteFunc: sub { my ($callback_data, $data) = @_; }
1543 1544 1545 1546 1547 1548 1549 1550 1551

=over

=item $callback_data: scalar, user data

=item $data: binary image data, to be written

=back

1552
=item $status = $surface->write_to_png_stream ($callback, $callback_data)
1553 1554 1555 1556 1557 1558 1559 1560 1561

=over

=item $callback: L<Cairo::WriteFunc>

=item $callback_data: scalar

=back

1562 1563
=back

1564 1565 1566 1567 1568 1569
=cut

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

=head3 PostScript Surfaces -- Rendering PostScript documents

1570 1571 1572
=over

=item $surface = Cairo::PsSurface->create ($filename, $width_in_points, $height_in_points) [1.2]
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583

=over

=item $filename: string

=item $width_in_points: double

=item $height_in_points: double

=back

1584
=item $surface = Cairo::PsSurface->create_for_stream ($callback, $callback_data, $width_in_points, $height_in_points) [1.2]
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597

=over

=item $callback: L<Cairo::WriteFunc>

=item $callback_data: scalar

=item $width_in_points: double

=item $height_in_points: double

=back

1598
=item $surface->set_size ($width_in_points, $height_in_points) [1.2]
1599 1600 1601 1602 1603 1604 1605 1606 1607

=over

=item $width_in_points: double

=item $height_in_points: double

=back

1608
=item $surface->dsc_begin_setup [1.2]
1609

1610
=item $surface->dsc_begin_page_setup [1.2]
1611

1612
=item $surface->dsc_comment ($comment) [1.2]
1613 1614 1615 1616 1617 1618 1619

=over

=item $comment: string

=back

1620
=item $surface->restrict_to_level ($level) [1.6]
1621 1622 1623 1624 1625 1626 1627

=over

=item $level: I<Cairo::PsLevel>

=back

1628
=item @levels = Cairo::PsSurface::get_levels [1.6]
1629

1630
=item $string = Cairo::PsSurface::level_to_string ($level) [1.6]
1631 1632 1633 1634 1635 1636 1637

=over

=item $level: I<Cairo::PsLevel>

=back

1638
=item $surface->set_eps ($eps) [1.6]
1639 1640 1641 1642 1643 1644 1645

=over

=item $eps: boolean

=back

1646 1647 1648
=item $eps = $surface->get_eps [1.6]

=back
1649 1650 1651 1652 1653

=cut

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

1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
=head3 Recording Surfaces -- Records all drawing operations

=over

=item $surface = Cairo::RecordingSurface->create ($content, $extents) [1.10]

=over

=item $content: I<Cairo::Content>

=item $extents: I<Cairo::Rectangle>

=back

=item ($x0, $y0, $width, $height) = $surface->ink_extents [1.10]

=back

=cut

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

1676 1677
=head3 SVG Surfaces -- Rendering SVG documents

1678 1679 1680
=over

=item $surface = Cairo::SvgSurface->create ($filename, $width_in_points, $height_in_points) [1.2]
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691

=over

=item $filename: string

=item $width_in_points: double

=item $height_in_points: double

=back

1692
=item $surface = Cairo::SvgSurface->create_for_stream ($callback, $callback_data, $width_in_points, $height_in_points) [1.2]
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705

=over

=item $callback: L<Cairo::WriteFunc>

=item $callback_data: scalar

=item $width_in_points: double

=item $height_in_points: double

=back

1706
=item $surface->restrict_to_version ($version) [1.2]
1707 1708 1709 1710 1711 1712 1713

=over

=item $version: I<Cairo::SvgVersion>

=back

1714
=item @versions = Cairo::SvgSurface::get_versions [1.2]
1715

1716
=item $string = Cairo::SvgSurface::version_to_string ($version) [1.2]
1717 1718 1719 1720 1721 1722 1723

=over

=item $version: I<Cairo::SvgVersion>

=back

1724 1725
=back

1726 1727 1728 1729 1730 1731 1732 1733
=cut

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

=head2 Utilities

=head3 Version Information -- Run-time and compile-time version checks.

1734
=over
1735

1736 1737 1738 1739 1740 1741
=item $version_code = Cairo->lib_version

=item $version_string = Cairo->lib_version_string

These two functions return the version of libcairo that the program is
currently running against.
1742

1743
=item $version_code = Cairo->LIB_VERSION
1744

1745
Returns the version of libcairo that L<Cairo> was compiled against.
1746

1747
=item $version_code = Cairo->LIB_VERSION_ENCODE ($major, $minor, $micro)
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758

=over

=item $major: integer

=item $minor: integer

=item $micro: integer

=back

1759 1760
Encodes the version C<$major.$minor.$micro> as an integer suitable for
comparison against C<< Cairo->lib_version >> and C<< Cairo->LIB_VERSION >>.
1761

1762 1763
=back

1764 1765 1766 1767 1768 1769 1770 1771
=cut

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

=head1 SEE ALSO

=over

1772
=item L<http://cairographics.org/documentation>
1773 1774 1775

Lists many available resources including tutorials and examples

1776
=item L<http://cairographics.org/manual/>
1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793

Contains the reference manual

=back

=head1 AUTHORS

=over

=item Ross McFarland E<lt>rwmcfa1 at neces dot comE<gt>

=item Torsten Schoenfeld E<lt>kaffeetisch at gmx dot deE<gt>

=back

=head1 COPYRIGHT

1794
Copyright (C) 2004-2011 by the cairo perl team
1795 1796

=cut