Games:...:Dg2Mp(3pm)

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

πŸ’– Games::Go::Sgf2Dg::Dg2Mp πŸ’–

okay bestie, welcome to the Perl extension corner of the manual-verse β€” this is Games:...:Dg2Mp, part of the User Contributed Perl Documentation, and it is literally the little module that takes your Go diagrams and glowes them up into MetaPost. slay.


✨ NAME ✨

Games::Go::Sgf2Dg::Dg2Mp β€” a Perl extension that converts Games::Go::Sgf2Dg::Diagrams into John Hobby's MetaPost (which is, iconic detail, adapted from Donald Knuth's Metafont). πŸ¦‹


🌸 SYNOPSIS 🌸

use Games::Go::Sgf2Dg::Dg2Mp

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

πŸ’… DESCRIPTION πŸ’…

so here's the tea. A Games::Go::Sgf2Dg::Dg2Mp object takes a Games::Go::Sgf2Dg::Diagram object and turns it into a TeX (.tex) file plus a MetaPost (.mp) file. no cap.

The MetaPost file holds the figures for every single one of the diagrams and overstones you need to build the complete game diagram. Then you run MetaPost (mpost, or possibly mp, depending on your setup 🫢) on that .mp file and out pop a whole set of figure files β€” each one an Encapsulated PostScript figure. ✨

Next: run TeX (tex) on the .tex file and you get a .dvi file that tries to include those Encapsulated PostScript figures. Then run dvips on the .dvi file (the one from TeX) and boom β€” the final PostScript (.ps) file containing the complete game diagram. main character energy fr fr. πŸ‘‘

If you want the full lore on the whole MetaPost system and its environment, go read 'man mpost' (or possibly 'man 'mp'). iykyk.


πŸŽ€ NEW πŸŽ€

my $dg2mp = Games::Go::Sgf2Dg::Dg2Mp->new (?options?)

A fresh new Games::Go::Sgf2Dg::Dg2Mp takes these options, bestie:

  • boardSizeX => number
  • boardSizeY => number β€” sets the size of the board. πŸ¦‹

Default: 19

  • doubleDigits => true | false β€” numbers on stones get wrapped back to 1 once they reach 100. Numbers tied to comments and diagram titles are not affected, so don't worry about those.

Default: false

  • stone_width => points
  • stone_height => points β€” stone_width and stone_height are what decide the size of the stones and the diagrams. πŸ’–

If stone_width isn't explicitly set, it gets calculated from stone_fontSize so there's room for up to three digits on a stone. The default stone_fontSize allows for three diagrams (with -coords) per 'letter' page, assuming comments don't take up extra space below the diagrams. And if doubleDigits is specified, the stones and board are slightly smaller (stone 100 may look a bit cramped 😭).

If stone_height isn't explicitly set, it'll be 1.05 * stone_width, which makes a slightly rectangular diagram.

Default: undef β€” determined from stone_fontSize

  • 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 should be displayed. Any portion of the board that extends beyond these numbers is not included in the output. 🚫
  • diaCoords => sub { # convert $x, $y to Diagram coordinates } β€” this callback defines a subroutine that converts coordinates from $x, $y into whatever coordinates your Games::Go::Sgf2Dg::Diagram object uses. The default diaCoords converts 1-based $x, $y into the same coordinates used in SGF format files. You only need to define this if you're using a different coordinate system in the Diagram. πŸ’œ

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

See also the diaCoords method below. πŸ‘‡

  • print => sub { my ($dg2mp, @tex) = @_; ... } β€” a user defined subroutine that replaces the default printing method. This callback gets called from the print method (below) with the reference to the Dg2Mp object and a list of lines that are part of the TeX diagram source.
  • stone_fontName => 'font' Default: 'cmssbx10' β€” quoting straight from the discussion on fonts in section 7 of A User's Manual for MetaPost (by John D. Hobby), and bestie this quote ate:
"...the new font name should be something that TEX would understand since MetaPost gets height and width information by reading the tfm file. (This is explained in The TEXbook. [5] ) It should be possible to use built-in PostScript fonts, but the names for them are system-dependent. Some systems may use rptmr or ps-times-roman instead of Times-Roman. A TEX font such as cmr10 is a little dangerous because it does not have a space character or certain ASCII symbols. In addition, MetaPost does not use the ligatures and kerning information that comes with a TEX font."
  • stone_fontSize => points β€” stone_fontSize determines the size of the stones and diagrams. Stone size is chosen so up to three digits can fit on a stone. πŸ”’

If doubleDigits is specified, the stones and board are slightly smaller (stone 100 may look a bit cramped 😭).

Default: 8


🧚 METHODS 🧚

  • $dg2mp->configure (option => value, ?...?) β€” change Dg2Mp options from values passed at new time.
  • my $coord = $dg2mp->diaCoords ($x, $y) β€” gives you access to the diaCoords option (see above). Returns coordinates in the converter's coordinate system for board coordinates ($x, $y). For example, to get a specific intersection structure:
my $int = $diagram->get($dg2mp->diaCoords(3, 4));
  • $dg2mp->print ($tex ? , ... ?) β€” prints raw TeX code to the file as defined at new time. Whether or not the file was defined, print accumulates the TeX code for later retrieval with converted. The TeX output filename is derived from the MetaPost filename by changing the .mp extension to .tex. πŸ’–
  • $dg2mp->print ($tex ? , ... ?) β€” prints raw MetaPost code to the MetaPost output file (as defined at ->new or ->configure time). πŸ¦‹
  • my $tex = $dg2mp->converted ($replacement_tex) β€” returns the TeX source code converted so far for the Dg2Mp object. If $replacement_tex is defined, the accumulated TeX source code gets replaced by $replacement_tex.
  • $dg2mp->comment ($comment ? , ... ?) β€” inserts the TeX comment character ('%') in front of each line of each comment and prints it to file. πŸ’…
  • my $tex_source = $dg2mp->convertDiagram ($diagram) β€” converts a Games::Go::Sgf2Dg::Diagram into TeX/MetaPost. If a file was defined in the new method, the TeX source is dumped into file.tex and the MetaPost source into file.mp. In any case, the TeX source is returned as a string scalar. 🌟
  • my $tex = $dg2mp->convertText ($text) β€” converts $text into TeX code by changing certain characters that aren't available in the TeX cmr10 font, and by converting \n\n into \hfil\break. convertText behavior is modified by texComments and simple options.

Returns the converted text. ✨

  • $dg2mp->close β€” print the TeX closer (\bye) and close the dg2mp object. Also closes the file if appropriate. 🫢

πŸ”₯ SEE ALSO πŸ”₯

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

πŸ’€ BUGS πŸ’€

Is this a trick question? πŸ™ˆ


perl v5.30.0 πŸŽ€ 2019-10-27 β€” that's the version and date, babes, and that's a wrap. go forth and convert those diagrams, bestie πŸ’–βœ¨

πŸ“¦ where this page comes from