OpenASIP  2.0
Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
EPSGenerator Class Reference

#include <EPSGenerator.hh>

Collaboration diagram for EPSGenerator:
Collaboration graph

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...
 
EPSGeneratoroperator= (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ EPSGenerator() [1/2]

EPSGenerator::EPSGenerator ( )

The Constructor.

Definition at line 51 of file EPSGenerator.cc.

51  :
52  hasTitle_(false), title_(""), creator_("TCE EPS Generator"),
53  lineWidth_(1), minX_(0), minY_(0), maxX_(0), maxY_(0),
56 
57  time_t currentTime;
58  time(&currentTime);
59  creationDate_ = ctime(&currentTime);
60 
61  fillColour_.r = 0;
62  fillColour_.g = 0;
63  fillColour_.b = 0;
64  lineColour_.r = 0;
65  lineColour_.g = 0;
66  lineColour_.b = 0;
67 }

References EPSGenerator::colour::b, creationDate_, fillColour_, EPSGenerator::colour::g, lineColour_, and EPSGenerator::colour::r.

◆ ~EPSGenerator()

EPSGenerator::~EPSGenerator ( )

The Destructor.

Definition at line 73 of file EPSGenerator.cc.

73  {
74  clearBuffer();
75 }

References clearBuffer().

Here is the call graph for this function:

◆ EPSGenerator() [2/2]

EPSGenerator::EPSGenerator ( const EPSGenerator )
private

Copying forbidden.

Member Function Documentation

◆ appendToBounds()

void EPSGenerator::appendToBounds ( int  x,
int  y 
)
private

Stretches eps bounds so that the given point is inside the bounds.

Definition at line 81 of file EPSGenerator.cc.

81  {
82 
83  if (boundsSet_) {
84  minX_ = (x < minX_) ? x : minX_;
85  maxX_ = (x > maxX_) ? x : maxX_;
86  minY_ = (y < minY_) ? y : minY_;
87  maxY_ = (y > maxY_) ? y : maxY_;
88  } else {
89  boundsSet_ = true;
90  minX_ = x;
91  maxX_ = x;
92  minY_ = y;
93  maxY_ = y;
94  }
95 }

References boundsSet_, maxX_, maxY_, minX_, and minY_.

Referenced by doDrawEllipse(), drawCirclePath(), drawLine(), drawPolygonPath(), and drawRectanglePath().

◆ clearBuffer()

void EPSGenerator::clearBuffer ( )

Clears the eps code buffer.

Definition at line 517 of file EPSGenerator.cc.

517  {
518  while(!buffer_.empty()) {
519  buffer_.pop();
520  }
521 }

References buffer_.

Referenced by EPSDC::Clear(), and ~EPSGenerator().

◆ doDrawEllipse()

void EPSGenerator::doDrawEllipse ( int  x,
int  y,
unsigned  width,
unsigned  height,
bool  fill 
)
private

Writes path of an ellipse outline to the eps buffer.

Parameters
xX-coordinate of the ellipse bounding box lower left corner.
yY-coordinate of the ellipse bounding box lower left corner.
widthWidth of the ellipse.
heightHeight of the ellipse.
fillTrue, if the ellipse shoud be filled.

Definition at line 348 of file EPSGenerator.cc.

349  {
350 
351  appendToBounds(x + width, y + height);
352  appendToBounds(x, y);
353 
354  buffer_.push("");
355 
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);
360 
361  buffer_.push("gsave");
362  buffer_.push(fmtTranslate.str());
363  buffer_.push(fmtScale.str());
364 
365 
366  std::string fmtEllipse = " 0 0 %4% 2 div 0 360 arc";
367 
368  boost::format ellipse = format(fmtEllipse) % x % y % width % height;
369  buffer_.push("newpath");
370  buffer_.push(ellipse.str());
371 
372  if (fill) {
373  buffer_.push(" gsave");
374  useFillColour();
375  buffer_.push(" fill");
376  buffer_.push(" grestore");
377  useLineColour();
378  }
379 
380  buffer_.push("stroke");
381  buffer_.push("grestore");
382 }

