Graphi...:Cairo(3pm)

πŸ“¦
version 0.47 Β· 2 versions
  • 0.47 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.47 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 angle is 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>

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