Author: manolo
Date: 2010-04-05 13:07:28 -0700 (Mon, 05 Apr 2010)
New Revision: 7434
Log:
Beginning of Fl_Clipboard_Writer creation: new files

Added:
   branches/branch-1.3-Fl_Printer/FL/Fl_Abstract_Printer.H
   branches/branch-1.3-Fl_Printer/FL/Fl_Clipboard_Writer.H
   branches/branch-1.3-Fl_Printer/FL/Fl_PSfile_Device.H
   branches/branch-1.3-Fl_Printer/src/Fl_Abstract_Printer.cxx
   branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer.cxx
   branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer_mac.cxx
   branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer_win32.cxx
   branches/branch-1.3-Fl_Printer/src/Fl_Gl_Device_Plugin.cxx

Added: branches/branch-1.3-Fl_Printer/FL/Fl_Abstract_Printer.H
===================================================================
--- branches/branch-1.3-Fl_Printer/FL/Fl_Abstract_Printer.H                     
        (rev 0)
+++ branches/branch-1.3-Fl_Printer/FL/Fl_Abstract_Printer.H     2010-04-05 
20:07:28 UTC (rev 7434)
@@ -0,0 +1,94 @@
+//
+// "$Id: Fl_Abstract_Printer.H 7337 2010-03-25 16:05:00Z manolo $"
+//
+// Printing support for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems on the following page:
+//
+//     http://www.fltk.org/str.php
+//
+
+/** \file Fl_Abstract_Printer.H 
+ \brief declaration of class Fl_Abstract_Printer.
+ */
+
+#ifndef Fl_Abstract_Printer_H
+#define Fl_Abstract_Printer_H
+
+#include <FL/Fl_Device.H>
+
+/**
+ \brief A virtual class for print support with several platform-specific 
implementations.
+ *
+ This class has no public constructor: don't instantiate it; use Fl_Printer or 
Fl_PSfile_Device instead.
+ */
+class Fl_Abstract_Printer : public Fl_Device {
+  friend class Fl_Pixmap;
+  friend class Fl_RGB_Image;
+  friend class Fl_Bitmap;
+private:
+#ifdef __APPLE__
+  struct chain_elt {
+    Fl_Image *image;
+    const uchar *data;
+    struct chain_elt *next;
+  };
+  void add_image(Fl_Image *image, const uchar *data); // adds an image to the 
page image list
+#endif
+  void traverse(Fl_Widget *widget); // finds subwindows of widget and prints 
them
+protected:
+  /** \brief horizontal offset to the origin of graphics coordinates */
+  int x_offset;
+  /** \brief vertical offset to the origin of graphics coordinates */
+  int y_offset;
+  /** \brief chained list of Fl_Image's used in this page */
+  struct chain_elt *image_list_; 
+  /** \brief the printer's graphics context, if there's one, NULL otherwise */
+  void *gc; 
+  /** \brief the constructor */
+  Fl_Abstract_Printer(void) { gc = NULL; bg_r_ = bg_g_ = bg_b_ = 0; };
+#ifdef __APPLE__
+  /** \brief deletes the page image list */
+  void delete_image_list(); 
+#endif
+public:
+  Fl_Device *set_current(void);
+  virtual int start_job(int pagecount, int *frompage = NULL, int *topage = 
NULL);
+  virtual int start_page(void);
+  virtual int printable_rect(int *w, int *h);
+  virtual void margins(int *left, int *top, int *right, int *bottom);
+  virtual void origin(int x, int y);
+  void origin(int *x, int *y);
+  virtual void scale(float scale_x, float scale_y);
+  virtual void rotate(float angle);
+  virtual void translate(int x, int y);
+  virtual void untranslate(void);
+  void print_widget(Fl_Widget* widget, int delta_x = 0, int delta_y = 0);
+  void print_window_part(Fl_Window *win, int x, int y, int w, int h, int 
delta_x = 0, int delta_y = 0);
+  virtual int end_page (void);
+  virtual void end_job (void);
+};
+
+#endif // Fl_Abstract_Printer_H
+
+//
+// End of "$Id: Fl_Abstract_Printer.H 7337 2010-03-25 16:05:00Z manolo $"
+//
+

Added: branches/branch-1.3-Fl_Printer/FL/Fl_Clipboard_Writer.H
===================================================================
--- branches/branch-1.3-Fl_Printer/FL/Fl_Clipboard_Writer.H                     
        (rev 0)
+++ branches/branch-1.3-Fl_Printer/FL/Fl_Clipboard_Writer.H     2010-04-05 
20:07:28 UTC (rev 7434)
@@ -0,0 +1,72 @@
+//
+// "$Id$"
+//
+// declaration of Fl_Clipboard_Writer class for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to:
+//
+//     http://www.fltk.org/str.php
+//
+
+#ifndef FL_CLIPBOARD_WRITER_H
+#define FL_CLIPBOARD_WRITER_H
+
+#include <FL/Fl_Device.H>
+
+/**
+ \brief Sends all graphics requests to the clipboard.
+ 
+ Presently implemented for the MSWindows and Mac OS X platforms only.
+ */
+class Fl_Clipboard_Writer : public Fl_Device {
+private:
+#ifdef __APPLE__
+  int width, height;
+  CFMutableDataRef pdfdata_;
+#endif
+  /** \brief the clipboard's graphics context, if there's one, NULL otherwise 
*/
+  void *gc;
+  void traverse(Fl_Widget *widget);
+  void translate(int x, int y);
+  void untranslate(void);
+  void copy_widget(Fl_Widget* widget, int delta_x, int delta_y);
+public:
+#ifdef __APPLE__
+  inline void bounds(int *pwidth, int *pheight) {*pwidth = width; *pheight = 
height; }
+#endif
+  /** \brief The constructor */
+  Fl_Clipboard_Writer() {type_ = clipboard;};
+  /** \brief To be called before any graphics request.
+   \param w The width in pixels of the clipboard drawing surface
+   \param h The height in pixels of the clipboard drawing surface
+   */
+  int start(int w, int h);
+  /** \brief Copies a widget of any kind to the clipboard */
+  inline void copy_widget(Fl_Widget* widget) { copy_widget(widget, 0, 0); };
+  /** \brief To be called after all graphics request were done */
+  int stop(void);
+  Fl_Device *set_current(void);
+};
+
+#endif // FL_CLIPBOARD_WRITER_H
+
+//
+// End of "$Id$".
+//