References appendToBounds(), buffer_, useFillColour(), and useLineColour().

Referenced by drawEllipse(), and drawFilledEllipse().

Here is the call graph for this function:

◆ drawCircle()

void EPSGenerator::drawCircle ( int  x,
int  y,
unsigned  radius 
)

Draws a circle.

Parameters
xX-coordinate of the circle centre.
yY-coordinate of the circle centre.
radiusRadius of the circle.

Definition at line 262 of file EPSGenerator.cc.

262  {
263  drawCirclePath(x, y, radius);
264  buffer_.push("stroke");
265 }

References buffer_, and drawCirclePath().

Referenced by EPSDC::drawCircle().

Here is the call graph for this function:

◆ drawCirclePath()

void EPSGenerator::drawCirclePath ( int  x,
int  y,
unsigned  radius 
)
private

Writes path of a circle outline to the eps buffer.

Parameters
xX-coordinate of the circle centre.
yY-coordinate of the circle centre.
radiusRadius of the circle.

Definition at line 294 of file EPSGenerator.cc.

294  {
295 
296  appendToBounds(x + radius, y + radius);
297  appendToBounds(x - radius, y - radius);
298 
299  buffer_.push("");
300 
301  std::string fmtCircle = " %1% %2% %3% 0 360 arc";
302 
303  boost::format circle = format(fmtCircle) % x % y % radius;
304  buffer_.push("newpath");
305  buffer_.push(circle.str());
306 }

References appendToBounds(), and buffer_.

Referenced by drawCircle(), and drawFilledCircle().

Here is the call graph for this function:

◆ drawEllipse()

void EPSGenerator::drawEllipse ( int  x,
int  y,
unsigned  width,
unsigned  height 
)

Draws outline of an ellipse.

Parameters
xX-coordinate of the ellipse bounding box lower left corner.
yY-coordinate of the ellipse bounding box lower left corner.
widthWidth of the ellipse.
heightHeight of the ellipse.

Definition at line 318 of file EPSGenerator.cc.

318  {
319  doDrawEllipse(x, y, width, height, false);
320 }

References doDrawEllipse().

Referenced by EPSDC::DoDrawEllipse().

Here is the call graph for this function:

◆ drawFilledCircle()

void EPSGenerator::drawFilledCircle ( int  x,
int  y,
unsigned  radius 
)

Draws a circle filled with the fill colour.

Parameters
xX-coordinate of the circle centre.
yY-coordinate of the circle centre.
radiusRadius of the circle.

Definition at line 275 of file EPSGenerator.cc.

275  {
276  drawCirclePath(x, y, radius);
277  buffer_.push(" gsave");
278  useFillColour();
279  buffer_.push(" fill");
280  buffer_.push(" grestore");
281  useLineColour();
282  buffer_.push("stroke");
283 }

References buffer_, drawCirclePath(), useFillColour(), and useLineColour().

Referenced by EPSDC::drawCircle().

Here is the call graph for this function:

◆ drawFilledEllipse()

void EPSGenerator::drawFilledEllipse ( int  x,
int  y,
unsigned  width,
unsigned  height 
)

Draws a filled ellipse.

Parameters
xX-coordinate of the ellipse bounding box lower left corner.
yY-coordinate of the ellipse bounding box lower left corner.
widthWidth of the ellipse.
heightHeight of the ellipse.

Definition at line 332 of file EPSGenerator.cc.

333  {
334 
335  doDrawEllipse(x, y, width, height, true);
336 }

References doDrawEllipse().

Referenced by EPSDC::DoDrawEllipse().

Here is the call graph for this function:

◆ drawFilledPolygon()

void EPSGenerator::drawFilledPolygon ( const VertexList vertices)

Draws a filled polygon.

Parameters
verticesVector of at least three coordinate pairs which are the polygon vertices.

Definition at line 206 of file EPSGenerator.cc.

