OpenASIP  2.0
EPSGenerator.hh
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 EPSGenerator.hh
26  *
27  * Declaration of EPSGenerator class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_EPS_GENERATOR_HH
34 #define TTA_EPS_GENERATOR_HH
35 
36 #include <string>
37 #include <iostream>
38 #include <queue>
39 #include "Exception.hh"
40 
41 class VertexList;
42 
43 /**
44  * EPSGenerator is a tool for drawing vector graphics to an eps file.
45  *
46  * The drawing is done into a buffer using various drawing methods.
47  * Once the drawing is done, the buffer which contains a valid .eps file
48  * can be written to an output stream.
49  *
50  * The coordinate system used by EPSGenerator corresponds to the
51  * Postscript coordinate system. Origo is in the lower left corner of the
52  * image and one pixel corresponds to one 72th of an inch.
53  */
54 class EPSGenerator {
55 public:
56  EPSGenerator();
57  ~EPSGenerator();
58 
59  void setCreator(std::string creator);
60  void setTitle(std::string title);
61 
62  void setLineWidth(unsigned width);
63  void setFont(unsigned size, std::string fontName = "Courier-Bold");
64  void setLineColour(double r, double g, double b);
65  void setFillColour(double r, double g, double b);
66 
67  void setScale(double scale);
68  void setMargins(unsigned x, unsigned y);
69 
70  void drawRectangle(int x, int y, unsigned width, unsigned height);
71  void drawFilledRectangle(int x, int y, unsigned width, unsigned height);
72 
73  void drawCircle(int x, int y, unsigned radius);
74  void drawFilledCircle(int x, int y, unsigned radius);
75 
76  void drawEllipse(int x, int y, unsigned width, unsigned height);
77  void drawFilledEllipse(int x, int y, unsigned width, unsigned height);
78 
79  void drawPolygon(const VertexList& vertices);
80  void drawFilledPolygon(const VertexList& vertices);
81 
82  void drawText(int x, int y, std::string text);
83 
84  void drawLine(int llx, int lly, int urx, int ury);
85 
86  void clearBuffer();
87  void writeEPS(std::ostream& stream);
88 
89 private:
90  /// Copying forbidden.
91  EPSGenerator(const EPSGenerator&);
92  /// Assignment forbidden.
94 
95  void useLineColour();
96  void useFillColour();
97 
98  void appendToBounds(int x, int y);
99 
100  void doDrawEllipse(
101  int x,
102  int y,
103  unsigned width,
104  unsigned height,
105  bool fill);
106 
107  void drawRectanglePath(int x, int y, unsigned width, unsigned height);
108  void drawCirclePath(int x, int y, unsigned radius);
109  void drawPolygonPath(const VertexList& vertices);
110 
111  struct colour {
112  double r;
113  double g;
114  double b;
115  };
116 
117  /// True, if the EPS file has a title.
118  bool hasTitle_;
119  /// Title of the EPS file.
120  std::string title_;
121 
122  /// String describing the creator of the document.
123  std::string creator_;
124  /// String describing the creation date of the EPS file.
125  std::string creationDate_;
126  /// Buffer for the .eps code to be written.
127  std::queue<std::string> buffer_;
128 
129  /// Current width of the lines drawn.
130  unsigned lineWidth_;
131 
132  /// Minimum x-coordinate used before scaling & translation.
133  int minX_;
134  /// Minimum y-coordinate used before scaling & translation.
135  int minY_;
136  /// Maximum x-coordinate used before scaling & translation.
137  int maxX_;
138  /// Maximum y-coordinate used before scaling & translation.
139  int maxY_;
140 
141  /// Final scaling factor for the eps file.
142  double scale_;
143 
144  /// True, if a point has been added to the bounds.
146 
147  /// Margin to add on the left and right side of the figure in pixels.
148  unsigned xMargin_;
149  /// Margin to add on the top and bottom side of the figure in pixels.
150  unsigned yMargin_;
151 
152  /// Current drawing colour for lines.
154  /// Current colour for filling shape backgrounds.
156 
157  /// Default margin width.
158  static const unsigned DEFAULT_MARGIN;
159 
160  /// Format string for postscript moveto command.
161  static const std::string FMT_MOVETO;
162  /// Format string for postscript lineto command.
163  static const std::string FMT_LINETO;
164  /// Format string for postscript rlineto command.
165  static const std::string FMT_RLINETO;
166 
167 };
168 
169 #endif
EPSGenerator::minY_
int minY_
Minimum y-coordinate used before scaling & translation.
Definition: EPSGenerator.hh:135
EPSGenerator::colour
Definition: EPSGenerator.hh:111
EPSGenerator::buffer_
std::queue< std::string > buffer_
Buffer for the .eps code to be written.
Definition: EPSGenerator.hh:127
EPSGenerator::appendToBounds
void appendToBounds(int x, int y)
Definition: EPSGenerator.cc:81
EPSGenerator::drawRectanglePath
void drawRectanglePath(int x, int y, unsigned width, unsigned height)
Definition: EPSGenerator.cc:141
EPSGenerator::drawFilledRectangle
void drawFilledRectangle(int x, int y, unsigned width, unsigned height)
Definition: EPSGenerator.cc:120
Exception.hh
EPSGenerator::colour::r
double r
Definition: EPSGenerator.hh:112
EPSGenerator::FMT_RLINETO
static const std::string FMT_RLINETO
Format string for postscript rlineto command.
Definition: EPSGenerator.hh:165
EPSGenerator
Definition: EPSGenerator.hh:54
EPSGenerator::boundsSet_
bool boundsSet_
True, if a point has been added to the bounds.
Definition: EPSGenerator.hh:145
EPSGenerator::scale_
double scale_
Final scaling factor for the eps file.
Definition: EPSGenerator.hh:142
EPSGenerator::EPSGenerator
EPSGenerator()
Definition: EPSGenerator.cc:51
EPSGenerator::setFont
void setFont(unsigned size, std::string fontName="Courier-Bold")
Definition: EPSGenerator.cc:460
EPSGenerator::FMT_MOVETO
static const std::string FMT_MOVETO
Format string for postscript moveto command.
Definition: EPSGenerator.hh:161
EPSGenerator::lineColour_
colour lineColour_
Current drawing colour for lines.
Definition: EPSGenerator.hh:153
EPSGenerator::setTitle
void setTitle(std::string title)
Definition: EPSGenerator.cc:428
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
EPSGenerator::drawPolygonPath
void drawPolygonPath(const VertexList &vertices)
Definition: EPSGenerator.cc:225
EPSGenerator::drawCirclePath
void drawCirclePath(int x, int y, unsigned radius)
Definition: EPSGenerator.cc:294
EPSGenerator::maxY_
int maxY_
Maximum y-coordinate used before scaling & translation.
Definition: EPSGenerator.hh:139
EPSGenerator::clearBuffer
void clearBuffer()
Definition: EPSGenerator.cc:517
EPSGenerator::drawFilledPolygon
void drawFilledPolygon(const VertexList &vertices)
Definition: EPSGenerator.cc:206
EPSGenerator::FMT_LINETO
static const std::string FMT_LINETO
Format string for postscript lineto command.
Definition: EPSGenerator.hh:163
EPSGenerator::setScale
void setScale(double scale)
Definition: EPSGenerator.cc:576
EPSGenerator::setMargins
void setMargins(unsigned x, unsigned y)
Definition: EPSGenerator.cc:594
EPSGenerator::drawText
void drawText(int x, int y, std::string text)
Definition: EPSGenerator.cc:392
EPSGenerator::operator=
EPSGenerator & operator=(const EPSGenerator &)
Assignment forbidden.
EPSGenerator::minX_
int minX_
Minimum x-coordinate used before scaling & translation.
Definition: EPSGenerator.hh:133
EPSGenerator::useFillColour
void useFillColour()
Definition: EPSGenerator.cc:614
EPSGenerator::setLineWidth
void setLineWidth(unsigned width)
Definition: EPSGenerator.cc:444
EPSGenerator::DEFAULT_MARGIN
static const unsigned DEFAULT_MARGIN
Default margin width.
Definition: EPSGenerator.hh:158
EPSGenerator::xMargin_
unsigned xMargin_
Margin to add on the left and right side of the figure in pixels.
Definition: EPSGenerator.hh:148
VertexList
Definition: VertexList.hh:42
EPSGenerator::creator_
std::string creator_
String describing the creator of the document.
Definition: EPSGenerator.hh:123
EPSGenerator::title_
std::string title_
Title of the EPS file.
Definition: EPSGenerator.hh:120
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
EPSGenerator::useLineColour
void useLineColour()
Definition: EPSGenerator.cc:604
EPSGenerator::colour::g
double g
Definition: EPSGenerator.hh:113
EPSGenerator::drawLine
void drawLine(int llx, int lly, int urx, int ury)
Definition: EPSGenerator.cc:171
EPSGenerator::drawCircle
void drawCircle(int x, int y, unsigned radius)
Definition: EPSGenerator.cc:262
EPSGenerator::lineWidth_
unsigned lineWidth_
Current width of the lines drawn.
Definition: EPSGenerator.hh:130
EPSGenerator::doDrawEllipse
void doDrawEllipse(int x, int y, unsigned width, unsigned height, bool fill)
Definition: EPSGenerator.cc:348
EPSGenerator::creationDate_
std::string creationDate_
String describing the creation date of the EPS file.
Definition: EPSGenerator.hh:125
EPSGenerator::maxX_
int maxX_
Maximum x-coordinate used before scaling & translation.
Definition: EPSGenerator.hh:137
EPSGenerator::hasTitle_
bool hasTitle_
True, if the EPS file has a title.
Definition: EPSGenerator.hh:118
EPSGenerator::yMargin_
unsigned yMargin_
Margin to add on the top and bottom side of the figure in pixels.
Definition: EPSGenerator.hh:150
EPSGenerator::~EPSGenerator
~EPSGenerator()
Definition: EPSGenerator.cc:73
EPSGenerator::writeEPS
void writeEPS(std::ostream &stream)
Definition: EPSGenerator.cc:529
EPSGenerator::colour::b
double b
Definition: EPSGenerator.hh:114
EPSGenerator::drawPolygon
void drawPolygon(const VertexList &vertices)
Definition: EPSGenerator.cc:192
EPSGenerator::setCreator
void setCreator(std::string creator)
Definition: EPSGenerator.cc:415
EPSGenerator::fillColour_
colour fillColour_
Current colour for filling shape backgrounds.
Definition: EPSGenerator.hh:155