diff --git a/FL/Fl_Printer.H b/FL/Fl_Printer.H index 877251e6e..472c1c6d1 100644 --- a/FL/Fl_Printer.H +++ b/FL/Fl_Printer.H @@ -44,13 +44,12 @@ #include #endif -#if defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN) -/** - \brief Print support under MSWindows and Mac OS X. -* +#if defined(__APPLE__) || defined(WIN32) +/* + Print support under MSWindows and Mac OS X. + Class Fl_System_Printer is implemented only on the MSWindows and Mac OS X platforms. Use Fl_Printer instead that is cross-platform and has the same API. - Fl_Printer is typedef'ed to Fl_System_Printer under MSWindows and Mac OS X. */ class Fl_System_Printer : public Fl_Paged_Device { private: @@ -75,9 +74,6 @@ private: #endif public: static const char *device_type; - /** - @brief The constructor. - */ Fl_System_Printer(void); int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); int start_page (void); @@ -91,78 +87,28 @@ public: int end_page (void); void end_job (void); - /** - @brief The destructor. - */ ~Fl_System_Printer(void); -#ifndef FL_DOXYGEN -public: - static const char *dialog_title; - static const char *dialog_printer; - static const char *dialog_range; - static const char *dialog_copies; - static const char *dialog_all; - static const char *dialog_pages; - static const char *dialog_from; - static const char *dialog_to; - static const char *dialog_properties; - static const char *dialog_copyNo; - static const char *dialog_print_button; - static const char *dialog_cancel_button; - static const char *dialog_print_to_file; - static const char *property_title; - static const char *property_pagesize; - static const char *property_mode; - static const char *property_use; - static const char *property_save; - static const char *property_cancel; -#endif // FL_DOXYGEN }; // class Fl_System_Printer -typedef Fl_System_Printer Fl_Printer; #endif -#if !(defined(__APPLE__) || defined(WIN32)) -/** - \brief Print support under Unix/Linux. - * +#if !(defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN)) +/* + Print support under Unix/Linux. + Class Fl_PostScript_Printer is implemented only on the Unix/Linux platform. Use Fl_Printer instead that is cross-platform and has the same API. - Fl_Printer is typedef'ed to Fl_PostScript_Printer under Unix/Linux. */ class Fl_PostScript_Printer : public Fl_PostScript_File_Device { public: static const char *device_type; int start_job(int pages, int *firstpage = NULL, int *lastpage = NULL); - -#ifndef FL_DOXYGEN - static const char *dialog_title; - static const char *dialog_printer; - static const char *dialog_range; - static const char *dialog_copies; - static const char *dialog_all; - static const char *dialog_pages; - static const char *dialog_from; - static const char *dialog_to; - static const char *dialog_properties; - static const char *dialog_copyNo; - static const char *dialog_print_button; - static const char *dialog_cancel_button; - static const char *dialog_print_to_file; - static const char *property_title; - static const char *property_pagesize; - static const char *property_mode; - static const char *property_use; - static const char *property_save; - static const char *property_cancel; -#endif // FL_DOXYGEN }; -typedef Fl_PostScript_Printer Fl_Printer; #endif /** - * @brief OS-independent print support. + * \brief OS-independent print support. * Fl_Printer allows to use all FLTK drawing, color, text, and clip functions, and to have them operate on printed page(s). There are two main, non exclusive, ways to use it. @@ -175,8 +121,6 @@ typedef Fl_PostScript_Printer Fl_Printer; In both cases, begin by start_job(), start_page(), printable_rect() and origin() calls and finish by end_page() and end_job() calls.

Platform specifics -
Fl_Printer is typedef'ed to Fl_PostScript_Printer under Unix/Linux - and to Fl_System_Printer otherwise. Both classes have the same API.

