Author: manolo
Date: 2010-02-27 23:12:36 -0800 (Sat, 27 Feb 2010)
New Revision: 7170
Log:
Fl_PS_Printer: implemented translation, scaling and rotation
and PostScript printing compiled for Mac and Win32.


Modified:
   branches/branch-1.3-Fl_Printer/FL/Fl_Device.H
   branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H
   branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx
   branches/branch-1.3-Fl_Printer/src/Fl_cocoa.mm
   branches/branch-1.3-Fl_Printer/src/Fl_win32.cxx
   branches/branch-1.3-Fl_Printer/src/Fl_x.cxx
   branches/branch-1.3-Fl_Printer/test/device.cxx
   branches/branch-1.3-Fl_Printer/test/print.cxx

Modified: branches/branch-1.3-Fl_Printer/FL/Fl_Device.H
===================================================================
--- branches/branch-1.3-Fl_Printer/FL/Fl_Device.H       2010-02-27 22:38:25 UTC 
(rev 7169)
+++ branches/branch-1.3-Fl_Printer/FL/Fl_Device.H       2010-02-28 07:12:36 UTC 
(rev 7170)
@@ -115,6 +115,7 @@
 
 
 class Fl_Display : public Fl_Device {
+  friend class Fl_PS_Printer; //RK: temporary hack for font sizes
 };
 
 #ifdef __APPLE__
@@ -128,13 +129,7 @@
   Fl_GDI_Display() {};
 };
 #else
-extern int   fl_height();
-extern int   fl_descent();
-extern double fl_width(unsigned int);
-extern double fl_width(const char* txt, int n);
 class Fl_Xlib_Display : public Fl_Display {
-protected:
-  friend class Fl_PS_Printer; //RK: temporary hack for font sizes
 public:
   Fl_Xlib_Display() {};
 };

Modified: branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H
===================================================================
--- branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H      2010-02-27 22:38:25 UTC 
(rev 7169)
+++ branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H      2010-02-28 07:12:36 UTC 
(rev 7170)
@@ -236,47 +236,6 @@
 };
 #endif
 
-const int NO_PAGE_FORMATS=30;
-const int page_formats[NO_PAGE_FORMATS][2]={
-
-// A* // index(Ai) = i
-{2384, 3370}, //A0
-{1684, 2384}, //A1
-{1191, 1684}, //A2
-{842, 1191},  //A3
-{595, 842},   //A4
-{420, 595},   //A5
-{297, 420},   //A6
-{210, 297},   //A7
-{148, 210},   //A8
-{105, 148},   //A9
-
-// B* // index(Bi) = i+10
-{2920, 4127}, //B0
-{2064, 2920}, //B1
-{1460, 2064}, //B2
-{1032, 1460}, //B3
-{729, 1032},  //B4
-{516, 729},   //B5
-{316, 516},   //B6
-{258, 516},   //B7
-{181, 258},   //B8
-{127, 181},   //B9
-{91,127},     //B10
-
-// others (look at Fl_Printer.H} //
-{462, 649},
-{312, 623},
-{541, 719},
-{595, 935},
-{1224, 790},
-{612, 1009},
-{612, 790},
-{791, 1224},
-{297, 683}
-
-};
-
 class Fl_PS_Printer : public Fl_Virtual_Printer { // defined for all 3 
platforms
   enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS};
   
@@ -322,11 +281,14 @@
   float scale_x;
   float scale_y;
   float angle;
+  int left_margin;
+  int top_margin;
   void translate(int x, int y);
   void untranslate(void);
   
 protected:
   double pw_, ph_;
+  static const int NO_PAGE_FORMATS=30;
   static const int page_formats[NO_PAGE_FORMATS][2];
   
   uchar bg_r, bg_g, bg_b;

Modified: branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx        2010-02-27 
22:38:25 UTC (rev 7169)
+++ branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx        2010-02-28 
07:12:36 UTC (rev 7170)
@@ -2,7 +2,6 @@
  *  Fl_PS_Printer.cxx
  *
  */
-#if ! ( defined(__APPLE__) || defined(WIN32) )
 #include <FL/Fl_Device.H>
 
 #include <FL/Fl.H>
@@ -12,6 +11,7 @@
 #include <stdio.h>
 #include <math.h>
 
