Games::Go::Dg2PDF3pm
Perl extension to convert games::go::diagrams to pdf (portable document format).
Usage
use Games::Go::Dg2PDF
my $dg2pdf = B<Games::Go::Dg2PDF-E<gt>new> (options);$dg2pdf->convertDiagram($diagram);
Overview
A Games::Go::Dg2PDF object converts a Games::Go::Diagram object into a PDF file.
Methods
- my $dg2pdf =
Games::Go::Dg2PDF->new(?options?) -
A
newGames::Go::Dg2PDF takes the following options:
General Dg2 Converter Options:
boardSize=> number-
Sets the size of the board.
Default: 19
doubleDigits=> true | false-
Numbers on stones are wrapped back to 1 after they reach 100. Numbers associated with comments and diagram titles are not affected.
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)-
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 to convert coordinates from
$x,$yto whatever coordinates are used in the Games::Go::Diagram object. The defaultdiaCoordsconverts 1-based$x,$yto 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
print=> sub { my ($dg2tex, @tex) = @_; ... }-
A user defined subroutine to replace the default printing method. This callback is called from the
printmethod (below) with the reference to theDg2TeXobject and a list of lines that are part of the TeX diagram source.
Dg2PDF-specific options:
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 equivilent 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 fonts names may be one of these (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.
Default: 11
stone_fontSize=> points-
The
stone_fontSizedetermines the size of the text inside stones, and may also determine the size of the stones and diagrams (seestone_heightandstone_widthbelow).Default: 5
stone_width=> points
stone_height=> points-
The
stone_widthandstone_heightdetermine the size of the stones and diagrams.If
stone_widthis not explicitly set, it is calculated from thestone_fontSizeto allow up to three digits on a stone . The defaultstone_fontSizeallows for three diagrams (with -coords) per 'letter' page if comments don't take up extra space below diagrams. IfdoubleDigitsis specified, the stones and board are slightly smaller (stone 100 may look a bit cramped).If
stone_heightis not explicitly set, it will be 1.05 *stone_width, creating a slightly rectangular diagram.Default: undef - determined from
stone_fontSize
- $dg2pdf->
configure(option => value, ?...?) -
Change Dg2PDF options from values passed at
newtime.
- $dg2pdf->
print($text ? , ... ?) -
prints raw PDF code tofileas defined atnewtime. Whether or notfilewas defined,printaccumulates the PDF code for later retrieval withconverted.
- $dg2pdf->
printComment($text ? , ... ?) -
Adds
$textto the diagram comments.
- $dg2pdf->
comment($comment ? , ... ?) -
Inserts the PDF comment character ('%') in front of each line of each comment and
prints it tofile.Note that this is not the same as the
printCommentmethod.
- my $canvas = $dg2pdf->
convertDiagram($diagram) -
Converts a Games::Go::Diagram into PDF.
- my $converted_text = $dg2pdf->
convertText($text) -
Converts
$textinto text for display - gee, that's not very hard. In fact, this method simply returns whatever is passed to it. This is really just a place-holder for more complicated converters.Returns the converted text.
- $title = $dg2pdf->
convertProperties(\%sgfHash) -
convertPropertiestakes a reference to a hash of properties as extracted from an SGF file. Each hash key is a property ID and the hash value is a reference to an array of property values:$hash->{propertyId}->[values]. The following SGF properties are recognized:- GN GameName
- EV EVent
- RO ROund
- PW PlayerWhite
- WR WhiteRank
- PB PlayerBlack
- BR BlackRank
- DT DaTe
- PC PlaCe
- GC GameComment
- KM KoMi
- RE REsult
- TM TiMe
Both long and short property names are recognized, and all unrecognized properties are ignored with no warnings. Note that these properties are all intended as game-level notations.
- $dg2pdf->
close -
prints some final PDF code to the diagram and closes the pdf object (file).
Copyright and license
Copyright (C) 2005 by Reid Augustin
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.
Releases
7 releases since Debian 4.0 (Etch); the text changed 2 times.