Fl_Pdf.H 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. //
  2. // "$Id: Fl_Pdf.H 7622 2010-05-27 17:50:51Z manolo $"
  3. //
  4. // Support for graphics output to PDF 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_Pdf.H
  28. \brief declaration of classes Fl_Pdf_Graphics_Driver, Fl_Pdf_File_Device.
  29. */
  30. #ifndef Fl_Pdf_H
  31. #define Fl_Pdf_H
  32. #include <FL/Fl_Paged_Device.H>
  33. #include <FL/fl_draw.H>
  34. #include "hpdf.h"
  35. /**
  36. \brief PDF graphical backend.
  37. *
  38. PDF text output is presently implemented only for the latin character set.
  39. FLTK's standard fonts are output using PDF's standard fonts: Helvetica, Courier,
  40. Times (and their bold, oblique, italic variants), Symbol, ZapfDingbats.
  41. */
  42. class Fl_Pdf_Graphics_Driver : public Fl_Graphics_Driver {
  43. #ifndef FL_DOXYGEN
  44. public:
  45. enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS};
  46. typedef struct page_format {
  47. int width;
  48. int height;
  49. const char *name;
  50. } page_format;
  51. class Clip {
  52. public:
  53. int x, y, w, h;
  54. Clip *prev;
  55. };
  56. Clip * clip_;
  57. int lang_level_;
  58. HPDF_Font pdf_font_;
  59. int gap_;
  60. int pages_;
  61. double width_;
  62. double height_;
  63. int shape_;
  64. int linewidth_;// need for clipping, lang level 1-2
  65. int linestyle_;//
  66. int interpolate_; //interpolation of images
  67. unsigned char cr_,cg_,cb_;
  68. char linedash_[256];//should be enough
  69. void concat(); // transform ror scalable dradings...
  70. void reconcat(); //invert
  71. void recover(); //recovers the state after grestore (such as line styles...)
  72. void reset();
  73. uchar * mask;
  74. int mx; // width of mask;
  75. int my; // mask lines
  76. //Fl_Color bg_;
  77. int (*close_cmd_)(FILE *);
  78. int page_policy_;
  79. int nPages;
  80. int orientation_;
  81. float scale_x;
  82. float scale_y;
  83. float angle;
  84. int left_margin;
  85. int top_margin;
  86. FILE *output;
  87. double pw_, ph_;
  88. uchar bg_r, bg_g, bg_b;
  89. HPDF_Page pdf_page;
  90. HPDF_Doc pdf;
  91. char *text_buffer;
  92. int text_buffer_size;
  93. int start_PDF (int pagecount, enum Fl_Paged_Device::Page_Format format,
  94. enum Fl_Paged_Device::Page_Layout layout);
  95. /* int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
  96. */
  97. void draw(const char* s, int n, int x, int y) {transformed_draw(s,n,x,y); };
  98. void draw(int angle, const char *str, int n, int x, int y);
  99. void transformed_draw(const char* s, int n, double x, double y); //precise text placing
  100. void transformed_draw(const char* s, double x, double y);
  101. void rtl_draw(const char* str, int n, int x, int y);
  102. int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
  103. 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);
  104. 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);
  105. 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);
  106. 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);
  107. enum Fl_Paged_Device::Page_Format page_format_;
  108. char *pdf_filename_;
  109. // implementation of drawing methods
  110. void color(Fl_Color c);
  111. //void bg_color(Fl_Color bg);
  112. void color(uchar r, uchar g, uchar b);
  113. void push_clip(int x, int y, int w, int h);
  114. int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
  115. int not_clipped(int x, int y, int w, int h);
  116. void push_no_clip();
  117. void pop_clip();
  118. void line_style(int style, int width=0, char* dashes=0);
  119. void rect(int x, int y, int w, int h);
  120. void rectf(int x, int y, int w, int h);
  121. void xyline(int x, int y, int x1);
  122. void xyline(int x, int y, int x1, int y2);
  123. void xyline(int x, int y, int x1, int y2, int x3);
  124. void yxline(int x, int y, int y1);
  125. void yxline(int x, int y, int y1, int x2);
  126. void yxline(int x, int y, int y1, int x2, int y3);
  127. void line(int x1, int y1, int x2, int y2);
  128. void line(int x1, int y1, int x2, int y2, int x3, int y3);
  129. void loop(int x0, int y0, int x1, int y1, int x2, int y2);
  130. void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  131. void polygon(int x0, int y0, int x1, int y1, int x2, int y2);
  132. void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  133. void point(int x, int y);
  134. void begin_points();
  135. void begin_line();
  136. void begin_loop();
  137. void begin_polygon();
  138. void vertex(double x, double y);
  139. void curve(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3);
  140. void circle(double x, double y, double r);
  141. void arc(double x, double y, double r, double start, double a);
  142. void arc(int x, int y, int w, int h, double a1, double a2);
  143. void pie(int x, int y, int w, int h, double a1, double a2);
  144. void end_points();
  145. void end_line();
  146. void end_loop();
  147. void end_polygon();
  148. void begin_complex_polygon(){begin_polygon();};
  149. void gap(){gap_=1;};
  150. void end_complex_polygon(){end_polygon();};
  151. void transformed_vertex(double x, double y);
  152. void fl_rotate(double d) {Fl_Graphics_Driver::rotate(-d);};
  153. void font(int face, int size);
  154. double width(const char* s, int n);
  155. int descent();
  156. int height();
  157. 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);};
  158. 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);};
  159. 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);};
  160. 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);};
  161. void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
  162. void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
  163. void draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
  164. public:
  165. static const char *class_id;
  166. const char *class_name() {return class_id;};
  167. void page_policy(int p);
  168. int page_policy(){return page_policy_;};
  169. void close_command( int (*cmd)(FILE *)){close_cmd_=cmd;};
  170. FILE * file() {return output;};
  171. //void orientation (int o);
  172. //Fl_Pdf_Graphics_Driver(FILE *o, int lang_level, int pages = 0); // ps (also multi-page) constructor
  173. //Fl_Pdf_Graphics_Driver(FILE *o, int lang_level, int x, int y, int w, int h); //eps constructor
  174. void interpolate(int i){interpolate_=i;};
  175. int interpolate(){return interpolate_;}
  176. void page(double pw, double ph, int media = 0);
  177. void page(int format);
  178. void page();
  179. void place(double x, double y, double tx, double ty, double scale = 1);
  180. #endif // FL_DOXYGEN
  181. Fl_Pdf_Graphics_Driver();
  182. ~Fl_Pdf_Graphics_Driver();
  183. int xdpi() {return 72;};
  184. int ydpi() {return 72;};
  185. };
  186. /**
  187. \brief To send graphical output to a PDF file.
  188. */
  189. class Fl_Pdf_File_Device : public Fl_Paged_Device {
  190. #ifdef __APPLE__
  191. CGContextRef gc;
  192. #endif
  193. protected:
  194. Fl_Pdf_Graphics_Driver *driver();
  195. public:
  196. static const char *class_id;
  197. const char *class_name() {return class_id;};
  198. Fl_Pdf_File_Device();
  199. ~Fl_Pdf_File_Device();
  200. void compress(int abool);
  201. HPDF_Doc pdf_doc();
  202. int start_job(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_job(const char *pdf_filename, int pagecount,
  205. enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
  206. enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT);
  207. int start_page (void);
  208. int printable_rect(int *w, int *h);
  209. void margins(int *left, int *top, int *right, int *bottom);
  210. void origin(int x, int y);
  211. void scale (float scale_x, float scale_y);
  212. void rotate(float angle);
  213. void translate(int x, int y);
  214. void untranslate(void);
  215. int end_page (void);
  216. void end_job(void);
  217. #ifdef __APPLE__
  218. void set_current() { fl_gc = gc; Fl_Paged_Device::set_current(); }
  219. #endif
  220. static const char *file_chooser_title;
  221. };
  222. #endif // Fl_Pdf_H
  223. //
  224. // End of "$Id: Fl_Pdf.H 7622 2010-05-27 17:50:51Z manolo $"
  225. //