+
 const int Fl_PS_Printer::page_formats[NO_PAGE_FORMATS][2]={
 
 // A* // index(Ai) = i
@@ -328,8 +328,6 @@
   output = fopen(fnfc.filename(), "w");
   if(output == NULL) return 1;
   this->set_current();
-  x_offset = 0;
-  y_offset = 0;
   if(frompage) *frompage = 1;
   if(topage) *topage = pagecount;
   
@@ -341,6 +339,9 @@
     fprintf(output, "%%%%Pages: %i\n", pagecount);
   else
     fprintf(output, "%%%%Pages: (atend)\n");
+  fprintf(output, "%%%%BeginFeature: *PageSize\n");
+  fprintf(output, "A4\n"); // TODO something better
+  fprintf(output, "%%%%EndFeature\n");
   fprintf(output, "%%%%EndComments\n");
   fprintf(output, prolog);
   if(lang_level_ >1)
@@ -475,11 +476,11 @@
   
   
   if(format &  LANDSCAPE){
-    ph_=Fl_Printer::page_formats[format & 0xFF][0];
-    pw_=Fl_Printer::page_formats[format & 0xFF][1];
+    ph_=Fl_PS_Printer::page_formats[format & 0xFF][0];
+    pw_=Fl_PS_Printer::page_formats[format & 0xFF][1];
   }else{
-    pw_=Fl_Printer::page_formats[format & 0xFF][0];
-    ph_=Fl_Printer::page_formats[format & 0xFF][1];
+    pw_=Fl_PS_Printer::page_formats[format & 0xFF][0];
+    ph_=Fl_PS_Printer::page_formats[format & 0xFF][1];
   }
   page(pw_,ph_,format & 0xFF00);//,orientation only;
 };
@@ -727,7 +728,7 @@
 "ZapfDingbats"
 };
 // TODO RK: CRITICAL: this is hacky/temporary implementation of fonts. All 
below should be replaced.
-extern Fl_Xlib_Display fl_disp;
+extern Fl_Display fl_display_device;
 
 void Fl_PS_Printer::font(int f, int s) {
   
@@ -736,22 +737,22 @@
     f = FL_COURIER;
   fprintf(output, "/%s SF\n" , _fontNames[f]);
   fprintf(output,"%i FS\n", s);
-  fl_disp.font(f,s); //Dirty hack for font measurement ;-(
+  fl_display_device.font(f,s); //Dirty hack for font measurement ;-(
   font_=f; size_=s;
 };
 
 /*double Fl_PS_Printer::width(unsigned c){
-  return fl_disp.width(c); //Dirty...
+  return fl_display_device.width(c); //Dirty...
 }
 
 double Fl_PS_Printer::width(const char* s, int n){;
-  return fl_disp.width(s,n); //Very Dirty...
+  return fl_display_device.width(s,n); //Very Dirty...
 }
 int Fl_PS_Printer::descent(){
-  return fl_disp.descent(); //A bit Dirty...
+  return fl_display_device.descent(); //A bit Dirty...
 }
 int Fl_PS_Printer::height(){
-  return fl_disp.height(); //Still Dirty...
+  return fl_display_device.height(); //Still Dirty...
 }*/
 
 void Fl_PS_Printer::color(Fl_Color c) {
@@ -1077,43 +1078,63 @@
 
 void Fl_PS_Printer::margins(int *left, int *top, int *right, int *bottom) // 
to implement
 {
+  if(left) *left = (int)(left_margin / scale_x + .5);
+  if(right) *right = (int)(left_margin / scale_x + .5);
+  if(top) *top = (int)(top_margin / scale_y + .5);
+  if(bottom) *bottom = (int)(top_margin / scale_y + .5);
 }
 
-int Fl_PS_Printer::printable_rect(int *w, int *h) // to implement
+int Fl_PS_Printer::printable_rect(int *w, int *h)
 //returns 0 iff OK
 {
+  if(w) *w = (int)((pw_ - 2 * left_margin) / scale_x + .5);
+  if(h) *h = (int)((ph_ - 2 * top_margin) / scale_y + .5);
   return 0;
 }
 
-void Fl_PS_Printer::origin(int x, int y) // to implement
+void Fl_PS_Printer::origin(int x, int y)
 {
+  x_offset = x;
+  y_offset = y;
+  fprintf(output, "GR GR GS %d %d TR  %f %f SC %d %d TR %f rotate GS\n", 
+         left_margin, top_margin, scale_x, scale_y, x, y, angle);
 }
 
-void Fl_PS_Printer::scale (float s_x, float s_y) // to implement
+void Fl_PS_Printer::scale (float s_x, float s_y)
 {
   scale_x = s_x;
   scale_y = s_y;
+  fprintf(output, "GR GR GS %d %d TR  %f %f SC %f rotate GS\n", 
+         left_margin, top_margin, scale_x, scale_y, angle);
 }
 
-void Fl_PS_Printer::rotate (float rot_angle) // to implement
+void Fl_PS_Printer::rotate (float rot_angle)
 {
-  angle = - rot_angle * M_PI / 180.;
+  angle = - rot_angle;
+  fprintf(output, "GR GR GS %d %d TR  %f %f SC %d %d TR %f rotate GS\n", 
+         left_margin, top_margin, scale_x, scale_y, x_offset, y_offset, angle);
 }
 
 void Fl_PS_Printer::translate(int x, int y)
 {
-  fprintf(output, "%d %d translate GS\n", x, y);
+  fprintf(output, "GS %d %d translate GS\n", x, y);
 }
 
 void Fl_PS_Printer::untranslate(void)
 {
-  fprintf(output, "GR\n");
+  fprintf(output, "GR GR\n");
 }
 
 int Fl_PS_Printer::start_page (void)
 {
   page(A4);
-  fprintf(output, "%d %d translate GS\n", 50, 80); // Temporary
+  x_offset = 0;
+  y_offset = 0;
+  scale_x = scale_y = 1.;
+  left_margin = 30;
+  top_margin = 30;
+  angle = 0;
+  fprintf(output, "GR GR GS %d %d translate GS\n", left_margin, top_margin);
   return 0;
 }
 
@@ -1127,5 +1148,3 @@
   current_display()->set_current();
 }
 
