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