diff --git a/FL/Fl_Printer.H b/FL/Fl_Printer.H index cdc4fd319..121f28a99 100644 --- a/FL/Fl_Printer.H +++ b/FL/Fl_Printer.H @@ -40,88 +40,6 @@ #include #endif -#if defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN) // PORTME: Fl_Surface_Driver ? - platform printer driver -/** - Print support under MSWindows and Mac OS. - - Class Fl_System_Printer is implemented only on the MSWindows and Mac OS platforms. - It has no public constructor. - Use Fl_Printer instead that is cross-platform and has the same API. - */ -class Fl_System_Printer : public Fl_Paged_Device { - friend class Fl_Printer; -private: -#ifdef __APPLE__ // PORTME: Fl_Surface_Driver ? - platform printer driver - float scale_x; - float scale_y; - float angle; // rotation angle in radians - PMPrintSession printSession; - PMPageFormat pageFormat; - PMPrintSettings printSettings; -#elif defined(WIN32) - int abortPrint; - PRINTDLG pd; - HDC hPr; - int prerr; - int left_margin; - int top_margin; - void absolute_printable_rect(int *x, int *y, int *w, int *h); -#endif -protected: - /** \brief The constructor */ - Fl_System_Printer(void); -public: - int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); - int start_page (void); - int printable_rect(int *w, int *h); - void margins(int *left, int *top, int *right, int *bottom); - void origin(int *x, int *y); - void origin(int x, int y); - void scale (float scale_x, float scale_y = 0.); - void rotate(float angle); - void translate(int x, int y); - void untranslate(void); - int end_page (void); - void end_job (void); -#ifdef __APPLE__ // PORTME: Fl_Surface_Driver ? - platform printer driver - void draw_decorated_window(Fl_Window *win, int x_offset, int y_offset); - void print_window_part(Fl_Window *win, int x, int y, int w, int h, int delta_x, int delta_y); -#endif - /** \brief The destructor */ - ~Fl_System_Printer(void); -}; // class Fl_System_Printer -#endif - -#if defined(FL_PORTING) - -# pragma message "FL_PORTING: define your own Fl_xxx_Printer class" -class Fl_XXX_Printer : public Fl_Paged_Device { - friend class Fl_Printer; -protected: - Fl_XXX_Printer(void) { } -}; - -#endif - -#if defined(FL_DOXYGEN) || !(defined(__APPLE__) || defined(WIN32) || defined(FL_PORTING)) - -/** - Print support under Unix/Linux. - - Class Fl_PostScript_Printer is implemented only on the Unix/Linux platform. - It has no public constructor. - Use Fl_Printer instead that is cross-platform and has the same API. - */ -class Fl_PostScript_Printer : public Fl_PostScript_File_Device { - friend class Fl_Printer; -protected: - /** The constructor */ - Fl_PostScript_Printer(void) {}; -public: - int start_job(int pages, int *firstpage = NULL, int *lastpage = NULL); -}; - -#endif /** * \brief OS-independent print support. @@ -183,6 +101,9 @@ public: */ class FL_EXPORT Fl_Printer : public Fl_Paged_Device { +private: + class Helper; + Helper *printer; public: /** \brief The constructor */ Fl_Printer(void); @@ -228,18 +149,87 @@ public: /** \} */ /** \brief The destructor */ ~Fl_Printer(void); - -private: -#if defined(WIN32) || defined(__APPLE__) // PORTME: Fl_Surface_Driver ? - system printer driver - Fl_System_Printer *printer; -#elif defined(FL_PORTING) -# pragma message "FL_PORTING: instantiate your own Fl_xxx_Printer here" - Fl_XXX_Printer *printer; -#else - Fl_PostScript_Printer *printer; -#endif }; +#if defined(__APPLE__) +class Fl_Printer::Helper : public Fl_Paged_Device { + friend class Fl_Printer; +private: + float scale_x; + float scale_y; + float angle; // rotation angle in radians + PMPrintSession printSession; + PMPageFormat pageFormat; + PMPrintSettings printSettings; +protected: + Helper(void); +public: + int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); + int start_page (void); + int printable_rect(int *w, int *h); + void margins(int *left, int *top, int *right, int *bottom); + void origin(int *x, int *y); + void origin(int x, int y); + void scale (float scale_x, float scale_y = 0.); + void rotate(float angle); + void translate(int x, int y); + void untranslate(void); + int end_page (void); + void end_job (void); + void draw_decorated_window(Fl_Window *win, int x_offset, int y_offset); + void print_window_part(Fl_Window *win, int x, int y, int w, int h, int delta_x, int delta_y); + ~Helper(void); +}; + +#elif defined(WIN32) + +class Fl_Printer::Helper : public Fl_Paged_Device { + friend class Fl_Printer; +private: + int abortPrint; + PRINTDLG pd; + HDC hPr; + int prerr; + int left_margin; + int top_margin; + void absolute_printable_rect(int *x, int *y, int *w, int *h); +protected: + Helper(void); +public: + int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); + int start_page (void); + int printable_rect(int *w, int *h); + void margins(int *left, int *top, int *right, int *bottom); + void origin(int *x, int *y); + void origin(int x, int y); + void scale (float scale_x, float scale_y = 0.); + void rotate(float angle); + void translate(int x, int y); + void untranslate(void); + int end_page (void); + void end_job (void); + ~Helper(void); +}; + +#elif defined(FL_PORTING) + +# pragma message "FL_PORTING: define your own Fl_Printer::Helper class" +class Fl_Printer::Helper : public Fl_Paged_Device { + friend class Fl_Printer; +protected: + Helper(void) { } +}; + +#else + +class Fl_Printer::Helper : public Fl_PostScript_File_Device { + friend class Fl_Printer; +public: + int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); +}; + +#endif + #endif // Fl_Printer_H // diff --git a/src/Fl_GDI_Printer.cxx b/src/Fl_GDI_Printer.cxx index a89bda453..c0bad87a0 100644 --- a/src/Fl_GDI_Printer.cxx +++ b/src/Fl_GDI_Printer.cxx @@ -28,12 +28,12 @@ extern HWND fl_window; -Fl_System_Printer::Fl_System_Printer(void) : Fl_Paged_Device() { +Fl_Printer::Helper::Helper(void) : Fl_Paged_Device() { hPr = NULL; driver(new Fl_GDI_Printer_Graphics_Driver); } -Fl_System_Printer::~Fl_System_Printer(void) { +Fl_Printer::Helper::~Helper(void) { if (hPr) end_job(); delete driver(); } @@ -54,7 +54,7 @@ static void WIN_SetupPrinterDeviceContext(HDC prHDC) } -int Fl_System_Printer::start_job (int pagecount, int *frompage, int *topage) +int Fl_Printer::Helper::start_job (int pagecount, int *frompage, int *topage) // returns 0 iff OK { if (pagecount == 0) pagecount = 10000; @@ -115,7 +115,7 @@ int Fl_System_Printer::start_job (int pagecount, int *frompage, int *topage) return err; } -void Fl_System_Printer::end_job (void) +void Fl_Printer::Helper::end_job (void) { Fl_Display_Device::display_device()->set_current(); if (hPr != NULL) { @@ -136,7 +136,7 @@ void Fl_System_Printer::end_job (void) hPr = NULL; } -void Fl_System_Printer::absolute_printable_rect(int *x, int *y, int *w, int *h) +void Fl_Printer::Helper::absolute_printable_rect(int *x, int *y, int *w, int *h) { POINT physPageSize; POINT pixelsPerInch; @@ -167,7 +167,7 @@ void Fl_System_Printer::absolute_printable_rect(int *x, int *y, int *w, int *h) SetWorldTransform(gc, &transform); } -void Fl_System_Printer::margins(int *left, int *top, int *right, int *bottom) +void Fl_Printer::Helper::margins(int *left, int *top, int *right, int *bottom) { int x = 0, y = 0, w = 0, h = 0; absolute_printable_rect(&x, &y, &w, &h); @@ -177,14 +177,14 @@ void Fl_System_Printer::margins(int *left, int *top, int *right, int *bottom) if (bottom) *bottom = y; } -int Fl_System_Printer::printable_rect(int *w, int *h) +int Fl_Printer::Helper::printable_rect(int *w, int *h) { int x, y; absolute_printable_rect(&x, &y, w, h); return 0; } -int Fl_System_Printer::start_page (void) +int Fl_Printer::Helper::start_page (void) { int rsult, w, h; @@ -203,14 +203,14 @@ int Fl_System_Printer::start_page (void) return rsult; } -void Fl_System_Printer::origin (int deltax, int deltay) +void Fl_Printer::Helper::origin (int deltax, int deltay) { SetWindowOrgEx( (HDC)driver()->gc(), - left_margin - deltax, - top_margin - deltay, NULL); x_offset = deltax; y_offset = deltay; } -void Fl_System_Printer::scale (float scalex, float scaley) +void Fl_Printer::Helper::scale (float scalex, float scaley) { if (scaley == 0.) scaley = scalex; int w, h; @@ -219,7 +219,7 @@ void Fl_System_Printer::scale (float scalex, float scaley) origin(0, 0); } -void Fl_System_Printer::rotate (float rot_angle) +void Fl_Printer::Helper::rotate (float rot_angle) { XFORM mat; float angle; @@ -232,7 +232,7 @@ void Fl_System_Printer::rotate (float rot_angle) SetWorldTransform((HDC)driver()->gc(), &mat); } -int Fl_System_Printer::end_page (void) +int Fl_Printer::Helper::end_page (void) { int rsult; @@ -263,7 +263,7 @@ static void do_translate(int x, int y, HDC gc) ModifyWorldTransform(gc, &tr, MWT_LEFTMULTIPLY); } -void Fl_System_Printer::translate (int x, int y) +void Fl_Printer::Helper::translate (int x, int y) { do_translate(x, y, (HDC)driver()->gc()); if (translate_stack_depth < translate_stack_max) { @@ -273,7 +273,7 @@ void Fl_System_Printer::translate (int x, int y) } } -void Fl_System_Printer::untranslate (void) +void Fl_Printer::Helper::untranslate (void) { if (translate_stack_depth > 0) { translate_stack_depth--; @@ -281,6 +281,11 @@ void Fl_System_Printer::untranslate (void) } } +void Fl_Printer::Helper::origin(int *x, int *y) +{ + Fl_Paged_Device::origin(x, y); +} + #endif // WIN32 // diff --git a/src/Fl_Printer.cxx b/src/Fl_Printer.cxx index ccde1ee58..58db4cca8 100644 --- a/src/Fl_Printer.cxx +++ b/src/Fl_Printer.cxx @@ -63,16 +63,6 @@ const char *Fl_Printer::property_cancel = NULL; #else -#if defined(WIN32) || defined(__APPLE__) // PORTME: Fl_Screen_Driver - platform printing -#elif defined(FL_PORTING) -# pragma message "FL_PORTING: implement the printer device specifics" -#else -#endif - -#if defined(WIN32) -#include "Fl_GDI_Printer.cxx" -#endif - // print dialog customization strings /** [this text may be customized at run-time] */ const char *Fl_Printer::dialog_title = "Print"; @@ -113,24 +103,9 @@ const char *Fl_Printer::property_save = "Save"; /** [this text may be customized at run-time] */ const char *Fl_Printer::property_cancel = "Cancel"; -#if defined(__APPLE__) || defined(WIN32) // PORTME: Fl_Screen_Driver - platform printing - -void Fl_System_Printer::origin(int *x, int *y) -{ - Fl_Paged_Device::origin(x, y); -} - -#endif Fl_Printer::Fl_Printer(void) { -#if defined(WIN32) || defined(__APPLE__) // PORTME: Fl_Screen_Driver - platform printing - printer = new Fl_System_Printer(); -#elif defined(FL_PORTING) -# pragma message "FL_PORTING: implement the printer device specifics" - printer = new Fl_XXX_Printer(); -#else - printer = new Fl_PostScript_Printer(); -#endif + printer = new Helper(); Fl_Surface_Device::driver(printer->driver()); } diff --git a/src/Fl_Quartz_Printer.mm b/src/Fl_Quartz_Printer.mm index c12777131..350ab53b7 100644 --- a/src/Fl_Quartz_Printer.mm +++ b/src/Fl_Quartz_Printer.mm @@ -18,7 +18,7 @@ #ifdef __APPLE__ #include -#include "drivers/Quartz/Fl_Quartz_Printer_Graphics_Driver.h" +#include "drivers/Quartz/Fl_Quartz_Printer_Graphics_Driver.H" #include #include @@ -42,7 +42,7 @@ typedef OSStatus extern void fl_quartz_restore_line_style_(CGContextRef gc); -Fl_System_Printer::Fl_System_Printer(void) +Fl_Printer::Helper::Helper(void) { x_offset = 0; y_offset = 0; @@ -50,11 +50,11 @@ Fl_System_Printer::Fl_System_Printer(void) driver(new Fl_Quartz_Printer_Graphics_Driver); } -Fl_System_Printer::~Fl_System_Printer(void) { +Fl_Printer::Helper::~Helper(void) { delete driver(); } -int Fl_System_Printer::start_job (int pagecount, int *frompage, int *topage) +int Fl_Printer::Helper::start_job (int pagecount, int *frompage, int *topage) //printing using a Quartz graphics context //returns 0 iff OK { @@ -145,7 +145,7 @@ int Fl_System_Printer::start_job (int pagecount, int *frompage, int *topage) return 0; } -void Fl_System_Printer::margins(int *left, int *top, int *right, int *bottom) +void Fl_Printer::Helper::margins(int *left, int *top, int *right, int *bottom) { PMPaper paper; PMGetPageFormatPaper(pageFormat, &paper); @@ -167,7 +167,7 @@ void Fl_System_Printer::margins(int *left, int *top, int *right, int *bottom) } } -int Fl_System_Printer::printable_rect(int *w, int *h) +int Fl_Printer::Helper::printable_rect(int *w, int *h) //returns 0 iff OK { OSStatus status; @@ -184,7 +184,7 @@ int Fl_System_Printer::printable_rect(int *w, int *h) return 0; } -void Fl_System_Printer::origin(int x, int y) +void Fl_Printer::Helper::origin(int x, int y) { x_offset = x; y_offset = y; @@ -198,7 +198,7 @@ void Fl_System_Printer::origin(int x, int y) CGContextSaveGState(gc); } -void Fl_System_Printer::scale (float s_x, float s_y) +void Fl_Printer::Helper::scale (float s_x, float s_y) { if (s_y == 0.) s_y = s_x; scale_x = s_x; @@ -213,7 +213,7 @@ void Fl_System_Printer::scale (float s_x, float s_y) CGContextSaveGState(gc); } -void Fl_System_Printer::rotate (float rot_angle) +void Fl_Printer::Helper::rotate (float rot_angle) { angle = - rot_angle * M_PI / 180.; CGContextRef gc = (CGContextRef)driver()->gc(); @@ -226,7 +226,7 @@ void Fl_System_Printer::rotate (float rot_angle) CGContextSaveGState(gc); } -void Fl_System_Printer::translate(int x, int y) +void Fl_Printer::Helper::translate(int x, int y) { CGContextRef gc = (CGContextRef)driver()->gc(); CGContextSaveGState(gc); @@ -234,14 +234,14 @@ void Fl_System_Printer::translate(int x, int y) CGContextSaveGState(gc); } -void Fl_System_Printer::untranslate(void) +void Fl_Printer::Helper::untranslate(void) { CGContextRef gc = (CGContextRef)driver()->gc(); CGContextRestoreGState(gc); CGContextRestoreGState(gc); } -int Fl_System_Printer::start_page (void) +int Fl_Printer::Helper::start_page (void) { OSStatus status = PMSessionBeginPageNoDialog(printSession, pageFormat, NULL); CGContextRef gc; @@ -291,7 +291,7 @@ int Fl_System_Printer::start_page (void) return status != noErr; } -int Fl_System_Printer::end_page (void) +int Fl_Printer::Helper::end_page (void) { CGContextRef gc = (CGContextRef)driver()->gc(); CGContextFlush(gc); @@ -302,7 +302,7 @@ int Fl_System_Printer::end_page (void) return status != noErr; } -void Fl_System_Printer::end_job (void) +void Fl_Printer::Helper::end_job (void) { OSStatus status; @@ -325,7 +325,7 @@ void Fl_System_Printer::end_job (void) } // version that prints at high res if using a retina display -void Fl_System_Printer::print_window_part(Fl_Window *win, int x, int y, int w, int h, int delta_x, int delta_y) +void Fl_Printer::Helper::print_window_part(Fl_Window *win, int x, int y, int w, int h, int delta_x, int delta_y) { Fl_Surface_Device *current = Fl_Surface_Device::surface(); Fl_Display_Device::display_device()->set_current(); @@ -339,6 +339,11 @@ void Fl_System_Printer::print_window_part(Fl_Window *win, int x, int y, int w, i CFRelease(img); } +void Fl_Printer::Helper::origin(int *x, int *y) +{ + Fl_Paged_Device::origin(x, y); +} + #endif // __APPLE__ // diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 2cde0dfd1..55b7f7d09 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -4373,7 +4373,7 @@ void Fl_Cocoa_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top, } -void Fl_System_Printer::draw_decorated_window(Fl_Window *win, int x_offset, int y_offset) +void Fl_Printer::Helper::draw_decorated_window(Fl_Window *win, int x_offset, int y_offset) { if (!win->shown() || win->parent() || !win->border() || !win->visible()) { this->print_widget(win, x_offset, y_offset); diff --git a/src/drivers/PostScript/Fl_PostScript.cxx b/src/drivers/PostScript/Fl_PostScript.cxx index 6a2641e22..9528c6023 100644 --- a/src/drivers/PostScript/Fl_PostScript.cxx +++ b/src/drivers/PostScript/Fl_PostScript.cxx @@ -1562,8 +1562,10 @@ void Fl_PostScript_File_Device::end_job (void) #elif defined(FL_PORTING) # pragma message "FL_PORTING: implement postscript printing" #else // X11 + + /** Starts a print job. */ -int Fl_PostScript_Printer::start_job(int pages, int *firstpage, int *lastpage) { +int Fl_Printer::Helper::start_job(int pages, int *firstpage, int *lastpage) { enum Fl_Paged_Device::Page_Format format; enum Fl_Paged_Device::Page_Layout layout;