FLTK 1.3.x
|
00001 // 00002 // "$Id: Fl_PostScript.H 8190 2011-01-05 10:21:45Z manolo $" 00003 // 00004 // Support for graphics output to PostScript file for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00032 #ifndef Fl_PostScript_H 00033 #define Fl_PostScript_H 00034 00035 #include <FL/Fl_Paged_Device.H> 00036 #include <FL/fl_draw.H> 00037 00064 class Fl_PostScript_Graphics_Driver : public Fl_Graphics_Driver { 00065 public: 00066 static const char *class_id; 00067 #ifndef FL_DOXYGEN 00068 public: 00069 enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS}; 00070 00071 class Clip { 00072 public: 00073 int x, y, w, h; 00074 Clip *prev; 00075 }; 00076 Clip * clip_; 00077 00078 int lang_level_; 00079 int font_; 00080 int size_; 00081 int gap_; 00082 int pages_; 00083 00084 double width_; 00085 double height_; 00086 00087 int shape_; 00088 int linewidth_;// need for clipping, lang level 1-2 00089 int linestyle_;// 00090 int interpolate_; //interpolation of images 00091 unsigned char cr_,cg_,cb_; 00092 char linedash_[256];//should be enough 00093 void concat(); // transform ror scalable dradings... 00094 void reconcat(); //invert 00095 void recover(); //recovers the state after grestore (such as line styles...) 00096 void reset(); 00097 00098 uchar * mask; 00099 int mx; // width of mask; 00100 int my; // mask lines 00101 //Fl_Color bg_; 00102 int (*close_cmd_)(FILE *); 00103 int page_policy_; 00104 int nPages; 00105 int orientation_; 00106 00107 float scale_x; 00108 float scale_y; 00109 float angle; 00110 int left_margin; 00111 int top_margin; 00112 00113 FILE *output; 00114 double pw_, ph_; 00115 00116 uchar bg_r, bg_g, bg_b; 00117 int start_postscript (int pagecount, enum Fl_Paged_Device::Page_Format format, enum Fl_Paged_Device::Page_Layout layout); 00118 /* int alpha_mask(const uchar * data, int w, int h, int D, int LD=0); 00119 */ 00120 void draw(const char* s, int n, int x, int y) {transformed_draw(s,n,x,y); }; 00121 void draw(int angle, const char *str, int n, int x, int y); 00122 void rtl_draw(const char* s, int n, int x, int y); 00123 void transformed_draw(const char* s, int n, double x, double y); //precise text placing 00124 void transformed_draw(const char* s, double x, double y); 00125 int alpha_mask(const uchar * data, int w, int h, int D, int LD=0); 00126 void draw_scaled_image(const uchar *data, double x, double y, double w, double h, int iw, int ih, int D=3, int LD=0); 00127 void draw_scaled_image_mono(const uchar *data, double x, double y, double w, double h, int iw, int ih, int D=3, int LD=0); 00128 void draw_scaled_image(Fl_Draw_Image_Cb call, void *data, double x, double y, double w, double h, int iw, int ih, int D); 00129 void draw_scaled_image_mono(Fl_Draw_Image_Cb call, void *data, double x, double y, double w, double h, int iw, int ih, int D); 00130 00131 enum Fl_Paged_Device::Page_Format page_format_; 00132 char *ps_filename_; 00133 // implementation of drawing methods 00134 void color(Fl_Color c); 00135 void color(uchar r, uchar g, uchar b); 00136 00137 void push_clip(int x, int y, int w, int h); 00138 int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H); 00139 int not_clipped(int x, int y, int w, int h); 00140 void push_no_clip(); 00141 void pop_clip(); 00142 00143 void line_style(int style, int width=0, char* dashes=0); 00144 00145 void rect(int x, int y, int w, int h); 00146 void rectf(int x, int y, int w, int h); 00147 00148 void xyline(int x, int y, int x1); 00149 void xyline(int x, int y, int x1, int y2); 00150 void xyline(int x, int y, int x1, int y2, int x3); 00151 00152 void yxline(int x, int y, int y1); 00153 void yxline(int x, int y, int y1, int x2); 00154 void yxline(int x, int y, int y1, int x2, int y3); 00155 00156 void line(int x1, int y1, int x2, int y2); 00157 void line(int x1, int y1, int x2, int y2, int x3, int y3); 00158 00159 void loop(int x0, int y0, int x1, int y1, int x2, int y2); 00160 void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3); 00161 void polygon(int x0, int y0, int x1, int y1, int x2, int y2); 00162 void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3); 00163 void point(int x, int y); 00164 00165 void begin_points(); 00166 void begin_line(); 00167 void begin_loop(); 00168 void begin_polygon(); 00169 void vertex(double x, double y); 00170 void curve(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3); 00171 void circle(double x, double y, double r); 00172 void arc(double x, double y, double r, double start, double a); 00173 void arc(int x, int y, int w, int h, double a1, double a2); 00174 void pie(int x, int y, int w, int h, double a1, double a2); 00175 void end_points(); 00176 void end_line(); 00177 void end_loop(); 00178 void end_polygon(); 00179 void begin_complex_polygon(){begin_polygon();}; 00180 void gap(){gap_=1;}; 00181 void end_complex_polygon(){end_polygon();}; 00182 void transformed_vertex(double x, double y); 00183 00184 void font(int face, int size); 00185 int font(){return font_;}; 00186 int size(){return size_;}; 00187 double width(unsigned c); 00188 double width(const char* s, int n); 00189 int descent(); 00190 int height(); 00191 00192 void draw_image(const uchar* d, int x,int y,int w,int h, int delta=3, int ldelta=0){draw_scaled_image(d,x,y,w,h,w,h,delta,ldelta);}; 00193 void draw_image_mono(const uchar* d, int x,int y,int w,int h, int delta=1, int ld=0){draw_scaled_image_mono(d,x,y,w,h,w,h,delta,ld);}; 00194 void draw_image(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=3){draw_scaled_image(call,data, x, y, w, h, w, h, delta);}; 00195 void draw_image_mono(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=1){draw_scaled_image_mono(call, data, x, y, w, h, w, h, delta);}; 00196 00197 public: 00198 void page_policy(int p); 00199 int page_policy(){return page_policy_;}; 00200 void close_command( int (*cmd)(FILE *)){close_cmd_=cmd;}; 00201 FILE * file() {return output;}; 00202 //void orientation (int o); 00203 //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int pages = 0); // ps (also multi-page) constructor 00204 //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int x, int y, int w, int h); //eps constructor 00205 void interpolate(int i){interpolate_=i;}; 00206 int interpolate(){return interpolate_;} 00207 00208 void page(double pw, double ph, int media = 0); 00209 void page(int format); 00210 00211 void place(double x, double y, double tx, double ty, double scale = 1); 00212 #endif // FL_DOXYGEN 00213 Fl_PostScript_Graphics_Driver(); 00214 void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy); 00215 void draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy); 00216 void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy); 00217 ~Fl_PostScript_Graphics_Driver(); 00218 }; 00219 00223 class Fl_PostScript_File_Device : public Fl_Paged_Device { 00224 #ifdef __APPLE__ 00225 Fl_CGContextRef gc; 00226 #endif 00227 protected: 00228 Fl_PostScript_Graphics_Driver *driver(); 00229 public: 00230 static const char *class_id; 00231 Fl_PostScript_File_Device(); 00232 ~Fl_PostScript_File_Device(); 00233 int start_job(int pagecount, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4, 00234 enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT); 00235 int start_job(FILE *ps_output, int pagecount, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4, 00236 enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT); 00237 int start_page (void); 00238 int printable_rect(int *w, int *h); 00239 void margins(int *left, int *top, int *right, int *bottom); 00240 void origin(int x, int y); 00241 void scale (float scale_x, float scale_y); 00242 void rotate(float angle); 00243 void translate(int x, int y); 00244 void untranslate(void); 00245 int end_page (void); 00246 void end_job(void); 00247 #ifdef __APPLE__ 00248 void set_current() { fl_gc = gc; Fl_Paged_Device::set_current(); } 00249 #endif 00250 00251 static const char *file_chooser_title; 00252 }; 00253 00254 #endif // Fl_PostScript_H 00255 00256 // 00257 // End of "$Id: Fl_PostScript.H 8190 2011-01-05 10:21:45Z manolo $" 00258 //