FLTK
Fl_PostScript.H
Go to the documentation of this file.
1 //
2 // Support for graphics output to PostScript file for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 2010-2020 by Bill Spitzak and others.
5 //
6 // This library is free software. Distribution and use rights are outlined in
7 // the file "COPYING" which should have been included with this file. If this
8 // file is missing or damaged, see the license at:
9 //
10 // https://www.fltk.org/COPYING.php
11 //
12 // Please see the following page on how to report bugs and issues:
13 //
14 // https://www.fltk.org/bugs.php
15 //
16 
21 #ifndef Fl_PostScript_H
22 #define Fl_PostScript_H
23 
24 #include <FL/Fl_Paged_Device.H>
25 #include <FL/fl_draw.H>
26 #include <stdarg.h>
27 
28 /* Signature of Fl_PostScript::close_command() functions passed as parameters. */
29 extern "C" {
30  typedef int (Fl_PostScript_Close_Command)(FILE *);
31 }
32 
42 class FL_EXPORT Fl_PostScript_Graphics_Driver : public Fl_Graphics_Driver {
43 private:
44  void transformed_draw_extra(const char* str, int n, double x, double y, int w, bool rtl);
45  void *prepare_rle85();
46  void write_rle85(uchar b, void *data);
47  void close_rle85(void *data);
48  void *prepare85();
49  void write85(void *data, const uchar *p, int len);
50  void close85(void *data);
51  int scale_for_image_(Fl_Image *img, int XP, int YP, int WP, int HP,int cx, int cy);
52 protected:
53  uchar **mask_bitmap() {return &mask;}
54 public:
55  Fl_PostScript_Graphics_Driver();
56 #ifndef FL_DOXYGEN
57  enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS};
58 
59  class Clip {
60  public:
61  int x, y, w, h;
62  Clip *prev;
63  };
64  Clip * clip_;
65 
66  int lang_level_;
67  int gap_;
68  int pages_;
69 
70  double width_;
71  double height_;
72 
73  int shape_;
74  int linewidth_;// need for clipping, lang level 1-2
75  int linestyle_;//
76  int interpolate_; //interpolation of images
77  unsigned char cr_,cg_,cb_;
78  char linedash_[256];//should be enough
79  void concat(); // transform ror scalable dradings...
80  void reconcat(); //invert
81  void recover(); //recovers the state after grestore (such as line styles...)
82  void reset();
83 
84  uchar * mask;
85  int mx; // width of mask;
86  int my; // mask lines
87  //Fl_Color bg_;
88  Fl_PostScript_Close_Command* close_cmd_;
89  int page_policy_;
90  int nPages;
91  int orientation_;
92 
93  float scale_x;
94  float scale_y;
95  float angle;
96  int left_margin;
97  int top_margin;
98 
99  FILE *output;
100  double pw_, ph_;
101 
102  uchar bg_r, bg_g, bg_b;
103  int start_postscript (int pagecount, enum Fl_Paged_Device::Page_Format format, enum Fl_Paged_Device::Page_Layout layout);
104  /* int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
105  */
106  void transformed_draw(const char* s, int n, double x, double y); //precise text placing
107  void transformed_draw(const char* s, double x, double y);
108  int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
109 
110  enum Fl_Paged_Device::Page_Format page_format_;
111  char *ps_filename_;
112 
113  void page_policy(int p);
114  int page_policy(){return page_policy_;};
115  void close_command(Fl_PostScript_Close_Command* cmd){close_cmd_=cmd;};
116  FILE * file() {return output;};
117  //void orientation (int o);
118  //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int pages = 0); // ps (also multi-page) constructor
119  //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int x, int y, int w, int h); //eps constructor
120  void interpolate(int i){interpolate_=i;};
121  int interpolate(){return interpolate_;}
122 
123  void page(double pw, double ph, int media = 0);
124  void page(int format);
125 #endif // FL_DOXYGEN
126 
127  // implementation of drawing methods
128  void color(Fl_Color c);
129  void color(uchar r, uchar g, uchar b);
130 
131  void push_clip(int x, int y, int w, int h);
132  int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
133  int not_clipped(int x, int y, int w, int h);
134  void push_no_clip();
135  void pop_clip();
136 
137  void line_style(int style, int width=0, char* dashes=0);
138 
139  void rect(int x, int y, int w, int h);
140  void rectf(int x, int y, int w, int h);
141 
142  void xyline(int x, int y, int x1);
143  void xyline(int x, int y, int x1, int y2);
144  void xyline(int x, int y, int x1, int y2, int x3);
145 
146  void yxline(int x, int y, int y1);
147  void yxline(int x, int y, int y1, int x2);
148  void yxline(int x, int y, int y1, int x2, int y3);
149 
150  void line(int x1, int y1, int x2, int y2);
151  void line(int x1, int y1, int x2, int y2, int x3, int y3);
152 
153  void loop(int x0, int y0, int x1, int y1, int x2, int y2);
154  void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
155  void polygon(int x0, int y0, int x1, int y1, int x2, int y2);
156  void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
157  void point(int x, int y);
158 
159  void begin_points();
160  void begin_line();
161  void begin_loop();
162  void begin_polygon();
163  void vertex(double x, double y);
164  void curve(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3);
165  void circle(double x, double y, double r);
166  void arc(double x, double y, double r, double start, double a);
167  void arc(int x, int y, int w, int h, double a1, double a2);
168  void pie(int x, int y, int w, int h, double a1, double a2);
169  void end_points();
170  void end_line();
171  void end_loop();
172  void end_polygon();
173  void begin_complex_polygon(){begin_polygon();};
174  void gap(){gap_=1;};
175  void end_complex_polygon(){end_polygon();};
176  void transformed_vertex(double x, double y);
177 
178  void draw_image(const uchar* d, int x,int y,int w,int h, int delta=3, int ldelta=0);
179  void draw_image_mono(const uchar* d, int x,int y,int w,int h, int delta=1, int ld=0);
180  void draw_image(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=3);
181  void draw_image_mono(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=1);
182 
183  void draw(const char* s, int nBytes, int x, int y) {transformed_draw(s,nBytes,x,y); };
184  void draw(const char* s, int nBytes, float x, float y) {transformed_draw(s,nBytes,x,y); };
185  void draw(int angle, const char *str, int n, int x, int y);
186  void rtl_draw(const char* s, int n, int x, int y);
187  void font(int face, int size);
188  double width(const char *, int);
189  double width(unsigned int u);
190  void text_extents(const char *c, int n, int &dx, int &dy, int &w, int &h);
191  int height();
192  int descent();
193  void draw_pixmap(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
194  void draw_bitmap(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
195  void draw_rgb(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
202  int clocale_printf(const char *format, ...);
203  ~Fl_PostScript_Graphics_Driver();
204  // ---
205  Fl_Bitmask create_bitmask(int w, int h, const uchar *array) { return 0L; }
206  virtual int has_feature(driver_feature feature_mask) { return feature_mask & PRINTER; }
207 
208  int start_eps(int width, int height);
209  void ps_origin(int x, int y);
210  void ps_translate(int, int);
211  void ps_untranslate();
212 };
213 
248 class FL_EXPORT Fl_PostScript_File_Device : public Fl_Paged_Device {
249 protected:
253  Fl_PostScript_Graphics_Driver *driver();
254 public:
264  int begin_job(int pagecount, int* from, int* to, char **perr_message);
274  int begin_job(int pagecount = 0, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
278  int start_job(int pagecount = 0, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
280  return begin_job(pagecount, format, layout);
281  }
292  int begin_job(FILE *ps_output, int pagecount = 0, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
296  int start_job(FILE *ps_output, int pagecount = 0, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
298  return begin_job(ps_output, pagecount, format, layout);
299  }
300 
301  int begin_page (void);
302  int printable_rect(int *w, int *h);
303  void margins(int *left, int *top, int *right, int *bottom);
304  void origin(int *x, int *y);
305  void origin(int x, int y);
306  void scale (float scale_x, float scale_y = 0.);
307  void rotate(float angle);
308  void translate(int x, int y);
309  void untranslate(void);
310  int end_page (void);
311  void end_job(void);
313  static const char *file_chooser_title;
315  FILE *file() { return driver()->file(); }
316 };
317 
336 class FL_EXPORT Fl_EPS_File_Surface : public Fl_Widget_Surface {
337 private:
338  void complete_();
339 protected:
341  inline Fl_PostScript_Graphics_Driver *driver() { return (Fl_PostScript_Graphics_Driver*)Fl_Surface_Device::driver(); }
342 public:
351  Fl_EPS_File_Surface(int width, int height, FILE *eps, Fl_Color background = FL_WHITE);
358  virtual int printable_rect(int *w, int *h);
360  FILE *file() { return driver() ? driver()->output : NULL; }
361  virtual void origin(int x, int y);
362  virtual void origin(int *px, int *py);
363  virtual void translate(int x, int y);
364  virtual void untranslate();
367  int close();
368 };
369 
370 #endif // Fl_PostScript_H
Represents page-structured drawing surfaces.
Definition: Fl_Paged_Device.H:36
Encapsulated PostScript drawing surface.
Definition: Fl_PostScript.H:336
The Fl_Pixmap class supports caching and drawing of colormap (pixmap) images, including transparency...
Definition: Fl_Pixmap.H:36
opaque Fl_Bitmask
mask
Definition: platform_types.h:36
Page_Layout
Possible page layouts.
Definition: Fl_Paged_Device.H:82
Base class for image caching, scaling and drawing.
Definition: Fl_Image.H:62
The Fl_RGB_Image class supports caching and drawing of full-color images with 1 to 4 channels of colo...
Definition: Fl_Image.H:287
int start_job(FILE *ps_output, int pagecount=0, enum Fl_Paged_Device::Page_Format format=Fl_Paged_Device::A4, enum Fl_Paged_Device::Page_Layout layout=Fl_Paged_Device::PORTRAIT)
Synonym of begin_job().
Definition: Fl_PostScript.H:296
FILE * file()
Returns the underlying FILE pointer.
Definition: Fl_PostScript.H:360
FILE * file()
Returns the underlying FILE* receiving all PostScript data.
Definition: Fl_PostScript.H:315
Fl_PostScript_Graphics_Driver * driver()
Returns the PostScript driver of this drawing surface.
Definition: Fl_PostScript.H:341
static const char * file_chooser_title
Label of the PostScript file chooser window.
Definition: Fl_PostScript.H:313
A surface on which any FLTK widget can be drawn.
Definition: Fl_Widget_Surface.H:25
declaration of class Fl_Paged_Device.
Page_Format
Possible page formats.
Definition: Fl_Paged_Device.H:46
utility header to pull drawing functions together
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:1042
The Fl_Bitmap class supports caching and drawing of mono-color (bitmap) images.
Definition: Fl_Bitmap.H:32
A4 format.
Definition: Fl_Paged_Device.H:51
To send graphical output to a PostScript file.
Definition: Fl_PostScript.H:248
Portrait orientation.
Definition: Fl_Paged_Device.H:83
int start_job(int pagecount=0, enum Fl_Paged_Device::Page_Format format=Fl_Paged_Device::A4, enum Fl_Paged_Device::Page_Layout layout=Fl_Paged_Device::PORTRAIT)
Synonym of begin_job().
Definition: Fl_PostScript.H:278
unsigned char uchar
unsigned char
Definition: fl_types.h:28
Fl_Graphics_Driver * driver()
Returns the graphics driver of this drawing surface.
Definition: Fl_Device.H:82