Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

EpsView.cxx

Go to the documentation of this file.
00001 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #else
00015 #ifdef _MSC_VER
00016 #include "msdevstudio/MSconfig.h"
00017 #endif
00018 #endif
00019 
00020 #include "EpsView.h"
00021 
00022 #include "FontBase.h"
00023 #include "Color.h"
00024 
00025 #include "plotters/PlotterBase.h"
00026 
00027 using namespace hippodraw;
00028 
00029 #ifdef ITERATOR_MEMBER_DEFECT
00030 using namespace std;
00031 #else
00032 using std::endl;
00033 using std::ofstream;
00034 using std::string;
00035 #endif
00036 
00037 EpsView::
00038 EpsView ( const string filename, double x, double y, double w, double h )
00039   : ViewBase(),
00040     m_boundingRect ( x, y, w, h )
00041 {
00042   initPlot ( filename, x, y, w, h );
00043 }
00044 
00045 EpsView::~EpsView()
00046 {
00047   m_outfile.close();
00048 }
00049 
00050 void EpsView::initPlot ( double aspect )
00051 {
00052 }
00053 
00058 void EpsView::initPlot ( const std::string & fname, 
00059                          double x, double y, double w, double h )
00060 {
00061 
00062   const char * fn = fname.c_str();
00063   m_outfile.open (fn, std::ios::out);
00064 
00065   m_outfile << "%%!PS-Adobe-3.0 EPSF-3.0" << endl;
00066   m_outfile << "%%Creator: HippoDraw" << endl;
00067 
00068   double x1 = 0;
00069   double y1 = 0;
00070   double x2 = x1 + w;
00071   double y2 = y1 + h;
00072 
00073   m_outfile << "%%BoundingBox: " 
00074           << x1 << " " << y1 << " " 
00075           << x2 << " " << y2 << endl; 
00076   
00077   m_outfile << "%%EndComments" << endl;
00078   m_outfile << endl << endl;
00079 
00080   m_outfile << "%% Add emulation of selectfont if needed" << endl;
00081   m_outfile << "%%   taken from PS Lang. Ref. Manual, Appendix D.4" << endl;
00082   m_outfile << "/*SF {" << endl;
00083   m_outfile << "  exch findfont exch" << endl;
00084   m_outfile << "  dup type /arraytype eq {makefont}{scalefont} ifelse setfont" 
00085             << endl;
00086   m_outfile << "} bind def" << endl;
00087   m_outfile << endl;
00088   m_outfile << "/languagelevel where" << endl;
00089   m_outfile << " {pop languagelevel} {1} ifelse" << endl;
00090   m_outfile << "2 lt {/SF /*SF load def}{/SF /selectfont load def} ifelse"
00091           << endl;
00092 
00093   m_outfile << "%%" << endl << "%%" << endl;
00094 }
00095 
00096 void EpsView::endPlot()
00097 {
00098   m_outfile << "%%EOF" << endl;
00099 }
00100 
00101 void EpsView::drawLines ( const std::vector< double > & x,
00102                           const std::vector< double > & y,
00103                           hippodraw::Line::Style style,
00104                           const Color & color,
00105                           float size )
00106 {
00107   m_outfile << "%% drawLines" << endl;
00108 
00109   m_outfile << "gsave" << endl;
00110 
00111   m_outfile << (float)(color.getRed() / 255.0) << " " 
00112           << (float)(color.getGreen() / 255.0) << " "
00113           << (float)(color.getBlue() / 255.0) << " setrgbcolor" << endl;
00114 
00115   m_outfile << size << " setlinewidth" << endl;
00116 
00117   switch (style)
00118     {
00119     case Line::Solid:
00120       m_outfile << "[] 0 setdash" << endl;
00121       break;
00122     case Line::Dot:
00123       m_outfile << "[3 5] 0 setdash" << endl;
00124       break;
00125     case Line::Dash:
00126       m_outfile << "[5 3] 0 setdash" << endl;
00127       break;
00128     case Line::DashDot:
00129       m_outfile << "[5 3 1 3] 0 setdash" << endl;
00130       break;
00131     default:
00132       break;
00133     }
00134   
00135   for ( unsigned int i = 0; i < x.size(); i = i+2 )
00136     {
00137       
00138       m_outfile << "gsave" << endl << "newpath systemdict begin" << endl;
00139       m_outfile << toViewX (x[i]) << " "
00140                 << toViewY (y[i]) << " moveto" << endl;
00141       m_outfile << toViewX (x[i+1]) << " "
00142                 << toViewY (y[i+1]) << " lineto" << endl;
00143       m_outfile << "end" << endl;
00144       m_outfile << "stroke grestore" << endl;
00145       
00146     }
00147 
00148   m_outfile << "grestore" << endl;
00149 
00150 }
00151 
00152 void EpsView::drawColorLines ( const std::vector< double > & x,
00153                                const std::vector< double > & y,
00154                                hippodraw::Line::Style style,
00155                                const std::vector < Color > & colors,
00156                                float size )
00157 {
00158   m_outfile << "%% drawLines" << endl;
00159   m_outfile << "gsave" << endl;
00160 
00161   for (unsigned int i = 0; i < x.size(); i+=2 ){
00162     
00163     const Color & color = colors[i];
00164     float red   = color.getRed () / 255.;
00165     float green = color.getGreen () / 255.;
00166     float blue  = color.getBlue () / 255.;
00167     m_outfile << red
00168               << " " << green
00169               << " " << blue
00170               << " setrgbcolor" << endl;
00171 
00172     m_outfile << size << " setlinewidth" << endl;
00173 
00174     switch (style)
00175       {
00176       case Line::Solid:
00177         m_outfile << "[] 0 setdash" << endl;
00178         break;
00179       case Line::Dot:
00180         m_outfile << "[3 5] 0 setdash" << endl;
00181         break;
00182       case Line::Dash:
00183         m_outfile << "[5 3] 0 setdash" << endl;
00184         break;
00185       case Line::DashDot:
00186         m_outfile << "[5 3 1 3] 0 setdash" << endl;
00187         break;
00188       default:
00189         break;
00190       }
00191   
00192     m_outfile << "gsave" << endl << "newpath systemdict begin" << endl;
00193     m_outfile << toViewX (x[i]) << " "
00194               << toViewY (y[i]) << " moveto" << endl;
00195     m_outfile << toViewX (x[i+1]) << " "
00196               << toViewY (y[i+1]) << " lineto" << endl;
00197     m_outfile << "end" << endl;
00198     m_outfile << "stroke grestore" << endl;
00199     
00200   }
00201   
00202   m_outfile << "grestore" << endl;
00203 
00204 }
00205 
00206 void EpsView::drawViewLines ( const std::vector< double > & x,
00207                               const std::vector< double > & y,
00208                               hippodraw::Line::Style style,
00209                               bool color,
00210                               float size )
00211 {
00212   m_outfile << "%% drawViewLines1" << endl;
00213   
00214   m_outfile << "gsave" << endl;
00215 
00216   m_outfile << size << " setlinewidth" << endl;
00217 
00218   switch (style)
00219     {
00220     case Line::Solid:
00221       m_outfile << "[] 0 setdash" << endl;
00222       break;
00223     case Line::Dot:
00224       m_outfile << "[3 5] 0 setdash" << endl;
00225       break;
00226     case Line::Dash:
00227       m_outfile << "[5 3] 0 setdash" << endl;
00228       break;
00229     case Line::DashDot:
00230       m_outfile << "[5 3 1 3] 0 setdash" << endl;
00231       break;
00232     default:
00233       break;
00234     }
00235 
00236     for ( unsigned int i = 0; i < x.size(); i = i+2 )
00237     {
00238     
00239       m_outfile << "gsave" << endl << "newpath systemdict begin" << endl;
00240       m_outfile << toX(x[i]) << " " << toY(y[i]) << " moveto" << endl;
00241       m_outfile << toX(x[i+1]) << " " << toY(y[i+1]) << " lineto" << endl;
00242       m_outfile << "end" << endl;
00243       m_outfile << "stroke grestore" << endl;
00244       
00245     }
00246 
00247     m_outfile << "grestore" << endl;
00248 
00249 }
00250  
00251 void EpsView::drawViewLines ( const std::vector< double > & x,
00252                               const std::vector< double > & y,
00253                               hippodraw::Line::Style style,
00254                               const Color & color,
00255                               float size )
00256 {
00257   
00258   m_outfile << "%% drawViewLines2" << endl;
00259 
00260   m_outfile << "gsave" << endl;
00261 
00262   m_outfile << (float)(color.getRed() / 255.0) << " " 
00263           << (float)(color.getGreen() / 255.0) << " "
00264           << (float)(color.getBlue() / 255.0) << " setrgbcolor" << endl;
00265 
00266   m_outfile << size << " setlinewidth" << endl;
00267 
00268   switch (style)
00269     {
00270     case Line::Solid:
00271       m_outfile << "[] 0 setdash" << endl;
00272       break;
00273     case Line::Dot:
00274       m_outfile << "[3 5] 0 setdash" << endl;
00275       break;
00276     case Line::Dash:
00277       m_outfile << "[5 3] 0 setdash" << endl;
00278       break;
00279     case Line::DashDot:
00280       m_outfile << "[5 3 1 3] 0 setdash" << endl;
00281       break;
00282     default:
00283       break;
00284     }
00285   
00286   for ( unsigned int i = 0; i < x.size(); i = i+2 )
00287     {
00288       
00289       m_outfile << "gsave" << endl << "newpath systemdict begin" << endl;
00290       m_outfile << toX(x[i]) << " " << toY(y[i]) << " moveto" << endl;
00291       m_outfile << toX(x[i+1]) << " " << toY(y[i+1]) << " lineto" << endl;
00292       m_outfile << "end" << endl;
00293       m_outfile << "stroke grestore" << endl;
00294       
00295     }
00296   
00297   m_outfile << "grestore" << endl;
00298   
00299 }
00300  
00301 void EpsView::drawPolyLine ( const std::vector< double > & xpoints,
00302                              const std::vector< double > & ypoints, 
00303                              hippodraw::Line::Style style,
00304                              const Color & color,
00305                              float size )
00306 {
00307   if ( style == Line::Invisible ) return;
00308 
00309   m_outfile << "%% drawPolyLine" << endl;
00310 
00311   m_outfile << "gsave" << endl;
00312 
00313   m_outfile << (float)(color.getRed() / 255.0) << " " 
00314             << (float)(color.getGreen() / 255.0) << " "
00315             << (float)(color.getBlue() / 255.0) << " setrgbcolor" << endl;
00316 
00317   m_outfile << size << " setlinewidth" << endl;
00318 
00319   switch (style)
00320     {
00321     case Line::Solid:
00322       m_outfile << "[] 0 setdash" << endl;
00323       break;
00324     case Line::Dot:
00325       m_outfile << "[1 1] 0 setdash" << endl;
00326       break;
00327     case Line::Dash:
00328       m_outfile << "[6 2] 0 setdash" << endl;
00329       break;
00330     case Line::DashDot:
00331       m_outfile << "[5 3 1 3] 0 setdash" << endl;
00332       break;
00333     case Line::DashDotDot:
00334       m_outfile << "[5 1 1 1 1 1] 0 setdash" << endl;
00335       break;
00336     default:
00337       break;
00338     }
00339   
00340   m_outfile << "gsave" << endl << "newpath systemdict begin" << endl;
00341   m_outfile << toViewX ( xpoints[0] ) << " " 
00342           << toViewY ( ypoints[0] ) << " moveto" << endl;
00343 
00344   for ( unsigned int i = 1; i < xpoints.size(); i++ )
00345     {
00346       
00347       m_outfile << toViewX ( xpoints[i] ) << " " 
00348               << toViewY ( ypoints[i] ) << " lineto" << endl;
00349     }
00350      
00351   m_outfile << "end" << endl;
00352   
00353   m_outfile << "stroke grestore" << endl;
00354 
00355   m_outfile << "grestore" << endl;
00356 
00357 }
00358 
00359 void
00360 EpsView::
00361 drawSquare ( double x1, double y1, double x2, double y2,
00362              int red, int green, int blue )
00363 {
00364   m_outfile << "%% drawSquareRGB" << endl;
00365 
00366   m_outfile << "gsave" << endl;
00367   
00368   m_outfile << (float)(red / 255.0) << " " 
00369           << (float)(green / 255.0) << " "
00370           << (float)(blue / 255.0) << " setrgbcolor" << endl;
00371   
00372   m_outfile << "newpath" << endl; 
00373   m_outfile << toViewX ((double)(x1)) << " " 
00374             << toViewY ((double)(y1)) << " moveto" << endl;
00375   m_outfile << toViewX ((double)(x2)) << " " 
00376             << toViewY ((double)(y1)) << " lineto" << endl;
00377   m_outfile << toViewX ((double)(x2)) << " " 
00378             << toViewY ((double)(y2)) << " lineto" << endl;
00379   m_outfile << toViewX ((double)(x1)) << " " 
00380             << toViewY ((double)(y2)) << " lineto" << endl;
00381   m_outfile << "closepath" << endl;
00382 
00383   m_outfile << "fill" << endl;
00384 
00385   m_outfile << "grestore" << endl;
00386 
00387 }
00388 
00389 void EpsView::drawViewSquare ( float x1, float y1, float x2, float y2,
00390                                int red, int green, int blue )
00391 {
00392   m_outfile << "%% drawSquareRGB" << endl;
00393 
00394   m_outfile << "gsave" << endl;
00395   
00396   m_outfile << (float)(red / 255.0) << " " 
00397           << (float)(green / 255.0) << " "
00398           << (float)(blue / 255.0) << " setrgbcolor" << endl;
00399   
00400   m_outfile << "newpath" << endl; 
00401   m_outfile << toX ((double)(x1)) << " " 
00402             << toY ((double)(y1)) << " moveto" << endl;
00403   m_outfile << toX ((double)(x2)) << " " 
00404             << toY ((double)(y1)) << " lineto" << endl;
00405   m_outfile << toX ((double)(x2)) << " " 
00406             << toY ((double)(y2)) << " lineto" << endl;
00407   m_outfile << toX ((double)(x1)) << " " 
00408             << toY ((double)(y2)) << " lineto" << endl;
00409   m_outfile << "closepath" << endl;
00410 
00411   m_outfile << "fill" << endl;
00412 
00413   m_outfile << "grestore" << endl;
00414 
00415 }
00416 
00417 void EpsView::drawPoints ( const std::vector<double> & x,
00418                            const std::vector<double> & y,
00419                            hippodraw::Symbol::Type type, 
00420                            float sym_size, 
00421                            const Color & color )
00422 {
00423   m_outfile << "%% drawPoints" << endl;
00424 
00425   m_outfile << "gsave" << endl;
00426 
00427   m_outfile << (float)(color.getRed() / 255.0) << " " 
00428           << (float)(color.getGreen() / 255.0) << " "
00429           << (float)(color.getBlue() / 255.0) << " setrgbcolor" << endl;
00430 
00431   bool filled = false;
00432 
00433   if ( type == Symbol::SOLIDSQUARE ||
00434        type == Symbol::FILLED_TRIANGLE ||
00435        type == Symbol::FILLED_CIRCLE ) filled = true;
00436 
00437   m_outfile << "gsave" << endl;
00438   m_outfile << "newpath systemdict begin" << endl;
00439   
00440   for (unsigned int i = 0; i < x.size(); i++)
00441     {
00442       
00443       switch ( type )
00444         {
00445         case Symbol::SQUARE:
00446         case Symbol::SOLIDSQUARE:
00447           
00448           m_outfile << toViewX (x[i])-(sym_size/2) << " " 
00449                   << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00450           m_outfile << toViewX (x[i])+(sym_size/2) << " " 
00451                     << toViewY (y[i])-(sym_size/2) << " lineto" << endl;
00452           m_outfile << toViewX (x[i])+(sym_size/2) << " " 
00453                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00454           m_outfile << toViewX (x[i])-(sym_size/2) << " " 
00455                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00456           m_outfile << "closepath" << endl;
00457           
00458           break;
00459           
00460         case Symbol::TRIANGLE:
00461         case Symbol::FILLED_TRIANGLE:
00462           m_outfile << toViewX (x[i]) << " " 
00463                     << toViewY (y[i]) + (sym_size/2) << " moveto" << endl;
00464           m_outfile << toViewX (x[i]) + (sym_size/2) << " " 
00465                     << toViewY (y[i])-(sym_size/2) << " lineto" << endl;
00466           m_outfile << toViewX (x[i]) - (sym_size/2) << " " 
00467                     << toViewY (y[i])-(sym_size/2) << " lineto" << endl;
00468           m_outfile << "closepath" << endl;
00469           break;
00470           
00471         case Symbol::CIRCLE:
00472         case Symbol::FILLED_CIRCLE:
00473           m_outfile << toViewX (x[i]) + (sym_size/2) << " "
00474                     << toViewY (y[i]) << " moveto" << endl;
00475           m_outfile << toViewX (x[i]) << " "
00476                     << toViewY (y[i]) << " "
00477                   << sym_size/2 << " "
00478                   << "0.0 360 arc" << endl;
00479           break;
00480 
00481         case Symbol::PLUS:
00482           m_outfile << toViewX (x[i])-(sym_size/2) << " " 
00483                     << toViewY (y[i]) << " moveto" << endl;
00484           m_outfile << toViewX (x[i])+(sym_size/2) << " " 
00485                     << toViewY (y[i]) << " lineto" << endl;
00486           m_outfile << toViewX (x[i]) << " " 
00487                     << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00488           m_outfile << toViewX (x[i]) << " " 
00489                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00490           break;
00491           
00492         case Symbol::TIMES:
00493           m_outfile << toViewX (x[i])-(sym_size/2) << " " 
00494                     << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00495           m_outfile << toViewX (x[i])+(sym_size/2) << " " 
00496                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00497           m_outfile << toViewX (x[i])+(sym_size/2) << " " 
00498                     << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00499           m_outfile << toViewX (x[i])-(sym_size/2) << " " 
00500                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00501           break;
00502 
00503         default:
00504           break;
00505         }
00506     }
00507 
00508   m_outfile << "end" << endl;
00509   
00510   if(filled)
00511     {
00512       m_outfile << "fill grestore" << endl;
00513     }
00514   else
00515     {
00516       m_outfile << "stroke grestore" << endl;
00517     }
00518 
00519   m_outfile << "grestore" << endl;
00520   
00521 }
00522 
00523 void
00524 EpsView::
00525 drawPoints ( const std::vector< double > & x,
00526              const std::vector< double > & y, 
00527              const std::vector< Color > & colors,
00528              hippodraw::Symbol::Type type, 
00529              float sym_size )
00530 {
00531   m_outfile << "%% drawPoints2" << endl;
00532 
00533   m_outfile << "gsave" << endl;
00534   
00535   bool filled = false;
00536 
00537   if ( type == Symbol::SOLIDSQUARE ||
00538        type == Symbol::FILLED_TRIANGLE ||
00539        type == Symbol::FILLED_CIRCLE ) filled = true;
00540 
00541   for (unsigned int i = 0; i < x.size(); i++)
00542     {
00543       m_outfile << "gsave" << endl;
00544 
00545       const Color & color = colors[i];
00546       float red   = color.getRed ();
00547       float green = color.getGreen ();
00548       float blue  = color.getBlue ();
00549       m_outfile << red << " "
00550                 << green << " "
00551                 << blue << " "
00552                 << "setrgbcolor"
00553                 << endl;
00554 
00555       m_outfile << "newpath systemdict begin" << endl;
00556 
00557       switch ( type )
00558         {
00559         case Symbol::SQUARE:
00560         case Symbol::SOLIDSQUARE:
00561           
00562           m_outfile << toViewX (x[i])-(sym_size/2) << " " 
00563                   << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00564           m_outfile << toViewX (x[i])+(sym_size/2) << " " 
00565                     << toViewY (y[i])-(sym_size/2) << " lineto" << endl;
00566           m_outfile << toViewX (x[i])+(sym_size/2) << " " 
00567                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00568           m_outfile << toViewX (x[i])-(sym_size/2) << " " 
00569                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00570           m_outfile << "closepath" << endl;
00571           
00572           break;
00573           
00574         case Symbol::TRIANGLE:
00575         case Symbol::FILLED_TRIANGLE:
00576           m_outfile << toViewX (x[i]) << " " 
00577                     << toViewY (y[i]) + (sym_size/2) << " moveto" << endl;
00578           m_outfile << toViewX (x[i]) + (sym_size/2) << " " 
00579                     << toViewY (y[i])-(sym_size/2) << " lineto" << endl;
00580           m_outfile << toViewX (x[i]) - (sym_size/2) << " " 
00581                     << toViewY (y[i])-(sym_size/2) << " lineto" << endl;
00582           m_outfile << "closepath" << endl;
00583           break;
00584           
00585         case Symbol::CIRCLE:
00586         case Symbol::FILLED_CIRCLE:
00587           m_outfile << toViewX (x[i]) + (sym_size/2) << " "
00588                   << toViewY (y[i]) << " moveto" << endl;
00589           m_outfile << toViewX (x[i]) << " "
00590                   << toViewY (y[i]) << " "
00591                   << sym_size/2 << " "
00592                   << "0.0 360 arc" << endl;
00593           break;
00594 
00595         case Symbol::PLUS:
00596           m_outfile << toViewX (x[i])-(sym_size/2) << " " 
00597                     << toViewY (y[i]) << " moveto" << endl;
00598           m_outfile << toViewX (x[i])+(sym_size/2) << " " 
00599                     << toViewY (y[i]) << " lineto" << endl;
00600           m_outfile << toViewX (x[i]) << " " 
00601                     << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00602           m_outfile << toViewX (x[i]) << " " 
00603                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00604           break;
00605           
00606         case Symbol::TIMES:
00607           m_outfile << toViewX (x[i])-(sym_size/2) << " " 
00608                     << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00609           m_outfile << toViewX (x[i])+(sym_size/2) << " " 
00610                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00611           m_outfile << toViewX (x[i])+(sym_size/2) << " " 
00612                     << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00613           m_outfile << toViewX (x[i])-(sym_size/2) << " " 
00614                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00615           break;
00616 
00617         default:
00618           break;
00619 
00620         }
00621    
00622       m_outfile << "end" << endl;
00623       
00624       if(filled)
00625         {
00626           m_outfile << "fill grestore" << endl;
00627         }
00628       else
00629         {
00630           m_outfile << "stroke grestore" << endl;
00631         }
00632     }
00633   
00634   m_outfile << "grestore" << endl;
00635 
00636 }
00637 
00638 void EpsView::drawMag ( float x, float y, int mag, float fontsize )
00639 {
00640   
00641   m_outfile << "%% drawMag" << endl;
00642   
00643   m_outfile << "(Helvetica) " << fontsize << " SF" << endl;
00644   
00645   m_outfile << x - m_boundingRect.getX()  << " "
00646             << toY(y) + m_draw_rect.getY() << " moveto" << endl;
00647   m_outfile << "(x10) show" << endl;
00648   m_outfile << 0 << " " 
00649             << fontsize/2 << " rmoveto" << endl;
00650   m_outfile << "(" << mag << ") show" << endl;
00651   
00652 }
00653 
00654 void EpsView::drawUserText ( const std::string &s, float x, float y,
00655                              float fontsize, float angle,
00656                              char xp, char yp )
00657 {
00658 
00659   m_outfile << "%% drawUserText" << endl;
00660 
00661   draw_Text ( s, toViewX (x), toViewY (y), fontsize, angle, xp, yp, 0 );
00662 
00663 }
00664 
00667 void EpsView::draw_Text ( const std::string &s, float x, float y,
00668                          float fontsize, float angle,
00669                          char xp, char yp, const FontBase * font )
00670 {
00671   float xStep = 0.0, yStep = 0.0;
00672      
00673   switch (yp)
00674     {
00675     case 'c':
00676       yStep = 0.4f;
00677       break;
00678           
00679     case 't':
00680       yStep = 0.8f;
00681       break;
00682 
00683     default:
00684       break;
00685     }
00686   
00687   switch (xp)
00688     {
00689 
00690     case 'c':
00691       xStep = 0.5f;
00692       break;
00693 
00694     case 'r':
00695       xStep = 1.0f;
00696       break;
00697 
00698     default:
00699       break;
00700     }
00701      
00702   m_outfile << "gsave" << endl;
00703 
00704   int size = 0;
00705   if ( font == 0 ) {
00706     m_outfile << "(Helvetica) " << fontsize << " SF" << endl;
00707     size = static_cast < int > ( fontsize );
00708   }
00709   else {
00710     string family ( "(" );
00711     family += font -> family ();
00712     family += ") ";
00713     size = font -> pointSize ();
00714     m_outfile << family << size << " SF" << endl;
00715   }
00716   m_outfile << x << " " << y << " translate " << angle << " rotate" << endl;
00717      
00718   m_outfile << "(" << s << ") stringwidth pop" << endl;
00719   m_outfile << xStep << " neg mul " << -size*yStep << " moveto" << endl;
00720   m_outfile << "(" << s << ") show" << endl;
00721   m_outfile << "grestore" << endl;
00722 
00723 }
00724 
00725 void EpsView::drawText ( const std::string &s, float x, float y,
00726                          float fontsize, float angle,
00727                          char xp, char yp, bool resize,
00728                          const FontBase * font )
00729 {
00730   // Resize ignored as the view size is always just bounding the contents
00731   m_outfile << "%% drawText" << endl;
00732      
00733   draw_Text ( s, toX(x), toY(y), fontsize, angle, xp, yp, font );
00734 }
00735 
00736 void EpsView:: update ( const Observable * display )
00737 {
00738 }
00739 
00740 float EpsView::userToDrawX ( double x ) const
00741 {
00742   return m_plotter -> userToMarginX( x );
00743 }
00744 
00745 float EpsView::userToDrawY ( double y ) const
00746 {
00747   return m_plotter->userToInvertedMarginY( y );
00748 }
00749 
00750 float EpsView::userToDrawColor ( double c ) const
00751 {
00752   return m_plotter->userToMarginColor( c );
00753 }
00754 
00755 /* virtual */
00756 HippoRectangle EpsView::getDrawRect() const
00757 {
00758   return m_draw_rect;
00759 }
00760 
00761 /* virtual */
00762 void EpsView::setDrawRect ( float x, float y, float w, float h )
00763 {
00764   m_draw_rect.setRect ( x, y, w, h );
00765 }
00766 
00767 float EpsView::toViewX ( double datX ) const
00768 {
00769   return ( m_draw_rect.getX() 
00770            + m_plotter->userToMarginX ( datX )
00771            - m_boundingRect.getX() );
00772 }
00773 
00774 float EpsView::toViewY ( double datY ) const
00775 {
00776 
00777   /* If you remove the s1 and the s2 from the return statements, you get
00778      the plots that look ok, but a plot on top in the canvas appears at the
00779      bottom in the eps file. Subtracting from s2 vertically inverts each
00780      plot, and then subtracting from s1 vertically inverts the entire eps
00781      file. The result is what is desired - Sanket. */
00782 
00783   float s1 = m_boundingRect.getY() + m_boundingRect.getHeight();
00784 
00785   float s2 = m_draw_rect.getY() + m_draw_rect.getHeight();
00786 
00787   return ( s1 - ( s2 -  ( m_plotter->userToMarginY ( datY )
00788                           - 2 * m_plotter->getMarginRect().getY()
00789                           + m_draw_rect.getHeight()
00790                           - m_plotter->getMarginRect().getHeight()
00791                           )
00792                   )
00793            );
00794 }
00795 
00796 float EpsView::toX ( double x ) const
00797 {  
00798   return static_cast < float > ( m_draw_rect.getX() 
00799                                  + x
00800                                  - m_boundingRect.getX() );
00801 }
00802 
00803 float EpsView::toY ( double y ) const
00804 {
00805   float s1 = m_boundingRect.getY() + m_boundingRect.getHeight();
00806   
00807   return static_cast < float > ( s1 - ( m_draw_rect.getY() + y ) );
00808 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3