206  {
207 
208  assert(vertices.size() > 2);
209  drawPolygonPath(vertices);
210  buffer_.push(" gsave");
211  useFillColour();
212  buffer_.push(" fill");
213  buffer_.push(" grestore");
214  useLineColour();
215  buffer_.push("stroke");
216 }

References assert, buffer_, drawPolygonPath(), VertexList::size(), useFillColour(), and useLineColour().

Referenced by EPSDC::DoDrawPolygon().

Here is the call graph for this function:

◆ drawFilledRectangle()

void EPSGenerator::drawFilledRectangle ( int  x,
int  y,
unsigned  width,
unsigned  height 
)

Draws a rectangle fileld with the fill colour set.

Parameters
xLower left corner x-coordinate of the rectangle.
yLower left corner y-coordinate of the rectangle.
widthWidth of the rectangle.
heightHeight of the rectangle.

Definition at line 120 of file EPSGenerator.cc.

121  {
122 
123  drawRectanglePath(x, y, width, height);
124  buffer_.push(" gsave");
125  useFillColour();
126  buffer_.push(" fill");
127  buffer_.push(" grestore");
128  useLineColour();
129  buffer_.push("stroke");
130 }

References buffer_, drawRectanglePath(), useFillColour(), and useLineColour().

Referenced by EPSDC::DoDrawRectangle().

Here is the call graph for this function:

◆ drawLine()

void EPSGenerator::drawLine ( int  x1,
int  y1,
int  x2,
int  y2 
)

Draws a line.

Parameters
x1X-coordinate of the first end point of the line.
y1Y-coordinate of the first end point of the line.
x2X-coordinate of the second end point of the line.
y2Y-coordinate of the second end point of the line.

Definition at line 171 of file EPSGenerator.cc.

171  {
172 
173  appendToBounds(x1, y1);
174  appendToBounds(x2, y2);
175 
176  format move = format(FMT_MOVETO) % x1 % y1;
177  format line = format(FMT_LINETO) % x2 % y2;
178  buffer_.push("");
179  buffer_.push("newpath");
180  buffer_.push(move.str());
181  buffer_.push(line.str() );
182  buffer_.push("stroke");
183 }

References appendToBounds(), buffer_, FMT_LINETO, and FMT_MOVETO.

Referenced by EPSDC::DoDrawLine().

Here is the call graph for this function:

◆ drawPolygon()

void EPSGenerator::drawPolygon ( const VertexList vertices)

Draws a polygon outline.

Parameters
verticesVector of at least three coordinate pairs which are the polygon vertices.

Definition at line 192 of file EPSGenerator.cc.

192  {
193  assert(vertices.size() > 2);
194  drawPolygonPath(vertices);
195  buffer_.push("stroke");
196 }

References assert, buffer_, drawPolygonPath(), and VertexList::size().

Referenced by EPSDC::DoDrawPolygon().

Here is the call graph for this function:

◆ drawPolygonPath()

void EPSGenerator::drawPolygonPath ( const VertexList vertices)
private

Writes path of a polygon outline to the eps buffer.

Parameters
verticesVector of at least three coordinate pairs which are the polygon vertices.

Definition at line 225 of file EPSGenerator.cc.

225  {
226 
227  assert(vertices.size() > 2);
228 
229  format move(FMT_MOVETO);
230 
231  int x = vertices.vertexX(0);
232  int y = vertices.vertexY(0);
233  appendToBounds(x, y);
234  move % x % y;
235 
236  buffer_.push("");
237  buffer_.push("newpath");
238  buffer_.push(move.str());
239 
240  for (unsigned i = 1; i < vertices.size(); i++) {
241 
242  x = vertices.vertexX(i);
243  y = vertices.vertexY(i);
244  appendToBounds(x, y);
245  format lineto(FMT_LINETO);
246  lineto % x % y;
247  buffer_.push(lineto.str());
248  }
249 
250  buffer_.push(" closepath");
251 }

References appendToBounds(), assert, buffer_, FMT_LINETO, FMT_MOVETO, VertexList::size(), VertexList::vertexX(), and VertexList::vertexY().

Referenced by drawFilledPolygon(), and drawPolygon().

