Fl_Printer.H 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // "$Id: Fl_Printer.H 9035 2011-09-14 15:17:32Z manolo $"
  3. //
  4. // Printing support 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_Printer.H
  19. \brief declaration of classes Fl_Printer, Fl_System_Printer and Fl_PostScript_Printer.
  20. */
  21. #ifndef Fl_Printer_H
  22. #define Fl_Printer_H
  23. #include <FL/x.H>
  24. #include <FL/Fl_Paged_Device.H>
  25. #include <FL/fl_draw.H>
  26. #include <FL/Fl_Pixmap.H>
  27. #include <FL/Fl_RGB_Image.H>
  28. #include <FL/Fl_Bitmap.H>
  29. #include <stdio.h>
  30. #if !(defined(__APPLE__) || defined(WIN32))
  31. #include <FL/Fl_PostScript.H>
  32. #elif defined(WIN32)
  33. #include <commdlg.h>
  34. #endif
  35. #if defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN)
  36. /**
  37. Print support under MSWindows and Mac OS.
  38. Class Fl_System_Printer is implemented only on the MSWindows and Mac OS platforms.
  39. It has no public constructor.
  40. Use Fl_Printer instead that is cross-platform and has the same API.
  41. */
  42. class Fl_System_Printer : public Fl_Paged_Device {
  43. friend class Fl_Printer;
  44. private:
  45. /** \brief the printer's graphics context, if there's one, NULL otherwise */
  46. void *gc;
  47. #ifdef __APPLE__
  48. float scale_x;
  49. float scale_y;
  50. float angle; // rotation angle in radians
  51. PMPrintSession printSession;
  52. PMPageFormat pageFormat;
  53. PMPrintSettings printSettings;
  54. #elif defined(WIN32)
  55. int abortPrint;
  56. PRINTDLG pd;
  57. HDC hPr;
  58. int prerr;
  59. int left_margin;
  60. int top_margin;
  61. void absolute_printable_rect(int *x, int *y, int *w, int *h);
  62. #endif
  63. protected:
  64. /** \brief The constructor */
  65. Fl_System_Printer(void);
  66. public:
  67. void set_current();
  68. static const char *class_id;
  69. const char *class_name() {return class_id;};
  70. int start_job(int pagecount, int *frompage = NULL, int *topage = NULL);
  71. int start_page (void);
  72. int printable_rect(int *w, int *h);
  73. void margins(int *left, int *top, int *right, int *bottom);
  74. void origin(int *x, int *y);
  75. void origin(int x, int y);
  76. void scale (float scale_x, float scale_y = 0.);
  77. void rotate(float angle);
  78. void translate(int x, int y);
  79. void untranslate(void);
  80. int end_page (void);
  81. void end_job (void);
  82. /** \brief The destructor */
  83. ~Fl_System_Printer(void);
  84. int xdpi();
  85. int ydpi();
  86. }; // class Fl_System_Printer
  87. #endif
  88. #if !(defined(__APPLE__) || defined(WIN32) )
  89. /**
  90. Print support under Unix/Linux.
  91. Class Fl_PostScript_Printer is implemented only on the Unix/Linux platform.
  92. It has no public constructor.
  93. Use Fl_Printer instead that is cross-platform and has the same API.
  94. */
  95. class Fl_PostScript_Printer : public Fl_PostScript_File_Device {
  96. friend class Fl_Printer;
  97. protected:
  98. /** The constructor */
  99. Fl_PostScript_Printer(void) {};
  100. public:
  101. static const char *class_id;
  102. const char *class_name() {return class_id;};
  103. int start_job(int pages, int *firstpage = NULL, int *lastpage = NULL);
  104. int xdpi() {return 72;};
  105. int ydpi() {return 72;};
  106. };
  107. #endif
  108. /**
  109. * \brief OS-independent print support.
  110. *
  111. Fl_Printer allows to use all FLTK drawing, color, text, and clip functions, and to have them operate
  112. on printed page(s). There are two main, non exclusive, ways to use it.
  113. <ul><li>Print any widget (standard, custom, Fl_Window, Fl_Gl_Window) as it appears
  114. on screen, with optional translation, scaling and rotation. This is done by calling print_widget(),
  115. print_window() or print_window_part().
  116. <li>Use a series of FLTK graphics commands (e.g., font, text, lines, colors, clip, image) to
  117. compose a page appropriately shaped for printing.
  118. </ul>
  119. In both cases, begin by start_job(), start_page(), printable_rect() and origin() calls
  120. and finish by end_page() and end_job() calls.
  121. <p><b>Platform specifics</b>
  122. <ul>
  123. <li>Unix/Linux platforms:
  124. Class Fl_RGB_Image prints but loses its transparency if it has one.
  125. See class Fl_PostScript_Graphics_Driver for a description of how UTF-8 strings appear in print.
  126. Use the static public attributes of this class to set the print dialog to other languages
  127. than English. For example, the "Printer:" dialog item Fl_Printer::dialog_printer can be set to French with:
  128. \code
  129. Fl_Printer::dialog_printer = "Imprimante:";
  130. \endcode
  131. before creation of the Fl_Printer object.
  132. Use Fl_PostScript_File_Device::file_chooser_title to customize the title of the file chooser dialog that opens
  133. when using the "Print To File" option of the print dialog.
  134. <li>MSWindows platform: Transparent Fl_RGB_Image 's don't print with exact transparency on most printers.
  135. Fl_RGB_Image 's don't rotate() well.
  136. A workaround is to use the print_window_part() call.
  137. <li>Mac OS X platform: all graphics requests print as on display.
  138. </ul>
  139. */
  140. class FL_EXPORT Fl_Printer : public Fl_Paged_Device {
  141. public:
  142. static const char *class_id;
  143. const char *class_name() {return class_id;};
  144. /** \brief The constructor */
  145. Fl_Printer(void);
  146. int start_job(int pagecount, int *frompage = NULL, int *topage = NULL);
  147. int start_page(void);
  148. int printable_rect(int *w, int *h);
  149. void margins(int *left, int *top, int *right, int *bottom);
  150. void origin(int *x, int *y);
  151. void origin(int x, int y);
  152. void scale(float scale_x, float scale_y = 0.);
  153. void rotate(float angle);
  154. void translate(int x, int y);
  155. void untranslate(void);
  156. int end_page (void);
  157. void end_job (void);
  158. void print_widget(Fl_Widget* widget, int delta_x=0, int delta_y=0);
  159. void print_window_part(Fl_Window *win, int x, int y, int w, int h, int delta_x=0, int delta_y=0);
  160. void set_current(void);
  161. Fl_Graphics_Driver* driver(void);
  162. /** \brief The destructor */
  163. ~Fl_Printer(void);
  164. int xdpi();
  165. int ydpi();
  166. /** \name These attributes are effective under the Xlib platform only.
  167. \{
  168. */
  169. static const char *dialog_title;
  170. static const char *dialog_printer;
  171. static const char *dialog_range;
  172. static const char *dialog_copies;
  173. static const char *dialog_all;
  174. static const char *dialog_pages;
  175. static const char *dialog_from;
  176. static const char *dialog_to;
  177. static const char *dialog_properties;
  178. static const char *dialog_copyNo;
  179. static const char *dialog_print_button;
  180. static const char *dialog_cancel_button;
  181. static const char *dialog_print_to_file;
  182. static const char *property_title;
  183. static const char *property_pagesize;
  184. static const char *property_mode;
  185. static const char *property_use;
  186. static const char *property_save;
  187. static const char *property_cancel;
  188. /** \} */
  189. private:
  190. #if defined(WIN32) || defined(__APPLE__)
  191. Fl_System_Printer *printer;
  192. #else
  193. Fl_PostScript_Printer *printer;
  194. #endif
  195. };
  196. #endif // Fl_Printer_H
  197. //
  198. // End of "$Id: Fl_Printer.H 9035 2011-09-14 15:17:32Z manolo $"
  199. //