1.1 --- a/src/lemon/graph_to_eps.h Fri Jan 28 09:04:34 2005 +0000
1.2 +++ b/src/lemon/graph_to_eps.h Fri Jan 28 09:09:59 2005 +0000
1.3 @@ -86,6 +86,11 @@
1.4 ConstMap<typename Graph::Edge,Color > _edgeColors;
1.5
1.6 ConstMap<typename Graph::Edge,double > _edgeWidths;
1.7 +
1.8 + static const double A4HEIGHT = 841.8897637795276;
1.9 + static const double A4WIDTH = 595.275590551181;
1.10 + static const double A4BORDER = 15;
1.11 +
1.12
1.13 double _edgeWidthScale;
1.14
1.15 @@ -112,6 +117,9 @@
1.16
1.17 bool _undir;
1.18 bool _pleaseRemoveOsStream;
1.19 +
1.20 + bool _scaleToA4;
1.21 +
1.22 ///Constructor
1.23
1.24 ///Constructor
1.25 @@ -135,7 +143,7 @@
1.26 _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
1.27 _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
1.28 _undir(false),
1.29 - _pleaseRemoveOsStream(_pros) {}
1.30 + _pleaseRemoveOsStream(_pros), _scaleToA4(false) {}
1.31 };
1.32
1.33 ///Helper class to implement the named parameters of \ref graphToEps()
1.34 @@ -143,6 +151,8 @@
1.35 ///Helper class to implement the named parameters of \ref graphToEps()
1.36 ///\todo Is 'helper class' a good name for this?
1.37 ///
1.38 +///\todo Follow PostScript's DSC.
1.39 +///\todo Use own dictionary.
1.40 template<class T> class GraphToEps : public T
1.41 {
1.42 typedef typename T::Graph Graph;
1.43 @@ -201,7 +211,7 @@
1.44 ///Sets the map of the node coordinates
1.45
1.46 ///Sets the map of the node coordinates.
1.47 - ///\param x must be a node map with xy<double> or xy<int> values.
1.48 + ///\param x must be a node map with xy<double> or \ref xy "xy<int>" values.
1.49 template<class X> GraphToEps<CoordsTraits<X> > coords(const X &x) {
1.50 dontPrint=true;
1.51 return GraphToEps<CoordsTraits<X> >(CoordsTraits<X>(*this,x));
1.52 @@ -359,6 +369,12 @@
1.53 ///
1.54 GraphToEps<T> &arrowWidth(double d) {_arrowWidth*=d;return *this;}
1.55
1.56 + ///Scales the drawing to fit to A4 page
1.57 +
1.58 + ///Scales the drawing to fit to A4 page
1.59 + ///
1.60 + GraphToEps<T> &scaleToA4() {_scaleToA4=true;return *this;}
1.61 +
1.62 ///Enables parallel edges
1.63
1.64 ///Enables parallel edges
1.65 @@ -441,11 +457,11 @@
1.66 bb+=p+_coords[n];
1.67 bb+=-p+_coords[n];
1.68 }
1.69 - os << "%%BoundingBox: "
1.70 - << bb.left()* _scale-_xBorder << ' '
1.71 - << bb.bottom()*_scale-_yBorder << ' '
1.72 - << bb.right()* _scale+_xBorder << ' '
1.73 - << bb.top()* _scale+_yBorder << '\n';
1.74 + if(!_scaleToA4) os << "%%BoundingBox: "
1.75 + << bb.left()* _scale-_xBorder << ' '
1.76 + << bb.bottom()*_scale-_yBorder << ' '
1.77 + << bb.right()* _scale+_xBorder << ' '
1.78 + << bb.top()* _scale+_yBorder << '\n';
1.79 //x1 y1 x2 y2 x3 y3 cr cg cb w
1.80 os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
1.81 << " 4 2 roll 1 index 1 index curveto stroke } bind def\n";
1.82 @@ -496,7 +512,25 @@
1.83 << " neg 2 div fosi .35 mul neg rmoveto show pop pop} def\n";
1.84
1.85 os << "\ngsave\n";
1.86 - if(_scale!=1.0) os << _scale << " dup scale\n";
1.87 + if(_scaleToA4)
1.88 + if(bb.height()>bb.width()) {
1.89 + double sc= min((A4HEIGHT-2*A4BORDER)/bb.height(),
1.90 + (A4WIDTH-2*A4BORDER)/bb.width());
1.91 + os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' '
1.92 + << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER << " translate\n"
1.93 + << sc << " dup scale\n"
1.94 + << -bb.left() << ' ' << -bb.bottom() << " translate\n";
1.95 + }
1.96 + else {
1.97 + //\todo Verify centering
1.98 + double sc= min((A4HEIGHT-2*A4BORDER)/bb.width(),
1.99 + (A4WIDTH-2*A4BORDER)/bb.height());
1.100 + os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' '
1.101 + << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER << " translate\n"
1.102 + << sc << " dup scale\n90 rotate\n"
1.103 + << -bb.left() << ' ' << -bb.top() << " translate\n";
1.104 + }
1.105 + else if(_scale!=1.0) os << _scale << " dup scale\n";
1.106
1.107 if(_showEdges) {
1.108 os << "%Edges:\ngsave\n";
1.109 @@ -658,7 +692,7 @@
1.110 os << "grestore\n";
1.111 }
1.112
1.113 - os << "grestore\n";
1.114 + os << "grestore\nshowpage\n";
1.115
1.116 //CleanUp:
1.117 if(_pleaseRemoveOsStream) {delete &os;}
1.118 @@ -697,7 +731,7 @@
1.119
1.120 ///Generates an EPS file from a graph
1.121
1.122 -//\ingroup misc
1.123 +///\ingroup misc
1.124 ///This function does the same as
1.125 ///\ref graphToEps(G &g,std::ostream& os)
1.126 ///but it writes its output into the file \c file_name