diff -r 100c8d5ee36b -r f196dc4f1b31 src/lemon/graph_to_eps.h --- a/src/lemon/graph_to_eps.h Fri Jan 28 09:04:34 2005 +0000 +++ b/src/lemon/graph_to_eps.h Fri Jan 28 09:09:59 2005 +0000 @@ -86,6 +86,11 @@ ConstMap _edgeColors; ConstMap _edgeWidths; + + static const double A4HEIGHT = 841.8897637795276; + static const double A4WIDTH = 595.275590551181; + static const double A4BORDER = 15; + double _edgeWidthScale; @@ -112,6 +117,9 @@ bool _undir; bool _pleaseRemoveOsStream; + + bool _scaleToA4; + ///Constructor ///Constructor @@ -135,7 +143,7 @@ _showNodeText(false), _nodeTexts(false), _nodeTextSize(1), _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0), _undir(false), - _pleaseRemoveOsStream(_pros) {} + _pleaseRemoveOsStream(_pros), _scaleToA4(false) {} }; ///Helper class to implement the named parameters of \ref graphToEps() @@ -143,6 +151,8 @@ ///Helper class to implement the named parameters of \ref graphToEps() ///\todo Is 'helper class' a good name for this? /// +///\todo Follow PostScript's DSC. +///\todo Use own dictionary. template class GraphToEps : public T { typedef typename T::Graph Graph; @@ -201,7 +211,7 @@ ///Sets the map of the node coordinates ///Sets the map of the node coordinates. - ///\param x must be a node map with xy or xy values. + ///\param x must be a node map with xy or \ref xy "xy" values. template GraphToEps > coords(const X &x) { dontPrint=true; return GraphToEps >(CoordsTraits(*this,x)); @@ -359,6 +369,12 @@ /// GraphToEps &arrowWidth(double d) {_arrowWidth*=d;return *this;} + ///Scales the drawing to fit to A4 page + + ///Scales the drawing to fit to A4 page + /// + GraphToEps &scaleToA4() {_scaleToA4=true;return *this;} + ///Enables parallel edges ///Enables parallel edges @@ -441,11 +457,11 @@ bb+=p+_coords[n]; bb+=-p+_coords[n]; } - os << "%%BoundingBox: " - << bb.left()* _scale-_xBorder << ' ' - << bb.bottom()*_scale-_yBorder << ' ' - << bb.right()* _scale+_xBorder << ' ' - << bb.top()* _scale+_yBorder << '\n'; + if(!_scaleToA4) os << "%%BoundingBox: " + << bb.left()* _scale-_xBorder << ' ' + << bb.bottom()*_scale-_yBorder << ' ' + << bb.right()* _scale+_xBorder << ' ' + << bb.top()* _scale+_yBorder << '\n'; //x1 y1 x2 y2 x3 y3 cr cg cb w os << "/lb { setlinewidth setrgbcolor newpath moveto\n" << " 4 2 roll 1 index 1 index curveto stroke } bind def\n"; @@ -496,7 +512,25 @@ << " neg 2 div fosi .35 mul neg rmoveto show pop pop} def\n"; os << "\ngsave\n"; - if(_scale!=1.0) os << _scale << " dup scale\n"; + if(_scaleToA4) + if(bb.height()>bb.width()) { + double sc= min((A4HEIGHT-2*A4BORDER)/bb.height(), + (A4WIDTH-2*A4BORDER)/bb.width()); + os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' ' + << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER << " translate\n" + << sc << " dup scale\n" + << -bb.left() << ' ' << -bb.bottom() << " translate\n"; + } + else { + //\todo Verify centering + double sc= min((A4HEIGHT-2*A4BORDER)/bb.width(), + (A4WIDTH-2*A4BORDER)/bb.height()); + os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' ' + << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER << " translate\n" + << sc << " dup scale\n90 rotate\n" + << -bb.left() << ' ' << -bb.top() << " translate\n"; + } + else if(_scale!=1.0) os << _scale << " dup scale\n"; if(_showEdges) { os << "%Edges:\ngsave\n"; @@ -658,7 +692,7 @@ os << "grestore\n"; } - os << "grestore\n"; + os << "grestore\nshowpage\n"; //CleanUp: if(_pleaseRemoveOsStream) {delete &os;} @@ -697,7 +731,7 @@ ///Generates an EPS file from a graph -//\ingroup misc +///\ingroup misc ///This function does the same as ///\ref graphToEps(G &g,std::ostream& os) ///but it writes its output into the file \c file_name