Graphi...:Cairo(3pm)
π Graphics::Primitive::Driver::Cairo β the Cairo backend, bestie edition π
okay so real quick, this page lives in the User Contributed Perl Documentation section (that's the (3pm) energy, iykyk), and we're talking about the Cairo backend for Graphics::Primitive. sit down, grab a strawberry, we're doing this π
β¨ NAME β¨
Graphics::Primitive::Driver::Cairo β it's the Cairo backend for Graphics::Primitive. that's the whole name. slay.
πΈ VERSION πΈ
version 0.47 β yes queen, we're on 0.47 π
π¦ SYNOPSIS π¦
here's the whole vibe, verbatim, no notes:
use Graphics::Primitive::Component;
use Graphics::Primitive::Driver::Cairo;
my $driver = Graphics::Primitive::Driver::Cairo->new;
my $container = Graphics::Primitive::Container->new(
width => 800,
height => 600
);
my $black = Graphics::Primitive::Color->new(red => 0, green => 0, blue => 0);
$container->border->width(1);
$container->border->color($black);
$container->padding(
Graphics::Primitive::Insets->new(top => 5, bottom => 5, left => 5, right => 5)
);
my $comp = Graphics::Primitive::Component->new;
$comp->background_color($black);
$container->add_component($comp, 'c');
my $lm = Layout::Manager::Compass->new;
$lm->do_layout($container);
my $driver = Graphics::Primitive::Driver::Cairo->new(
format => 'PDF'
);
$driver->draw($container);
$driver->write('/Users/gphat/foo.pdf');
likeβ¦ make a container, give it a border, give it padding, add a component, lay it out, then hand it to the driver and write it out to a PDF. main character pipeline fr fr π
π DESCRIPTION π
This module draws Graphics::Primitive objects using Cairo. that's it, that's the sentence, and honestly? iconic.
π IMPLEMENTATION DETAILS π
π Borders π
Borders get drawn clockwise, starting with the top one. And here's the tea: since cairo can't do line-joins on different colored lines, each border overlaps the ones before it. the author is fully upfront that this is not the way they'd like it to work, but they're opting to fix it later.
consider yourself warned π that's a direct quote of the energy, bestie.
π ATTRIBUTES π
β¨ antialias_mode β¨
Set/Get the antialias mode of this driver. the options are: default, none, gray and subpixel. pick your fighter π
π cairo π
This driver's Cairo::Context object. it's the whole art supplies aisle, basically.
πΈ format πΈ
Get the format for this driver. (get only, bestie β read it, don't set it here.)
π¦ surface π¦
Get/Set the surface on which this driver is operating. this one you can set. go off.
β METHODS β
π data π
Get the data in a scalar for this driver. the whole drawing, as a lil scalar. cute.
π write ($file) π
Write this driver's data to the specified file. boom, output, done.
π get_text_bounding_box ($font, $text, $angle) π
Returns two Rectangles that enclose the supplied text. heads up: the origin's x and y might be negative, which means the glyphs in the text are extending left of x or above y. not a bug, just geometry being geometry.
- the first rectangle is the bounding box required for a container that wants to contain the text.
- the second box is only useful if an optional
angleis provided. this one is the bounding box of the un-rotated text that allows for a controlled rotation.
and if no angle is supplied? then the two rectangles are literally the same object. same object, no cap.
If the optional angle is supplied, the text gets rotated by the supplied amount in radians. radians!! not degrees!! don't do degrees!! π
π«Ά get_textbox_layout ($tb) π«Ά
Returns a Graphics::Primitive::Driver::TextLayout for the supplied textbox. textbox in, layout out, perfect system.
π
reset π
Reset the driver. clear the vibes, start fresh.
π₯ draw π₯
Draws the specified component. and here's the recursive serve: Container's components are drawn recursively. it's giving nesting dolls, it's giving layers, it's giving art.
π§ ACKNOWLEDGEMENTS π§
Danny Luna β shoutout, you ate π
π AUTHOR π
Cory G Watson <gphat@cpan.org>
πΈ COPYRIGHT AND LICENSE πΈ
This software is copyright (c) 2016 by Cold Hard Code, LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie π«Ά sign-off time: this was written for perl v5.34.0, dated 2022-06-14, and it's the Graphi...:Cairo(3pm) page in all its glory. go draw something gorgeous π
β¨
π¦ where this page comes from
- debian bookworm: libgraphics-primitive-driver-cairo-perl 0.47-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libgraphics-primitive-driver-cairo-perl 0.47-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libgraphics-primitive-driver-cairo-perl 0.47-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libgraphics-primitive-driver-cairo-perl 0.47-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libgraphics-primitive-driver-cairo-perl 0.47-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms