Games:...:Dg2PDF(3pm)

πŸ“¦
version 4.252 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– NAME πŸ’–

Games::Go::Sgf2Dg::Dg2PDF β€” bestie, it converts Games::Go::Sgf2Dg::Diagram objects into PDF files. That's it, that's the whole job. ✨

(It lives in the User Contributed Perl Documentation, section 3pm, so you already know it's giving "helpful stranger on the internet" energy. 🫢)


πŸ¦‹ SYNOPSIS πŸ¦‹

use Games::Go::Sgf2Dg::Dg2PDF

 my $dg2pdf = B<Games::Go::Sgf2Dg::Dg2PDF-E<gt>new> (options);
 $dg2pdf->convertDiagram($diagram);

🌸 DESCRIPTION 🌸

Okay so picture this: you've got a Games::Go::Sgf2Dg::Diagram object. It's cute, it's got stones, it's got opinions. A Games::Go::Sgf2Dg::Dg2PDF object takes that diagram and turns it into a PDF file. Glow-up complete. πŸ’…


✨ NEW ✨

my $dg2pdf = Games::Go::Sgf2Dg::Dg2PDF->new (?options?)

A brand new Games::Go::Sgf2Dg::Dg2PDF accepts these options, and no, you don't have to use all of them, but they're all right there waiting:

  • boardSizeX => number, boardSizeY => number β€” sets the size of the board, duh.

Default: 19

  • doubleDigits => true | false β€” numbers on stones loop back around to 1 once they hit 100. Important note though: numbers tied to comments and diagram titles are not affected by this. They stay as they are.

Default: false

  • coords => true | false β€” generates a coordinate grid. ✨

Default: false

  • topLine => number (Default: 1), bottomLine => number (Default: 19), leftLine => number (Default: 1), rightLine => number (Default: 19) β€” these are the edges of the board that actually get shown. Anything on the board that spills past these numbers just... doesn't make it into the output. Not invited. πŸ™ˆ
  • diaCoords => sub { # convert $x, $y to Diagram coordinates } β€” this callback is a lil subroutine you define to convert coordinates from $x, $y into whatever coordinate system your Games::Go::Sgf2Dg::Diagram object is living in. The default diaCoords turns 1-based $x, $y into the same coordinates used in SGF format files. You literally only need to define this if your Diagram is using a different coordinate system.

Default:

sub { my ($x, $y) = @_;
      $x = chr($x - 1 + ord('a')); # convert 1 to 'a', etc
      $y = chr($y - 1 + ord('a'));
      return("$x$y"); },           # concatenate two letters

Also go peek at the diaCoords method down below. πŸ‘€

  • print => sub { my ($dg2tex, @tex) = @_; ... } β€” a user defined subroutine that replaces the default printing method. This callback gets called from the print method (below, keep scrolling) and receives a reference to the Dg2TeX object plus a list of lines that are part of the TeX diagram source.
  • pageSize => 'page size' β€” may be one of:
    • a0 - a6
    • letter
    • broadsheet
    • ledger
    • tabloid
    • legal
    • executive
    • 36x36

Default: 'letter'

  • topMargin => points, bottomMargin => points, leftMargin => points, rightMargin => points β€” margins are set in PDF 'user space units', which are approximately equivalent to points (1/72 of an inch).

Default for all margins: 72 * .70 (7/10s of an inch)

  • text_fontName => 'font' (Default: 'Times-Roman'), stone_fontName => 'font' (Default: 'Courier-Bold') β€” text and stone font names may be one of these, and heads up, they are case sensitive:
    • Courier
    • Courier-Bold
    • Courier-BoldOblique
    • Courier-Oblique
    • Helvetica
    • Helvetica-Bold
    • Helvetica-BoldOblique
    • Helvetica-Oblique
    • Times-Roman
    • Times-Bold
    • Times-Italic
    • Times-BoldItalic
  • text_fontSize => points β€” the point size for the comment text. Diagram titles use this size plus 4, and the game title uses this size plus 6. Iconic scaling behavior tbh.

Default: 11

  • stone_fontSize => points β€” this one sets the size of the text inside stones, and it may also decide the size of the stones and diagrams (see lineHeight and lineWidth below, they're all in cahoots).

Default: 5

  • lineWidth => points, lineHeight => points β€” together these determine the size of the stones and diagrams.

If lineWidth isn't explicitly set, it gets calculated from stone_fontSize so you can fit up to three digits on a stone. The default stone_fontSize allows for three diagrams (with -coords) per 'letter' page, as long as comments don't take up extra space below the diagrams. If doubleDigits is specified, the stones and board get slightly smaller β€” stone 100 may look a bit cramped. 😭

If lineHeight isn't explicitly set, it'll be 1.05 * lineWidth, which creates a slightly rectangular diagram.

Default: undef β€” determined from stone_fontSize


πŸŽ€ METHODS πŸŽ€

  • $dg2pdf->configure (option => value, ?...?) β€” changes Dg2PDF options from values passed at new time.
  • my $coord = $dg2mp->diaCoords ($x, $y) β€” gives you access to the diaCoords option (yeah, the one up there ⬆️). It returns coordinates in the converter's coordinate system for board coordinates $x, $y. So like, if you want a specific intersection structure:
my $int = $diagram->get($dg2mp->diaCoords(3, 4));
  • $dg2pdf->print ($text ? , ... ?) β€” prints raw PDF code to the file as defined at new time. And here's the thing: whether or not a file was defined, print accumulates the PDF code for later retrieval with converted. Bestie keeps receipts. πŸ“
  • $dg2pdf->printComment ($text ? , ... ?) β€” adds $text to the diagram comments.
  • $dg2pdf->comment ($comment ? , ... ?) β€” sticks the PDF comment character ('%') in front of every line of every comment and prints it to the file.
Real talk: this is not the same as the printComment method. Do not confuse them, I'm begging. 😭
  • my $canvas = $dg2pdf->convertDiagram ($diagram) β€” converts a Games::Go::Sgf2Dg::Diagram into PDF. (The main character method, honestly. πŸ‘‘)
  • my $converted_text = $dg2pdf->convertText ($text) β€” converts $text into text for display.

Returns the converted text.

  • $title = $dg2pdf->convertGameProps (\%sgfHash) β€” convertGameProps takes a reference to a hash of properties as extracted from an SGF file. Each hash key is a property ID, and each hash value is a reference to an array of property values: $hash->{propertyId}->[values]. These SGF properties get recognized:
    • GN GameName
    • EV EVent
    • RO ROund
    • DT DaTe
    • PW PlayerWhite
    • WR WhiteRank
    • PB PlayerBlack
    • BR BlackRank
    • PC PlaCe
    • KM KoMi
    • RU RUles
    • TM TiMe
    • OT OverTime (byo-yomi)
    • RE REsult
    • AN ANnotator
    • SO Source
    • US USer (entered by)
    • CP CoPyright
    • GC GameComment

Both long and short property names are recognized, and every unrecognized property is ignored with no warnings. Silent treatment, respectfully. Also note that all of these properties are intended as game-level notations.

  • $dg2pdf->close β€” prints some final PDF code to the diagram and closes the pdf object (file). Say bye bye. πŸ‘‹

🌈 SEE ALSO 🌈

  • sgf2dg(1) β€” script to convert SGF format files to Go diagrams.

πŸ’€ BUGS πŸ’€

You think I'd admit it?


That's the whole page, babe! 🫢 This was User Contributed Perl Documentation for Games:...:Dg2PDF(3pm), perl v5.30.0, dated 2019-10-27. Go forth and PDF-ify those Go diagrams, bestie. πŸ’–βœ¨

πŸ“¦ where this page comes from