-#endif // ! ( defined(__APPLE__) || defined(WIN32) )
-

Modified: branches/branch-1.3-Fl_Printer/src/Fl_cocoa.mm
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_cocoa.mm      2010-02-27 22:38:25 UTC 
(rev 7169)
+++ branches/branch-1.3-Fl_Printer/src/Fl_cocoa.mm      2010-02-28 07:12:36 UTC 
(rev 7170)
@@ -111,8 +111,8 @@
 static Fl_Region MacRegionMinusRect(Fl_Region r, int x,int y,int w,int h);
 static void cocoaMouseHandler(NSEvent *theEvent);
 
-static Fl_Quartz_Display default_display;
-Fl_Device *fl_device = (Fl_Device*)&default_display;
+FL_EXPORT Fl_Quartz_Display fl_display_device;
+Fl_Device *fl_device = (Fl_Device*)&fl_display_device;
 
 // public variables
 int fl_screen;
@@ -2867,6 +2867,7 @@
 - (void)printPanel
 {
   Fl_Printer printer;
+//  Fl_PS_Printer printer;
   int w, h;
   Fl_Window *win = Fl::first_window();
   if(!win) return;

Modified: branches/branch-1.3-Fl_Printer/src/Fl_win32.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_win32.cxx     2010-02-27 22:38:25 UTC 
(rev 7169)
+++ branches/branch-1.3-Fl_Printer/src/Fl_win32.cxx     2010-02-28 07:12:36 UTC 
(rev 7170)
@@ -95,10 +95,9 @@
   for async mode proper operation, not mentioning the side effects...
 */
 
-static Fl_GDI_Display default_display;
-Fl_Device *fl_device = (Fl_Device*)&default_display;
+FL_EXPORT Fl_Display fl_display_device;
+Fl_Device *fl_device = (Fl_Device*)&fl_display_device;
 
-
 // dynamic wsock dll handling api:
 #if defined(__CYGWIN__) && !defined(SOCKET)
 # define SOCKET int

Modified: branches/branch-1.3-Fl_Printer/src/Fl_x.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_x.cxx 2010-02-27 22:38:25 UTC (rev 
7169)
+++ branches/branch-1.3-Fl_Printer/src/Fl_x.cxx 2010-02-28 07:12:36 UTC (rev 
7170)
@@ -51,8 +51,8 @@
 #  include <X11/Xlocale.h>
 #  include <X11/Xlib.h>
 
-FL_EXPORT Fl_Xlib_Display fl_disp;
-Fl_Device *fl_device = (Fl_Device*)&fl_disp;
+FL_EXPORT Fl_Xlib_Display fl_display_device;
+Fl_Device *fl_device = (Fl_Device*)&fl_display_device;
 
 ////////////////////////////////////////////////////////////////
 // interface to poll/select call:

Modified: branches/branch-1.3-Fl_Printer/test/device.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/test/device.cxx      2010-02-27 22:38:25 UTC 
(rev 7169)
+++ branches/branch-1.3-Fl_Printer/test/device.cxx      2010-02-28 07:12:36 UTC 
(rev 7170)
@@ -29,7 +29,7 @@
 #include <FL/Fl_Round_Button.H>
 
 
-#include <FL/Fl_Device.H>
+#include <FL/Fl_Printer.H>
 
 //#include "fl_printer_chooser.H"
 

Modified: branches/branch-1.3-Fl_Printer/test/print.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/test/print.cxx       2010-02-27 22:38:25 UTC 
(rev 7169)
+++ branches/branch-1.3-Fl_Printer/test/print.cxx       2010-02-28 07:12:36 UTC 
(rev 7170)
@@ -110,6 +110,7 @@
   d->redraw();
 }
 
+#include <FL/Fl_Printer.H>
 void print_cb(Fl_Widget* o, void* v) {
   int w, h;
   Drawing *d = (Drawing *)v;

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to