OpenASIP  2.0
EPSDC.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file EPSDC.cc
26  *
27  * Implementation of EPSDC class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "EPSDC.hh"
34 #include "WxConversion.hh"
35 #include "VertexList.hh"
36 #include "Conversion.hh"
37 
38 #if !wxCHECK_VERSION(3, 0, 0)
39 /**
40  * The Constructor.
41  */
42 EPSDC::EPSDC() : wxDC(), fill_(false), fontSize_(0) {
43 }
44 
45 /**
46  * The Destructor.
47  */
49 }
50 
51 /**
52  * Returns true, if the DC is ok to use.
53  *
54  * @return always true
55  */
56 bool
57 EPSDC::Ok() const {
58  return true;
59 }
60 
61 /**
62  * Draws a line on the dc.
63  *
64  * @param x1 x-coordinate of the first end of the line.
65  * @param y1 y-coordinate of the first end of the line.
66  * @param x2 x-coordinate of the second end of the line.
67  * @param y2 y-coordinate of the second end of the line.
68  */
69 void
70 EPSDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) {
71  eps_.drawLine(x1, -1 * y1, x2, -1 * y2);
72 }
73 
74 /**
75  * Draws a polygon on the dc.
76  *
77  * @param n Number of vertices.
78  * @param vertices Vertices.
79  * @param xOffset Offset for x-coordinates.
80  * @param yOffset Offset for y-coordinates.
81  */
82 void
84  int n,
85  wxPoint vertices[],
86  wxCoord xOffset,
87  wxCoord yOffset,
88  int /* fillStyle */) {
89 
90  // Create VertexList of the vertices.
91  VertexList list;
92  for (int i = 0; i < n; i++) {
93  list.addVertex(vertices[i].x + xOffset, -1 * (vertices[i].y + yOffset));
94  }
95 
96  if (fill_) {
97  eps_.drawFilledPolygon(list);
98  } else {
99  eps_.drawPolygon(list);
100  }
101 
102 }
103 
104 /**
105  * Draws a rectangle on the dc.
106  *
107  * @param x Lower left corner x-coordinate of the canvas.
108  * @param y Lower left corner y-coordinate of the canvas.
109  */
110 void
111 EPSDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) {
112  if (fill_) {
113  eps_.drawFilledRectangle(x, (-1 * y - height), width, height);
114  } else {
115  eps_.drawRectangle(x, (-1 * y - height), width, height);
116  }
117 }
118 
119 /**
120  * Draws text on the dc.
121  *
122  * @param text Text to draw.
123  * @param x x-coordinate of the lower left corner of the text.
124  * @param y y-coordinate of the lower left corner of the text.
125  */
126 void
127 EPSDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) {
128  std::string textStr = WxConversion::toString(text);
129  eps_.drawText(x, -1 * y - 12, textStr);
130 }
131 
132 /**
133  * Clears all drawings on the canvas.
134  */
135 void
137  eps_.clearBuffer();
138 }
139 
140 /**
141  * Sets the dc font.
142  *
143  * Only font size is currently set.
144  *
145  * @param font Font to set.
146  */
147 void
148 EPSDC::SetFont(const wxFont& font) {
149  fontSize_ = font.GetPointSize();
151 }
152 
153 
154 /**
155  * NOT IMPLEMENTED
156  */
157 void
158 EPSDC::SetPen(const wxPen& pen) {
159  wxColour lineColour = pen.GetColour();
160  eps_.setLineWidth(pen.GetWidth());
161  setLineColour(lineColour);
162 }
163 
164 /**
165  * Sets the brush used for filling shapes with colour.
166  *
167  * Only solid and transparent brushes are supported. Everything else
168  * is interpreted as transparent brush.
169  */
170 void
171 EPSDC::SetBrush(const wxBrush& brush) {
172  if (brush.GetStyle() == wxSOLID) {
173  fill_ = true;
174  wxColour fillColour = brush.GetColour();
175  setFillColour(fillColour);
176  } else {
177  fill_ = false;
178  }
179 }
180 
181 
182 
183 /**
184  * Sets the eps-file title.
185  *
186  * @param title String which will be set as the eps file title.
187  */
188 void
189 EPSDC::setTitle(const std::string& title) {
190  eps_.setTitle(title);
191 }
192 
193 /**
194  * Sets the eps-file creator string.
195  *
196  * @param creator String describin the eps file creator.
197  */
198 void
199 EPSDC::setCreator(const std::string& creator) {
200  eps_.setCreator(creator);
201 }
202 
203 /**
204  * Writes the generated eps file to an output stream.
205  *
206  * @param stream Output stream where the eps file contents will be written.
207  */
208 void
209 EPSDC::writeToStream(std::ostream& stream) {
210  eps_.writeEPS(stream);
211 }
212 
213 
214 /**
215  * Bitmap drawing not implemented.
216  *
217  * @return Always false.
218  */
219 bool
221  return false;
222 }
223 
224 
225 /**
226  * Called by the device context client before the drawing is started.
227  *
228  * @return Always true.
229  */
230 bool
231 EPSDC::StartDoc(const wxString& /* message */) {
232  return true;
233 }
234 
235 
236 /**
237  * NOT IMPLEMENTED.
238  */
239 void
241  const wxString& /* text */, wxCoord, wxCoord, double) {
242 }
243 
244 /**
245  * NOT IMPLEMENTED.
246  */
247 void
248 EPSDC::DoDrawPoint(wxCoord, wxCoord) {
249 }
250 
251 /**
252  * NOT IMPLEMENTED
253  */
254 bool
255 EPSDC::DoFloodFill(wxCoord, wxCoord, const wxColour&, int) {
256  return false;
257 }
258 
259 
260 /**
261  * NOT IMPLEMENTED
262  */
263 void
264 EPSDC::DoGetSize(wxCoord*, wxCoord*) const {
265 }
266 
267 /**
268  * NOT IMPLEMENTED
269  */
270 void
271 EPSDC::DoDrawArc(wxCoord, wxCoord, wxCoord, wxCoord, wxCoord, wxCoord) {
272 }
273 
274 /**
275  * NOT IMPLEMENTED
276  */
277 void
278 EPSDC::DoDrawIcon(const wxIcon&, wxCoord, wxCoord) {
279 }
280 
281 /**
282  * NOT IMPLEMENTED
283  */
284 void
285 EPSDC::DoCrossHair(wxCoord, wxCoord) {
286 }
287 
288 
289 /**
290  * NOT IMPLEMENTED
291  */
292 void
293 EPSDC::DoDrawBitmap(const wxBitmap&, wxCoord, wxCoord, bool) {
294 }
295 
296 /**
297  * Called before the drawing ends.
298  */
299 void
301  // Do nothing.
302 }
303 
304 /**
305  * Called when the drawing ends.
306  */
307 void
309  // Do nothing.
310 }
311 
312 
313 
314 /**
315  * NOT IMPLEMENTED
316  */
317 void
319  int,
320  wxPoint[] /* points[] */,
321  wxCoord,
322  wxCoord) {
323 }
324 
325 
326 /**
327  * NOT IMPLEMENTED
328  */
329 void
331  wxCoord,
332  wxCoord,
333  wxCoord,
334  wxCoord,
335  double,
336  double) {
337 }
338 
339 /**
340  * Not implemented, falls back to a rectangle.
341  */
342 void
344  wxCoord x,
345  wxCoord y,
346  wxCoord width,
347  wxCoord height,
348  double) {
349  DoDrawRectangle(x, y, width, height);
350 }
351 
352 /**
353  * Draws an ellipse on the dc.
354  *
355  * @param x Ellipse bounding box lower left corner x-coordinate.
356  * @param y Ellipse bounding box lower left corner y-coordinate.
357  * @param width Ellipse width.
358  * @param height Ellipse height.
359  */
360 void
361 EPSDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) {
362 
363  y = -1 * y -height;
364 
365  // Check if the ellipse is actually circle, which will generated more
366  // simple postscript-code.
367  if (width == height) {
368  x += width / 2;
369  y += width / 2;
370  drawCircle(x, y, width / 2);
371  return;
372  }
373 
374  if (fill_) {
375  eps_.drawFilledEllipse(x, y, width, height);
376  } else {
377  eps_.drawEllipse(x, y, width, height);
378  }
379 }
380 
381 
382 /**
383  * NOT IMPLEMENTED
384  */
385 bool
387  wxCoord,
388  wxCoord,
389  wxCoord,
390  wxCoord,
391  wxDC*,
392  wxCoord,
393  wxCoord,
394  int,
395  bool,
396  wxCoord,
397  wxCoord) {
398 
399  return false;
400 }
401 
402 /**
403  * Sets the line drawing colour of the eps generator.
404  *
405  * @param colour New line drawing colour.
406  */
407 void
408 EPSDC::setLineColour(const wxColour& colour) {
409  double redC = (double)colour.Red() / 255;
410  double greenC = (double)colour.Green() / 255;
411  double blueC = (double)colour.Blue() / 255;
412  eps_.setLineColour(redC, greenC, blueC);
413 }
414 
415 /**
416  * Sets the filling colour of the eps generator.
417  *
418  * @param colour New filing colour.
419  */
420 void
421 EPSDC::setFillColour(const wxColour& colour) {
422  double redC = (double)colour.Red() / 255;
423  double greenC = (double)colour.Green() / 255;
424  double blueC = (double)colour.Blue() / 255;
425  eps_.setFillColour(redC, greenC, blueC);
426 }
427 
428 
429 /**
430  * Draws a circle.
431  *
432  * @param x X-coordinate of the circle centre.
433  * @param y Y-coordinate of the circle centre.
434  * @param radius Radius of the circle.
435  */
436 void
437 EPSDC::drawCircle(int x, int y, unsigned radius) {
438 
439  if (fill_) {
440  eps_.drawFilledCircle(x, y, radius);
441  } else {
442  eps_.drawCircle(x, y, radius);
443  }
444 }
445 
446 /**
447  * Returns crude approximation of the width and height of a text on the dc.
448  *
449  * @param w Approximation of width is set as the value of w.
450  * @param h Approximation of height is set as the value of h.
451  */
452 void
454  const wxString& text,
455  wxCoord* w,
456  wxCoord* h,
457  wxCoord*,
458  wxCoord*,
459  wxFont*) const {
460 
461  // TODO: find a better way to approximate text extent.
462  *h = fontSize_;
463  *w = Conversion::toInt((fontSize_ * 72.0 / 120) * text.Length());
464 }
465 
466 /**
467  * NOT IMPLEMENTED
468  *
469  * @return Always false.
470  */
471 bool
472 EPSDC::DoGetPixel(wxCoord, wxCoord, wxColour*) const {
473  return false;
474 }
475 
476 /**
477  * NOT IMPLEMENTED
478  */
479 void
481 }
482 
483 
484 /**
485  * NOT IMPLEMENTED
486  *
487  * @return Always false.
488  */
489 bool
491  return false;
492 }
493 
494 
495 /**
496  * NOT IMPLEMENTED
497  */
498 void
499 EPSDC::SetBackground(const wxBrush&) {
500 }
501 
502 
503 /**
504  * NOT IMPLEMENTED
505  */
506 void
508 }
509 
510 
511 /**
512  * NOT IMPLEMENTED
513  */
514 void
515 EPSDC::SetPalette(const wxPalette&) {
516 }
517 
518 /**
519  * NOT IMPLEMENTED
520  */
521 void
523 }
524 
525 
526 /**
527  * NOT IMPLEMENTED
528  *
529  * @return Always zero.
530  */
531 wxCoord
533  return 0;
534 }
535 
536 /**
537  * NOT IMPLEMENTED
538  *
539  * @return Always zero.
540  */
541 wxCoord
543  return 0;
544 }
545 
546 /**
547  * NOT IMPLEMENTED
548  *
549  * @return Always zero.
550  */
551 int
553  return 0;
554 }
555 
556 /**
557  * Starts a new page in the document.
558  */
559 void
561  // Do nothing.
562 }
563 
564 /**
565  * Ends current page.
566  */
567 void
569  // Do nothing.
570 }
571 
572 /**
573  * Ends the document that is being drawn on.
574  */
575 void
577  // Do nothing.
578 }
579 #endif
EPSDC::DoDrawRectangle
virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
Definition: EPSDC.cc:111
VertexList.hh
EPSDC::GetCharHeight
virtual wxCoord GetCharHeight() const
Definition: EPSDC.cc:532
EPSDC::SetPen
virtual void SetPen(const wxPen &pen)
Definition: EPSDC.cc:158
EPSDC::DoBlit
virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, int logicalFunc=wxCOPY, bool useMask=false, wxCoord xsrcMask=-1, wxCoord ysrcMask=-1)
Definition: EPSDC.cc:386
EPSDC::EndDoc
virtual void EndDoc()
Definition: EPSDC.cc:576
EPSDC::setLineColour
void setLineColour(const wxColour &colour)
Definition: EPSDC.cc:408
EPSDC::DoFloodFill
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour &colour, int style)
Definition: EPSDC.cc:255
EPSDC::Ok
virtual bool Ok() const
Definition: EPSDC.cc:57
EPSDC::StartDoc
virtual bool StartDoc(const wxString &message)
Definition: EPSDC.cc:231
EPSGenerator::drawFilledRectangle
void drawFilledRectangle(int x, int y, unsigned width, unsigned height)
Definition: EPSGenerator.cc:120
EPSDC::DoSetClippingRegionAsRegion
virtual void DoSetClippingRegionAsRegion(const wxRegion &region)
Definition: EPSDC.cc:480
EPSDC::DoDrawBitmap
virtual void DoDrawBitmap(const wxBitmap &bitmap, wxCoord x, wxCoord y, bool transparent)
Definition: EPSDC.cc:293
EPSDC::setFillColour
void setFillColour(const wxColour &colour)
Definition: EPSDC.cc:421
EPSDC::~EPSDC
virtual ~EPSDC()
Definition: EPSDC.cc:48
EPSDC::DoGetTextExtent
virtual void DoGetTextExtent(const wxString &text, wxCoord *w, wxCoord *h, wxCoord *descent=NULL, wxCoord *externalLeading=NULL, wxFont *font=NULL) const
Definition: EPSDC.cc:453
EPSDC.hh
EPSGenerator::setFont
void setFont(unsigned size, std::string fontName="Courier-Bold")
Definition: EPSGenerator.cc:460
EPSDC::BeginDrawing
virtual void BeginDrawing()
Definition: EPSDC.cc:300
EPSDC::StartPage
virtual void StartPage()
Definition: EPSDC.cc:560
EPSDC::DoDrawRotatedText
virtual void DoDrawRotatedText(const wxString &text, wxCoord x, wxCoord y, double angle)
Definition: EPSDC.cc:240
EPSDC::Clear
virtual void Clear()
Definition: EPSDC.cc:136
EPSGenerator::setTitle
void setTitle(std::string title)
Definition: EPSGenerator.cc:428
EPSDC::DoDrawIcon
virtual void DoDrawIcon(const wxIcon &icon, wxCoord x, wxCoord y)
Definition: EPSDC.cc:278
EPSGenerator::drawEllipse
void drawEllipse(int x, int y, unsigned width, unsigned height)
Definition: EPSGenerator.cc:318
EPSGenerator::drawFilledCircle
void drawFilledCircle(int x, int y, unsigned radius)
Definition: EPSGenerator.cc:275
EPSGenerator::drawRectangle
void drawRectangle(int x, int y, unsigned width, unsigned height)
Definition: EPSGenerator.cc:106
EPSDC::SetPalette
virtual void SetPalette(const wxPalette &palette)
Definition: EPSDC.cc:515
EPSGenerator::clearBuffer
void clearBuffer()
Definition: EPSGenerator.cc:517
EPSDC::setTitle
void setTitle(const std::string &title)
Definition: EPSDC.cc:189
EPSDC::writeToStream
void writeToStream(std::ostream &stream)
Definition: EPSDC.cc:209
EPSGenerator::drawFilledPolygon
void drawFilledPolygon(const VertexList &vertices)
Definition: EPSGenerator.cc:206
EPSDC::DoDrawPoint
virtual void DoDrawPoint(wxCoord x, wxCoord y)
Definition: EPSDC.cc:248
EPSGenerator::drawText
void drawText(int x, int y, std::string text)
Definition: EPSGenerator.cc:392
Conversion.hh
EPSDC::EPSDC
EPSDC()
Definition: EPSDC.cc:42
EPSGenerator::setLineWidth
void setLineWidth(unsigned width)
Definition: EPSGenerator.cc:444
EPSDC::SetBackgroundMode
virtual void SetBackgroundMode(int mode)
Definition: EPSDC.cc:507
EPSDC::CanDrawBitmap
virtual bool CanDrawBitmap() const
Definition: EPSDC.cc:220
VertexList
Definition: VertexList.hh:42
EPSDC::DoDrawLine
virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: EPSDC.cc:70
EPSDC::DoDrawArc
virtual void DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc)
Definition: EPSDC.cc:271
EPSDC::DoDrawRoundedRectangle
virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius=20)
Definition: EPSDC.cc:343
EPSDC::GetCharWidth
virtual wxCoord GetCharWidth() const
Definition: EPSDC.cc:542
EPSGenerator::drawFilledEllipse
void drawFilledEllipse(int x, int y, unsigned width, unsigned height)
Definition: EPSGenerator.cc:332
EPSGenerator::setFillColour
void setFillColour(double r, double g, double b)
Definition: EPSGenerator.cc:499
EPSGenerator::setLineColour
void setLineColour(double r, double g, double b)
Definition: EPSGenerator.cc:475
EPSDC::SetLogicalFunction
virtual void SetLogicalFunction(int function)
Definition: EPSDC.cc:522
EPSDC::CanGetTextExtent
virtual bool CanGetTextExtent() const
Definition: EPSDC.cc:490
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
EPSDC::SetBrush
virtual void SetBrush(const wxBrush &brush)
Definition: EPSDC.cc:171
EPSDC::EndDrawing
virtual void EndDrawing()
Definition: EPSDC.cc:308
EPSGenerator::drawLine
void drawLine(int llx, int lly, int urx, int ury)
Definition: EPSGenerator.cc:171
EPSDC::EndPage
virtual void EndPage()
Definition: EPSDC.cc:568
EPSDC::DoCrossHair
virtual void DoCrossHair(wxCoord x, wxCoord y)
Definition: EPSDC.cc:285
EPSDC::SetFont
virtual void SetFont(const wxFont &font)
Definition: EPSDC.cc:148
EPSDC::DoDrawLines
virtual void DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
Definition: EPSDC.cc:318
EPSDC::fill_
bool fill_
True, if background brush is set to fill the shapes.
Definition: EPSDC.hh:191
EPSDC::SetBackground
virtual void SetBackground(const wxBrush &brush)
Definition: EPSDC.cc:499
EPSDC::DoDrawEllipticArc
virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double start, double end)
Definition: EPSDC.cc:330
EPSGenerator::drawCircle
void drawCircle(int x, int y, unsigned radius)
Definition: EPSGenerator.cc:262
EPSDC::DoGetSize
virtual void DoGetSize(wxCoord *width, wxCoord *height) const
Definition: EPSDC.cc:264
WxConversion.hh
EPSDC::DoDrawText
virtual void DoDrawText(const wxString &text, wxCoord x, wxCoord y)
Definition: EPSDC.cc:127
EPSDC::DoDrawEllipse
virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
Definition: EPSDC.cc:361
EPSDC::DoGetPixel
virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *colour) const
Definition: EPSDC.cc:472
Conversion::toInt
static int toInt(const T &source)
EPSDC::setCreator
void setCreator(const std::string &creator)
Definition: EPSDC.cc:199
WxConversion::toString
static std::string toString(const wxString &source)
EPSDC::GetDepth
virtual int GetDepth() const
Definition: EPSDC.cc:552
EPSDC::DoDrawPolygon
virtual void DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset=0, wxCoord yoffset=0, int fillStyle=wxODDEVEN_RULE)
Definition: EPSDC.cc:83
EPSDC::eps_
EPSGenerator eps_
EPSGenerator generating the postscript code.
Definition: EPSDC.hh:189
EPSGenerator::writeEPS
void writeEPS(std::ostream &stream)
Definition: EPSGenerator.cc:529
EPSGenerator::drawPolygon
void drawPolygon(const VertexList &vertices)
Definition: EPSGenerator.cc:192
VertexList::addVertex
void addVertex(int x, int y)
Definition: VertexList.cc:57
EPSGenerator::setCreator
void setCreator(std::string creator)
Definition: EPSGenerator.cc:415
EPSDC::drawCircle
void drawCircle(int x, int y, unsigned radius)
Definition: EPSDC.cc:437
EPSDC::fontSize_
unsigned fontSize_
Current font size.
Definition: EPSDC.hh:193