Added: branches/branch-1.3-Fl_Printer/FL/Fl_PSfile_Device.H
===================================================================
--- branches/branch-1.3-Fl_Printer/FL/Fl_PSfile_Device.H                        
        (rev 0)
+++ branches/branch-1.3-Fl_Printer/FL/Fl_PSfile_Device.H        2010-04-05 
20:07:28 UTC (rev 7434)
@@ -0,0 +1,269 @@
+//
+// "$Id: Fl_PSfile_Device.H 7356 2010-03-29 12:52:28Z manolo $"
+//
+// Support for graphics output to PostScript file for the Fast Light Tool Kit 
(FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems on the following page:
+//
+//     http://www.fltk.org/str.php
+//
+
+#include <FL/Fl_Printer.H> // must stay here
+
+#ifndef Fl_PSfile_Device_H
+#define Fl_PSfile_Device_H
+
+#define NO_PAGE_FORMATS 30 /* MSVC6 compilation fix */
+
+/**
+ \brief Sends all graphics to a local PostScript file; same API as Fl_Printer 
class.
+ *
+ This class has the same API as class Fl_Printer except for start_job() member 
function.
+ <p>PostScript text output is presently implemented only for the latin 
character set.
+ FLTK's standard fonts are output using PostScript's standard fonts: 
Helvetica, Courier, 
+ Times (and their bold, oblique, italic variants), Symbol, ZapfDingbats.
+ */
+FL_EXPORT class Fl_PSfile_Device : public  Fl_Abstract_Printer {
+  public: 
+    /**
+     \brief Possible page formats.
+     */
+    enum Page_Format {
+      A0 = 0,
+      A1,
+      A2,
+      A3,
+      A4,
+      A5,
+      A6,
+      A7,
+      A8,
+      A9,
+      B0,
+      B1,
+      B2,
+      B3,
+      B4,
+      B5,
+      B6,
+      B7,
+      B8,
+      B9,
+      B10,
+      C5E,
+      DLE,
+      EXECUTIVE,
+      FOLIO,
+      LEDGER,
+      LEGAL,
+      LETTER,
+      TABLOID,
+      ENVELOPE,
+      MEDIA = 0x1000
+    };
+    
+    /**
+     \brief Possible page layouts.
+     */
+    enum Page_Layout {PORTRAIT = 0, LANDSCAPE = 0x100, REVERSED = 0x200, 
ORIENTATION = 0x300};
+    
+#ifndef FL_DOXYGEN
+  private:
+    enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS};
+    
+    class Clip{
+    public:
+      int x, y, w, h;
+      Clip *prev;
+    };
+    Clip * clip_;
+    
+    int lang_level_;
+    int font_;
+    int size_;
+    Fl_Color color_;
+    int gap_;
+    int pages_;
+    
+    double width_;
+    double height_;
+    
+    int shape_;
+    int linewidth_;// need for clipping, lang level 1-2
+    int linestyle_;//
+    int interpolate_; //interpolation of images
+    unsigned char cr_,cg_,cb_;
+    char  linedash_[256];//should be enought
+    void concat();  // transform ror scalable dradings...
+    void reconcat(); //invert
+    void recover(); //recovers the state afrer grestore (such as line 
styles...)
+    void reset();
+    
+    uchar * mask;
+    int mx; // width of mask;
+    int my; // mask lines
+    //Fl_Color bg_;
+    int (*close_cmd_)(FILE *);
+    int page_policy_;
+    int nPages;
+    int orientation_;
+    
+    float scale_x;
+    float scale_y;
+    float angle;
+    int left_margin;
+    int top_margin;
+  protected:
+    typedef struct page_format {
+      int width;
+      int height;
+      const char *name;
+    } page_format;
+   
+    FILE *output;
+    double pw_, ph_;
+    static const page_format page_formats[NO_PAGE_FORMATS];
+    
+    uchar bg_r, bg_g, bg_b;
+    int start_postscript (int pagecount, enum Page_Format format, enum 
Page_Layout layout);
+    /*  int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
+     */
+    void draw(const char* s, int n, int x, int y) {transformed_draw(s,n,x,y); 
};
+    void draw(int angle, const char *str, int n, int x, int y);
+    void transformed_draw(const char* s, int n, double x, double y); //precise 
text placing
+    void transformed_draw(const char* s, double x, double y);
+    int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
+    void draw_scaled_image(const uchar *data, double x, double y, double w, 
double h, int iw, int ih, int D=3, int LD=0);
+    void draw_scaled_image_mono(const uchar *data, double x, double y, double 
w, double h, int iw, int ih, int D=3, int LD=0);
+    void draw_scaled_image(Fl_Draw_Image_Cb call, void *data, double x, double 
y, double w, double h, int iw, int ih, int D);
+    void draw_scaled_image_mono(Fl_Draw_Image_Cb call, void *data, double x, 
double y, double w, double h, int iw, int ih, int D);
+    
+    enum Page_Format page_format_;
+    char *ps_filename_;
+    // implementation of drawing methods
+    void color(Fl_Color c);
+    //void bg_color(Fl_Color bg);
+    void color(uchar r, uchar g, uchar b);
+    Fl_Color color(){return color_;};
+    
+    void push_clip(int x, int y, int w, int h);
+    int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
+    int not_clipped(int x, int y, int w, int h);
+    void push_no_clip();
+    void pop_clip();
+    
+    void line_style(int style, int width=0, char* dashes=0);
+    
+    void rect(int x, int y, int w, int h);
+    void rectf(int x, int y, int w, int h);
+    
+    void xyline(int x, int y, int x1);
+    void xyline(int x, int y, int x1, int y2);
+    void xyline(int x, int y, int x1, int y2, int x3);
+    
+    void yxline(int x, int y, int y1);
+    void yxline(int x, int y, int y1, int x2);
+    void yxline(int x, int y, int y1, int x2, int y3);
+    
+    void line(int x1, int y1, int x2, int y2);
+    void line(int x1, int y1, int x2, int y2, int x3, int y3);  
+    
+    void loop(int x0, int y0, int x1, int y1, int x2, int y2);
+    void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
+    void polygon(int x0, int y0, int x1, int y1, int x2, int y2);
+    void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int 
y3);
+    void point(int x, int y);
+    
+    void begin_points();
+    void begin_line();
+    void begin_loop();
+    void begin_polygon();
+    void vertex(double x, double y);
+    void curve(double x, double y, double x1, double y1, double x2, double y2, 
double x3, double y3);
+    void circle(double x, double y, double r);
+    void arc(double x, double y, double r, double start, double a);
+    void arc(int x, int y, int w, int h, double a1, double a2);
+    void pie(int x, int y, int w, int h, double a1, double a2);
+    void end_points();
+    void end_line();
+    void end_loop();
+    void end_polygon();
+    void begin_complex_polygon(){begin_polygon();};
+    void gap(){gap_=1;};
+    void end_complex_polygon(){end_polygon();};
+    void transformed_vertex(double x, double y);
+    
+    void font(int face, int size);
+    int font(){return font_;};
+    int size(){return size_;};
+    double width(unsigned c);
+    double width(const char* s, int n);
+    int descent();
+    int height();
+    
+    void draw_image(const uchar* d, int x,int y,int w,int h, int delta=3, int 
ldelta=0){draw_scaled_image(d,x,y,w,h,w,h,delta,ldelta);};
+    void draw_image_mono(const uchar* d, int x,int y,int w,int h, int delta=1, 
int ld=0){draw_scaled_image_mono(d,x,y,w,h,w,h,delta,ld);};
+    void draw_image(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int 
h, int delta=3){draw_scaled_image(call,data, x, y, w, h, w, h, delta);};
+    void draw_image_mono(Fl_Draw_Image_Cb call, void* data, int x,int y, int 
w, int h, int delta=1){draw_scaled_image_mono(call, data, x, y, w, h, w, h, 
delta);};
+    
+    void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
+    void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int 
cy);
+    void draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int 
cy);
+    
+  public:
+    void page_policy(int p);
+    int page_policy(){return page_policy_;};
+    void close_command( int (*cmd)(FILE *)){close_cmd_=cmd;};
+    FILE * file() {return output;};
+    //void orientation (int o);
+    //Fl_PSfile_Device(FILE *o, int lang_level, int pages = 0); // ps (also 
multi-page) constructor
+    //Fl_PSfile_Device(FILE *o, int lang_level, int x, int y, int w, int h); 
//eps constructor
+    void interpolate(int i){interpolate_=i;};
+    int interpolate(){return interpolate_;}
+    
+    void page(double pw, double ph, int media = 0);
+    void page(int format);
+    
+    void place(double x, double y, double tx, double ty, double scale = 1);
+    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 scale (float scale_x, float scale_y);
+    void rotate(float angle);
+    void translate(int x, int y);
+    void untranslate(void);
+    int end_page (void);    
+    void end_job(void);
+#endif // FL_DOXYGEN
+  Fl_PSfile_Device(void);
+  int start_job(int pagecount, enum Page_Format format = A4, enum Page_Layout 
layout = PORTRAIT);
+  int start_job(FILE *ps_output, int pagecount, enum Page_Format format = A4, 
enum Page_Layout layout = PORTRAIT);
+  virtual ~Fl_PSfile_Device();
+  
+  /** [this text may be customized at run-time] */
+  static const char *file_chooser_title; 
+};
+
+#endif // Fl_PSfile_Device_H
+
+//
+// End of "$Id: Fl_PSfile_Device.H 7356 2010-03-29 12:52:28Z manolo $"
+//

