Fl_PostScript.H 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. //
  2. // "$Id: Fl_PostScript.H 7719 2010-10-12 09:25:37Z manolo $"
  3. //
  4. // Support for graphics output to PostScript file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. /** \file Fl_PostScript.H
  28. \brief declaration of classes Fl_PostScript_Graphics_Driver, Fl_PostScript_File_Device.
  29. */
  30. #ifndef Fl_PostScript_H
  31. #define Fl_PostScript_H
  32. #include <FL/Fl_Paged_Device.H>
  33. #include <FL/fl_draw.H>
  34. #define NO_PAGE_FORMATS 30 /* MSVC6 compilation fix */
  35. /**
  36. \brief PostScript graphical backend.
  37. *
  38. PostScript text uses vectorial fonts for the latin alphabet (exactly: all unicode
  39. characters between U+0020 and U+017F, that is, ASCII, Latin-1 Supplement and Latin Extended-A charts)
  40. plus a few other characters:
  41. <table>
  42. <tr> <th>Char</th><th>Codepoint</th><th>Name</th> <th>Char</th><th>Codepoint</th><th>Name</th> <th>Char</th><th>Codepoint</th><th>Name</th></tr>
  43. <tr><td>ƒ</td><td>U+0192</td><td>florin</td><td>‚</td><td>U+201A</td><td>quotesinglbase</td><td>™</td><td>U+2122</td><td>trademark</td></tr>
  44. <tr><td>ˆ</td><td>U+02C6</td><td>circumflex</td><td>“</td><td>U+201C</td><td>quotedblleft</td><td>∂</td><td>U+2202</td><td>partialdiff</td></tr>
  45. <tr><td>ˇ</td><td>U+02C7</td><td>caron</td><td>”</td><td>U+201D</td><td>quotedblright</td><td>Δ</td><td>U+2206</td><td>Delta</td></tr>
  46. <tr><td>˘</td><td>U+02D8</td><td>breve</td><td>„</td><td>U+201E</td><td>quotedblbase</td><td>∑</td><td>U+2211</td><td>summation</td></tr>
  47. <tr><td>˙</td><td>U+02D9</td><td>dotaccent</td><td>†</td><td>U+2020</td><td>dagger</td><td>√</td><td>U+221A</td><td>radical</td></tr>
  48. <tr><td>˚</td><td>U+02DA</td><td>ring</td><td>‡</td><td>U+2021</td><td>daggerdbl</td><td>∞</td><td>U+221E</td><td>infinity</td></tr>
  49. <tr><td>˛</td><td>U+02DB</td><td>ogonek</td><td>•</td><td>U+2022</td><td>bullet</td><td>≠</td><td>U+2260</td><td>notequal</td></tr>
  50. <tr><td>˜</td><td>U+02DC</td><td>tilde</td><td>…</td><td>U+2026</td><td>ellipsis</td><td>≤</td><td>U+2264</td><td>lessequal</td></tr>
  51. <tr><td>˝</td><td>U+02DD</td><td>hungarumlaut</td><td>‰</td><td>U+2030</td><td>perthousand</td><td>≥</td><td>U+2265</td><td>greaterequal</td></tr>
  52. <tr><td>–</td><td>U+2013</td><td>endash</td><td>‹</td><td>U+2039</td><td>guilsinglleft</td><td>◊</td><td>U+25CA</td><td>lozenge</td></tr>
  53. <tr><td>—</td><td>U+2014</td><td>emdash</td><td>›</td><td>U+203A</td><td>guilsinglright</td><td>fi</td><td>U+FB01</td><td>fi</td></tr>
  54. <tr><td>‘</td><td>U+2018</td><td>quoteleft</td><td>/</td><td>U+2044</td><td>fraction</td><td>fl</td><td>U+FB02</td><td>fl</td></tr>
  55. <tr><td>’</td><td>U+2019</td><td>quoteright</td><td>€</td><td>U+20AC</td><td>Euro</td><td></td><td>U+F8FF</td><td>apple (Mac OS only)</td></tr>
  56. </table>
  57. <br> All other unicode characters are output as a bitmap.
  58. <br> FLTK standard fonts are output using PostScript standard fonts: Helvetica, Courier,
  59. Times (and their bold, oblique, italic variants).
  60. */
  61. class Fl_PostScript_Graphics_Driver : public Fl_Graphics_Driver {
  62. public:
  63. static const char *device_type;
  64. /**
  65. \brief Possible page formats.
  66. */
  67. enum Page_Format {
  68. A0 = 0,
  69. A1,
  70. A2,
  71. A3,
  72. A4,
  73. A5,
  74. A6,
  75. A7,
  76. A8,
  77. A9,
  78. B0,
  79. B1,
  80. B2,
  81. B3,
  82. B4,
  83. B5,
  84. B6,
  85. B7,
  86. B8,
  87. B9,
  88. B10,
  89. C5E,
  90. DLE,
  91. EXECUTIVE,
  92. FOLIO,
  93. LEDGER,
  94. LEGAL,
  95. LETTER,
  96. TABLOID,
  97. ENVELOPE,
  98. MEDIA = 0x1000
  99. };
  100. /**
  101. \brief Possible page layouts.
  102. */
  103. enum Page_Layout {PORTRAIT = 0, LANDSCAPE = 0x100, REVERSED = 0x200, ORIENTATION = 0x300};
  104. #ifndef FL_DOXYGEN
  105. public:
  106. enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS};
  107. typedef struct page_format {
  108. int width;
  109. int height;
  110. const char *name;
  111. } page_format;
  112. class Clip {
  113. public:
  114. int x, y, w, h;
  115. Clip *prev;
  116. };
  117. Clip * clip_;
  118. int lang_level_;
  119. int font_;
  120. int size_;
  121. int gap_;
  122. int pages_;
  123. double width_;
  124. double height_;
  125. int shape_;
  126. int linewidth_;// need for clipping, lang level 1-2
  127. int linestyle_;//
  128. int interpolate_; //interpolation of images
  129. unsigned char cr_,cg_,cb_;
  130. char linedash_[256];//should be enough
  131. void concat(); // transform ror scalable dradings...
  132. void reconcat(); //invert
  133. void recover(); //recovers the state after grestore (such as line styles...)
  134. void reset();
  135. uchar * mask;
  136. int mx; // width of mask;
  137. int my; // mask lines
  138. //Fl_Color bg_;
  139. int (*close_cmd_)(FILE *);
  140. int page_policy_;
  141. int nPages;
  142. int orientation_;
  143. float scale_x;
  144. float scale_y;
  145. float angle;
  146. int left_margin;
  147. int top_margin;
  148. FILE *output;
  149. double pw_, ph_;
  150. static const page_format page_formats[NO_PAGE_FORMATS];
  151. uchar bg_r, bg_g, bg_b;
  152. int start_postscript (int pagecount, enum Page_Format format, enum Page_Layout layout);
  153. /* int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
  154. */
  155. void draw(const char* s, int n, int x, int y) {transformed_draw(s,n,x,y); };
  156. void draw(int angle, const char *str, int n, int x, int y);
  157. void transformed_draw(const char* s, int n, double x, double y); //precise text placing
  158. void transformed_draw(const char* s, double x, double y);
  159. int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
  160. 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);
  161. 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);
  162. 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);
  163. 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);
  164. enum Page_Format page_format_;
  165. char *ps_filename_;
  166. // implementation of drawing methods
  167. void color(Fl_Color c);
  168. void color(uchar r, uchar g, uchar b);
  169. void push_clip(int x, int y, int w, int h);
  170. int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
  171. int not_clipped(int x, int y, int w, int h);
  172. void push_no_clip();
  173. void pop_clip();
  174. void line_style(int style, int width=0, char* dashes=0);
  175. void rect(int x, int y, int w, int h);
  176. void rectf(int x, int y, int w, int h);
  177. void xyline(int x, int y, int x1);
  178. void xyline(int x, int y, int x1, int y2);
  179. void xyline(int x, int y, int x1, int y2, int x3);
  180. void yxline(int x, int y, int y1);
  181. void yxline(int x, int y, int y1, int x2);
  182. void yxline(int x, int y, int y1, int x2, int y3);
  183. void line(int x1, int y1, int x2, int y2);
  184. void line(int x1, int y1, int x2, int y2, int x3, int y3);
  185. void loop(int x0, int y0, int x1, int y1, int x2, int y2);
  186. void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  187. void polygon(int x0, int y0, int x1, int y1, int x2, int y2);
  188. void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  189. void point(int x, int y);
  190. void begin_points();
  191. void begin_line();
  192. void begin_loop();
  193. void begin_polygon();
  194. void vertex(double x, double y);
  195. void curve(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3);
  196. void circle(double x, double y, double r);
  197. void arc(double x, double y, double r, double start, double a);
  198. void arc(int x, int y, int w, int h, double a1, double a2);
  199. void pie(int x, int y, int w, int h, double a1, double a2);
  200. void end_points();
  201. void end_line();
  202. void end_loop();
  203. void end_polygon();
  204. void begin_complex_polygon(){begin_polygon();};
  205. void gap(){gap_=1;};
  206. void end_complex_polygon(){end_polygon();};
  207. void transformed_vertex(double x, double y);
  208. void font(int face, int size);
  209. int font(){return font_;};
  210. int size(){return size_;};
  211. double width(unsigned c);
  212. double width(const char* s, int n);
  213. int descent();
  214. int height();
  215. 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);};
  216. 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);};
  217. 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);};
  218. 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);};
  219. public:
  220. void page_policy(int p);
  221. int page_policy(){return page_policy_;};
  222. void close_command( int (*cmd)(FILE *)){close_cmd_=cmd;};
  223. FILE * file() {return output;};
  224. //void orientation (int o);
  225. //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int pages = 0); // ps (also multi-page) constructor
  226. //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int x, int y, int w, int h); //eps constructor
  227. void interpolate(int i){interpolate_=i;};
  228. int interpolate(){return interpolate_;}
  229. void page(double pw, double ph, int media = 0);
  230. void page(int format);
  231. void place(double x, double y, double tx, double ty, double scale = 1);
  232. #endif // FL_DOXYGEN
  233. Fl_PostScript_Graphics_Driver();
  234. void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
  235. void draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
  236. void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
  237. ~Fl_PostScript_Graphics_Driver();
  238. };
  239. /**
  240. \brief To send graphical output to a PostScript file.
  241. */
  242. class Fl_PostScript_File_Device : public Fl_Paged_Device {
  243. #ifdef __APPLE__
  244. CGContextRef gc;
  245. #endif
  246. protected:
  247. Fl_PostScript_Graphics_Driver *driver();
  248. public:
  249. static const char *device_type;
  250. Fl_PostScript_File_Device();
  251. ~Fl_PostScript_File_Device();
  252. int start_job(int pagecount, enum Fl_PostScript_Graphics_Driver::Page_Format format = Fl_PostScript_Graphics_Driver::A4,
  253. enum Fl_PostScript_Graphics_Driver::Page_Layout layout = Fl_PostScript_Graphics_Driver::PORTRAIT);
  254. int start_job(FILE *ps_output, int pagecount, enum Fl_PostScript_Graphics_Driver::Page_Format format = Fl_PostScript_Graphics_Driver::A4,
  255. enum Fl_PostScript_Graphics_Driver::Page_Layout layout = Fl_PostScript_Graphics_Driver::PORTRAIT);
  256. int start_page (void);
  257. int printable_rect(int *w, int *h);
  258. void margins(int *left, int *top, int *right, int *bottom);
  259. void origin(int x, int y);
  260. void scale (float scale_x, float scale_y);
  261. void rotate(float angle);
  262. void translate(int x, int y);
  263. void untranslate(void);
  264. int end_page (void);
  265. void end_job(void);
  266. #ifdef __APPLE__
  267. void set_current() { fl_gc = gc; Fl_Paged_Device::set_current(); }
  268. #endif
  269. static const char *file_chooser_title;
  270. };
  271. #endif // Fl_PostScript_H
  272. //
  273. // End of "$Id: Fl_PostScript.H 7719 2010-10-12 09:25:37Z manolo $"
  274. //