00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 #ifndef _PDFgraphing_H_
00014 #define _PDFgraphing_H_
00015 
00016 
00017 #include "vector"
00018 
00019 #include "iostream"
00020 using namespace std;
00021 
00022  
00023 
00024 
00025 
00026 
00028 class PDFPageObject
00029 {
00030   
00032   
00033   
00034   
00036 
00037  public:  
00038   
00040   
00041   
00042   
00044         
00045 public:
00046   
00047   virtual void write( ostream& os ) { cout << "ERROR. Should not be used" << endl; }
00048 };
00049 
00050 
00051 
00052 
00053 
00054 
00056 class udPDFPageObjectText : public PDFPageObject
00057 {
00059   
00060   
00061   
00063 
00064  public:  
00065 
00067 
00072   udPDFPageObjectText( double x , double y , const string& t, int s = 12 ) : 
00073         theX(x), theY(y), text(t), tSize(s) { }
00074   
00076   
00077   
00078   
00080         
00081 public:
00082   
00083   void write( ostream& os );
00084 
00086   
00087   
00088   
00090     
00091  private:
00092   double theX, theY;
00093   string text;
00094   int tSize;
00095 };
00096 
00097 
00098 
00099 
00100 
00101 
00103 class PDFPageObjectLine : public PDFPageObject
00104 {
00106   
00107   
00108   
00110 
00111  public:  
00113 
00116   PDFPageObjectLine( double x1 , double y1 , double x2 , double y2 ) : theX1(x1), theX2(x2), theY1(y1), theY2(y2) { }
00117   
00119   
00120   
00121   
00123         
00124 public:
00125   
00126   void write( ostream& os ) {
00127     os << theX1 << " " << theY1 << " m" << endl;
00128     os << theX2 << " " << theY2 << " l" << endl;
00129     os << "S" << endl;
00130   }
00131 
00133   
00134   
00135   
00137     
00138  private:
00139   double theX1, theY1;
00140   double theX2, theY2;
00141 };
00142 
00143 
00144 
00145 
00146 
00148 class udPDFPageObjectLine : public PDFPageObject
00149 {
00151   
00152   
00153   
00155 
00157 
00162  public:  
00163   udPDFPageObjectLine( double x1 , double y1 , double x2 , double y2, double gc = 0, bool d = false ) : 
00164   theX1(x1), theX2(x2), theY1(y1), theY2(y2), gray_color( gc), dashed( d ) { }
00165   
00167   
00168   
00169   
00171         
00172 public:
00173   
00174   void write( ostream& os );
00175 
00177   
00178   
00179   
00181     
00182  private:
00183   double theX1, theY1;
00184   double theX2, theY2;
00185   double gray_color;
00186   bool dashed;
00187 };
00188 
00189 
00190 
00191 
00192 
00193 
00195 class udPDFPageObjectVertLine : public udPDFPageObjectLine
00196 {
00198   
00199   
00200   
00202 
00203  public:  
00205 
00212   udPDFPageObjectVertLine( double x , double y , double s ,  double gc = 0, bool d = false ) :  
00213                         udPDFPageObjectLine( x , y , x , y + s, gc, d  )  { }
00214   
00215 };
00216 
00217 
00218 
00219 
00220 
00221 
00223 class udPDFPageObjectHorizLine : public udPDFPageObjectLine
00224 {
00226   
00227   
00228   
00230 
00231  public:  
00232 
00234 
00240   udPDFPageObjectHorizLine( double x , double y , double s ,  double gc = 0, bool d = false ) :  
00241                         udPDFPageObjectLine( x , y , x + s , y, gc, d  )  { }
00242   
00243 };
00244 
00245 
00246 
00247 
00248 
00250 class udPDFPageObjectRect : public PDFPageObject
00251 {
00253   
00254   
00255   
00257 
00258  public:  
00259 
00261 
00267   udPDFPageObjectRect( double x , double y , double w , double h, double bc = 0, double f = -1 ) : 
00268                         theX(x), theY(y), theW(w), theH(h), border_color(bc), theFill( f )  { }
00269   
00271   
00272   
00273   
00275         
00276 public:
00277   
00278   void write( ostream& os );
00279 
00281   
00282   
00283   
00285     
00286  private:
00287   double theX, theY;
00288   double theW, theH;
00289   double theFill;
00290   double border_color;
00291 };
00292 
00293 
00294 
00295 
00296 
00297 
00299 class udPDFPageObjectSquare : public udPDFPageObjectRect
00300 {
00302   
00303   
00304   
00306 
00307  public:  
00308 
00310 
00316   udPDFPageObjectSquare( double x , double y , double s, double bc = 0,double f = -1 ) :
00317           udPDFPageObjectRect( x , y , s , s, bc, f ) { }
00318   
00319 };
00320 
00321 
00322 
00323 
00324 
00325 
00327 class udPDFPageObjectCircle : public PDFPageObject
00328 {
00330   
00331   
00332   
00334 
00335  public:  
00336 
00338 
00344   udPDFPageObjectCircle( double cx , double cy , double r, double bc = 0,double f = -1 ) : 
00345   theX(cx), theY(cy), theRad(r), border_color(bc), theFill( f )   { }
00346   
00348   
00349   
00350   
00352         
00353 public:
00354   
00355   void write( ostream& os );
00356 
00358   
00359   
00360   
00362     
00363  private:
00364   double theX, theY;
00365   double theRad;
00366   double theFill;
00367   double border_color;
00368 };
00369 
00370 
00371 
00372 
00373 
00375 class PDFPage
00376 {
00378   
00379   
00380   
00382 
00383  public:  
00384 
00385   PDFPage( ) { }
00386   ~PDFPage( ) {
00387     for( vector< PDFPageObject* >::const_iterator o_it=theObjects.begin( ) ; o_it!=theObjects.end( ) ; ++o_it )
00388       delete *o_it;
00389   }
00390 
00392   void writeContents( ostream& os ) {
00393     for( vector< PDFPageObject* >::const_iterator o_it=theObjects.begin( ) ; o_it!=theObjects.end( ) ; ++o_it )
00394       (*o_it)->write( os );
00395   }
00396 
00398   void addObject( PDFPageObject* obj ) { theObjects.push_back( obj ); }
00399   
00401   static int width() { return 612; }
00403   static int height() { return 792; }
00404 
00406   static int mWidth() { return width() - lMargin() - rMargin(); }
00408   static int mHeight() { return height() - tMargin() - bMargin(); }
00410   static int mRightEnd() { return mWidth() + lMargin(); }
00412   static int mBottomEnd() { return mHeight() + tMargin(); }
00413   
00415   static int lMargin() { return 30; } 
00417   static int rMargin() { return 20; }
00419   static int tMargin() { return 20; } 
00421   static int bMargin() { return 20; }
00422 
00424   
00425   
00426   
00428     
00429  private:
00430   vector< PDFPageObject* > theObjects;
00431 
00432 };
00433 
00434 
00435 
00436 
00437 
00438 
00439 
00441 class PDFStructure
00442 {
00443 
00445   
00446   
00447   
00449 
00450  public:  
00451   
00452   PDFStructure( ) { }
00453   ~PDFStructure( ) { 
00454     for( vector< PDFPage* >::iterator p_it=thePages.begin() ; p_it!=thePages.end( ) ; ++p_it )
00455       delete *p_it;
00456   }
00457   
00458   
00460   
00461   
00462   
00464         
00465 public:
00466 
00468   void save( const char* filename );
00470   void newPage( ) { 
00471     thePages.push_back( new PDFPage( ) );
00472   }
00473 
00475 
00479   void addObject( int p , PDFPageObject* obj ) { thePages[p]->addObject( obj ); }
00480 
00482   
00483   
00484   
00486 
00487  private:
00488   
00489   pair< const char* , int > preparePageContents( int p ) const;
00490   
00492   
00493   
00494   
00496     
00497  private:
00498  
00499   vector< PDFPage* > thePages;
00500   
00501 };
00502 
00503 
00504 #endif
00505