*/ -#ifdef FL_DOXYGEN -// this class is NOT compiled. It's here for Doxygen documentation purpose only -class Fl_Printer : public Fl_System_Printer, Fl_PostScript_Printer { +class Fl_Printer : public Fl_Paged_Device { public: static const char *device_type; - /** @brief The constructor */ + /** \brief The constructor */ Fl_Printer(void); int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); int start_page(void); @@ -213,7 +155,7 @@ public: void untranslate(void); int end_page (void); void end_job (void); - /** @brief The destructor */ + /** \brief The destructor */ ~Fl_Printer(void); /** \name These attributes are effective under the Xlib platform only. @@ -239,8 +181,13 @@ public: static const char *property_save; static const char *property_cancel; /** \} */ -}; +private: +#if defined(WIN32) || defined(__APPLE__) + Fl_System_Printer *printer; +#else + Fl_PostScript_Printer *printer; #endif +}; #endif // Fl_Printer_H diff --git a/src/Fl_GDI_Printer.cxx b/src/Fl_GDI_Printer.cxx index d2f9d1d59..d65efaddd 100644 --- a/src/Fl_GDI_Printer.cxx +++ b/src/Fl_GDI_Printer.cxx @@ -34,13 +34,13 @@ extern HWND fl_window; -Fl_Printer::Fl_System_Printer(void) : Fl_Paged_Device() { +Fl_System_Printer::Fl_System_Printer(void) : Fl_Paged_Device() { hPr = NULL; type_ = device_type; driver(fl_graphics_driver); } -Fl_Printer::~Fl_System_Printer(void) { +Fl_System_Printer::~Fl_System_Printer(void) { if (hPr) end_job(); } @@ -61,7 +61,7 @@ static void WIN_SetupPrinterDeviceContext(HDC prHDC) } -int Fl_Printer::start_job (int pagecount, int *frompage, int *topage) +int Fl_System_Printer::start_job (int pagecount, int *frompage, int *topage) // returns 0 iff OK { DWORD commdlgerr; @@ -116,7 +116,7 @@ int Fl_Printer::start_job (int pagecount, int *frompage, int *topage) return err; } -void Fl_Printer::end_job (void) +void Fl_System_Printer::end_job (void) { Fl_Display_Device::display_device()->set_current(); if (hPr != NULL) { @@ -137,7 +137,7 @@ void Fl_Printer::end_job (void) hPr = NULL; } -void Fl_Printer::absolute_printable_rect(int *x, int *y, int *w, int *h) +void Fl_System_Printer::absolute_printable_rect(int *x, int *y, int *w, int *h) { POINT physPageSize; POINT pixelsPerInch; @@ -163,7 +163,7 @@ void Fl_Printer::absolute_printable_rect(int *x, int *y, int *w, int *h) origin(x_offset, y_offset); } -void Fl_Printer::margins(int *left, int *top, int *right, int *bottom) +void Fl_System_Printer::margins(int *left, int *top, int *right, int *bottom) { int x, y, w, h; absolute_printable_rect(&x, &y, &w, &h); @@ -173,14 +173,14 @@ void Fl_Printer::margins(int *left, int *top, int *right, int *bottom) if (bottom) *bottom = y; } -int Fl_Printer::printable_rect(int *w, int *h) +int Fl_System_Printer::printable_rect(int *w, int *h) { int x, y; absolute_printable_rect(&x, &y, w, h); return 0; } -int Fl_Printer::start_page (void) +int Fl_System_Printer::start_page (void) { int rsult, w, h; @@ -201,14 +201,14 @@ int Fl_Printer::start_page (void) return rsult; } -void Fl_Printer::origin (int deltax, int deltay) +void Fl_System_Printer::origin (int deltax, int deltay) { SetWindowOrgEx(fl_gc, - left_margin - deltax, - top_margin - deltay, NULL); x_offset = deltax; y_offset = deltay; } -void Fl_Printer::scale (float scalex, float scaley) +void Fl_System_Printer::scale (float scalex, float scaley) { int w, h; SetWindowExtEx(fl_gc, (int)(720 / scalex + 0.5), (int)(720 / scaley + 0.5), NULL); @@ -216,7 +216,7 @@ void Fl_Printer::scale (float scalex, float scaley) origin(0, 0); } -void Fl_Printer::rotate (float rot_angle) +void Fl_System_Printer::rotate (float rot_angle) { XFORM mat; float angle; @@ -229,7 +229,7 @@ void Fl_Printer::rotate (float rot_angle) SetWorldTransform(fl_gc, &mat); } -int Fl_Printer::end_page (void) +int Fl_System_Printer::end_page (void) { int rsult; @@ -261,7 +261,7 @@ static void do_translate(int x, int y) ModifyWorldTransform(fl_gc, &tr, MWT_LEFTMULTIPLY); } -void Fl_Printer::translate (int x, int y) +void Fl_System_Printer::translate (int x, int y) { do_translate(x, y); if (translate_stack_depth < translate_stack_max) { @@ -271,7 +271,7 @@ void Fl_Printer::translate (int x, int y) } } -void Fl_Printer::untranslate (void) +void Fl_System_Printer::untranslate (void) { if (translate_stack_depth > 0) { translate_stack_depth--; diff --git a/src/Fl_PostScript.cxx b/src/Fl_PostScript.cxx index 01fb5c07f..5e98e899e 100644 --- a/src/Fl_PostScript.cxx +++ b/src/Fl_PostScript.cxx @@ -1471,7 +1471,7 @@ void Fl_PostScript_File_Device::end_job (void) } #if ! (defined(__APPLE__) || defined(WIN32) ) -int Fl_Printer::start_job(int pages, int *firstpage, int *lastpage) { +int Fl_PostScript_Printer::start_job(int pages, int *firstpage, int *lastpage) { enum Fl_Paged_Device::Page_Format format; enum Fl_Paged_Device::Page_Layout layout; diff --git a/src/Fl_Printer.cxx b/src/Fl_Printer.cxx index 94d53e280..a1c33a661 100644 --- a/src/Fl_Printer.cxx +++ b/src/Fl_Printer.cxx @@ -77,6 +77,11 @@ const char *Fl_Printer::property_save = "Save"; const char *Fl_Printer::property_cancel = "Cancel"; const char *Fl_Printer::device_type = "Fl_Printer"; +#if defined(__APPLE__) || defined(WIN32) +const char *Fl_System_Printer::device_type = "Fl_Printer"; +#elif !defined(FL_DOXYGEN) +const char *Fl_PostScript_Printer::device_type = "Fl_Printer"; +#endif #if defined(__APPLE__) || defined(WIN32) void Fl_System_Printer::set_current(void) @@ -90,6 +95,75 @@ void Fl_System_Printer::set_current(void) } #endif +Fl_Printer::Fl_Printer(void) { +#if defined(WIN32) || defined(__APPLE__) + printer = new Fl_System_Printer(); +#else + printer = new Fl_PostScript_Printer(); +#endif +} + +int Fl_Printer::start_job(int pagecount, int *frompage, int *topage) +{ + return printer->start_job(pagecount, frompage, topage); +} + +int Fl_Printer::start_page(void) +{ + return printer->start_page(); +} + +int Fl_Printer::printable_rect(int *w, int *h) +{ + return printer->printable_rect(w, h); +} + +void Fl_Printer::margins(int *left, int *top, int *right, int *bottom) +{ + printer->margins(left, top, right, bottom); +} + +void Fl_Printer::origin(int x, int y) +{ + printer->origin(x, y); +} + +void Fl_Printer::scale(float scale_x, float scale_y) +{ + printer->scale(scale_x, scale_y); +} + +void Fl_Printer::rotate(float angle) +{ + printer->rotate(angle); +} + +void Fl_Printer::translate(int x, int y) +{ + printer->translate(x, y); +} + +void Fl_Printer::untranslate(void) +{ + printer->untranslate(); +} + +int Fl_Printer::end_page (void) +{ + return printer->end_page(); +} + +void Fl_Printer::end_job (void) +{ + printer->end_job(); +} + +Fl_Printer::~Fl_Printer(void) +{ + delete printer; +} + + // // End of "$Id$". // diff --git a/src/Fl_Quartz_Printer.mm b/src/Fl_Quartz_Printer.mm index e531fa706..31de4137a 100644 --- a/src/Fl_Quartz_Printer.mm +++ b/src/Fl_Quartz_Printer.mm @@ -47,7 +47,7 @@ Fl_System_Printer::Fl_System_Printer(void) Fl_System_Printer::~Fl_System_Printer(void) {} -int Fl_Printer::start_job (int pagecount, int *frompage, int *topage) +int Fl_System_Printer::start_job (int pagecount, int *frompage, int *topage) //printing using a Quartz graphics context //returns 0 iff OK { @@ -139,7 +139,7 @@ int Fl_Printer::start_job (int pagecount, int *frompage, int *topage) return 0; } -void Fl_Printer::margins(int *left, int *top, int *right, int *bottom) +void Fl_System_Printer::margins(int *left, int *top, int *right, int *bottom) { PMPaper paper; PMGetPageFormatPaper(pageFormat, &paper); @@ -161,7 +161,7 @@ void Fl_Printer::margins(int *left, int *top, int *right, int *bottom) } } -int Fl_Printer::printable_rect(int *w, int *h) +int Fl_System_Printer::printable_rect(int *w, int *h) //returns 0 iff OK { OSStatus status; @@ -178,7 +178,7 @@ int Fl_Printer::printable_rect(int *w, int *h) return 0; } -void Fl_Printer::origin(int x, int y) +void Fl_System_Printer::origin(int x, int y) { x_offset = x; y_offset = y; @@ -191,7 +191,7 @@ void Fl_Printer::origin(int x, int y) CGContextSaveGState(fl_gc); } -void Fl_Printer::scale (float s_x, float s_y) +void Fl_System_Printer::scale (float s_x, float s_y) { scale_x = s_x; scale_y = s_y; @@ -204,7 +204,7 @@ void Fl_Printer::scale (float s_x, float s_y) CGContextSaveGState(fl_gc); } -void Fl_Printer::rotate (float rot_angle) +void Fl_System_Printer::rotate (float rot_angle) { angle = - rot_angle * M_PI / 180.; CGContextRestoreGState(fl_gc); @@ -216,20 +216,20 @@ void Fl_Printer::rotate (float rot_angle) CGContextSaveGState(fl_gc); } -void Fl_Printer::translate(int x, int y) +void Fl_System_Printer::translate(int x, int y) { CGContextSaveGState(fl_gc); CGContextTranslateCTM(fl_gc, x, y ); CGContextSaveGState(fl_gc); } -void Fl_Printer::untranslate(void) +void Fl_System_Printer::untranslate(void) { CGContextRestoreGState(fl_gc); CGContextRestoreGState(fl_gc); } -int Fl_Printer::start_page (void) +int Fl_System_Printer::start_page (void) { OSStatus status = PMSessionBeginPageNoDialog(printSession, pageFormat, NULL); #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 @@ -278,7 +278,7 @@ int Fl_Printer::start_page (void) return status != noErr; } -int Fl_Printer::end_page (void) +int Fl_System_Printer::end_page (void) { CGContextFlush(fl_gc); CGContextRestoreGState(fl_gc); @@ -289,7 +289,7 @@ int Fl_Printer::end_page (void) return status != noErr; } -void Fl_Printer::end_job (void) +void Fl_System_Printer::end_job (void) { OSStatus status;