Here is the call graph for this function:

◆ drawRectangle()

void EPSGenerator::drawRectangle ( int  x,
int  y,
unsigned  width,
unsigned  height 
)

Draws a rectangle.

Parameters
xLower left corner x-coordinate of the rectangle.
yLower left corner y-coordinate of the rectangle.
widthWidth of the rectangle.
heightHeight of the rectangle.

Definition at line 106 of file EPSGenerator.cc.

106  {
107  drawRectanglePath(x, y, width, height);
108  buffer_.push("stroke");
109 }

References buffer_, and drawRectanglePath().

Referenced by EPSDC::DoDrawRectangle().

Here is the call graph for this function:

◆ drawRectanglePath()

void EPSGenerator::drawRectanglePath ( int  x,
int  y,
unsigned  width,
unsigned  height 
)
private

Writes path of a rectangle outline to the eps buffer.

Parameters
xLower left corner x-coordinate of the rectangle.
yLower left corner y-coordinate of the rectangle.
widthWidth of the rectangle.
heightHeight of the rectangle.

Definition at line 141 of file EPSGenerator.cc.

142  {
143 
144  appendToBounds(x, y);
145  appendToBounds(x + width, y + height);
146 
147  format move = format(FMT_MOVETO) % x % y;
148  format line1 = format(FMT_RLINETO) % width % 0;
149  format line2 = format(FMT_RLINETO) % 0 % height;
150  format line3 = format(FMT_RLINETO) % (-1 * (int)width) % 0;
151 
152  buffer_.push("");
153  buffer_.push("newpath");
154  buffer_.push(move.str());
155  buffer_.push(line1.str());
156  buffer_.push(line2.str());
157  buffer_.push(line3.str());
158  buffer_.push(" closepath");
159 }

References appendToBounds(), buffer_, FMT_MOVETO, and FMT_RLINETO.

Referenced by drawFilledRectangle(), and drawRectangle().

Here is the call graph for this function:

◆ drawText()

void EPSGenerator::drawText ( int  x,
int  y,
std::string  text 
)

Draws text to the eps with the current font set with setFont method.

Parameters
xX-coordinate of the text bounds lower left corner.
yY-coordinate of the text bounds lower left corner.
textText to draw.

Definition at line 392 of file EPSGenerator.cc.

392  {
393 
394  format fmtMoveTo("%1% %2% moveto");
395  format fmtShowText(" (%1%) show");
396 
397  fmtMoveTo % x % y;
398  fmtShowText % text;
399 
400  buffer_.push("");
401  buffer_.push(fmtMoveTo.str());
402  buffer_.push(fmtShowText.str());
403 
404 }

References buffer_.

Referenced by EPSDC::DoDrawText().

◆ operator=()

EPSGenerator& EPSGenerator::operator= ( const EPSGenerator )
private

Assignment forbidden.

◆ setCreator()

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.

Parameters
creatorString describing the creator of the eps-file.

Definition at line 415 of file EPSGenerator.cc.

415  {
416  creator_ = creator;
417 }

References creator_.

Referenced by EPSDC::setCreator().

◆ setFillColour()

void EPSGenerator::setFillColour ( double  r,
double  g,
double  b 
)

Sets the shape filling colour.

Parameters
rRed component scaled between 0 and 1.
gGreen component scaled between 0 and 1.
bBlue component scaled between 0 and 1.

Definition at line 499 of file EPSGenerator.cc.

499  {
500  if (r < 0 || g < 0 || b < 0 || r > 1 || g > 1 || b > 1) {
501  std::string error =
502  "Colour component values must be between 0 and 1.";
503  std::string proc = "EPSGenerator::setFillColour";
504  OutOfRange e(__FILE__, __LINE__, proc, error);
505  throw e;
506  }
507 
508  fillColour_.r = r;
509  fillColour_.g = g;
510  fillColour_.b = b;
511 }

References EPSGenerator::colour::b, fillColour_, EPSGenerator::colour::g, and EPSGenerator::colour::r.

Referenced by EPSDC::setFillColour().

