mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 06:14:28 +08:00
Add classes Fl_SVG_File_Surface and Fl_EPS_File_Surface to draw to SVG and EPS.
Test programs device and pixmap_browser use these new classes. Class Fl_SVG_File_Surface can be optionally made non functional using the --disable-svg configure option or turning off OPTION_USE_SVG in CMake. Class Fl_EPS_File_Surface can be optionally made non functional using the --disable-print configure option or turning off OPTION_PRINT_SUPPORT in CMake.
This commit is contained in:
+58
-1
@@ -3,7 +3,7 @@
|
||||
//
|
||||
// Support for graphics output to PostScript file for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
// Copyright 2010-2019 by Bill Spitzak and others.
|
||||
// Copyright 2010-2020 by Bill Spitzak and others.
|
||||
//
|
||||
// This library is free software. Distribution and use rights are outlined in
|
||||
// the file "COPYING" which should have been included with this file. If this
|
||||
@@ -206,6 +206,11 @@ public:
|
||||
// ---
|
||||
Fl_Bitmask create_bitmask(int w, int h, const uchar *array) { return 0L; }
|
||||
virtual int has_feature(driver_feature feature_mask) { return feature_mask & PRINTER; }
|
||||
|
||||
int start_eps(int width, int height);
|
||||
void ps_origin(int x, int y);
|
||||
void ps_translate(int, int);
|
||||
void ps_untranslate();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -310,6 +315,58 @@ public:
|
||||
static const char *file_chooser_title;
|
||||
};
|
||||
|
||||
/** Encapsulated PostScript drawing surface.
|
||||
This drawing surface allows to store any FLTK graphics in vectorial form in an "Encapsulated PostScript" file.
|
||||
\n Usage example:
|
||||
\code
|
||||
Fl_Window *win = ...// Window to draw to an .eps file
|
||||
int ww = win->decorated_w();
|
||||
int wh = win->decorated_h();
|
||||
FILE *eps = fl_fopen("/path/to/mywindow.eps", "w");
|
||||
if (eps) {
|
||||
Fl_EPS_File_Surface *surface = new Fl_EPS_File_Surface(ww, wh, eps, win->color());
|
||||
Fl_Surface_Device::push_current(surface);
|
||||
surface->draw_decorated_window(win);
|
||||
Fl_Surface_Device::pop_current();
|
||||
delete surface; // the .eps file is not complete until the destructor was run
|
||||
fclose(eps);
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
class FL_EXPORT Fl_EPS_File_Surface : public Fl_Widget_Surface {
|
||||
private:
|
||||
void complete_();
|
||||
protected:
|
||||
/** Returns the PostScript driver of this drawing surface. */
|
||||
inline Fl_PostScript_Graphics_Driver *driver() { return (Fl_PostScript_Graphics_Driver*)Fl_Surface_Device::driver(); }
|
||||
public:
|
||||
/**
|
||||
Constructor.
|
||||
\param width,height Width and height of the EPS drawing area
|
||||
\param eps A writable FILE pointer where the Encapsulated PostScript data will be sent
|
||||
\param background Color expected to cover the background of the EPS drawing area.
|
||||
This parameter affects only the drawing of transparent Fl_RGB_Image objects:
|
||||
transparent areas of RGB images are blended with the \p background color.
|
||||
*/
|
||||
Fl_EPS_File_Surface(int width, int height, FILE *eps, Fl_Color background = FL_WHITE);
|
||||
/**
|
||||
Destructor.
|
||||
The underlying FILE pointer remains open after destruction of the Fl_EPS_File_Surface object
|
||||
unless close() was called.
|
||||
*/
|
||||
~Fl_EPS_File_Surface();
|
||||
virtual int printable_rect(int *w, int *h);
|
||||
/** Returns the underlying FILE pointer */
|
||||
FILE *file() { return driver()->output; }
|
||||
virtual void origin(int x, int y);
|
||||
virtual void origin(int *px, int *py);
|
||||
virtual void translate(int x, int y);
|
||||
virtual void untranslate();
|
||||
/** Closes using fclose() the underlying FILE pointer.
|
||||
The only operation possible with the Fl_EPS_File_Surface object after calling close() is its destruction. */
|
||||
int close();
|
||||
};
|
||||
|
||||
#endif // Fl_PostScript_H
|
||||
|
||||
//
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// Declaration of Fl_SVG_File_Surface in the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
// Copyright 2020 by Bill Spitzak and others.
|
||||
//
|
||||
// This library is free software. Distribution and use rights are outlined in
|
||||
// the file "COPYING" which should have been included with this file. If this
|
||||
// file is missing or damaged, see the license at:
|
||||
//
|
||||
// https://www.fltk.org/COPYING.php
|
||||
//
|
||||
// Please report all bugs and problems on the following page:
|
||||
//
|
||||
// https://www.fltk.org/str.php
|
||||
//
|
||||
|
||||
#ifndef Fl_SVG_File_Surface_H
|
||||
#define Fl_SVG_File_Surface_H
|
||||
|
||||
#include <FL/Fl_Widget_Surface.H>
|
||||
#include <stdio.h>
|
||||
|
||||
/** A drawing surface producing a Scalable Vector Graphics (SVG) file.
|
||||
This drawing surface allows to store any FLTK graphics in vectorial form in a "Scalable Vector Graphics" file.
|
||||
\n Usage example:
|
||||
\code
|
||||
Fl_Window *win = ...// Window to draw to a .svg file
|
||||
int ww = win->decorated_w();
|
||||
int wh = win->decorated_h();
|
||||
FILE *svg = fl_fopen("/path/to/mywindow.svg", "w");
|
||||
if (svg) {
|
||||
Fl_SVG_File_Surface *surface = new Fl_SVG_File_Surface(ww, wh, svg);
|
||||
Fl_Surface_Device::push_current(surface);
|
||||
fl_color(FL_WHITE);
|
||||
fl_rectf(0, 0, ww, wh);
|
||||
surface->draw_decorated_window(win);
|
||||
Fl_Surface_Device::pop_current();
|
||||
delete surface; // the .svg file is not complete until the destructor was run
|
||||
fclose(svg);
|
||||
}
|
||||
\endcode
|
||||
\note FLTK uses the PNG and JPEG libraries to encode images to the SVG format. If JPEG is
|
||||
not available at application build time, PNG is enough (but produces a quite larger output).
|
||||
If PNG isn't available either, images don't appear in the SVG output.
|
||||
*/
|
||||
class FL_EXPORT Fl_SVG_File_Surface : public Fl_Widget_Surface {
|
||||
int width_, height_;
|
||||
public:
|
||||
/**
|
||||
Constructor of the SVG drawing surface.
|
||||
\param width,height Width and height of the graphics area in FLTK drawing units
|
||||
\param svg A writable FILE pointer where the SVG data are to be sent. The resulting SVG data are not complete until after destruction of the Fl_SVG_File_Surface object or after calling close().
|
||||
*/
|
||||
Fl_SVG_File_Surface(int width, int height, FILE *svg);
|
||||
/**
|
||||
Destructor.
|
||||
The underlying FILE pointer remains open after destruction of the Fl_SVG_File_Surface object
|
||||
unless close() was called.
|
||||
*/
|
||||
~Fl_SVG_File_Surface();
|
||||
/** Returns the underlying FILE pointer */
|
||||
FILE *file();
|
||||
virtual void origin(int x, int y);
|
||||
virtual void translate(int x, int y);
|
||||
virtual void untranslate();
|
||||
virtual int printable_rect(int *w, int *h);
|
||||
/** Closes with function fclose() the FILE pointer where SVG data is output.
|
||||
The only operation possible after this on the Fl_SVG_File_Surface object is its destruction.
|
||||
\return The value returned by fclose(). */
|
||||
int close();
|
||||
};
|
||||
|
||||
#endif /* Fl_SVG_File_Surface_H */
|
||||
Reference in New Issue
Block a user