Added: branches/branch-1.3-Fl_Printer/src/Fl_Abstract_Printer.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Abstract_Printer.cxx                  
        (rev 0)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Abstract_Printer.cxx  2010-04-05 
20:07:28 UTC (rev 7434)
@@ -0,0 +1,295 @@
+//
+// "$Id: Fl_Abstract_Printer.cxx 7364 2010-03-30 12:09:09Z manolo $"
+//
+// implementation of Fl_Abstract_Printer class for the Fast Light Tool Kit 
(FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to:
+//
+//     http://www.fltk.org/str.php
+//
+/** \file Fl_Abstract_Printer.cxx
+ \brief implementation of class Fl_Abstract_Printer.
+ */
+
+#include <FL/Fl.H>
+#include <FL/Fl_Printer.H>
+
+/**
+ @brief Draws the widget on the printed page.
+ *
+ The widget's position on the printed page is determined by the last call to 
origin()
+ and by the optional delta_x and delta_y arguments.
+ Its dimensions are in points unless there was a previous call to scale().
+ @param[in] widget Any FLTK widget (e.g., standard, custom, window).
+ @param[in] delta_x Optional horizontal offset for positioning the widget 
relatively
+ to the current origin of graphics functions.
+ @param[in] delta_y Same as above, vertically.
+ */
+void Fl_Abstract_Printer::print_widget(Fl_Widget* widget, int delta_x, int 
delta_y) 
+{ 
+  int old_x, old_y, new_x, new_y, is_window;
+  if ( ! widget->visible() ) return;
+  is_window = (widget->as_window() != NULL);
+  widget->damage(FL_DAMAGE_ALL);
+  // set origin to the desired top-left position of the widget
+  origin(&old_x, &old_y);
+  new_x = old_x + delta_x;
+  new_y = old_y + delta_y;
+  if (!is_window) {
+    new_x -= widget->x();
+    new_y -= widget->y();
+  }
+  if (new_x != old_x || new_y != old_y) {
+    translate(new_x - old_x, new_y - old_y );
+  }
+  // if widget is a window, clip all drawings to the window area
+  if (is_window) fl_push_clip(0, 0, widget->w(), widget->h() );
+  // we do some trickery to recognize OpenGL windows and draw them via a plugin
+  int drawn_by_plugin = 0;
+  if (widget->as_gl_window()) {
+    Fl_Plugin_Manager pm("fltk:device");  
+    Fl_Device_Plugin *pi = 
(Fl_Device_Plugin*)pm.plugin("opengl.device.fltk.org");
+    if (pi) drawn_by_plugin = pi->print(this, widget, 0, 0);
+  }
+  if (!drawn_by_plugin) {
+    widget->draw();
+  }
+  if (is_window) fl_pop_clip();
+  // find subwindows of widget and print them
+  traverse(widget);
+  // reset origin to where it was
+  if (new_x != old_x || new_y != old_y) {
+    untranslate();
+  }
+}
+
+
+void Fl_Abstract_Printer::traverse(Fl_Widget *widget)
+{
+  Fl_Group *g = widget->as_group();
+  if (!g) return;
+  int n = g->children();
+  for (int i = 0; i < n; i++) {
+    Fl_Widget *c = g->child(i);
+    if ( !c->visible() ) continue;
+    if ( c->as_window() ) {
+      print_widget(c, c->x(), c->y());
+    }
+    else traverse(c);
+  }
+}
+
+/**
+ @brief Computes the page coordinates of the current origin of graphics 
functions.
+ *
+ @param[out] x If non-null, *x is set to the horizontal page offset of 
graphics origin.
+ @param[out] y Same as above, vertically.
+ */
+void Fl_Abstract_Printer::origin(int *x, int *y)
+{
+  if (x) *x = x_offset;
+  if (y) *y = y_offset;
+}
+
+/**
+ @brief Prints a rectangular part of an on-screen window.
+ *
+ @param win The window from where to capture.
+ @param x The rectangle left
+ @param y The rectangle top
+ @param w The rectangle width
+ @param h The rectangle height
+ @param delta_x Optional horizontal offset from current graphics origin where 
to print the captured rectangle.
+ @param delta_y As above, vertically.
+ */
+void Fl_Abstract_Printer::print_window_part(Fl_Window *win, int x, int y, int 
w, int h, int delta_x, int delta_y)
+{
+  int slice, width, offset, count = 0;
+  Fl_Device::display_device()->set_current();
+  Fl_Window *save_front = Fl::first_window();
+  win->show();
+  fl_gc = NULL;
+  Fl::check();
+  win->make_current();
+  uchar *image_data[20];
+#ifdef WIN32 // because of bug in StretchDIBits, vertically cut image in 
pieces of width slice
+  slice = 500;
+#else
+  slice = w;
+#endif
+  for ( offset = 0; offset < w; offset += slice) {
+    width = slice; 
+    if (offset + width > w) width = w - offset;
+    image_data[count++] = fl_read_image(NULL, x + offset, y, width, h);
+  }  
+  save_front->show();
+  this->set_current();
+  for ( int i = 0, offset = 0; i < count; i++, offset += slice) {
+    width = slice; 
+    if (offset + width > w) width = w - offset;
+    fl_draw_image(image_data[i], delta_x + offset, delta_y, width, h, 3);
+#ifdef __APPLE__
+    add_image(NULL, image_data[i]);
+#else
+    delete image_data[i];
+#endif
+  }
+}
+
+#ifdef __APPLE__
+void Fl_Abstract_Printer::add_image(Fl_Image *image, const uchar *data)
+{
+  struct chain_elt *elt =  (struct chain_elt *)calloc(sizeof(struct 
chain_elt), 1);
+  elt->image = image;
+  elt->data = data;
+  if (image_list_) { elt->next = image_list_; }
+  image_list_ = elt;
+}
+
+void Fl_Abstract_Printer::delete_image_list()
+{
+  while(image_list_) {
+    struct chain_elt *next = image_list_->next;
+    if(image_list_->image) delete image_list_->image;
+    if (image_list_->data) delete (uchar*) image_list_->data; // msvc6 
compilation fix
+    free(image_list_);
+    image_list_ = next;
+  }
+}
+#endif
+
+Fl_Device *Fl_Abstract_Printer::set_current(void)
+{
+#ifdef __APPLE__
+  fl_gc = (CGContextRef)gc;
+#elif defined(WIN32)
+  fl_gc = (HDC)gc;
+#else
+  fl_gc = (_XGC*)gc;
+#endif
+  return this->Fl_Device::set_current();
+}
+
+
+/**
+ @brief Starts a print job.
+ *
+ @param[in] pagecount the total number of pages of the job
+ @param[out] frompage if non-null, *frompage is set to the first page the user 
wants printed
+ @param[out] topage if non-null, *topage is set to the last page the user 
wants printed
+ @return 0 iff OK
+ */
+int Fl_Abstract_Printer::start_job(int pagecount, int *frompage, int *topage) 
{return 1;}
+
+/**
+ @brief Starts a new printed page
+ *
+ The page coordinates are initially in points, i.e., 1/72 inch, 
+ and with origin at the top left of the printable page area.
+ @return 0 iff OK
+ */
+int Fl_Abstract_Printer::start_page (void) {return 1;}
+
+/**
+ @brief Computes the width and height of the printable area of the page.
+ *
+ Values are in the same unit as that used by FLTK drawing functions,
+ are unchanged by calls to origin(), but are changed by scale() calls.
+ Values account for the user-selected paper type and print orientation.
+ @return 0 iff OK.
+ */
+int Fl_Abstract_Printer::printable_rect(int *w, int *h) {return 1;}
+
+/**
+ @brief Computes the dimensions of margins that lie between the printable page 
area and
+ the full page.
+ *
+ Values are in the same unit as that used by FLTK drawing functions. They are 
changed
+ by scale() calls.
+ @param[out] left If non-null, *left is set to the left margin size.
+ @param[out] top If non-null, *top is set to the top margin size.
+ @param[out] right If non-null, *right is set to the right margin size.
+ @param[out] bottom If non-null, *bottom is set to the bottom margin size.
+ */
+void Fl_Abstract_Printer::margins(int *left, int *top, int *right, int 
*bottom) {}
+
+/**
+ @brief Sets the position in page coordinates of the origin of graphics 
functions.
+ *
+ Arguments should be expressed relatively to the result of a previous 
printable_rect() call.
+ That is, <tt>printable_rect(&w, &h); origin(w/2, 0);</tt> sets the graphics 
origin at the
+ top center of the page printable area.
+ Origin() calls are not affected by rotate() calls.
+ Successive origin() calls don't combine their effects.
+ @param[in] x Horizontal position in page coordinates of the desired origin of 
graphics functions.
+ @param[in] y Same as above, vertically.
+ */
+void Fl_Abstract_Printer::origin(int x, int y) {}
+
+/**
+ @brief Changes the scaling of page coordinates.
+ *
+ This function also resets the origin of graphics functions at top left of 
printable page area.
+ After a scale() call, do a printable_rect() call to get the new dimensions of 
the printable page area.
+ Successive scale() calls don't combine their effects.
+ @param scale_x Horizontal dimensions of plot are multiplied by this quantity.
+ @param scale_y Same as above, vertically.
+ */
+void Fl_Abstract_Printer::scale (float scale_x, float scale_y) {}
+
+/**
+ @brief Rotates the graphics operations relatively to paper.
+ *
+ The rotation is centered on the current graphics origin. 
+ Successive rotate() calls don't combine their effects.
+ @param angle Rotation angle in counterclockwise degrees.
+ */
+void Fl_Abstract_Printer::rotate(float angle) {}
+
+/**
+ @brief To be called at the end of each page.
+ *
+ @return 0 iff OK.
+ */
+int Fl_Abstract_Printer::end_page (void) {return 1;}
+
+/**
+ @brief To be called at the end of a print job.
+ */
+void Fl_Abstract_Printer::end_job (void) {}
+
+/**
+ @brief Translates the current graphics origin accounting for the current 
rotation.
+ *
+ This function is only useful after a rotate() call. 
+ Each translate() call must be matched by an untranslate() call.
+ Successive translate() calls add up their effects.
+ */
+void Fl_Abstract_Printer::translate(int x, int y) {}
+
+/**
+ @brief Undoes the effect of a previous translate() call.
+ */
+void Fl_Abstract_Printer::untranslate(void) {}
+
+//
+// End of "$Id: Fl_Abstract_Printer.cxx 7364 2010-03-30 12:09:09Z manolo $".
+//
+

Added: branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer.cxx                  
        (rev 0)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer.cxx  2010-04-05 
20:07:28 UTC (rev 7434)
@@ -0,0 +1,113 @@
+//
+// "$Id$"
+//
+// implementation of Fl_Clipboard_Writer class for the Fast Light Tool Kit 
(FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to:
+//
+//     http://www.fltk.org/str.php
+//
+
+#ifdef __APPLE__
+#include "Fl_Clipboard_Writer_mac.cxx"
+#elif defined(WIN32)
+#include "Fl_Clipboard_Writer_win32.cxx"
+#endif
+
+#include <FL/Fl_Printer.H>
+
+#if !(defined(WIN32) || defined(__APPLE__))
+// not implemented yet
+int Fl_Clipboard_Writer::start(int w, int h) {}
+int Fl_Clipboard_Writer::stop(void) {}
+void Fl_Clipboard_Writer::translate(int x, int y) {}
+void Fl_Clipboard_Writer::untranslate(void) {}
+#endif
+
+Fl_Device *Fl_Clipboard_Writer::set_current(void)
+{
+#ifdef __APPLE__
+  fl_gc = (CGContextRef)gc;
+#elif defined(WIN32)
+  fl_gc = (HDC)gc;
+#else
+  fl_gc = (_XGC*)0;
+#endif
+  return this->Fl_Device::set_current();
+}
+
+void Fl_Clipboard_Writer::copy_widget(Fl_Widget* widget, int delta_x, int 
delta_y) 
+{ 
+  int new_x, new_y, is_window;
+  if ( ! widget->visible() ) return;
+  is_window = (widget->as_window() != NULL);
+  widget->damage(FL_DAMAGE_ALL);
+  // set origin to the desired top-left position of the widget
+  new_x = delta_x;
+  new_y = delta_y;
+  if (!is_window) {
+    new_x -= widget->x();
+    new_y -= widget->y();
+  }
+  if (new_x != 0 || new_y != 0) {
+    translate(new_x, new_y );
+  }
+#ifndef WIN32 // doesn't  work on WIN32. Why ?
+  // if widget is a window, clip all drawings to the window area
+  if (is_window) fl_push_clip(0, 0, widget->w(), widget->h() );
+#endif
+  // we do some trickery to recognize OpenGL windows and draw them via a plugin
+  int drawn_by_plugin = 0;
+  if (widget->as_gl_window()) {
+     Fl_Plugin_Manager pm("fltk:device");  
+     Fl_Device_Plugin *pi = 
(Fl_Device_Plugin*)pm.plugin("opengl.device.fltk.org");
+     if (pi) drawn_by_plugin = pi->copy(this, widget, 0, 0);
+  }
+  if (!drawn_by_plugin) {
+    widget->draw();
+  }
+  if (is_window) fl_pop_clip();
+  // find subwindows of widget and print them
+  traverse(widget);
+  // reset origin to where it was
+  if (new_x != 0 || new_y != 0) {
+    untranslate();
+  }
+}
+
+void Fl_Clipboard_Writer::traverse(Fl_Widget *widget)
+{
+  Fl_Group *g = widget->as_group();
+  if (!g) return;
+  int n = g->children();
+  for (int i = 0; i < n; i++) {
+    Fl_Widget *c = g->child(i);
+    if ( !c->visible() ) continue;
+    if ( c->as_window() ) {
+      copy_widget(c, c->x(), c->y());
+    }
+    else traverse(c);
+  }
+}
+
+//
+// End of "$Id$".
+//
+

Added: branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer_mac.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer_mac.cxx              
                (rev 0)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer_mac.cxx      
2010-04-05 20:07:28 UTC (rev 7434)
@@ -0,0 +1,175 @@
+//
+// "$Id$"
+//
+// mac implementation of Fl_Clipboard_Writer class for the Fast Light Tool Kit 
(FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to:
+//
+//     http://www.fltk.org/str.php
+//
+
+#ifdef __APPLE__
+
+#include <FL/Fl_Clipboard_Writer.H>
+#include <FL/x.H>
+#include <FL/fl_draw.H>
+#include <QuickTime/ImageCompression.h>
+
+static size_t MyPutBytes (void* info, const void* buffer, size_t count)
+{
+  CFDataAppendBytes ((CFMutableDataRef) info, (const UInt8 *)buffer, count);
+  return count;
+}
+
+int Fl_Clipboard_Writer::start(int w, int h)
+{
+  Fl_X::q_release_context();
+  width = w;
+  height = h;
+  //prepare to draw in pdf context
+  CGRect bounds = CGRectMake(0, 0, w, h );     
+  pdfdata_ = CFDataCreateMutable(NULL, 0);
+  CGDataConsumerRef myconsumer;
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+  if(CGDataConsumerCreateWithCFData != NULL) {
+    myconsumer = CGDataConsumerCreateWithCFData (pdfdata_);
+    }
+  else
+#endif
+    {
+    static CGDataConsumerCallbacks callbacks = { MyPutBytes, NULL };
+    myconsumer = CGDataConsumerCreate ((void*) pdfdata_, &callbacks);
+    }
+  fl_gc = CGPDFContextCreate (myconsumer, &bounds, NULL);
+  CGDataConsumerRelease (myconsumer);
+  if (fl_gc == NULL) return 1;
+  CGContextBeginPage (fl_gc, NULL);
+  CGContextTranslateCTM(fl_gc, 0, h);
+  CGContextScaleCTM(fl_gc, 1.0f, -1.0f);
+  CGContextSaveGState(fl_gc);
+  fl_window = (void *)1; // TODO: something better
+  fl_clip_region(0);
+  fl_line_style(FL_SOLID);
+  gc = fl_gc;
+  return 0;
+}
+
+int Fl_Clipboard_Writer::stop(void)
+{
+  int w, h;
+  CGContextRestoreGState(fl_gc);
+  // first, write the pdf data to the clipboard
+  w = width; h = height;
+  CGContextEndPage (fl_gc);
+  CGContextRelease (fl_gc);
+  PasteboardRef clipboard = NULL;
+  PasteboardCreate (kPasteboardClipboard, &clipboard);
+  PasteboardClear(clipboard);
+  PasteboardPutItemFlavor (clipboard, (PasteboardItemID)1, 
+                          CFSTR("com.adobe.pdf"), // kUTTypePDF
+                          pdfdata_, kPasteboardFlavorNoFlags);
+    
+  // second, transform this PDF to a bitmap image and put it as PICT/tiff in 
clipboard
+  CGDataProviderRef prov = CGDataProviderCreateWithData(NULL, 
CFDataGetBytePtr(pdfdata_), CFDataGetLength(pdfdata_), NULL);
+  CGPDFDocumentRef pdfdoc = CGPDFDocumentCreateWithProvider(prov);
+  CGDataProviderRelease(prov);
+  CGColorSpaceRef space = 
CGColorSpaceCreateWithName(/*kCGColorSpaceGenericRGB*/ kCGColorSpaceUserRGB);
+  const int scale = 2;
+  w *= scale; h *= scale;
+  void *mem = malloc(w * h * sizeof(int));
+  fl_gc = CGBitmapContextCreate(mem, w, h, 8, w * 4, space, 
kCGImageAlphaPremultipliedFirst /*| kCGBitmapByteOrder32Host*/);
+  CFRelease(space);
+  if (fl_gc == NULL) { free(mem); return 1; }
+  CGRect rect = CGRectMake(0, 0, w, h);
+  CGContextSetRGBFillColor(fl_gc,  1,1,1,1);//need to clear background
+  CGContextFillRect(fl_gc, rect);
+  CGContextDrawPDFDocument(fl_gc, rect, pdfdoc, 1);
+  CGPDFDocumentRelease(pdfdoc);
+  CFRelease(pdfdata_);
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+  if(CGImageDestinationCreateWithData != NULL) {
+    CFMutableDataRef pictdata = CFDataCreateMutable(NULL, 0);
+#if __LP64__
+    CFStringRef  uti = CFSTR("public.tiff");
+#else
+    CFStringRef  uti = CFSTR("com.apple.pict");
+#endif
+    CGImageRef image = CGBitmapContextCreateImage(fl_gc);
+    CGImageDestinationRef dest = CGImageDestinationCreateWithData(pictdata, 
uti, 1, NULL);
+    CGImageDestinationAddImage(dest, image, NULL);
+    CGImageDestinationFinalize(dest);
+    CGImageRelease(image);
+    CFRelease(dest);
+#if !__LP64__
+    CFRange range = CFRangeMake(0, 512);
+    CFDataDeleteBytes(pictdata, range);// The PICT clipboard REQUIRES only the 
image data, not the header.
+#endif
+    PasteboardPutItemFlavor(clipboard, (PasteboardItemID)1, uti, pictdata, 
kPasteboardFlavorNoFlags );
+    CFRelease (pictdata);
+    }
+  else
+#endif
+  { // other way for < 10.4 that uses QuickTime:
+    GraphicsExportComponent exporter;
+    OSErr err = OpenADefaultComponent(GraphicsExporterComponentType, 
/*kQTFileTypePicture*/ 'PICT', &exporter);
+    err = GraphicsExportSetInputCGBitmapContext(exporter, fl_gc);
+    Handle dataHandle = NewHandle(0);
+    err = GraphicsExportSetOutputHandle(exporter, dataHandle);
+    unsigned long size;
+    err = GraphicsExportDoExport(exporter, &size);
+    err = CloseComponent(exporter); 
+    if(GetHandleSize(dataHandle) > 512) {
+      HLock(dataHandle);
+      // The clipboard REQUIRES only the image data, not the header.
+      CFDataRef pictdata = CFDataCreate(NULL, (const UInt8 *)*dataHandle + 
512, GetHandleSize(dataHandle) - 512);
+      HUnlock(dataHandle);
+      PasteboardPutItemFlavor(clipboard, (PasteboardItemID)1, 
+                             CFSTR("com.apple.pict"),
+                             pictdata,
+                             kPasteboardFlavorNoFlags ); 
+      CFRelease (pictdata);    
+    }
+    DisposeHandle(dataHandle);
+  }
+  CFRelease (clipboard);    
+  CGContextRelease(fl_gc);
+  fl_gc = NULL;
+  free(mem);
+  return 0;
+}
+
+void Fl_Clipboard_Writer::translate(int x, int y)
+{
+  CGContextSaveGState(fl_gc);
+  CGContextTranslateCTM(fl_gc, x, y );
+  CGContextSaveGState(fl_gc);
+}
+
+void Fl_Clipboard_Writer::untranslate(void)
+{
+  CGContextRestoreGState(fl_gc);
+  CGContextRestoreGState(fl_gc);
+}
+
+#endif // __APPLE__
+
+//
+// End of "$Id$".
+//

Added: branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer_win32.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer_win32.cxx            
                (rev 0)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer_win32.cxx    
2010-04-05 20:07:28 UTC (rev 7434)
@@ -0,0 +1,114 @@
+//
+// "$Id$"
+//
+// MSWin implementation of Fl_Clipboard_Writer class for the Fast Light Tool 
Kit (FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to:
+//
+//     http://www.fltk.org/str.php
+//
+
+#ifdef WIN32
+
+#include <FL/Fl_Clipboard_Writer.H>
+#include <FL/x.H>
+#include <FL/fl_draw.H>
+
+
+int Fl_Clipboard_Writer::start(int w, int h)
+{
+  HDC oldflgc = fl_gc;
+  int factor = 32; // empirically set
+  RECT rect; rect.left = 0; rect.top = 0; rect.right=w*factor; 
rect.bottom=h*factor;
+  fl_gc = CreateEnhMetaFile (NULL, NULL, &rect, NULL);
+  if (fl_gc != NULL) {
+    SetGraphicsMode(fl_gc, GM_ADVANCED); // to allow for translations
+    SetTextAlign(fl_gc, TA_BASELINE|TA_LEFT);
+    SetBkMode(fl_gc, TRANSPARENT);
+  } 
+  else {
+    fl_gc = oldflgc;
+    return 1;
+  }
+  fl_clip_region(0);
+  fl_color(FL_BLACK);
+  fl_line_style(FL_SOLID);
+SelectObject(fl_gc, (HGDIOBJ)(fl_current_xmap->pen));
+  gc = fl_gc;
+  this->set_current();
+  return 0;
+}
+
+int Fl_Clipboard_Writer::stop(void)
+{
+  int w, h;
+  HENHMETAFILE hmf = CloseEnhMetaFile (fl_gc);
+  if ( hmf != NULL ) {
+    if ( OpenClipboard (NULL) ){
+      EmptyClipboard ();
+      SetClipboardData (CF_ENHMETAFILE, hmf);
+      CloseClipboard ();
+    }
+    DeleteEnhMetaFile(hmf);
+  }
+  DeleteDC(fl_gc);
+  Fl_Device::display_device()->set_current();
+  fl_gc = NULL;
+  return 0;
+}
+
+static int translate_stack_depth = 0;
+const int translate_stack_max = 5;
+static int translate_stack_x[translate_stack_max];
+static int translate_stack_y[translate_stack_max];
+
+static void do_translate(int x, int y)
+{
+  XFORM tr;
+  tr.eM11 = tr.eM22 = 1;
+  tr.eM12 = tr.eM21 = 0;
+  tr.eDx =  x;
+  tr.eDy =  y;
+  ModifyWorldTransform(fl_gc, &tr, MWT_LEFTMULTIPLY);
+}
+
+void Fl_Clipboard_Writer::translate(int x, int y)
+{
+  do_translate(x, y);
+  if (translate_stack_depth < translate_stack_max) {
+    translate_stack_x[translate_stack_depth] = x;
+    translate_stack_y[translate_stack_depth] = y;
+    translate_stack_depth++;
+  }
+}
+
+void Fl_Clipboard_Writer::untranslate(void)
+{
+  if (translate_stack_depth > 0) {
+    translate_stack_depth--;
+    do_translate( - translate_stack_x[translate_stack_depth], - 
translate_stack_y[translate_stack_depth] );
+  }
+}
+
+#endif // WIN32
+
+//
+// End of "$Id$".
+//

Added: branches/branch-1.3-Fl_Printer/src/Fl_Gl_Device_Plugin.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Gl_Device_Plugin.cxx                  
        (rev 0)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Gl_Device_Plugin.cxx  2010-04-05 
20:07:28 UTC (rev 7434)
@@ -0,0 +1,164 @@
+//
+// "$Id: Fl_Gl_Device_Plugin.cxx 7348 2010-03-28 06:58:39Z manolo $"
+//
+// implementation of class Fl_Gl_Device_Plugin for the Fast Light Tool Kit 
(FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to:
+//
+//     http://www.fltk.org/str.php
+//
+
+#include <FL/Fl_Printer.H>
+#include <FL/Fl_Clipboard_Writer.H>
+#include <FL/Fl_Gl_Window.H>
+#include "Fl_Gl_Choice.H"
+#include "FL/Fl.H"
+#ifndef __APPLE__
+#include "FL/fl_draw.H"
+#endif
+
+#if defined(__APPLE__)
+static void imgProviderReleaseData (void *info, const void *data, size_t size)
+{
+  free((void *)data);
+}
+#endif
+
+static void print_gl_window(Fl_Abstract_Printer *printer, Fl_Clipboard_Writer 
*clipboard, Fl_Gl_Window *glw, int x, int y)
+{
+#ifdef WIN32
+  HDC save_gc = fl_gc;
+  const int bytesperpixel = 3;
+#elif defined(__APPLE__)
+  CGContextRef save_gc = fl_gc;
+  const int bytesperpixel = 4;
+#else
+  _XGC *save_gc = fl_gc;
+  const int bytesperpixel = 3;
+#endif
+  fl_gc = NULL;
+#ifdef WIN32
+  Fl::check();
+  Fl_Window *win = (Fl_Window*)glw;
+  while( win->window() ) win = win->window();
+  win->redraw();
+  Fl::check();
+  glw->make_current();
+#else
+  glw->make_current();
+  glw->redraw();
+  glFlush();
+  Fl::check();
+  glFinish();
+#endif
+  // Read OpenGL context pixels directly.
+  // For extra safety, save & restore OpenGL states that are changed
+  glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
+  glPixelStorei(GL_PACK_ALIGNMENT, 4); /* Force 4-byte alignment */
+  glPixelStorei(GL_PACK_ROW_LENGTH, 0);
+  glPixelStorei(GL_PACK_SKIP_ROWS, 0);
+  glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
+  // Read a block of pixels from the frame buffer
+  int mByteWidth = glw->w() * bytesperpixel;                
+  mByteWidth = (mByteWidth + 3) & ~3;    // Align to 4 bytes
+  uchar *baseAddress = (uchar*)malloc(mByteWidth * glw->h());
+  glReadPixels(0, 0, glw->w(), glw->h(), 
+#ifdef WIN32
+              GL_RGB, GL_UNSIGNED_BYTE,
+#elif defined(__APPLE__)
+              GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
+#else // FIXME Linux/Unix
+              GL_RGB, GL_UNSIGNED_BYTE,
+#endif
+              baseAddress);
+  glPopClientAttrib();
+  fl_gc = save_gc;
+#if defined(__APPLE__)
+#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
+#define kCGBitmapByteOrder32Big 0
+#define CGBitmapInfo CGImageAlphaInfo
+#endif
+  CGColorSpaceRef cSpace = CGColorSpaceCreateDeviceRGB();
+  CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, baseAddress, 
mByteWidth * glw->h(), imgProviderReleaseData);
+  CGImageRef image = CGImageCreate(glw->w(), glw->h(), 8, 8*bytesperpixel, 
mByteWidth, cSpace,
+#if __BIG_ENDIAN__
+               (CGBitmapInfo)(kCGImageAlphaNoneSkipFirst | 
kCGBitmapByteOrder32Big) /* XRGB Big Endian */
+#else
+                 kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little /* 
XRGB Little Endian */
+#endif
+   , provider, NULL, false, kCGRenderingIntentDefault);
+  if(image == NULL) return;
+  CGContextSaveGState(fl_gc);
+  int w, h;
+  if(printer) printer->printable_rect(&w, &h);
+  else clipboard->bounds(&w, &h);
+  CGContextTranslateCTM(fl_gc, 0, h);
+  CGContextScaleCTM(fl_gc, 1.0f, -1.0f);
+  CGRect rect = { { x, h - y - glw->h() }, { glw->w(), glw->h() } };
+  Fl_X::q_begin_image(rect, 0, 0, glw->w(), glw->h());
+  CGContextDrawImage(fl_gc, rect, image);
+  Fl_X::q_end_image();
+  CGContextRestoreGState(fl_gc);
+  CGImageRelease(image);
+  CGColorSpaceRelease(cSpace);
+  CGDataProviderRelease(provider);  
+#else
+  fl_draw_image(baseAddress + (glw->h() - 1) * mByteWidth, x, y , glw->w(), 
glw->h(), bytesperpixel, - mByteWidth);
+  free(baseAddress);
+#endif // __APPLE__
+}
+
+/**
+ This class will make sure that OpenGL printing is available if fltk_gl
+ was linked to the program.
+ */
+class Fl_Gl_Device_Plugin : public Fl_Device_Plugin {
+public:
+  Fl_Gl_Device_Plugin() : Fl_Device_Plugin(name()) { }
+  /** \brief Returns the plugin name */
+  virtual const char *name() { return "opengl.device.fltk.org"; }
+  /** \brief Prints a widget 
+   \param p the printer
+   \param w the widget
+   \param x,y offsets where to print relatively to coordinates origin
+   */
+  virtual int print(Fl_Abstract_Printer *p, Fl_Widget *w, int x, int y) {
+    Fl_Gl_Window *glw = w->as_gl_window();
+    if (!glw) return 0;
+    print_gl_window(p, NULL, glw, x, y);
+    return 1; 
+  }
+  virtual int copy(Fl_Clipboard_Writer *c, Fl_Widget *w, int x, int y) {
+    Fl_Gl_Window *glw = w->as_gl_window();
+    if (!glw) return 0;
+    print_gl_window(NULL, c, glw, x, y);
+    return 1; 
+  }
+};
+
+static Fl_Gl_Device_Plugin Gl_Device_Plugin;
+
+// The purpose of this variable, used in Fl_Gl_Window.cxx, is only to force 
this file to be loaded
+// whenever Fl_Gl_Window.cxx is loaded, that is, whenever fltk_gl is.
+FL_EXPORT int fl_gl_load_plugin = 0;
+
+//
+// End of "$Id: Fl_Gl_Device_Plugin.cxx 7348 2010-03-28 06:58:39Z manolo $".
+//

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

Reply via email to