FLTK 1.3.2
Fl_PostScript.H
Go to the documentation of this file.
1 //
2 // "$Id: Fl_PostScript.H 9683 2012-09-20 11:23:38Z manolo $"
3 //
4 // Support for graphics output to PostScript file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 2010-2011 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
23 #ifndef Fl_PostScript_H
24 #define Fl_PostScript_H
25 
26 #include <FL/Fl_Paged_Device.H>
27 #include <FL/fl_draw.H>
28 
56 public:
57  static const char *class_id;
58  const char *class_name() {return class_id;};
60 #ifndef FL_DOXYGEN
61  enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS};
62 
63 class Clip {
64  public:
65  int x, y, w, h;
66  Clip *prev;
67  };
68  Clip * clip_;
69 
70  int lang_level_;
71  int gap_;
72  int pages_;
73 
74  double width_;
75  double height_;
76 
77  int shape_;
78  int linewidth_;// need for clipping, lang level 1-2
79  int linestyle_;//
80  int interpolate_; //interpolation of images
81  unsigned char cr_,cg_,cb_;
82  char linedash_[256];//should be enough
83  void concat(); // transform ror scalable dradings...
84  void reconcat(); //invert
85  void recover(); //recovers the state after grestore (such as line styles...)
86  void reset();
87 
88  uchar * mask;
89  int mx; // width of mask;
90  int my; // mask lines
91  //Fl_Color bg_;
92  int (*close_cmd_)(FILE *);
93  int page_policy_;
94  int nPages;
95  int orientation_;
96 
97  float scale_x;
98  float scale_y;
99  float angle;
100  int left_margin;
101  int top_margin;
102 
103  FILE *output;
104  double pw_, ph_;
105 
106  uchar bg_r, bg_g, bg_b;
107  int start_postscript (int pagecount, enum Fl_Paged_Device::Page_Format format, enum Fl_Paged_Device::Page_Layout layout);
108  /* int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
109  */
110  void transformed_draw(const char* s, int n, double x, double y); //precise text placing
111  void transformed_draw(const char* s, double x, double y);
112  int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
113 
114  enum Fl_Paged_Device::Page_Format page_format_;
115  char *ps_filename_;
116 
117  void page_policy(int p);
118  int page_policy(){return page_policy_;};
119  void close_command( int (*cmd)(FILE *)){close_cmd_=cmd;};
120  FILE * file() {return output;};
121  //void orientation (int o);
122  //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int pages = 0); // ps (also multi-page) constructor
123  //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int x, int y, int w, int h); //eps constructor
124  void interpolate(int i){interpolate_=i;};
125  int interpolate(){return interpolate_;}
126 
127  void page(double pw, double ph, int media = 0);
128  void page(int format);
129 #endif // FL_DOXYGEN
130 
131  // implementation of drawing methods
132  void color(Fl_Color c);
133  void color(uchar r, uchar g, uchar b);
134 
135  void push_clip(int x, int y, int w, int h);
136  int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
137  int not_clipped(int x, int y, int w, int h);
138  void push_no_clip();
139  void pop_clip();
140 
141  void line_style(int style, int width=0, char* dashes=0);
142 
143  void rect(int x, int y, int w, int h);
144  void rectf(int x, int y, int w, int h);
145 
146  void xyline(int x, int y, int x1);
147  void xyline(int x, int y, int x1, int y2);
148  void xyline(int x, int y, int x1, int y2, int x3);
149 
150  void yxline(int x, int y, int y1);
151  void yxline(int x, int y, int y1, int x2);
152  void yxline(int x, int y, int y1, int x2, int y3);
153 
154  void line(int x1, int y1, int x2, int y2);
155  void line(int x1, int y1, int x2, int y2, int x3, int y3);
156 
157  void loop(int x0, int y0, int x1, int y1, int x2, int y2);
158  void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
159  void polygon(int x0, int y0, int x1, int y1, int x2, int y2);
160  void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
161  void point(int x, int y);
162 
163  void begin_points();
164  void begin_line();
165  void begin_loop();
166  void begin_polygon();
167  void vertex(double x, double y);
168  void curve(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3);
169  void circle(double x, double y, double r);
170  void arc(double x, double y, double r, double start, double a);
171  void arc(int x, int y, int w, int h, double a1, double a2);
172  void pie(int x, int y, int w, int h, double a1, double a2);
173  void end_points();
174  void end_line();
175  void end_loop();
176  void end_polygon();
178  void gap(){gap_=1;};
180  void transformed_vertex(double x, double y);
181 
182  void draw_image(const uchar* d, int x,int y,int w,int h, int delta=3, int ldelta=0);
183  void draw_image_mono(const uchar* d, int x,int y,int w,int h, int delta=1, int ld=0);
184  void draw_image(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=3);
185  void draw_image_mono(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=1);
186 
187  void draw(const char* s, int nBytes, int x, int y) {transformed_draw(s,nBytes,x,y); };
188 #ifdef __APPLE__
189  void draw(const char* s, int nBytes, float x, float y) {transformed_draw(s,nBytes,x,y); };
190 #endif
191  void draw(int angle, const char *str, int n, int x, int y);
192  void rtl_draw(const char* s, int n, int x, int y);
193  void font(int face, int size);
194  double width(const char *, int);
195  void text_extents(const char *c, int n, int &dx, int &dy, int &w, int &h);
196  int height();
197  int descent();
198  void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
199  void draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
200  void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
202 };
203 
207 class FL_EXPORT Fl_PostScript_File_Device : public Fl_Paged_Device {
208 #ifdef __APPLE__
209  CGContextRef gc;
210 #endif
211 protected:
213 public:
214  static const char *class_id;
215  const char *class_name() {return class_id;};
218  int start_job(int pagecount, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
220  int start_job(FILE *ps_output, int pagecount, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
222  int start_page (void);
223  int printable_rect(int *w, int *h);
224  void margins(int *left, int *top, int *right, int *bottom);
225  void origin(int *x, int *y);
226  void origin(int x, int y);
227  void scale (float scale_x, float scale_y = 0.);
228  void rotate(float angle);
229  void translate(int x, int y);
230  void untranslate(void);
231  int end_page (void);
232  void end_job(void);
233 #ifdef __APPLE__
234  void set_current() { fl_gc = gc; Fl_Paged_Device::set_current(); }
235 #endif
236 
237  static const char *file_chooser_title;
238 };
239 
240 #endif // Fl_PostScript_H
241 
242 //
243 // End of "$Id: Fl_PostScript.H 9683 2012-09-20 11:23:38Z manolo $"
244 //