You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
7.2KB

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