◆ setFont()

void EPSGenerator::setFont ( unsigned  size,
std::string  fontName = "Courier-Bold" 
)

Sets the font face and size.

Parameters
sizeFont height in pixels.
fontNameName of the font. The name must be valid post script font name.

Definition at line 460 of file EPSGenerator.cc.

460  {
461  format setFont = format("/%2% findfont %1% scalefont setfont");
462  setFont % size % fontName;
463  buffer_.push("");
464  buffer_.push(setFont.str());
465 }

References buffer_.

Referenced by EPSDC::SetFont().

◆ setLineColour()

void EPSGenerator::setLineColour ( double  r,
double  g,
double  b 
)

Sets the line drawing colour.

Parameters
rRed component scaled between 0 and 1.
gGreen component scaled between 0 and 1.
bBlue component scaled between 0 and 1.

Definition at line 475 of file EPSGenerator.cc.

475  {
476  if (r < 0 || g < 0 || b < 0 || r > 1 || g > 1 || b > 1) {
477  std::string error =
478  "Colour component values must be between 0 and 1.";
479  std::string proc = "EPSGenerator::setLineColour";
480  OutOfRange e(__FILE__, __LINE__, proc, error);
481  throw e;
482  }
483 
484  lineColour_.r = r;
485  lineColour_.g = g;
486  lineColour_.b = b;
487 
488  useLineColour();
489 }

References EPSGenerator::colour::b, EPSGenerator::colour::g, lineColour_, EPSGenerator::colour::r, and useLineColour().

Referenced by EPSDC::setLineColour().

Here is the call graph for this function:

◆ setLineWidth()

void EPSGenerator::setLineWidth ( unsigned  width)

Sets the line width of the shapes that are drawn after this function call.

Parameters
widthWidth of the lines drawn to the eps.

Definition at line 444 of file EPSGenerator.cc.

444  {
445  lineWidth_ = width;
446  buffer_.push("");
447  std::string setlinewidth = "%1% setlinewidth";
448  buffer_.push(str(format(setlinewidth) % width));
449 }

References buffer_, and lineWidth_.

Referenced by EPSDC::SetPen().

◆ setMargins()

void EPSGenerator::setMargins ( unsigned  x,
unsigned  y 
)

Sets the eps margins.

Parameters
xLeft and right side margin.
yTop and bottom margin.

Definition at line 594 of file EPSGenerator.cc.

594  {
595  xMargin_ = x;
596  yMargin_ = y;
597 }

References xMargin_, and yMargin_.

◆ setScale()

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.

Parameters
scaleScaling factor.

Definition at line 576 of file EPSGenerator.cc.

576  {
577  if (scale < 0) {
578  std::string error = "Scaling factor must be greater than zero.";
579  std::string proc = "EPSGenerator::setScale";
580  OutOfRange e(__FILE__, __LINE__, proc, error);
581  throw e;
582  }
583 
584  scale_ = scale;
585 }

References scale_.

◆ setTitle()

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.

Parameters
titleTitle of the eps file.

Definition at line 428 of file EPSGenerator.cc.

428  {
429 
430  if (title.length() > 0) {
431  hasTitle_ = true;
432  } else {
433  hasTitle_ = false;
434  }
435  title_ = title;
436 }

References hasTitle_, and title_.

Referenced by EPSDC::setTitle().

◆ useFillColour()

void EPSGenerator::useFillColour ( )
private

Sets the eps drawing colour to the current filling colour.

Definition at line 614 of file EPSGenerator.cc.

614  {
615  format setColour("%1% %2% %3% setrgbcolor");
616  setColour % fillColour_.r % fillColour_.g % fillColour_.b;
617  buffer_.push(setColour.str());
618 }

References EPSGenerator::colour::b, buffer_, fillColour_, EPSGenerator::colour::g, and EPSGenerator::colour::r.

Referenced by doDrawEllipse(), drawFilledCircle(), drawFilledPolygon(), and drawFilledRectangle().

◆ useLineColour()

void EPSGenerator::useLineColour ( )
private

