OpenASIP 2.2
Loading...
Searching...
No Matches
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
41class 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 */
55public:
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
89private:
90 /// Copying forbidden.
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.
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
void setTitle(std::string title)
unsigned yMargin_
Margin to add on the top and bottom side of the figure in pixels.
void useLineColour()
void drawLine(int llx, int lly, int urx, int ury)
unsigned lineWidth_
Current width of the lines drawn.
void drawRectangle(int x, int y, unsigned width, unsigned height)
bool hasTitle_
True, if the EPS file has a title.
static const std::string FMT_MOVETO
Format string for postscript moveto command.
double scale_
Final scaling factor for the eps file.
EPSGenerator(const EPSGenerator &)
Copying forbidden.
static const unsigned DEFAULT_MARGIN
Default margin width.
void drawPolygon(const VertexList &vertices)
int minX_
Minimum x-coordinate used before scaling & translation.
void drawFilledCircle(int x, int y, unsigned radius)
void drawFilledRectangle(int x, int y, unsigned width, unsigned height)
std::string title_
Title of the EPS file.
void drawFilledPolygon(const VertexList &vertices)
int minY_
Minimum y-coordinate used before scaling & translation.
void drawText(int x, int y, std::string text)
unsigned xMargin_
Margin to add on the left and right side of the figure in pixels.
void doDrawEllipse(int x, int y, unsigned width, unsigned height, bool fill)
void appendToBounds(int x, int y)
void setFont(unsigned size, std::string fontName="Courier-Bold")
colour lineColour_
Current drawing colour for lines.
colour fillColour_
Current colour for filling shape backgrounds.
void setMargins(unsigned x, unsigned y)
static const std::string FMT_LINETO
Format string for postscript lineto command.
std::string creationDate_
String describing the creation date of the EPS file.
void drawCirclePath(int x, int y, unsigned radius)
void drawPolygonPath(const VertexList &vertices)
void drawCircle(int x, int y, unsigned radius)
void drawEllipse(int x, int y, unsigned width, unsigned height)
int maxY_
Maximum y-coordinate used before scaling & translation.
void drawRectanglePath(int x, int y, unsigned width, unsigned height)
void drawFilledEllipse(int x, int y, unsigned width, unsigned height)
void setLineColour(double r, double g, double b)
void writeEPS(std::ostream &stream)
int maxX_
Maximum x-coordinate used before scaling & translation.
EPSGenerator & operator=(const EPSGenerator &)
Assignment forbidden.
bool boundsSet_
True, if a point has been added to the bounds.
std::queue< std::string > buffer_
Buffer for the .eps code to be written.
static const std::string FMT_RLINETO
Format string for postscript rlineto command.
void setLineWidth(unsigned width)
std::string creator_
String describing the creator of the document.
void setFillColour(double r, double g, double b)
void useFillColour()
void setScale(double scale)
void setCreator(std::string creator)