Fl_PostScript.H 10.0 KB

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