38
38
* \brief Interface for drawing.
40
40
IpePainter-derived classes are used for drawing to the screen and for
41
generating PDF output.
41
generating PDF and Postscript output.
43
43
The IpePainter maintains a stack of graphics states, which includes
44
44
stroke and fill color, line width, dash style, miter limit, line cap
55
55
define - they are set to a default absolute value (normal, black,
58
Attributes must not be changed after a path has been
59
started. (Although this does not seem to be stated explicitely in the
60
PDF Reference, Acrobat Reader 4 complains if the dash style is set
61
after a path has been defined.)
63
Derived classes need to implement the functions for drawing paths,
66
58
A null color is drawn as if it was void. Ipe objects exploit this:
67
59
only group objects ever need to explicitly contain a 'void' color.
71
63
A null line width is drawn as whatever is the standard of the drawing
66
The painter is either in "general" or in "path construction" mode.
67
The NewPath() member starts path construction mode. In this mode,
68
only the path construction operators (MoveTo, LineTo, CurveTo, Rect,
69
DrawArc, DrawEllipse, ClosePath), the transformation operators
70
(Transform, Untransform, Translate), and the stack operators (Push,
71
Pop) are admissible. (Pushs and pops must balance inside path
72
construction. Note that pushs and pops inside path construction only
73
affect the current (painter-internal) tranformation matrix, they do
74
not generate Postscript gsave/grestore operators.) The path is drawn
75
using DrawPath, this ends path construction mode. Path construction
76
operators cannot be used in general mode.
78
Derived classes need to implement the DoXXX functions for drawing paths,
76
82
//! Constructor takes a (cascaded) style sheet, which is not owned.
124
131
iState.back().iMatrix = iState.back().iMatrix * m;
127
//! Start a new open path.
128
void IpePainter::BeginPath(const IpeVector &)
133
//! Start a new closed path.
134
void IpePainter::BeginClosedPath(const IpeVector &)
139
//! Add line segment to path.
140
void IpePainter::LineTo(const IpeVector &)
145
//! Add a Bezier segment to path.
146
void IpePainter::CurveTo(const IpeVector &, const IpeVector &,
152
//! Add a rectangle to the path.
153
/*! Has a default implementation in terms of LineTo, but derived
154
classes can reimplement for efficiency. */
134
//! Enter path construction mode.
135
void IpePainter::NewPath()
138
iInPath = iState.size(); // save current nesting level
142
//! Start a new subpath.
143
void IpePainter::MoveTo(const IpeVector &v)
149
//! Add line segment to current subpath.
150
void IpePainter::LineTo(const IpeVector &v)
156
//! Add a Bezier segment to current subpath.
157
void IpePainter::CurveTo(const IpeVector &v1, const IpeVector &v2,
161
DoCurveTo(v1, v2, v3);
164
//! Add a rectangle subpath to the path.
165
/*! Has a default implementation in terms of MoveTo and LineTo, but
166
derived classes can reimplement for efficiency. */
155
167
void IpePainter::Rect(const IpeRect &re)
157
BeginClosedPath(re.Min());
158
170
LineTo(re.BottomRight());
159
171
LineTo(re.Max());
160
172
LineTo(re.TopLeft());
165
void IpePainter::EndPath()
171
void IpePainter::EndClosedPath()
176
//! Close the current subpath.
177
void IpePainter::ClosePath()
176
183
//! Save current graphics state.
179
186
State state = iState.back();
180
187
iState.push_back(state);
183
192
//! Restore previous graphics state.
184
193
void IpePainter::Pop()
195
assert(int(iState.size()) > IpeMax(1, iInPath));
186
196
iState.pop_back();
189
201
//! Fill and/or stroke a path (depending on color).
190
/*! As in PDF, an "path" can consist of several components that are
191
defined by sequences of BeginClosedPath() and EndClosedPath(). */
202
/*! As in PDF, an "path" can consist of several subpaths. */
192
203
void IpePainter::DrawPath()
205
// check that pushs and pops next inside path construction
206
assert(iInPath == int(iState.size()));
197
211
//! Render a bitmap.
198
212
/*! Assumes the transformation matrix has been set up to map the unit
199
213
square to the image area on the paper.
201
void IpePainter::DrawBitmap(IpeBitmap)
215
void IpePainter::DrawBitmap(IpeBitmap bitmap)
218
DoDrawBitmap(bitmap);
206
221
//! Render a text object.
207
222
/*! Stroke color is already set, and the origin is the lower-left
208
223
corner of the text box. */
209
void IpePainter::DrawText(const IpeText *)
224
void IpePainter::DrawText(const IpeText *text)
214
230
//! Set stroke color, resolving symbolic color.
256
272
//! Set font size of text objects.
257
273
/*! Paradoxically, this isn't actually used to render text, but for
258
saving Ipegroup objects! Text goes through the Pdflatex interface,
274
saving Ipegroup objects! Text goes through the IpeLatex interface,
259
275
and the visitor that scans for text objects and writes them to the
260
276
Latex source file finds the text size information itself.
297
313
piece computed from the formula above.
299
315
This does not modify the transformation matrix. The path is
300
generated as a sequence BeginClosedPath .. CurveTo .. EndClosedPath,
316
generated as a sequence MoveTo .. CurveTo .. ClosePath operators,
301
317
but is not actually drawn (DrawPath is not called).
303
319
void IpePainter::DrawEllipse()
372
388
// --------------------------------------------------------------------
390
//! Perform push on output medium (if necessary).
391
/*! This is not called when client uses Push during path construction! */
392
void IpePainter::DoPush()
397
//! Perform pop on output medium (if necessary).
398
/*! This is not called when client uses Pop during path construction! */
399
void IpePainter::DoPop()
404
//! Perform new path operator.
405
void IpePainter::DoNewPath()
410
//! Perform moveto operator.
411
void IpePainter::DoMoveTo(const IpeVector &)
416
//! Perform lineto operator.
417
void IpePainter::DoLineTo(const IpeVector &)
422
//! Perform curveto operator.
423
void IpePainter::DoCurveTo(const IpeVector &, const IpeVector &,
429
//! Perform closepath operator.
430
void IpePainter::DoClosePath()
435
//! Actually draw the path.
436
void IpePainter::DoDrawPath()
442
void IpePainter::DoDrawBitmap(IpeBitmap)
447
//! Draw a text object.
448
void IpePainter::DoDrawText(const IpeText *)
453
// --------------------------------------------------------------------