Graphi...:Driver(3pm)

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

πŸ’– Graphi...:Driver πŸ’–

okay bestie, gather round 🫢 this one's Graphi...:Driver from section 3pm of the User Contributed Perl Documentation β€” yes the header really does abbreviate it like that, iconic of it honestly πŸ’…


✨ NAME ✨

Graphics::Primitive::Driver β€” it's a Role for driver implementations πŸŽ€


🌸 DESCRIPTION 🌸

so like… what is even the point of a library-agnostic intermediary representation of graphical components if you can't feed them to a library-specific implementation that actually turns them into drawings?? psht, none!! 😭 literally zero. the whole thing is giving "beautiful theory, no output" energy.

so yeah β€” to write a driver for Graphics::Primitive, you implement this role. that's the whole vibe. periodt. πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

my $c = Graphics::Primitive::Component->new({
  origin => Geometry::Primitive::Point->new({
      x => $x, y => $y
  }),
  width => 500, height => 350
});

🎨 CANVASES 🎨

when a path gets added to the internal list via do, it is stored in the paths attribute as a hashref. that hashref has two keys: path and op ✨

  • the path is, well… the path. ground-breaking, i know πŸ’€
  • the op is the operation that was provided to do

and bc canvases are literally just lists of paths, you should also go read the next section, bestie. no skipping πŸ™ˆ


🧚 PATHS AND HINTING 🧚

paths are lists of primitives 🌈 and primitives are all descendants of Geometry::Shape, which means they all have point_start and point_end. those two attributes are what let primitives chain together, like a little conga line of shapes 🫢

so to draw a path: iterate over the primitives, drawing each one. that's it, that's the job.

and when you pull each path from the arrayref, you should pull its accompanying hints via get_hint β€” the indexes match so like, they line up perfectly, no cap ✨ the hint may hand you some extra info:

πŸ”₯ PRIMITIVE HINTS πŸ”₯

  • contiguous β€” true if this primitive is contiguous with the previous one. example: it's used to determine if a new sub-path is needed for the Cairo driver πŸ‘€

πŸ’… OPERATION HINTS πŸ’…

  • preserve
(yeah that's the whole entry bestie β€” the page lists preserve and does not elaborate. we simply do not invent lore here πŸ™ˆ)

⚠️ WARNING ⚠️

Only this class or the driver itself should call methods starting with an underscore, because this interface may change. so like… hands off the underscore methods, bestie, they're not for you, they're private and they're volatile 😭 respect the boundary fr fr.

πŸ‘‘ METHODS πŸ‘‘

  • _do_stroke ($strokeop) β€” perform a stroke ✏️
  • _do_fill ($fillop) β€” perform a fill 🎨
  • _draw_arc ($arc) β€” draw an arc 🌈
  • _draw_canvas ($canvas) β€” draw a canvas πŸ–ΌοΈ
  • _draw_component ($comp) β€” draw a component 🧩
  • _draw_line ($line) β€” draw a line βž–
  • _draw_rectangle ($rect) β€” draw a rectangle 🟦
  • _draw_textbox β€” draw a textbox πŸ’¬
  • _resize ($width, $height) β€” resize the current working surface to the size specified πŸ“
  • _finish_page β€” finish the current 'page' and start a new one. some drivers that are not paginated may need to emulate this behaviour 🫠
  • data β€” retrieve the results of this driver's operations πŸ“¦
  • draw β€” draws the given Graphics::Primitive::Component. if the component is a container then all components therein are drawn, recursively πŸŒ€
  • get_text_bounding_box β€” given a Font and a string, returns a bounding box of the rendered text πŸ”€
  • finalize β€” finalize the supplied component and any child components, recursively 🏁
  • prepare β€” prepare the supplied component and any child components, recursively πŸ› οΈ
  • write β€” write out the results of this driver's operations to the specified file πŸ’Ύ

πŸ’œ AUTHOR πŸ’œ

Cory Watson, "<gphat@cpan.org>" β€” ty for your service king 🫑


Copyright 2008-2010 by Cory G Watson.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page, bestie!! πŸŽ€ this was perl v5.34.0, dated 2022-06-14, served up fresh from the User Contributed Perl Documentation πŸ’– slay, go write a driver, you've got this πŸ’…βœ¨

πŸ“¦ where this page comes from