[Lemon-commits] [lemon_svn] alpar: r1502 - in hugo/trunk/src: demo lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:45:54 CET 2006


Author: alpar
Date: Fri Jan 28 10:09:59 2005
New Revision: 1502

Modified:
   hugo/trunk/src/demo/graph_to_eps_demo.cc
   hugo/trunk/src/lemon/graph_to_eps.h

Log:
Add a 'scaleToA4()' function.


Modified: hugo/trunk/src/demo/graph_to_eps_demo.cc
==============================================================================
--- hugo/trunk/src/demo/graph_to_eps_demo.cc	(original)
+++ hugo/trunk/src/demo/graph_to_eps_demo.cc	Fri Jan 28 10:09:59 2005
@@ -140,7 +140,19 @@
     edgeWidthScale(.3).edgeWidths(widths).
     nodeTexts(id).nodeTextSize(3).
     enableParallel().parEdgeDist(1).
-    //    hideNodes().
     drawArrows().arrowWidth(1).arrowLength(1).
-    run();;
+    run();
+
+  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
+    nodeScale(2).nodeSizes(sizes).
+    coords(coords).
+    nodeShapes(shapes).
+    nodeColors(composeMap(colorSet,colors)).
+    edgeColors(composeMap(colorSet,ecolors)).
+    edgeWidthScale(.3).edgeWidths(widths).
+    nodeTexts(id).nodeTextSize(3).
+    enableParallel().parEdgeDist(1).
+    drawArrows().arrowWidth(1).arrowLength(1).
+    run();
+
 }

Modified: hugo/trunk/src/lemon/graph_to_eps.h
==============================================================================
--- hugo/trunk/src/lemon/graph_to_eps.h	(original)
+++ hugo/trunk/src/lemon/graph_to_eps.h	Fri Jan 28 10:09:59 2005
@@ -86,6 +86,11 @@
   ConstMap<typename Graph::Edge,Color > _edgeColors;
 
   ConstMap<typename Graph::Edge,double > _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 T> 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<double> or xy<int> values. 
+  ///\param x must be a node map with xy<double> or \ref xy "xy<int>" values. 
   template<class X> GraphToEps<CoordsTraits<X> > coords(const X &x) {
     dontPrint=true;
     return GraphToEps<CoordsTraits<X> >(CoordsTraits<X>(*this,x));
@@ -359,6 +369,12 @@
   ///
   GraphToEps<T> &arrowWidth(double d) {_arrowWidth*=d;return *this;}
   
+  ///Scales the drawing to fit to A4 page
+
+  ///Scales the drawing to fit to A4 page
+  ///
+  GraphToEps<T> &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



More information about the Lemon-commits mailing list