~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/ipelib/ipepainter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2005-02-24 22:09:16 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050224220916-9vxiiqjz066r5489
Tags: 6.0pre23-2
debian/control: Ipe should depend on exact version of libipe.
Closes: #296771.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 * \brief Interface for drawing.
39
39
 
40
40
 IpePainter-derived classes are used for drawing to the screen and for
41
 
 generating PDF output.
 
41
 generating PDF and Postscript output.
42
42
 
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,
56
56
 solid, etc.).
57
57
 
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.)
62
 
 
63
 
 Derived classes need to implement the functions for drawing paths,
64
 
 images, and texts.
65
 
 
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.
68
60
 
71
63
 A null line width is drawn as whatever is the standard of the drawing
72
64
 medium.
73
65
 
 
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.
 
77
 
 
78
 Derived classes need to implement the DoXXX functions for drawing paths,
 
79
 images, and texts.
74
80
*/
75
81
 
76
82
//! Constructor takes a (cascaded) style sheet, which is not owned.
81
87
  iStyleSheet = style;
82
88
  State state;
83
89
  iState.push_back(state);
 
90
  iInPath = 0;
84
91
}
85
92
 
86
93
//! Virtual destructor.
124
131
  iState.back().iMatrix = iState.back().iMatrix * m;
125
132
}
126
133
 
127
 
//! Start a new open path.
128
 
void IpePainter::BeginPath(const IpeVector &)
129
 
{
130
 
  // nothing
131
 
}
132
 
 
133
 
//! Start a new closed path.
134
 
void IpePainter::BeginClosedPath(const IpeVector &)
135
 
{
136
 
  // nothing
137
 
}
138
 
 
139
 
//! Add line segment to path.
140
 
void IpePainter::LineTo(const IpeVector &)
141
 
{
142
 
  // nothing
143
 
}
144
 
 
145
 
//! Add a Bezier segment to path.
146
 
void IpePainter::CurveTo(const IpeVector &, const IpeVector &,
147
 
                         const IpeVector &)
148
 
{
149
 
  // nothing
150
 
}
151
 
 
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()
 
136
{
 
137
  assert(!iInPath);
 
138
  iInPath = iState.size(); // save current nesting level
 
139
  DoNewPath();
 
140
}
 
141
 
 
142
//! Start a new subpath.
 
143
void IpePainter::MoveTo(const IpeVector &v)
 
144
{
 
145
  assert(iInPath > 0);
 
146
  DoMoveTo(v);
 
147
}
 
148
 
 
149
//! Add line segment to current subpath.
 
150
void IpePainter::LineTo(const IpeVector &v)
 
151
{
 
152
  assert(iInPath > 0);
 
153
  DoLineTo(v);
 
154
}
 
155
 
 
156
//! Add a Bezier segment to current subpath.
 
157
void IpePainter::CurveTo(const IpeVector &v1, const IpeVector &v2,
 
158
                         const IpeVector &v3)
 
159
{
 
160
  assert(iInPath > 0);
 
161
  DoCurveTo(v1, v2, v3);
 
162
}
 
163
 
 
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)
156
168
{
157
 
  BeginClosedPath(re.Min());
 
169
  MoveTo(re.Min());
158
170
  LineTo(re.BottomRight());
159
171
  LineTo(re.Max());
160
172
  LineTo(re.TopLeft());
161
 
  EndClosedPath();
162
 
}
163
 
 
164
 
//! End open path.
165
 
void IpePainter::EndPath()
166
 
{
167
 
  // nothing
168
 
}
169
 
 
170
 
//! End closed path.
171
 
void IpePainter::EndClosedPath()
172
 
{
173
 
  // nothing
 
173
  ClosePath();
 
174
}
 
175
 
 
176
//! Close the current subpath.
 
177
void IpePainter::ClosePath()
 
178
{
 
179
  assert(iInPath > 0);
 
180
  DoClosePath();
174
181
}
175
182
 
