Fl_PostScript.H 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // "$Id: Fl_PostScript.H 9993 2013-09-25 08:55:01Z 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. /** Signature of Fl_PostScript::close_command() functions passed as parameters. */
  52. extern "C" {
  53. typedef int (Fl_PostScript_Close_Command)(FILE *);
  54. }
  55. class FL_EXPORT Fl_PostScript_Graphics_Driver : public Fl_Graphics_Driver {
  56. public:
  57. static const char *class_id;
  58. const char *class_name() {return class_id;};
  59. Fl_PostScript_Graphics_Driver();
  60. #ifndef FL_DOXYGEN
  61. enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS};
  62. class Clip {
  63. public:
  64. int x, y, w, h;
  65. Clip *prev;
  66. };
  67. Clip * clip_;
  68. int lang_level_;
  69. int gap_;
  70. int pages_;
  71. double width_;
  72. double height_;
  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. uchar * mask;
  84. int mx; // width of mask;
  85. int my; // mask lines
  86. //Fl_Color bg_;
  87. Fl_PostScript_Close_Command* close_cmd_;
  88. int page_policy_;
  89. int nPages;
  90. int orientation_;
  91. float scale_x;
  92. float scale_y;
  93. float angle;
  94. int left_margin;
  95. int top_margin;
  96. FILE *output;
  97. double pw_, ph_;
  98. uchar bg_r, bg_g, bg_b;
  99. int start_postscript (int pagecount, enum Fl_Paged_Device::Page_Format format, enum Fl_Paged_Device::Page_Layout layout);
  100. /* int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
  101. */
  102. void transformed_draw(const char* s, int n, double x, double y); //precise text placing
  103. void transformed_draw(const char* s, double x, double y);
  104. int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
  105. enum Fl_Paged_Device::Page_Format page_format_;
  106. char *ps_filename_;
  107. void page_policy(int p);
  108. int page_policy(){return page_policy_;};
  109. void close_command(Fl_PostScript_Close_Command* cmd){close_cmd_=cmd;};
  110. FILE * file() {return output;};
  111. //void orientation (int o);
  112. //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int pages = 0); // ps (also multi-page) constructor
  113. //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int x, int y, int w, int h); //eps constructor
  114. void interpolate(int i){interpolate_=i;};
  115. int interpolate(){return interpolate_;}
  116. void page(double pw, double ph, int media = 0);
  117. void page(int format);
  118. #endif // FL_DOXYGEN
  119. // implementation of drawing methods
  120. void color(Fl_Color c);
  121. void color(uchar r, uchar g, uchar b);
  122. void push_clip(int x, int y, int w, int h);
  123. int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
  124. int not_clipped(int x, int y, int w, int h);
  125. void push_no_clip();
  126. void pop_clip();
  127. void line_style(int style, int width=0, char* dashes=0);
  128. void rect(int x, int y, int w, int h);
  129. void rectf(int x, int y, int w, int h);
  130. void xyline(int x, int y, int x1);
  131. void xyline(int x, int y, int x1, int y2);
  132. void xyline(int x, int y, int x1, int y2, int x3);
  133. void yxline(int x, int y, int y1);
  134. void yxline(int x, int y, int y1, int x2);
  135. void yxline(int x, int y, int y1, int x2, int y3);
  136. void line(int x1, int y1, int x2, int y2);
  137. void line(int x1, int y1, int x2, int y2, int x3, int y3);
  138. void loop(int x0, int y0, int x1, int y1, int x2, int y2);
  139. void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  140. void polygon(int x0, int y0, int x1, int y1, int x2, int y2);
  141. void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  142. void point(int x, int y);
  143. void begin_points();
  144. void begin_line();
  145. void begin_loop();
  146. void begin_polygon();
  147. void vertex(double x, double y);
  148. void curve(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3);
  149. void circle(double x, double y, double r);
  150. void arc(double x, double y, double r, double start, double a);
  151. void arc(int x, int y, int w, int h, double a1, double a2);
  152. void pie(int x, int y, int w, int h, double a1, double a2);
  153. void end_points();
  154. void end_line();
  155. void end_loop();
  156. void end_polygon();
  157. void begin_complex_polygon(){begin_polygon();};
  158. void gap(){gap_=1;};
  159. void end_complex_polygon(){end_polygon();};
  160. void transformed_vertex(double x, double y);
  161. void draw_image(const uchar* d, int x,int y,int w,int h, int delta=3, int ldelta=0);
  162. void draw_image_mono(const uchar* d, int x,int y,int w,int h, int delta=1, int ld=0);
  163. void draw_image(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=3);
  164. void draw_image_mono(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=1);
  165. void draw(const char* s, int nBytes, int x, int y) {transformed_draw(s,nBytes,x,y); };
  166. #ifdef __APPLE__
  167. void draw(const char* s, int nBytes, float x, float y) {transformed_draw(s,nBytes,x,y); };
  168. #endif
  169. void draw(int angle, const char *str, int n, int x, int y);
  170. void rtl_draw(const char* s, int n, int x, int y);
  171. void font(int face, int size);
  172. double width(const char *, int);
  173. double width(unsigned int u);
  174. void text_extents(const char *c, int n, int &dx, int &dy, int &w, int &h);
  175. int height();
  176. int descent();
  177. void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
  178. void draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
  179. void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
  180. ~Fl_PostScript_Graphics_Driver();
  181. };
  182. /**
  183. \brief To send graphical output to a PostScript file.
  184. */
  185. class FL_EXPORT Fl_PostScript_File_Device : public Fl_Paged_Device {
  186. #ifdef __APPLE__
  187. CGContextRef gc;
  188. #endif
  189. protected:
  190. Fl_PostScript_Graphics_Driver *driver();
  191. public:
  192. static const char *class_id;
  193. const char *class_name() {return class_id;};
  194. Fl_PostScript_File_Device();
  195. ~Fl_PostScript_File_Device();
  196. int start_job(int pagecount, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
  197. enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT);
  198. int start_job(FILE *ps_output, int pagecount, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
  199. enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT);
  200. int start_page (void);
  201. int printable_rect(int *w, int *h);
  202. void margins(int *left, int *top, int *right, int *bottom);
  203. void origin(int *x, int *y);
  204. void origin(int x, int y);
  205. void scale (float scale_x, float scale_y = 0.);
  206. void rotate(float angle);
  207. void translate(int x, int y);
  208. void untranslate(void);
  209. int end_page (void);
  210. void end_job(void);
  211. #ifdef __APPLE__
  212. void set_current() { fl_gc = gc; Fl_Paged_Device::set_current(); }
  213. #endif
  214. static const char *file_chooser_title;
  215. };
  216. #endif // Fl_PostScript_H
  217. //
  218. // End of "$Id: Fl_PostScript.H 9993 2013-09-25 08:55:01Z manolo $"
  219. //