Sets the eps drawing colour to the current line drawing colour.

Definition at line 604 of file EPSGenerator.cc.

604  {
605  format setColour("%1% %2% %3% setrgbcolor");
606  setColour % lineColour_.r % lineColour_.g % lineColour_.b;
607  buffer_.push(setColour.str());
608 }

References EPSGenerator::colour::b, buffer_, EPSGenerator::colour::g, lineColour_, and EPSGenerator::colour::r.

Referenced by doDrawEllipse(), drawFilledCircle(), drawFilledPolygon(), drawFilledRectangle(), and setLineColour().

◆ writeEPS()

void EPSGenerator::writeEPS ( std::ostream &  ostream)

Generates an eps file which contains the graphics client drew.

Parameters
ostreamOutput stream to write the eps file contents to.

Definition at line 529 of file EPSGenerator.cc.

529  {
530 
531  int w = (int)(scale_*(maxX_ - minX_ + 2 * xMargin_));
532  int h = (int)(scale_*(maxY_ - minY_ + 2 * yMargin_));
533 
534  // Write eps headers.
535  ostream << "%!PS-Adobe-3.0 EPSF-3.0" << endl;
536  ostream << "%%BoundingBox: 0 0 " << w << " " << h << " " << endl;
537  if (hasTitle_) {
538  ostream << "%%Title: (" << title_ << ")" << endl;
539  }
540  ostream << "%%Creator: " << creator_ << endl;
541  ostream << "%%CreationDate: " << creationDate_ << endl;
542  ostream << "%%EndComments" << endl;
543 
544 
545  // Set scaling factor & translation. The coordinate system is translated
546  // so that the minimum x and y coordinates are zero.
547  ostream << scale_ << " " << scale_ << " scale" << endl;
548  ostream << minX_ * -1 + (int)xMargin_ << " "
549  << minY_ * -1 + (int)yMargin_ << " translate" << endl;
550 
551 
552  // Write the postscript drawing code from the code buffer to the
553  // output stream.
554  while (!buffer_.empty()) {
555  std::string line = buffer_.front();
556  buffer_.pop();
557  ostream << line << endl;
558  }
559  ostream << endl << "showpage" << endl << endl;
560 
561  // Write end of file comment.
562  ostream << "%%EOF" << endl;
563 }

References buffer_, creationDate_, creator_, hasTitle_, maxX_, maxY_, minX_, minY_, scale_, title_, xMargin_, and yMargin_.

Referenced by EPSDC::writeToStream().

Member Data Documentation

◆ boundsSet_

bool EPSGenerator::boundsSet_
private

True, if a point has been added to the bounds.

Definition at line 145 of file EPSGenerator.hh.

Referenced by appendToBounds().

◆ buffer_

std::queue<std::string> EPSGenerator::buffer_
private

◆ creationDate_

std::string EPSGenerator::creationDate_
private

String describing the creation date of the EPS file.

Definition at line 125 of file EPSGenerator.hh.

Referenced by EPSGenerator(), and writeEPS().

◆ creator_

std::string EPSGenerator::creator_
private

String describing the creator of the document.

Definition at line 123 of file EPSGenerator.hh.

Referenced by setCreator(), and writeEPS().

◆ DEFAULT_MARGIN

const unsigned EPSGenerator::DEFAULT_MARGIN = 20
staticprivate

Default margin width.

Definition at line 158 of file EPSGenerator.hh.

◆ fillColour_

colour EPSGenerator::fillColour_
private

Current colour for filling shape backgrounds.

Definition at line 155 of file EPSGenerator.hh.

Referenced by EPSGenerator(), setFillColour(), and useFillColour().

◆ FMT_LINETO

const std::string EPSGenerator::FMT_LINETO = " %1% %2% lineto"
staticprivate

Format string for postscript lineto command.

Definition at line 163 of file EPSGenerator.hh.

Referenced by drawLine(), and drawPolygonPath().

◆ FMT_MOVETO

const std::string EPSGenerator::FMT_MOVETO = " %1% %2% moveto"
staticprivate

