Add a 'scaleToA4()' function.
1.1 --- a/src/demo/graph_to_eps_demo.cc Fri Jan 28 09:04:34 2005 +0000
1.2 +++ b/src/demo/graph_to_eps_demo.cc Fri Jan 28 09:09:59 2005 +0000
1.3 @@ -140,7 +140,19 @@
1.4 edgeWidthScale(.3).edgeWidths(widths).
1.5 nodeTexts(id).nodeTextSize(3).
1.6 enableParallel().parEdgeDist(1).
1.7 - // hideNodes().
1.8 drawArrows().arrowWidth(1).arrowLength(1).
1.9 - run();;
1.10 + run();
1.11 +
1.12 + graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
1.13 + nodeScale(2).nodeSizes(sizes).
1.14 + coords(coords).
1.15 + nodeShapes(shapes).
1.16 + nodeColors(composeMap(colorSet,colors)).
1.17 + edgeColors(composeMap(colorSet,ecolors)).
1.18 + edgeWidthScale(.3).edgeWidths(widths).
1.19 + nodeTexts(id).nodeTextSize(3).
1.20 + enableParallel().parEdgeDist(1).
1.21 + drawArrows().arrowWidth(1).arrowLength(1).
1.22 + run();
1.23 +
1.24 }
2.1 --- a/src/lemon/graph_to_eps.h Fri Jan 28 09:04:34 2005 +0000
2.2 +++ b/src/lemon/graph_to_eps.h Fri Jan 28 09:09:59 2005 +0000
2.3 @@ -86,6 +86,11 @@
2.4 ConstMap<typename Graph::Edge,Color > _edgeColors;
2.5
2.6 ConstMap<typename Graph::Edge,double > _edgeWidths;
2.7 +
2.8 + static const double A4HEIGHT = 841.8897637795276;
2.9 + static const double A4WIDTH = 595.275590551181;
2.10 + static const double A4BORDER = 15;
2.11 +
2.12
2.13 double _edgeWidthScale;
2.14
2.15 @@ -112,6 +117,9 @@
2.16
2.17 bool _undir;
2.18 bool _pleaseRemoveOsStream;
2.19 +
2.20 + bool _scaleToA4;
2.21 +
2.22 ///Constructor
2.23
2.24 ///Constructor
2.25 @@ -135,7 +143,7 @@
2.26 _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
2.27 _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
2.28 _undir(false),
2.29 - _pleaseRemoveOsStream(_pros) {}
2.30 + _pleaseRemoveOsStream(_pros), _scaleToA4(false) {}
2.31 };
2.32
2.33 ///Helper class to implement the named parameters of \ref graphToEps()
2.34 @@ -143,6 +151,8 @@
2.35 ///Helper class to implement the named parameters of \ref graphToEps()
2.36 ///\todo Is 'helper class' a good name for this?
2.37 ///
2.38 +///\todo Follow PostScript's DSC.
2.39 +///\todo Use own dictionary.
2.40 template<class T> class GraphToEps : public T
2.41 {
2.42 typedef typename T::Graph Graph;
2.43 @@ -201,7 +211,7 @@
2.44 ///Sets the map of the node coordinates
2.45
2.46 ///Sets the map of the node coordinates.
2.47 - ///\param x must be a node map with xy<double> or xy<int> values.
2.48 + ///\param x must be a node map with xy<double> or \ref xy "xy<int>" values.
2.49 template<class X> GraphToEps<CoordsTraits<X> > coords(const X &x) {
2.50 dontPrint=true;
2.51 return GraphToEps<CoordsTraits<X> >(CoordsTraits<X>(*this,x));
2.52 @@ -359,6 +369,12 @@
2.53 ///
2.54 GraphToEps<T> &arrowWidth(double d) {_arrowWidth*=d;return *this;}
2.55
2.56 + ///Scales the drawing to fit to A4 page
2.57 +
2.58 + ///Scales the drawing to fit to A4 page
2.59 + ///
2.60 + GraphToEps<T> &scaleToA4() {_scaleToA4=true;return *this;}
2.61 +
2.62 ///Enables parallel edges
2.63
2.64 ///Enables parallel edges
2.65 @@ -441,11 +457,11 @@
2.66 bb+=p+_coords[n];
2.67 bb+=-p+_coords[n];
2.68 }
2.69 - os << "%%BoundingBox: "
2.70 - << bb.left()* _scale-_xBorder << ' '
2.71 - << bb.bottom()*_scale-_yBorder << ' '
2.72 - << bb.right()* _scale+_xBorder << ' '
2.73 - << bb.top()* _scale+_yBorder << '\n';
2.74 + if(!_scaleToA4) os << "%%BoundingBox: "
2.75 + << bb.left()* _scale-_xBorder << ' '
2.76 + << bb.bottom()*_scale-_yBorder << ' '
2.77 + << bb.right()* _scale+_xBorder << ' '
2.78 + << bb.top()* _scale+_yBorder << '\n';
2.79 //x1 y1 x2 y2 x3 y3 cr cg cb w
2.80 os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
2.81 << " 4 2 roll 1 index 1 index curveto stroke } bind def\n";
2.82 @@ -496,7 +512,25 @@
2.83 << " neg 2 div fosi .35 mul neg rmoveto show pop pop} def\n";
2.84
2.85 os << "\ngsave\n";
2.86 - if(_scale!=1.0) os << _scale << " dup scale\n";
2.87 + if(_scaleToA4)
2.88 + if(bb.height()>bb.width()) {
2.89 + double sc= min((A4HEIGHT-2*A4BORDER)/bb.height(),
2.90 + (A4WIDTH-2*A4BORDER)/bb.width());
2.91 + os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' '
2.92 + << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER << " translate\n"
2.93 + << sc << " dup scale\n"
2.94 + << -bb.left() << ' ' << -bb.bottom() << " translate\n";
2.95 + }
2.96 + else {
2.97 + //\todo Verify centering
2.98 + double sc= min((A4HEIGHT-2*A4BORDER)/bb.width(),
2.99 + (A4WIDTH-2*A4BORDER)/bb.height());
2.100 + os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' '
2.101 + << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER << " translate\n"
2.102 + << sc << " dup scale\n90 rotate\n"
2.103 + << -bb.left() << ' ' << -bb.top() << " translate\n";
2.104 + }
2.105 + else if(_scale!=1.0) os << _scale << " dup scale\n";
2.106
2.107 if(_showEdges) {
2.108 os << "%Edges:\ngsave\n";
2.109 @@ -658,7 +692,7 @@
2.110 os << "grestore\n";
2.111 }
2.112
2.113 - os << "grestore\n";
2.114 + os << "grestore\nshowpage\n";
2.115
2.116 //CleanUp:
2.117 if(_pleaseRemoveOsStream) {delete &os;}
2.118 @@ -697,7 +731,7 @@
2.119
2.120 ///Generates an EPS file from a graph
2.121
2.122 -//\ingroup misc
2.123 +///\ingroup misc
2.124 ///This function does the same as
2.125 ///\ref graphToEps(G &g,std::ostream& os)
2.126 ///but it writes its output into the file \c file_name