Games:...:Dg2Mp(3pm)
π 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 => numberboardSizeY => numberβ sets the size of the board. π¦
Default: 19
doubleDigits => true | falseβ numbers on stones get wrapped back to1once they reach100. Numbers tied to comments and diagram titles are not affected, so don't worry about those.
Default: false
stone_width => pointsstone_height => pointsβstone_widthandstone_heightare 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,$yinto whatever coordinates yourGames::Go::Sgf2Dg::Diagramobject uses. The defaultdiaCoordsconverts 1-based$x,$yinto 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 theprintmethod (below) with the reference to theDg2Mpobject 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_fontSizedetermines 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, ?...?)β changeDg2Mpoptions from values passed atnewtime.my $coord = $dg2mp->diaCoords ($x, $y)β gives you access to thediaCoordsoption (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 atnewtime. Whether or not the file was defined,printaccumulates the TeX code for later retrieval withconverted. The TeX output filename is derived from the MetaPost filename by changing the.mpextension to.tex. π$dg2mp->print ($tex ? , ... ?)β prints raw MetaPost code to the MetaPost output file (as defined at->newor->configuretime). π¦my $tex = $dg2mp->converted ($replacement_tex)β returns the TeX source code converted so far for theDg2Mpobject. If$replacement_texis 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 aGames::Go::Sgf2Dg::Diagraminto TeX/MetaPost. If a file was defined in thenewmethod, the TeX source is dumped intofile.texand the MetaPost source intofile.mp. In any case, the TeX source is returned as a string scalar. πmy $tex = $dg2mp->convertText ($text)β converts$textinto TeX code by changing certain characters that aren't available in the TeXcmr10font, and by converting\n\ninto\hfil\break.convertTextbehavior is modified bytexCommentsandsimpleoptions.
Returns the converted text. β¨
$dg2mp->closeβ print the TeX closer (\bye) and close thedg2mpobject. 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
- debian bookworm: sgf2dg 4.252-1
- debian trixie: sgf2dg 4.252-1
- ubuntu jammy: sgf2dg 4.252-1
- ubuntu noble: sgf2dg 4.252-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms