You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
10KB

  1. //
  2. // "$Id: Fl_PostScript.H 8699 2011-05-20 16:39:06Z 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; 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. /**
  35. \brief PostScript graphical backend.
  36. *
  37. PostScript text uses vectorial fonts for the latin alphabet (exactly: all unicode
  38. characters between U+0020 and U+017F, that is, ASCII, Latin-1 Supplement and Latin Extended-A charts)
  39. plus a few other characters:
  40. <table>
  41. <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>
  42. <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>
  43. <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>
  44. <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>
  45. <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>
  46. <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>
  47. <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>
  48. <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>
  49. <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>
  50. <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>
  51. <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>
  52. <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>
  53. <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>
  54. <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>
  55. </table>
  56. <br> All other unicode characters are output as a bitmap.
  57. <br> FLTK standard fonts are output using PostScript standard fonts: Helvetica, Courier,
  58. Times (and their bold, oblique, italic variants).
  59. */
  60. class FL_EXPORT Fl_PostScript_Graphics_Driver : public Fl_Graphics_Driver {
  61. public:
  62. static const char *class_id;
  63. const char *class_name() {return class_id;};
  64. Fl_PostScript_Graphics_Driver();
  65. #ifndef FL_DOXYGEN
  66. enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS};
  67. class Clip {
  68. public:
  69. int x, y, w, h;
  70. Clip *prev;
  71. };
  72. Clip * clip_;
  73. int lang_level_;
  74. int gap_;
  75. int pages_;
  76. double width_;
  77. double height_;
  78. int shape_;
  79. int linewidth_;// need for clipping, lang level 1-2
  80. int linestyle_;//
  81. int interpolate_; //interpolation of images
  82. unsigned char cr_,cg_,cb_;
  83. char linedash_[256];//should be enough
  84. void concat(); // transform ror scalable dradings...
  85. void reconcat(); //invert
  86. void recover(); //recovers the state after grestore (such as line styles...)
  87. void reset();
  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. float scale_x;
  97. float scale_y;
  98. float angle;
  99. int left_margin;
  100. int top_margin;
  101. FILE *output;
  102. double pw_, ph_;
  103. uchar bg_r, bg_g, bg_b;
  104. int start_postscript (int pagecount, enum Fl_Paged_Device::Page_Format format, enum Fl_Paged_Device::Page_Layout layout);
  105. /* int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
  106. */
  107. void transformed_draw(const char* s, int n, double x, double y); //precise text placing
  108. void transformed_draw(const char* s, double x, double y);
  109. int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
  110. enum Fl_Paged_Device::Page_Format page_format_;
  111. char *ps_filename_;
  112. void page_policy(int p);
  113. int page_policy(){return page_policy_;};
  114. void close_command( int (*cmd)(FILE *)){close_cmd_=cmd;};
  115. FILE * file() {return output;};
  116. //void orientation (int o);
  117. //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int pages = 0); // ps (also multi-page) constructor
  118. //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int x, int y, int w, int h); //eps constructor
  119. void interpolate(int i){interpolate_=i;};
  120. int interpolate(){return interpolate_;}
  121. void page(double pw, double ph, int media = 0);
  122. void page(int format);
  123. #endif // FL_DOXYGEN
  124. // implementation of drawing methods
  125. void color(Fl_Color c);
  126. void color(uchar r, uchar g, uchar b);
  127. void push_clip(int x, int y, int w, int h);
  128. int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
  129. int not_clipped(int x, int y, int w, int h);
  130. void push_no_clip();
  131. void pop_clip();
  132. void line_style(int style, int width=0, char* dashes=0);
  133. void rect(int x, int y, int w, int h);
  134. void rectf(int x, int y, int w, int h);
  135. void xyline(int x, int y, int x1);
  136. void xyline(int x, int y, int x1, int y2);
  137. void xyline(int x, int y, int x1, int y2, int x3);
  138. void yxline(int x, int y, int y1);
  139. void yxline(int x, int y, int y1, int x2);
  140. void yxline(int x, int y, int y1, int x2, int y3);
  141. void line(int x1, int y1, int x2, int y2);
  142. void line(int x1, int y1, int x2, int y2, int x3, int y3);
  143. void loop(int x0, int y0, int x1, int y1, int x2, int y2);
  144. void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  145. void polygon(int x0, int y0, int x1, int y1, int x2, int y2);
  146. void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  147. void point(int x, int y);
  148. void begin_points();
  149. void begin_line();
  150. void begin_loop();
  151. void begin_polygon();
  152. void vertex(double x, double y);
  153. void curve(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3);
  154. void circle(double x, double y, double r);
  155. void arc(double x, double y, double r, double start, double a);
  156. void arc(int x, int y, int w, int h, double a1, double a2);
  157. void pie(int x, int y, int w, int h, double a1, double a2);
  158. void end_points();
  159. void end_line();
  160. void end_loop();
  161. void end_polygon();
  162. void begin_complex_polygon(){begin_polygon();};
  163. void gap(){gap_=1;};
  164. void end_complex_polygon(){end_polygon();};
  165. void transformed_vertex(double x, double y);
  166. void draw_image(const uchar* d, int x,int y,int w,int h, int delta=3, int ldelta=0);
  167. void draw_image_mono(const uchar* d, int x,int y,int w,int h, int delta=1, int ld=0);
  168. void draw_image(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=3);
  169. void draw_image_mono(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=1);
  170. void draw(const char* s, int n, int x, int y) {transformed_draw(s,n,x,y); };
  171. #ifdef __APPLE__
  172. void draw(const char* s, int n, float x, float y) {transformed_draw(s,n,x,y); };
  173. #endif
  174. void draw(int angle, const char *str, int n, int x, int y);
  175. void rtl_draw(const char* s, int n, int x, int y);
  176. void font(int face, int size);
  177. double width(const char *, int);
  178. void text_extents(const char *c, int n, int &dx, int &dy, int &w, int &h);
  179. int height();
  180. int descent();
  181. void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
  182. void draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
  183. void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
  184. ~Fl_PostScript_Graphics_Driver();
  185. };
  186. /**
  187. \brief To send graphical output to a PostScript file.
  188. */
  189. class FL_EXPORT Fl_PostScript_File_Device : public Fl_Paged_Device {
  190. #ifdef __APPLE__
  191. Fl_CGContextRef gc;
  192. #endif
  193. protected:
  194. Fl_PostScript_Graphics_Driver *driver();
  195. public:
  196. static const char *class_id;
  197. const char *class_name() {return class_id;};
  198. Fl_PostScript_File_Device();
  199. ~Fl_PostScript_File_Device();
  200. int start_job(int pagecount, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
  201. enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT);
  202. int start_job(FILE *ps_output, int pagecount, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
  203. enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT);
  204. int start_page (void);
  205. int printable_rect(int *w, int *h);
  206. void margins(int *left, int *top, int *right, int *bottom);
  207. void origin(int *x, int *y);
  208. void origin(int x, int y);
  209. void scale (float scale_x, float scale_y = 0.);
  210. void rotate(float angle);
  211. void translate(int x, int y);
  212. void untranslate(void);
  213. int end_page (void);
  214. void end_job(void);
  215. #ifdef __APPLE__
  216. void set_current() { fl_gc = gc; Fl_Paged_Device::set_current(); }
  217. #endif
  218. static const char *file_chooser_title;
  219. };
  220. #endif // Fl_PostScript_H
  221. //
  222. // End of "$Id: Fl_PostScript.H 8699 2011-05-20 16:39:06Z manolo $"
  223. //