176
183
//! Save current graphics state.
178
185
{
179
186
  State state = iState.back();
180
187
  iState.push_back(state);
 
188
  if (!iInPath)
 
189
    DoPush();
181
190
}
182
191
 
183
192
//! Restore previous graphics state.
184
193
void IpePainter::Pop()
185
194
{
 
195
  assert(int(iState.size()) > IpeMax(1, iInPath));
186
196
  iState.pop_back();
 
197
  if (!iInPath)
 
198
    DoPop();
187
199
}
188
200
 
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()
193
204
{
194
 
  // nothing
 
205
  // check that pushs and pops next inside path construction
 
206
  assert(iInPath == int(iState.size()));
 
207
  DoDrawPath();
 
208
  iInPath = 0;
195
209
}
196
210
 
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.
200
214
*/
201
 
void IpePainter::DrawBitmap(IpeBitmap)
 
215
void IpePainter::DrawBitmap(IpeBitmap bitmap)
202
216
{
203
 
  // nothing
 
217
  assert(!iInPath);
 
218
  DoDrawBitmap(bitmap);
204
219
}
205
220
 
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)
210
225
{
211
 
  // nothing
 
226
  assert(!iInPath);
 
227
  DoDrawText(text);
212
228
}
213
229
 
214
230
//! Set stroke color, resolving symbolic color.
255
271
 
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.
261
277
*/
297
313
  piece computed from the formula above.
298
314
 
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).
302
318
*/
303
319
void IpePainter::DrawEllipse()
310
326
  IpeVector q2(-1.0, BETA);
311
327
  IpeVector q3(-1.0, 0.0);
312
328
 
313
 
  BeginClosedPath(p0);
 
329
  MoveTo(p0);
314
330
  CurveTo(p1, p2, p3);
315
331
  CurveTo(q1, q2, q3);
316
332
  CurveTo(-p1, -p2, -p3);
317
333
  CurveTo(-q1, -q2, -q3);
318
 
  EndClosedPath();
 
334
  ClosePath();
319
335
}
320
336
 
321
337
//! Draw an arc of the unit circle of length \a alpha.
370
386
}
371
387
 
372
388
// --------------------------------------------------------------------
 
389
 
 
390
//! Perform push on output medium (if necessary).
 
391
/*! This is not called when client uses Push during path construction! */
 
392
void IpePainter::DoPush()
 
393
{
 
394
  // nothing
 
395
}
 
396
 
 
397
//! Perform pop on output medium (if necessary).
 
398
/*! This is not called when client uses Pop during path construction! */
 
399
void IpePainter::DoPop()
 
400
{
 
401
  // nothing
 
402
}
 
403
 
 
404
//! Perform new path operator.
 
405
void IpePainter::DoNewPath()
 
406
{
 
407
  // nothing
 
408
}
 
409
 
 
410
//! Perform moveto operator.
 
411
void IpePainter::DoMoveTo(const IpeVector &)
 
412
{
 
413
  // nothing
 
414
}
 
415
 
 
416
//! Perform lineto operator.
 
417
void IpePainter::DoLineTo(const IpeVector &)
 
418
{
 
419
  // nothing
 
420
}
 
421
 
 
422
//! Perform curveto operator.
 
423
void IpePainter::DoCurveTo(const IpeVector &, const IpeVector &,
 
424
                           const IpeVector &)
 
425
{
 
426
  // nothing
 
427
}
 
428
 
 
429
//! Perform closepath operator.
 
430
void IpePainter::DoClosePath()
 
431
{
 
432
  // nothing
 
433
}
 
434
 
 
435
//! Actually draw the path.
 
436
void IpePainter::DoDrawPath()
 
437
{
 
438
  // nothing
 
439
}
 
440
 
 
441
//! Draw a bitmap.
 
442
void IpePainter::DoDrawBitmap(IpeBitmap)
 
443
{
 
444
  // nothing
 
445
}
 
446
 
 
447
//! Draw a text object.
 
448
void IpePainter::DoDrawText(const IpeText *)
 
449
{
 
450
  // nothing
 
451
}
 
452
 
 
453
// --------------------------------------------------------------------