Cairo - Perl interface to the cairo library
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");
Cairo::Context is the main object used when drawing with Cairo. To draw with Cairo, you create a Cairo::Context, set the target surface, and drawing options for the Cairo::Context, create shapes with methods like "$cr-"move_to> and "$cr->line_to", and then draw shapes with "$cr->stroke" or "$cr->fill".
Cairo::Context's can be pushed to a stack via "$cr->save". They may then safely be changed, without loosing the current state. Use "$cr->restore" to restore to the saved state. =over
$cr = Cairo::Context->create ($surface)
$cr->push_group_with_content ($content) [1.2]
$pattern = $cr->pop_group [1.2]
$cr->pop_group_to_source [1.2]
$surface = $cr->get_group_target [1.2]
$cr->set_source_rgb ($red, $green, $blue)
$cr->set_source_rgba ($red, $green, $blue, $alpha)
$cr->set_source_surface ($surface, $x, $y)
$cr->set_antialias ($antialias)
$antialias = $cr->get_antialias
$cr->set_fill_rule ($fill_rule)
$fill_rule = $cr->get_fill_rule
$cr->set_line_join ($line_join)
$line_join = $cr->get_line_join
($offset, @dashes) = $cr->get_dash [1.4]
$cr->set_tolerance ($tolerance)
$tolerance = $cr->get_tolerance
($x1, $y1, $x2, $y2) = $cr->clip_extents [1.4]
@rectangles = $cr->copy_clip_rectangle_list [1.4]
($x1, $y1, $x2, $y2) = $cr->fill_extents
$cr->mask_surface ($surface, $surface_x, $surface_y)
$cr->paint_with_alpha ($alpha)
($x1, $y1, $x2, $y2) = $cr->stroke_extents
$bool = $cr->in_stroke ($x, $y)
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 => [] }, ];
Cairo::Path is a data structure for holding a path. This data structure serves as the return value for "$cr->copy_path_data" and "$cr->copy_path_data_flat" as well the input value for "$cr->append_path".
Cairo::Path is represented as an array reference that contains path elements, represented by hash references with two keys: type and points. The value for type can be either of the following:
The value for points is an array reference which contains zero or more points. Points are represented as array references that contain two doubles: x and y. The necessary number of points depends on the type of the path element:
The semantics and ordering of the coordinate values are consistent with "$cr->move_to", "$cr->line_to", "$cr->curve_to", and "$cr->close_path".
($x, $y) = $cr->get_current_point
$cr->arc ($xc, $yc, $radius, $angle1, $angle2)
$cr->arc_negative ($xc, $yc, $radius, $angle1, $angle2)
$cr->curve_to ($x1, $y1, $x2, $y2, $x3, $y3)
$cr->rectangle ($x, $y, $width, $height)
$cr->rel_curve_to ($dx1, $dy1, $dx2, $dy2, $dx3, $dy3)
Patterns --- Gradients and filtered sources
$type = $pattern->get_type [1.2]
$pattern->set_matrix ($matrix)
$matrix = $pattern->get_matrix
$pattern = Cairo::SolidPattern->create_rgb ($red, $green, $blue)
$pattern = Cairo::SolidPattern->create_rgba ($red, $green, $blue, $alpha)
($r, $g, $b, $a) = $pattern->get_rgba [1.4]
$pattern = Cairo::SurfacePattern->create ($surface)
$pattern->set_extend ($extend)
$extend = $pattern->get_extend
$pattern->set_filter ($filter)
$filter = $pattern->get_filter
$surface = $pattern->get_surface [1.4]
$pattern = Cairo::LinearGradient->create ($x0, $y0, $x1, $y1)
($x0, $y0, $x1, $y1) = $pattern->get_points [1.4]
$pattern = Cairo::RadialGradient->create ($cx0, $cy0, $radius0, $cx1, $cy1, $radius1)
($x0, $y0, $r0, $x1, $y1, $r1) = $pattern->get_circles [1.4]
$pattern->add_color_stop_rgb (double offset, double red, double green, double blue)
$pattern->add_color_stop_rgba (double offset, double red, double green, double blue, double alpha)
@stops = $pattern->get_color_stops [1.4]
A color stop is represented as an array reference with five elements: offset, red, green, blue, and alpha.
Transformations --- Manipulating the current transformation matrix
($x, $y) = $cr->user_to_device ($x, $y)
($dx, $dy) = $cr->user_to_device_distance ($dx, $dy)
($x, $y) = $cr->device_to_user ($x, $y)
($dx, $dy) = $cr->device_to_user_distance ($dx, $dy)
Text --- Rendering text and sets of glyphs
Glyphs are represented as anonymous hash references with three keys: index, x and y. Example:
my @glyphs = ({ index => 1, x => 2, y => 3 }, { index => 2, x => 3, y => 4 }, { index => 3, x => 4, y => 5 });
$cr->select_font_face ($family, $slant, $weight)
$cr->set_font_matrix ($matrix)
$matrix = $cr->get_font_matrix
$cr->set_font_options ($options)
$options = $cr->get_font_options
$cr->set_scaled_font ($scaled_font) [1.2]
$scaled_font = $cr->get_scaled_font [1.4]
$cr->set_font_face ($font_face)
$cr->set_scaled_font ($scaled_font)
$extents = $cr->text_extents ($utf8)
$extents = $cr->glyph_extents (...)
$type = $font_face->get_type [1.2]
Scaled Fonts --- Caching metrics for a particular font size
$scaled_font = Cairo::ScaledFont->create ($font_face, $font_matrix, $ctm, $options)
$status = $scaled_font->status
$extents = $scaled_font->extents
$extents = $scaled_font->text_extents ($utf8) [1.2]
$extents = $scaled_font->glyph_extents (...)
$font_face = $scaled_font->get_font_face [1.2]
$options = $scaled_font->get_font_options [1.2]
$font_matrix = $scaled_font->get_font_matrix [1.2]
$ctm = $scaled_font->get_ctm [1.2]
$type = $scaled_font->get_type [1.2]
Font Options --- How a font should be rendered
$font_options = Cairo::FontOptions->create
$status = $font_options->status
$bools = $font_options->equal ($other)
$font_options->set_antialias ($antialias)
$antialias = $font_options->get_antialias
$font_options->set_subpixel_order ($subpixel_order)
$subpixel_order = $font_options->get_subpixel_order
$font_options->set_hint_style ($hint_style)
$hint_style = $font_options->get_hint_style
$font_options->set_hint_metrics ($hint_metrics)
$hint_metrics = $font_options->get_hint_metrics
$string = Cairo->version_string
$version_code = Cairo->VERSION
$version_code = Cairo->VERSION_ENCODE ($major, $minor, $micro)
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |