Fl_Printer.H 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. //
  2. // "$Id: Fl_Printer.H 7894 2010-11-26 10:22:40Z manolo $"
  3. //
  4. // Printing support 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_Printer.H
  28. \brief declaration of classes Fl_System_Printer, Fl_PostScript_Printer, Fl_Printer, Fl_Device_Plugin.
  29. */
  30. #ifndef Fl_Printer_H
  31. #define Fl_Printer_H
  32. #include <FL/Fl_Paged_Device.H>
  33. #include <FL/fl_draw.H>
  34. #include <FL/Fl_Pixmap.H>
  35. #include <FL/Fl_RGB_Image.H>
  36. #include <FL/Fl_Bitmap.H>
  37. #include <stdio.h>
  38. #if !(defined(__APPLE__) || defined(WIN32))
  39. #include <FL/Fl_PostScript.H>
  40. #endif
  41. #if defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN)
  42. /**
  43. \brief Print support under MSWindows and Mac OS X.
  44. *
  45. Class Fl_System_Printer is implemented only on the MSWindows and Mac OS X platforms.
  46. Use Fl_Printer instead that is cross-platform and has the same API.
  47. Fl_Printer is typedef'ed to Fl_System_Printer under MSWindows and Mac OS X.
  48. */
  49. class Fl_System_Printer : public Fl_Paged_Device {
  50. private:
  51. /** \brief the printer's graphics context, if there's one, NULL otherwise */
  52. void *gc;
  53. void set_current(void);
  54. #ifdef __APPLE__
  55. float scale_x;
  56. float scale_y;
  57. float angle; // rotation angle in radians
  58. PMPrintSession printSession;
  59. PMPageFormat pageFormat;
  60. PMPrintSettings printSettings;
  61. #elif defined(WIN32)
  62. int abortPrint;
  63. PRINTDLG pd;
  64. HDC hPr;
  65. int prerr;
  66. int left_margin;
  67. int top_margin;
  68. void absolute_printable_rect(int *x, int *y, int *w, int *h);
  69. #endif
  70. public:
  71. static const char *device_type;
  72. /**
  73. @brief The constructor.
  74. */
  75. Fl_System_Printer(void);
  76. int start_job(int pagecount, int *frompage = NULL, int *topage = NULL);
  77. int start_page (void);
  78. int printable_rect(int *w, int *h);
  79. void margins(int *left, int *top, int *right, int *bottom);
  80. void origin(int x, int y);
  81. void scale (float scale_x, float scale_y);
  82. void rotate(float angle);
  83. void translate(int x, int y);
  84. void untranslate(void);
  85. int end_page (void);
  86. void end_job (void);
  87. /**
  88. @brief The destructor.
  89. */
  90. ~Fl_System_Printer(void);
  91. #ifndef FL_DOXYGEN
  92. public:
  93. static const char *dialog_title;
  94. static const char *dialog_printer;
  95. static const char *dialog_range;
  96. static const char *dialog_copies;
  97. static const char *dialog_all;
  98. static const char *dialog_pages;
  99. static const char *dialog_from;
  100. static const char *dialog_to;
  101. static const char *dialog_properties;
  102. static const char *dialog_copyNo;
  103. static const char *dialog_print_button;
  104. static const char *dialog_cancel_button;
  105. static const char *dialog_print_to_file;
  106. static const char *property_title;
  107. static const char *property_pagesize;
  108. static const char *property_mode;
  109. static const char *property_use;
  110. static const char *property_save;
  111. static const char *property_cancel;
  112. #endif // FL_DOXYGEN
  113. }; // class Fl_System_Printer
  114. typedef Fl_System_Printer Fl_Printer;
  115. #endif
  116. #if !(defined(__APPLE__) || defined(WIN32))
  117. /**
  118. \brief Print support under Unix/Linux.
  119. *
  120. Class Fl_PostScript_Printer is implemented only on the Unix/Linux platform.
  121. Use Fl_Printer instead that is cross-platform and has the same API.
  122. Fl_Printer is typedef'ed to Fl_PostScript_Printer under Unix/Linux.
  123. */
  124. class Fl_PostScript_Printer : public Fl_PostScript_File_Device {
  125. public:
  126. static const char *device_type;
  127. int start_job(int pages, int *firstpage = NULL, int *lastpage = NULL);
  128. #ifndef FL_DOXYGEN
  129. static const char *dialog_title;
  130. static const char *dialog_printer;
  131. static const char *dialog_range;
  132. static const char *dialog_copies;
  133. static const char *dialog_all;
  134. static const char *dialog_pages;
  135. static const char *dialog_from;
  136. static const char *dialog_to;
  137. static const char *dialog_properties;
  138. static const char *dialog_copyNo;
  139. static const char *dialog_print_button;
  140. static const char *dialog_cancel_button;
  141. static const char *dialog_print_to_file;
  142. static const char *property_title;
  143. static const char *property_pagesize;
  144. static const char *property_mode;
  145. static const char *property_use;
  146. static const char *property_save;
  147. static const char *property_cancel;
  148. #endif // FL_DOXYGEN
  149. };
  150. typedef Fl_PostScript_Printer Fl_Printer;
  151. #endif
  152. /**
  153. * @brief OS-independent print support.
  154. *
  155. Fl_Printer allows to use all FLTK drawing, color, text, and clip functions, and to have them operate
  156. on printed page(s). There are two main, non exclusive, ways to use it.
  157. <ul><li>Print any widget (standard, custom, Fl_Window, Fl_Gl_Window) as it appears
  158. on screen, with optional translation, scaling and rotation. This is done by calling print_widget()
  159. or print_window_part().
  160. <li>Use a series of FLTK graphics commands (e.g., font, text, lines, colors, clip, image) to
  161. compose a page appropriately shaped for printing.
  162. </ul>
  163. In both cases, begin by start_job(), start_page(), printable_rect() and origin() calls
  164. and finish by end_page() and end_job() calls.
  165. <p><b>Platform specifics</b>
  166. <br>Fl_Printer is typedef'ed to Fl_PostScript_Printer under Unix/Linux
  167. and to Fl_System_Printer otherwise. Both classes have the same API.
  168. <ul>
  169. <li>Unix/Linux platforms:
  170. Class Fl_RGB_Image prints but loses its transparency if it has one.
  171. See class Fl_PostScript_Graphics_Driver for a description of how UTF-8 strings appear in print.
  172. Use the static public attributes of this class to set the print dialog to other languages
  173. than English. For example, the "Printer:" dialog item Fl_Printer::dialog_printer can be set to French with:
  174. \code
  175. Fl_Printer::dialog_printer = "Imprimante:";
  176. \endcode
  177. before creation of the Fl_Printer object.
  178. Use Fl_PostScript_File_Device::file_chooser_title to customize the title of the file chooser dialog that opens
  179. when using the "Print To File" option of the print dialog.
  180. <li>MSWindows platform: Transparent Fl_RGB_Image 's don't print with exact transparency on most printers.
  181. Fl_RGB_Image 's don't rotate() well.
  182. A workaround is to use the print_window_part() call.
  183. <li>Mac OS X platform: all graphics requests print as on display.
  184. </ul>
  185. */
  186. #ifdef FL_DOXYGEN
  187. // this class is NOT compiled. It's here for Doxygen documentation purpose only
  188. class Fl_Printer : public Fl_System_Printer, Fl_PostScript_Printer {
  189. public:
  190. static const char *device_type;
  191. /** @brief The constructor */
  192. Fl_Printer(void);
  193. int start_job(int pagecount, int *frompage = NULL, int *topage = NULL);
  194. int start_page(void);
  195. int printable_rect(int *w, int *h);
  196. void margins(int *left, int *top, int *right, int *bottom);
  197. void origin(int x, int y);
  198. void scale(float scale_x, float scale_y);
  199. void rotate(float angle);
  200. void translate(int x, int y);
  201. void untranslate(void);
  202. int end_page (void);
  203. void end_job (void);
  204. /** @brief The destructor */
  205. ~Fl_Printer(void);
  206. /** \name These attributes are effective under the Xlib platform only.
  207. \{
  208. */
  209. static const char *dialog_title;
  210. static const char *dialog_printer;
  211. static const char *dialog_range;
  212. static const char *dialog_copies;
  213. static const char *dialog_all;
  214. static const char *dialog_pages;
  215. static const char *dialog_from;
  216. static const char *dialog_to;
  217. static const char *dialog_properties;
  218. static const char *dialog_copyNo;
  219. static const char *dialog_print_button;
  220. static const char *dialog_cancel_button;
  221. static const char *dialog_print_to_file;
  222. static const char *property_title;
  223. static const char *property_pagesize;
  224. static const char *property_mode;
  225. static const char *property_use;
  226. static const char *property_save;
  227. static const char *property_cancel;
  228. /** \} */
  229. };
  230. #endif
  231. /**
  232. This plugin socket allows the integration of new device drivers for special
  233. window or screen types. It is currently used to provide an automated printing
  234. service for OpenGL windows, if linked with fltk_gl.
  235. */
  236. class Fl_Device_Plugin : public Fl_Plugin {
  237. public:
  238. /** \brief The constructor */
  239. Fl_Device_Plugin(const char *name)
  240. : Fl_Plugin(klass(), name) { }
  241. /** \brief Returns the class name */
  242. virtual const char *klass() { return "fltk:device"; }
  243. /** \brief Returns the plugin name */
  244. virtual const char *name() = 0;
  245. /** \brief Prints a widget
  246. \param w the widget
  247. \param x,y offsets where to print relatively to coordinates origin
  248. \param height height of the current drawing area
  249. */
  250. virtual int print(Fl_Widget* w, int x, int y, int height) { return 0; }
  251. };
  252. #endif // Fl_Printer_H
  253. //
  254. // End of "$Id: Fl_Printer.H 7894 2010-11-26 10:22:40Z manolo $"
  255. //