33#include <boost/format.hpp>
52 hasTitle_(
false), title_(
""), creator_(
"TCE EPS Generator"),
53 lineWidth_(1), minX_(0), minY_(0), maxX_(0), maxY_(0),
54 scale_(1) ,boundsSet_(
false), xMargin_(DEFAULT_MARGIN),
55 yMargin_(DEFAULT_MARGIN) {
121 int x,
int y,
unsigned width,
unsigned height) {
142 int x,
int y,
unsigned width,
unsigned height) {
150 format line3 = format(
FMT_RLINETO) % (-1 * (int)width) % 0;
240 for (
unsigned i = 1; i < vertices.
size(); i++) {
301 std::string fmtCircle =
" %1% %2% %3% 0 360 arc";
303 boost::format circle = format(fmtCircle) % x % y % radius;
333 int x,
int y,
unsigned width,
unsigned height) {
349 int x,
int y,
unsigned width,
unsigned height,
bool fill) {
356 format fmtScale = format(
"1 %1% %2% div scale");
357 format fmtTranslate = format(
"%1% %2% translate");
358 fmtScale % width % height;
359 fmtTranslate % (x + width / 2) % (y + height / 2);
362 buffer_.push(fmtTranslate.str());
366 std::string fmtEllipse =
" 0 0 %4% 2 div 0 360 arc";
368 boost::format ellipse = format(fmtEllipse) % x % y % width % height;
394 format fmtMoveTo(
"%1% %2% moveto");
395 format fmtShowText(
" (%1%) show");
402 buffer_.push(fmtShowText.str());
430 if (title.length() > 0) {
447 std::string setlinewidth =
"%1% setlinewidth";
448 buffer_.push(str(format(setlinewidth) % width));
461 format
setFont = format(
"/%2% findfont %1% scalefont setfont");
476 if (r < 0 || g < 0 || b < 0 || r > 1 || g > 1 || b > 1) {
478 "Colour component values must be between 0 and 1.";
479 std::string proc =
"EPSGenerator::setLineColour";
480 OutOfRange e(__FILE__, __LINE__, proc, error);
500 if (r < 0 || g < 0 || b < 0 || r > 1 || g > 1 || b > 1) {
502 "Colour component values must be between 0 and 1.";
503 std::string proc =
"EPSGenerator::setFillColour";
504 OutOfRange e(__FILE__, __LINE__, proc, error);
535 ostream <<
"%!PS-Adobe-3.0 EPSF-3.0" << endl;
536 ostream <<
"%%BoundingBox: 0 0 " << w <<
" " << h <<
" " << endl;
538 ostream <<
"%%Title: (" <<
title_ <<
")" << endl;
540 ostream <<
"%%Creator: " <<
creator_ << endl;
542 ostream <<
"%%EndComments" << endl;
555 std::string line =
buffer_.front();
557 ostream << line << endl;
559 ostream << endl <<
"showpage" << endl << endl;
562 ostream <<
"%%EOF" << endl;
578 std::string error =
"Scaling factor must be greater than zero.";
579 std::string proc =
"EPSGenerator::setScale";
580 OutOfRange e(__FILE__, __LINE__, proc, error);
605 format setColour(
"%1% %2% %3% setrgbcolor");
615 format setColour(
"%1% %2% %3% setrgbcolor");
#define assert(condition)
find Finds info of the inner loops in the false
void setTitle(std::string title)
unsigned yMargin_
Margin to add on the top and bottom side of the figure in pixels.
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.
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.
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 setScale(double scale)
void setCreator(std::string creator)
int vertexY(size_t index) const
int vertexX(size_t index) const