OpenASIP
2.0
|
#include <EPSGenerator.hh>
Classes | |
struct | colour |
Public Member Functions | |
EPSGenerator () | |
~EPSGenerator () | |
void | setCreator (std::string creator) |
void | setTitle (std::string title) |
void | setLineWidth (unsigned width) |
void | setFont (unsigned size, std::string fontName="Courier-Bold") |
void | setLineColour (double r, double g, double b) |
void | setFillColour (double r, double g, double b) |
void | setScale (double scale) |
void | setMargins (unsigned x, unsigned y) |
void | drawRectangle (int x, int y, unsigned width, unsigned height) |
void | drawFilledRectangle (int x, int y, unsigned width, unsigned height) |
void | drawCircle (int x, int y, unsigned radius) |
void | drawFilledCircle (int x, int y, unsigned radius) |
void | drawEllipse (int x, int y, unsigned width, unsigned height) |
void | drawFilledEllipse (int x, int y, unsigned width, unsigned height) |
void | drawPolygon (const VertexList &vertices) |
void | drawFilledPolygon (const VertexList &vertices) |
void | drawText (int x, int y, std::string text) |
void | drawLine (int llx, int lly, int urx, int ury) |
void | clearBuffer () |
void | writeEPS (std::ostream &stream) |
Private Member Functions | |
EPSGenerator (const EPSGenerator &) | |
Copying forbidden. More... | |
EPSGenerator & | operator= (const EPSGenerator &) |
Assignment forbidden. More... | |
void | useLineColour () |
void | useFillColour () |
void | appendToBounds (int x, int y) |
void | doDrawEllipse (int x, int y, unsigned width, unsigned height, bool fill) |
void | drawRectanglePath (int x, int y, unsigned width, unsigned height) |
void | drawCirclePath (int x, int y, unsigned radius) |
void | drawPolygonPath (const VertexList &vertices) |
Private Attributes | |
bool | hasTitle_ |
True, if the EPS file has a title. More... | |
std::string | title_ |
Title of the EPS file. More... | |
std::string | creator_ |
String describing the creator of the document. More... | |
std::string | creationDate_ |
String describing the creation date of the EPS file. More... | |
std::queue< std::string > | buffer_ |
Buffer for the .eps code to be written. More... | |
unsigned | lineWidth_ |
Current width of the lines drawn. More... | |
int | minX_ |
Minimum x-coordinate used before scaling & translation. More... | |
int | minY_ |
Minimum y-coordinate used before scaling & translation. More... | |
int | maxX_ |
Maximum x-coordinate used before scaling & translation. More... | |
int | maxY_ |
Maximum y-coordinate used before scaling & translation. More... | |
double | scale_ |
Final scaling factor for the eps file. More... | |
bool | boundsSet_ |
True, if a point has been added to the bounds. More... | |
unsigned | xMargin_ |
Margin to add on the left and right side of the figure in pixels. More... | |
unsigned | yMargin_ |
Margin to add on the top and bottom side of the figure in pixels. More... | |
colour | lineColour_ |
Current drawing colour for lines. More... | |
colour | fillColour_ |
Current colour for filling shape backgrounds. More... | |
Static Private Attributes | |
static const unsigned | DEFAULT_MARGIN = 20 |
Default margin width. More... | |
static const std::string | FMT_MOVETO = " %1% %2% moveto" |
Format string for postscript moveto command. More... | |
static const std::string | FMT_LINETO = " %1% %2% lineto" |
Format string for postscript lineto command. More... | |
static const std::string | FMT_RLINETO = " %1% %2% rlineto" |
Format string for postscript rlineto command. More... | |
EPSGenerator is a tool for drawing vector graphics to an eps file.
The drawing is done into a buffer using various drawing methods. Once the drawing is done, the buffer which contains a valid .eps file can be written to an output stream.
The coordinate system used by EPSGenerator corresponds to the Postscript coordinate system. Origo is in the lower left corner of the image and one pixel corresponds to one 72th of an inch.
Definition at line 54 of file EPSGenerator.hh.
EPSGenerator::EPSGenerator | ( | ) |
The Constructor.
Definition at line 51 of file EPSGenerator.cc.
References EPSGenerator::colour::b, creationDate_, fillColour_, EPSGenerator::colour::g, lineColour_, and EPSGenerator::colour::r.
EPSGenerator::~EPSGenerator | ( | ) |
The Destructor.
Definition at line 73 of file EPSGenerator.cc.
References clearBuffer().
|
private |
Copying forbidden.
|
private |
Stretches eps bounds so that the given point is inside the bounds.
Definition at line 81 of file EPSGenerator.cc.
References boundsSet_, maxX_, maxY_, minX_, and minY_.
Referenced by doDrawEllipse(), drawCirclePath(), drawLine(), drawPolygonPath(), and drawRectanglePath().
void EPSGenerator::clearBuffer | ( | ) |
Clears the eps code buffer.
Definition at line 517 of file EPSGenerator.cc.
References buffer_.
Referenced by EPSDC::Clear(), and ~EPSGenerator().
|
private |
Writes path of an ellipse outline to the eps buffer.
x | X-coordinate of the ellipse bounding box lower left corner. |
y | Y-coordinate of the ellipse bounding box lower left corner. |
width | Width of the ellipse. |
height | Height of the ellipse. |
fill | True, if the ellipse shoud be filled. |
Definition at line 348 of file EPSGenerator.cc.
References appendToBounds(), buffer_, useFillColour(), and useLineColour().
Referenced by drawEllipse(), and drawFilledEllipse().
void EPSGenerator::drawCircle | ( | int | x, |
int | y, | ||
unsigned | radius | ||
) |
Draws a circle.
x | X-coordinate of the circle centre. |
y | Y-coordinate of the circle centre. |
radius | Radius of the circle. |
Definition at line 262 of file EPSGenerator.cc.
References buffer_, and drawCirclePath().
Referenced by EPSDC::drawCircle().
|
private |
Writes path of a circle outline to the eps buffer.
x | X-coordinate of the circle centre. |
y | Y-coordinate of the circle centre. |
radius | Radius of the circle. |
Definition at line 294 of file EPSGenerator.cc.
References appendToBounds(), and buffer_.
Referenced by drawCircle(), and drawFilledCircle().
void EPSGenerator::drawEllipse | ( | int | x, |
int | y, | ||
unsigned | width, | ||
unsigned | height | ||
) |
Draws outline of an ellipse.
x | X-coordinate of the ellipse bounding box lower left corner. |
y | Y-coordinate of the ellipse bounding box lower left corner. |
width | Width of the ellipse. |
height | Height of the ellipse. |
Definition at line 318 of file EPSGenerator.cc.
References doDrawEllipse().
Referenced by EPSDC::DoDrawEllipse().
void EPSGenerator::drawFilledCircle | ( | int | x, |
int | y, | ||
unsigned | radius | ||
) |
Draws a circle filled with the fill colour.
x | X-coordinate of the circle centre. |
y | Y-coordinate of the circle centre. |
radius | Radius of the circle. |
Definition at line 275 of file EPSGenerator.cc.
References buffer_, drawCirclePath(), useFillColour(), and useLineColour().
Referenced by EPSDC::drawCircle().
void EPSGenerator::drawFilledEllipse | ( | int | x, |
int | y, | ||
unsigned | width, | ||
unsigned | height | ||
) |
Draws a filled ellipse.
x | X-coordinate of the ellipse bounding box lower left corner. |
y | Y-coordinate of the ellipse bounding box lower left corner. |
width | Width of the ellipse. |
height | Height of the ellipse. |
Definition at line 332 of file EPSGenerator.cc.
References doDrawEllipse().
Referenced by EPSDC::DoDrawEllipse().
void EPSGenerator::drawFilledPolygon | ( | const VertexList & | vertices | ) |
Draws a filled polygon.
vertices | Vector of at least three coordinate pairs which are the polygon vertices. |
Definition at line 206 of file EPSGenerator.cc.
References assert, buffer_, drawPolygonPath(), VertexList::size(), useFillColour(), and useLineColour().
Referenced by EPSDC::DoDrawPolygon().
void EPSGenerator::drawFilledRectangle | ( | int | x, |
int | y, | ||
unsigned | width, | ||
unsigned | height | ||
) |
Draws a rectangle fileld with the fill colour set.
x | Lower left corner x-coordinate of the rectangle. |
y | Lower left corner y-coordinate of the rectangle. |
width | Width of the rectangle. |
height | Height of the rectangle. |
Definition at line 120 of file EPSGenerator.cc.
References buffer_, drawRectanglePath(), useFillColour(), and useLineColour().
Referenced by EPSDC::DoDrawRectangle().
void EPSGenerator::drawLine | ( | int | x1, |
int | y1, | ||
int | x2, | ||
int | y2 | ||
) |
Draws a line.
x1 | X-coordinate of the first end point of the line. |
y1 | Y-coordinate of the first end point of the line. |
x2 | X-coordinate of the second end point of the line. |
y2 | Y-coordinate of the second end point of the line. |
Definition at line 171 of file EPSGenerator.cc.
References appendToBounds(), buffer_, FMT_LINETO, and FMT_MOVETO.
Referenced by EPSDC::DoDrawLine().
void EPSGenerator::drawPolygon | ( | const VertexList & | vertices | ) |
Draws a polygon outline.
vertices | Vector of at least three coordinate pairs which are the polygon vertices. |
Definition at line 192 of file EPSGenerator.cc.
References assert, buffer_, drawPolygonPath(), and VertexList::size().
Referenced by EPSDC::DoDrawPolygon().
|
private |
Writes path of a polygon outline to the eps buffer.
vertices | Vector of at least three coordinate pairs which are the polygon vertices. |
Definition at line 225 of file EPSGenerator.cc.
References appendToBounds(), assert, buffer_, FMT_LINETO, FMT_MOVETO, VertexList::size(), VertexList::vertexX(), and VertexList::vertexY().
Referenced by drawFilledPolygon(), and drawPolygon().
void EPSGenerator::drawRectangle | ( | int | x, |
int | y, | ||
unsigned | width, | ||
unsigned | height | ||
) |
Draws a rectangle.
x | Lower left corner x-coordinate of the rectangle. |
y | Lower left corner y-coordinate of the rectangle. |
width | Width of the rectangle. |
height | Height of the rectangle. |
Definition at line 106 of file EPSGenerator.cc.
References buffer_, and drawRectanglePath().
Referenced by EPSDC::DoDrawRectangle().
|
private |
Writes path of a rectangle outline to the eps buffer.
x | Lower left corner x-coordinate of the rectangle. |
y | Lower left corner y-coordinate of the rectangle. |
width | Width of the rectangle. |
height | Height of the rectangle. |
Definition at line 141 of file EPSGenerator.cc.
References appendToBounds(), buffer_, FMT_MOVETO, and FMT_RLINETO.
Referenced by drawFilledRectangle(), and drawRectangle().
void EPSGenerator::drawText | ( | int | x, |
int | y, | ||
std::string | text | ||
) |
Draws text to the eps with the current font set with setFont method.
x | X-coordinate of the text bounds lower left corner. |
y | Y-coordinate of the text bounds lower left corner. |
text | Text to draw. |
Definition at line 392 of file EPSGenerator.cc.
References buffer_.
Referenced by EPSDC::DoDrawText().
|
private |
Assignment forbidden.
void EPSGenerator::setCreator | ( | std::string | creator | ) |
Sets the creator string of the image.
The creator string will be set as the Creator comment of the generated eps file.
creator | String describing the creator of the eps-file. |
Definition at line 415 of file EPSGenerator.cc.
References creator_.
Referenced by EPSDC::setCreator().
void EPSGenerator::setFillColour | ( | double | r, |
double | g, | ||
double | b | ||
) |
Sets the shape filling colour.
r | Red component scaled between 0 and 1. |
g | Green component scaled between 0 and 1. |
b | Blue component scaled between 0 and 1. |
Definition at line 499 of file EPSGenerator.cc.
References EPSGenerator::colour::b, fillColour_, EPSGenerator::colour::g, and EPSGenerator::colour::r.
Referenced by EPSDC::setFillColour().
void EPSGenerator::setFont | ( | unsigned | size, |
std::string | fontName = "Courier-Bold" |
||
) |
Sets the font face and size.
size | Font height in pixels. |
fontName | Name of the font. The name must be valid post script font name. |
Definition at line 460 of file EPSGenerator.cc.
References buffer_.
Referenced by EPSDC::SetFont().
void EPSGenerator::setLineColour | ( | double | r, |
double | g, | ||
double | b | ||
) |
Sets the line drawing colour.
r | Red component scaled between 0 and 1. |
g | Green component scaled between 0 and 1. |
b | Blue component scaled between 0 and 1. |
Definition at line 475 of file EPSGenerator.cc.
References EPSGenerator::colour::b, EPSGenerator::colour::g, lineColour_, EPSGenerator::colour::r, and useLineColour().
Referenced by EPSDC::setLineColour().
void EPSGenerator::setLineWidth | ( | unsigned | width | ) |
Sets the line width of the shapes that are drawn after this function call.
width | Width of the lines drawn to the eps. |
Definition at line 444 of file EPSGenerator.cc.
References buffer_, and lineWidth_.
Referenced by EPSDC::SetPen().
void EPSGenerator::setMargins | ( | unsigned | x, |
unsigned | y | ||
) |
void EPSGenerator::setScale | ( | double | scale | ) |
Sets the coordinate system scaling factors for the coordinate axels.
This function sets only the final scaling factor of the image. Only the last scaling factor set before calling writeEPS has effect on the final eps file.
scale | Scaling factor. |
Definition at line 576 of file EPSGenerator.cc.
References scale_.
void EPSGenerator::setTitle | ( | std::string | title | ) |
Sets the title of the eps file.
Title string will be set as the title comment of the generated eps file. If the title string is empty, the title comment will be omitted.
title | Title of the eps file. |
Definition at line 428 of file EPSGenerator.cc.
References hasTitle_, and title_.
Referenced by EPSDC::setTitle().
|
private |
Sets the eps drawing colour to the current filling colour.
Definition at line 614 of file EPSGenerator.cc.
References EPSGenerator::colour::b, buffer_, fillColour_, EPSGenerator::colour::g, and EPSGenerator::colour::r.
Referenced by doDrawEllipse(), drawFilledCircle(), drawFilledPolygon(), and drawFilledRectangle().
|
private |
Sets the eps drawing colour to the current line drawing colour.
Definition at line 604 of file EPSGenerator.cc.
References EPSGenerator::colour::b, buffer_, EPSGenerator::colour::g, lineColour_, and EPSGenerator::colour::r.
Referenced by doDrawEllipse(), drawFilledCircle(), drawFilledPolygon(), drawFilledRectangle(), and setLineColour().
void EPSGenerator::writeEPS | ( | std::ostream & | ostream | ) |
Generates an eps file which contains the graphics client drew.
ostream | Output stream to write the eps file contents to. |
Definition at line 529 of file EPSGenerator.cc.
References buffer_, creationDate_, creator_, hasTitle_, maxX_, maxY_, minX_, minY_, scale_, title_, xMargin_, and yMargin_.
Referenced by EPSDC::writeToStream().
|
private |
True, if a point has been added to the bounds.
Definition at line 145 of file EPSGenerator.hh.
Referenced by appendToBounds().
|
private |
Buffer for the .eps code to be written.
Definition at line 127 of file EPSGenerator.hh.
Referenced by clearBuffer(), doDrawEllipse(), drawCircle(), drawCirclePath(), drawFilledCircle(), drawFilledPolygon(), drawFilledRectangle(), drawLine(), drawPolygon(), drawPolygonPath(), drawRectangle(), drawRectanglePath(), drawText(), setFont(), setLineWidth(), useFillColour(), useLineColour(), and writeEPS().
|
private |
String describing the creation date of the EPS file.
Definition at line 125 of file EPSGenerator.hh.
Referenced by EPSGenerator(), and writeEPS().
|
private |
String describing the creator of the document.
Definition at line 123 of file EPSGenerator.hh.
Referenced by setCreator(), and writeEPS().
|
staticprivate |
Default margin width.
Definition at line 158 of file EPSGenerator.hh.
|
private |
Current colour for filling shape backgrounds.
Definition at line 155 of file EPSGenerator.hh.
Referenced by EPSGenerator(), setFillColour(), and useFillColour().
|
staticprivate |
Format string for postscript lineto command.
Definition at line 163 of file EPSGenerator.hh.
Referenced by drawLine(), and drawPolygonPath().
|
staticprivate |
Format string for postscript moveto command.
Definition at line 161 of file EPSGenerator.hh.
Referenced by drawLine(), drawPolygonPath(), and drawRectanglePath().
|
staticprivate |
Format string for postscript rlineto command.
Definition at line 165 of file EPSGenerator.hh.
Referenced by drawRectanglePath().
|
private |
True, if the EPS file has a title.
Definition at line 118 of file EPSGenerator.hh.
Referenced by setTitle(), and writeEPS().
|
private |
Current drawing colour for lines.
Definition at line 153 of file EPSGenerator.hh.
Referenced by EPSGenerator(), setLineColour(), and useLineColour().
|
private |
Current width of the lines drawn.
Definition at line 130 of file EPSGenerator.hh.
Referenced by setLineWidth().
|
private |
Maximum x-coordinate used before scaling & translation.
Definition at line 137 of file EPSGenerator.hh.
Referenced by appendToBounds(), and writeEPS().
|
private |
Maximum y-coordinate used before scaling & translation.
Definition at line 139 of file EPSGenerator.hh.
Referenced by appendToBounds(), and writeEPS().
|
private |
Minimum x-coordinate used before scaling & translation.
Definition at line 133 of file EPSGenerator.hh.
Referenced by appendToBounds(), and writeEPS().
|
private |
Minimum y-coordinate used before scaling & translation.
Definition at line 135 of file EPSGenerator.hh.
Referenced by appendToBounds(), and writeEPS().
|
private |
Final scaling factor for the eps file.
Definition at line 142 of file EPSGenerator.hh.
Referenced by setScale(), and writeEPS().
|
private |
Title of the EPS file.
Definition at line 120 of file EPSGenerator.hh.
Referenced by setTitle(), and writeEPS().
|
private |
Margin to add on the left and right side of the figure in pixels.
Definition at line 148 of file EPSGenerator.hh.
Referenced by setMargins(), and writeEPS().
|
private |
Margin to add on the top and bottom side of the figure in pixels.
Definition at line 150 of file EPSGenerator.hh.
Referenced by setMargins(), and writeEPS().