Format string for postscript moveto command.

Definition at line 161 of file EPSGenerator.hh.

Referenced by drawLine(), drawPolygonPath(), and drawRectanglePath().

◆ FMT_RLINETO

const std::string EPSGenerator::FMT_RLINETO = " %1% %2% rlineto"
staticprivate

Format string for postscript rlineto command.

Definition at line 165 of file EPSGenerator.hh.

Referenced by drawRectanglePath().

◆ hasTitle_

bool EPSGenerator::hasTitle_
private

True, if the EPS file has a title.

Definition at line 118 of file EPSGenerator.hh.

Referenced by setTitle(), and writeEPS().

◆ lineColour_

colour EPSGenerator::lineColour_
private

Current drawing colour for lines.

Definition at line 153 of file EPSGenerator.hh.

Referenced by EPSGenerator(), setLineColour(), and useLineColour().

◆ lineWidth_

unsigned EPSGenerator::lineWidth_
private

Current width of the lines drawn.

Definition at line 130 of file EPSGenerator.hh.

Referenced by setLineWidth().

◆ maxX_

int EPSGenerator::maxX_
private

Maximum x-coordinate used before scaling & translation.

Definition at line 137 of file EPSGenerator.hh.

Referenced by appendToBounds(), and writeEPS().

◆ maxY_

int EPSGenerator::maxY_
private

Maximum y-coordinate used before scaling & translation.

Definition at line 139 of file EPSGenerator.hh.

Referenced by appendToBounds(), and writeEPS().

◆ minX_

int EPSGenerator::minX_
private

Minimum x-coordinate used before scaling & translation.

Definition at line 133 of file EPSGenerator.hh.

Referenced by appendToBounds(), and writeEPS().

◆ minY_

int EPSGenerator::minY_
private

Minimum y-coordinate used before scaling & translation.

Definition at line 135 of file EPSGenerator.hh.

Referenced by appendToBounds(), and writeEPS().

◆ scale_

double EPSGenerator::scale_
private

Final scaling factor for the eps file.

Definition at line 142 of file EPSGenerator.hh.

Referenced by setScale(), and writeEPS().

◆ title_

std::string EPSGenerator::title_
private

Title of the EPS file.

Definition at line 120 of file EPSGenerator.hh.

Referenced by setTitle(), and writeEPS().

◆ xMargin_

unsigned EPSGenerator::xMargin_
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().

◆ yMargin_

unsigned EPSGenerator::yMargin_
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().


The documentation for this class was generated from the following files:
EPSGenerator::minY_
int minY_
Minimum y-coordinate used before scaling & translation.
Definition: EPSGenerator.hh:135
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::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::boundsSet_
bool boundsSet_
True, if a point has been added to the bounds.
Definition: EPSGenerator.hh:145
OutOfRange
Definition: Exception.hh:320
EPSGenerator::scale_
double scale_
Final scaling factor for the eps file.
Definition: EPSGenerator.hh:142
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
VertexList::size
size_t size() const
Definition: VertexList.cc:68
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
assert
#define assert(condition)
Definition: Application.hh:86
EPSGenerator::FMT_LINETO
static const std::string FMT_LINETO
Format string for postscript lineto command.
Definition: EPSGenerator.hh:163
VertexList::vertexY
int vertexY(size_t index) const
Definition: VertexList.cc:101
VertexList::vertexX
int vertexX(size_t index) const
Definition: VertexList.cc:80
EPSGenerator::minX_
int minX_
Minimum x-coordinate used before scaling & translation.
Definition: EPSGenerator.hh:133
EPSGenerator::useFillColour
void useFillColour()
Definition: EPSGenerator.cc:614
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
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::useLineColour
void useLineColour()
Definition: EPSGenerator.cc:604
EPSGenerator::colour::g
double g
Definition: EPSGenerator.hh:113
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::colour::b
double b
Definition: EPSGenerator.hh:114
EPSGenerator::fillColour_
colour fillColour_
Current colour for filling shape backgrounds.
Definition: EPSGenerator.hh:155