some updates to the webpage
[PyX.git] / manual / canvas.tex
blobfc8105148cfa8b6057354512a8f78d40d4c93306
1 \section{Module \module{canvas}}
2 \label{canvas}
4 \sectionauthor{J\"org Lehmann}{joergl@users.sourceforge.net}
6 One of the central modules for the PostScript access in \PyX{} is
7 named \verb|canvas|. Besides providing the class \verb|canvas|, which
8 presents a collection of visual elements like paths, other canvases,
9 \TeX{} or \LaTeX{} elements, it contains the class
10 \texttt{canvas.clip} which allows clipping of the output.
12 A canvas may also be embedded in another one using its \texttt{insert}
13 method. This may be useful when you want to apply a transformation on
14 a whole set of operations..
16 \declaremodule{}{canvas}
18 \subsection{Class \class{canvas}}
20 This is the basic class of the canvas module, which serves to collect
21 various graphical and text elements you want to write eventually to an
22 (E)PS file.
24 \begin{classdesc}{canvas}{attrs=[], texrunner=None}
25 Construct a new canvas, applying the given \var{attrs}, which can be
26 instances of \class{trafo.trafo}, \class{canvas.clip},
27 \class{style.strokestyle} or \class{style.fillstyle}. The
28 \var{texrunner} argument can be used to specify the texrunner
29 instance used for the \method{text()} method of the canvas. If not
30 specified, it defaults to \var{text.defaulttexrunner}.
31 \end{classdesc}
34 Paths can be drawn on the canvas using one of the following methods:
36 \begin{methoddesc}{draw}{path, attrs}
37 Draws \var{path} on the canvas applying the given \var{attrs}.
38 \end{methoddesc}
40 \begin{methoddesc}{fill}{path, attrs=[]}
41 Fills the given \var{path} on the canvas applying the given
42 \var{attrs}.
43 \end{methoddesc}
45 \begin{methoddesc}{stroke}{path, attrs=[]}
46 Strokes the given \var{path} on the canvas applying the given
47 \var{attrs}.
48 \end{methoddesc}
50 Arbitrary allowed elements like other \class{canvas} instances can
51 be inserted in the canvas using
53 \begin{methoddesc}{insert}{item, attrs=[]}
54 Inserts an instance of \class{base.canvasitem} into the canvas. If
55 \var{attrs} are present, \var{item} is inserted into a new
56 \class{canvas}instance with \var{attrs} as arguments passed to its
57 constructor is created. Then this \class{canvas} instance is
58 inserted itself into the canvas.
59 \end{methoddesc}
61 Text output on the canvas is possible using
63 \begin{methoddesc}{text}{x, y, text, attrs=[]}
64 Inserts \var{text} at position (\var{x}, \var{y}) into the
65 canvas applying \var{attrs}. This is a shortcut for
66 \texttt{insert(texrunner.text(x, y, text, attrs))}).
67 \end{methoddesc}
69 The \class{canvas} class provides access to the total geometrical size
70 of its element:
72 \begin{methoddesc}{bbox}{}
73 Returns the bounding box enclosing all elements of the canvas.
74 \end{methoddesc}
76 A canvas also allows one to set its TeX runner:
78 \begin{methoddesc}{settexrunner}{texrunner}
79 Sets a new \var{texrunner} for the canvas.
80 \end{methoddesc}
82 The contents of the canvas can be written using the following two
83 convenience methods, which wrap the canvas into a single page
84 document.
86 \begin{methoddesc}{writeEPSfile}{file, *args, **kwargs}
87 Writes the canvas to \var{file} using the EPS format. \var{file}
88 either has to provide a write method or it is used as a string
89 containing the filename (the extension \texttt{.eps} is appended
90 automatically, if it is not present). This method constructs a
91 single page document, passing \var{args} and \var{kwargs} to the
92 \class{document.page} constructor and the calls the
93 \method{writeEPSfile} method of this \class{document.document}
94 instance passing the \var{file}.
95 \end{methoddesc}
97 \begin{methoddesc}{writePSfile}{file, *args, **kwargs}
98 Similar to \method{writeEPSfile} but using the PS format.
99 \end{methoddesc}
101 \begin{methoddesc}{writePDFfile}{file, *args, **kwargs}
102 Similar to \method{writeEPSfile} but using the PDF format.
103 \end{methoddesc}
105 \begin{methoddesc}{writetofile}{filename, *args, **kwargs}
106 Determine the file type (EPS, PS, or PDF) from the file extension
107 of \var{filename} and call the corresponding write method with
108 the given arguments \var{arg} and \var{kwargs}.
109 \end{methoddesc}
111 \begin{methoddesc}{pipeGS}{filename="-", device=None, resolution=100,
112 gscommand="gs", gsoptions="",
113 textalphabits=4, graphicsalphabits=4, **kwargs}
114 This method pipes the content of a canvas to the ghostscript
115 interpreter directly to generate other output formats. At least
116 \var{filename} or \var{device} must be set. \var{filename} specifies
117 the name of the output file. No file extension will be added to that
118 name in any case. When no \var{filename} is specified, the output is
119 written to stdout. \var{device} specifies a ghostscript output
120 device by a string. Depending on your ghostscript configuration
121 \code{"png16"}, \code{"png16m"}, \code{"png256"}, \code{"png48"},
122 \code{"pngalpha"}, \code{"pnggray"}, \code{"pngmono"},
123 \code{"jpeg"}, and \code{"jpeggray"} might be available among
124 others. See the output of \texttt{gs --help} and the ghostscript
125 documentation for more information. When \var{filename} is specified
126 but the device is not set, \code{"png16m"} is used when the filename
127 ends in \texttt{.eps} and \code{"jpeg"} is used when the filename
128 ends in \texttt{.jpg}.
130 \var{resolution} specifies the resolution in dpi (dots per inch).
131 \var{gscmd} is the command to be used to invoke ghostscript.
132 \var{gsoptions} are an option string passed to the ghostscript
133 interpreter. \var{textalphabits} are \var{graphicsalphabits} are
134 conventient parameters to set the \texttt{TextAlphaBits} and
135 \texttt{GraphicsAlphaBits} options of ghostscript. You can skip
136 the addition of those option by set their value to \code{None}.
138 \var{kwargs} are passed to the \method{writeEPSfile} method (not
139 counting the \var{file} parameter), which is used to generate the
140 input for ghostscript. By that you gain access to the
141 \class{document.page} constructor arguments.
142 \end{methoddesc}
144 For more information about the possible arguments of the
145 \class{document.page} constructor, we refer to Sect.~\ref{document}.
147 %%% Local Variables:
148 %%% mode: latex
149 %%% TeX-master: "manual.tex"
150 %%% End: