Back to index

plt-scheme  4.2.1
PSDC.h
Go to the documentation of this file.
00001 /*
00002  * File:      wx_dcps.h
00003  * Purpose:   PostScript device context
00004  * Author:    Julian Smart
00005  * Created:   1993
00006  * Updated:   
00007  * Copyright: (c) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (c) 1993, AIAI, University of Edinburgh
00009  */
00010 
00011 #ifndef wx_dcpsh
00012 #define wx_dcpsh
00013 
00014 #ifdef __GNUG__
00015 # ifndef wx_mac
00016 #  pragma interface
00017 # endif
00018 #endif
00019 
00020 #ifdef wx_xt
00021 class wxBitmap;
00022 class wxBrush;
00023 class wxColour;
00024 class wxColourMap;
00025 class wxFont;
00026 class wxList;
00027 class wxPen;
00028 class ofstream;
00029 #else
00030 #include "wx_dc.h"
00031 #endif
00032 
00033 class wxMemoryDC;
00034 class wxPath;
00035 #ifdef wx_mac
00036 class wxPrintData;
00037 #endif
00038 
00039 #if USE_POSTSCRIPT
00040 
00041 #ifdef IN_CPROTO
00042 typedef       void    *wxPostScriptDC ;
00043 #else
00044 
00045 #ifdef wx_xt
00046 # define DRAW_TEXT_CONST /* empty */
00047 #else
00048 # define DRAW_TEXT_CONST const
00049 #endif
00050 
00051 class wxPSStream;
00052 
00053 class wxPostScriptDC: public wxDC
00054 {
00055  public:
00056 #ifdef wx_xt
00057   char *title;
00058 #endif
00059   int page_number;
00060   wxPSStream *pstream;    // PostScript output stream
00061   char *filename;
00062   long boundingboxpos, fontlistpos;
00063   unsigned char currentRed;
00064   unsigned char currentGreen;
00065   unsigned char currentBlue;
00066   double clipx, clipy, clipw, cliph;
00067 
00068   double max_x, max_y, min_x, min_y;
00069 
00070   char *current_font_name, *next_font_name;
00071   double current_font_size, next_font_size;
00072 
00073   double paper_x, paper_y, paper_w, paper_h, paper_x_scale, paper_y_scale;
00074   double paper_margin_x, paper_margin_y;
00075   Bool landscape, resetFont, level2ok;
00076   char *afm_path;
00077 
00078   int mode, use_paper_bbox, as_eps;
00079   char *preview_cmd, *print_cmd, *print_opts;
00080 
00081   void *used_fonts;
00082 
00083   // Create a printer DC
00084   wxPostScriptDC(Bool interactive = TRUE, wxWindow *parent = NULL, Bool usePaperBBox = FALSE, Bool asEPS = TRUE);
00085 
00086   ~wxPostScriptDC(void);
00087 
00088   Bool Create(Bool interactive = TRUE, wxWindow *parent = NULL, Bool usePaperBBox = FALSE, Bool asEPS = TRUE);
00089 
00090   Bool PrinterDialog(Bool interactive, wxWindow *parent, Bool usePaperBBox);
00091 
00092   inline virtual void BeginDrawing(void) {} ;
00093   inline virtual void EndDrawing(void) {} ;
00094 
00095   Bool GetPixel(double x1, double y1, wxColour *col) ;
00096 
00097   void DrawLine(double x1, double y1, double x2, double y2);
00098   void DrawArc(double x1,double y1,double w,double h,double start,double end);
00099   void DrawPoint(double x, double y);
00100   void DrawPoint(wxPoint* point) { DrawPoint(point->x, point->y); }
00101   void DrawLines(int n, wxPoint points[], double xoffset = 0, double yoffset = 0);
00102   void DrawPolygon(int n, wxPoint points[], double xoffset = 0, double yoffset = 0, int fillStyle=wxODDEVEN_RULE);
00103   void  DrawPath(wxPath *p, double dx, double dy, int fillStyle=wxODDEVEN_RULE);
00104 
00105   void DrawSpline(double x1, double y1, double x2, double y2, double x3, double y3);
00106 
00107   void DrawRectangle(double x, double y, double width, double height);
00108   void DrawRoundedRectangle(double x, double y, double width, double height, double radius = 20);
00109   void DrawEllipse(double x, double y, double width, double height);
00110   void DrawText(DRAW_TEXT_CONST char *text, double x, double y, 
00111               Bool combine = FALSE, Bool use16 = FALSE, 
00112               int dt = 0, double angle = 0.0);
00113 
00114   void Clear(void);
00115   void SetFont(wxFont *font);
00116   void SetPen(wxPen *pen);
00117   void SetBrush(wxBrush *brush);
00118   void SetBackground(wxColour *c);
00119   void SetClippingRect(double x, double y, double width, double height);
00120   wxRegion *GetClippingRegion();
00121   void SetClippingRegion(wxRegion *r);
00122   void DestroyClippingRegion(void);
00123 
00124   Bool StartDoc(char *message);
00125   void EndDoc(void);
00126   void StartPage(void);
00127   void EndPage(void);
00128 
00129   double GetCharHeight(void);
00130   double GetCharWidth(void);
00131   void GetTextExtent(const char *string, double *x, double *y,
00132                      double *descent = NULL, double *externalLeading = NULL, 
00133                    wxFont *theFont = NULL, 
00134                    Bool combine = FALSE, Bool use16 = FALSE, int dt = 0, int slen = -1);
00135   void SetMapMode(int mode);
00136   void SetUserScale(double x, double y);
00137   double DeviceToLogicalX(int x);
00138   double DeviceToLogicalY(int y);
00139   double DeviceToLogicalXRel(int x);
00140   double DeviceToLogicalYRel(int y);
00141   double UnscrolledDeviceToLogicalX(int x);
00142   double UnscrolledDeviceToLogicalY(int y);
00143   int LogicalToDeviceX(double x);
00144   int LogicalToDeviceY(double y);
00145   int LogicalToDeviceXRel(double x);
00146   int LogicalToDeviceYRel(double y);
00147   int LogicalToUnscrolledDeviceX(double x);
00148   int LogicalToUnscrolledDeviceY(double y);
00149   double FLogicalToDeviceX(double x);
00150   double FLogicalToDeviceY(double y);
00151   double FLogicalToDeviceXRel(double x);
00152   double FLogicalToDeviceYRel(double y);
00153   double FLogicalToUnscrolledDeviceX(double x);
00154   double FLogicalToUnscrolledDeviceY(double y);
00155 
00156   double FsLogicalToDeviceX(double x, double o, double s);
00157   double FsLogicalToDeviceY(double y, double o, double s);
00158   double FsLogicalToDeviceXRel(double x, double o, double s);
00159   double FsLogicalToDeviceYRel(double y, double o, double s);
00160 
00161   Bool Blit(double xdest, double ydest, double width, double height,
00162             wxBitmap *source, double xsrc, double ysrc, int rop = wxSOLID, wxColour *c = NULL, wxBitmap *mask=NULL);
00163   Bool Blit(double xdest, double ydest, double width, double height,
00164             wxMemoryDC *source, double xsrc, double ysrc, int rop = wxSOLID, wxColour *c = NULL, wxMemoryDC *mask=NULL);
00165   inline Bool CanGetTextExtent(void) { return USE_AFM_FOR_POSTSCRIPT; }
00166   inline Bool CanDrawBitmap(void) { return TRUE; }
00167 
00168   void GetSize(double *width, double *height);
00169   void GetSizeMM(double *width, double *height);
00170 
00171   inline void SetColourMap(wxColourMap *WXUNUSED(cmap)) {}
00172 
00173   void SetBackgroundMode(int mode);
00174   void SetTextBackground(wxColour *col);
00175   void SetTextForeground(wxColour *col);
00176   void TryColour(wxColour *src, wxColour *dest);
00177 
00178   Bool GlyphAvailable(int c, wxFont *f = NULL);
00179 
00180   void CalcBoundingBoxClip(double x, double y);
00181 
00182   void SetAntiAlias(int mode);
00183 
00184   virtual int CacheFontMetricsKey();
00185 
00186   virtual Bool Ok() { return ok; }
00187 };
00188 
00189 #ifndef wx_xt
00190 
00191 // Print Orientation (Should also add Left, Right)
00192 enum {
00193   PS_PORTRAIT,
00194   PS_LANDSCAPE
00195 };// ps_orientation = PS_PORTRAIT;
00196 
00197 // Print Actions
00198 enum {
00199   PS_PRINTER,
00200   PS_FILE,
00201   PS_PREVIEW
00202 };// ps_action = PS_PREVIEW;
00203 
00204 #endif
00205 
00206 extern void wxInitializePrintSetupData(Bool init = TRUE);
00207 
00208 class wxPrintSetupData : public wxObject {
00209 public:
00210     wxPrintSetupData(void);
00211     ~wxPrintSetupData(void);
00212 
00213     void copy (wxPrintSetupData* data);
00214 
00215     void  SetPrinterCommand(char *cmd);
00216     void  SetPaperName(char *paper);
00217     void  SetPrintPreviewCommand(char *cmd);
00218     void  SetPrinterOptions(char *flags);
00219     void  SetPrinterFile(char *f);
00220     void  SetAFMPath(char *f);
00221     void  SetPrinterMode(int mode);
00222     void  SetPrinterOrientation(int orient);
00223     void  SetPrinterScaling(double x, double y)
00224        { printer_scale_x = x; printer_scale_y = y; }
00225     void  SetPrinterTranslation(double x, double y)
00226        { printer_translate_x = x; printer_translate_y = y; }
00227     void  SetColour(Bool col)
00228        { print_colour = col; }
00229     void  SetLevel2(Bool l2)
00230        { print_level_2 = l2; }
00231     void SetEditorMargin(long x, long y)
00232         { emargin_h = x; emargin_v = y; }
00233     void SetMargin(double x, double y)
00234         { ps_margin_h = x; ps_margin_v = y; }
00235 
00236     inline char *GetPrinterCommand(void)
00237        { return printer_command; }
00238     inline char *GetPrintPreviewCommand(void)
00239        { return preview_command; }
00240     inline char *GetPrinterOptions(void)
00241        { return printer_flags; }
00242     inline char *GetPrinterFile(void)
00243        { return printer_file; }
00244     inline char *GetPaperName(void)
00245        { return paper_name; }
00246     inline int GetPrinterOrientation(void)
00247        {  return printer_orient; }
00248     inline void GetPrinterScaling(double *x, double *y)
00249        { *x=printer_scale_x; *y=printer_scale_y; }
00250     inline void GetPrinterTranslation(double *x, double *y)
00251        { *x=printer_translate_x; *y=printer_translate_y; }
00252     inline int GetPrinterMode(void)
00253        { return printer_mode; }
00254     inline char *GetAFMPath(void)
00255        { return afm_path; }
00256     inline Bool GetColour(void)
00257        { return print_colour; }
00258     inline Bool GetLevel2()
00259        { return print_level_2; }
00260     void GetEditorMargin(long *x, long *y)
00261         { *x = emargin_h; *y = emargin_v; }
00262     void GetMargin(double *x, double *y)
00263         { *x = ps_margin_h; *y = ps_margin_v; }
00264 
00265     Bool CanShowNative();
00266     Bool ShowNative(wxWindow *parent);
00267 
00268 private:
00269     friend class wxPostScriptDC;
00270 
00271     char   *printer_command;
00272     char   *preview_command;
00273     char   *printer_flags;
00274     char   *printer_file;
00275     int    printer_orient;
00276     double  printer_scale_x;
00277     double  printer_scale_y;
00278     double  printer_translate_x;
00279     double  printer_translate_y;
00280     int    printer_mode;
00281     char   *afm_path;
00282     char   *paper_name;
00283     Bool   print_colour;
00284     Bool   print_level_2;
00285     long   emargin_h, emargin_v;
00286     double  ps_margin_h, ps_margin_v;
00287 #ifdef wx_mac
00288  public:
00289     wxPrintData *native;
00290 #endif
00291 };
00292 
00293 extern wxPrintSetupData *wxGetThePrintSetupData();
00294 extern void wxSetThePrintSetupData(wxPrintSetupData *);
00295 
00296 class wxPrintPaperType : public wxObject {
00297 public:
00298     wxPrintPaperType(char *name=NULL, int wmm=0, int hmm=0, int wp=0, int hp=0);
00299     ~wxPrintPaperType(void);
00300 public:
00301     int   widthMM;
00302     int   heightMM;
00303     int   widthPixels;
00304     int   heightPixels;
00305     char  *pageName;
00306 };
00307 
00308 class wxPrintPaperDatabase : public wxList {
00309 public:
00310     wxPrintPaperDatabase(void);
00311     ~wxPrintPaperDatabase(void);
00312 
00313     void CreateDatabase(void);
00314     void ClearDatabase(void);
00315 
00316     void AddPaperType(char *name, int wmm, int hmm, int wp, int hp);
00317     wxPrintPaperType *FindPaperType(char *name);
00318 };
00319 
00320 extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
00321 
00322 #endif // IN_CPROTO
00323 #endif // USE_POSTSCRIPT
00324 #endif // wx_dcpsh