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:
ManoloFLTK 2020-06-27 09:56:00 +02:00
parent 93f19c3a24
commit 26e6c3f930
17 changed files with 1424 additions and 72 deletions

View File

@ -18,6 +18,8 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2020
New Features and Extensions
- (add new items here)
- New classes Fl_SVG_File_Surface and Fl_EPS_File_Surface to save any FLTK
graphics to SVG or EPS files, respectively.
- New fl_putenv() is a cross-platform putenv() wrapper (see docs).
- New Fl::keyboard_screen_scaling(0) call stops recognition of ctrl/+/-/0/
keystrokes as scaling all windows of a screen.
@ -87,9 +89,6 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2020
of Fl_Clock, Fl_Clock_Output, and derived widgets.
- New method Fl_Tabs::tab_align() allows to set alignment of tab labels,
particularly to support icons on tab labels (STR #3076).
- Added '--enable-print' option to configure effective under X11 platforms
and with 'yes' default value. Using '--enable-print=no' removes print
and PostScript support from the FLTK library, thus reducing its size.
- Added Fl_Surface_Device::push_current(new_surface) and
Fl_Surface_Device::pop_current() to set/unset the current surface
receiving graphics commands.
@ -101,8 +100,13 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2020
New Configuration Options (ABI Version)
- The library can be built without support for SVG images using the
--disable-nanosvg configure option or turning off OPTION_USE_NANOSVG in CMake.
- The library can be built without support for reading SVG images or writing
graphics in SVG format using the --disable-svg configure option
or turning off OPTION_USE_SVG in CMake.
- The library can be built without support for PostScript, thus reducing
its size, using the --disable-print configure option or turning off
OPTION_PRINT_SUPPORT in CMake. That makes classes Fl_PostScript_File_Device,
Fl_EPS_File_Surface and Fl_Printer (under X11 platform only) ineffective.
- FLTK's ABI version can be configured with 'configure' and CMake.
See documentation in README.abi-version.txt.
@ -119,6 +123,7 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2020
Other Improvements
- (add new items here)
- Support for building for the arm64 architecture used by macOS 11.0 "Big Sur".
- Add optional argument to Fl_Printer::begin_job() to receive
a string describing the error when an error occurs.
- Fix Windows-specific bug when the program tries to enlarge a

View File

@ -179,11 +179,11 @@ else ()
endif (PKG_CAIRO_FOUND)
#######################################################################
option(OPTION_USE_NANOSVG "support SVG images" ON)
option(OPTION_USE_SVG "read/write SVG files" ON)
if(OPTION_USE_NANOSVG)
set(FLTK_USE_NANOSVG 1)
endif(OPTION_USE_NANOSVG)
if(OPTION_USE_SVG)
set(FLTK_USE_SVG 1)
endif(OPTION_USE_SVG)
#######################################################################
set(HAVE_GL LIB_GL OR LIB_MesaGL)

View File

@ -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
//

73
FL/Fl_SVG_File_Surface.H Normal file
View File

@ -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 */

View File

@ -320,12 +320,12 @@
#cmakedefine HAVE_PNG_SET_TRNS_TO_ALPHA 1
/*
* FLTK_USE_NANOSVG
* FLTK_USE_SVG
*
* Do we want FLTK to support SVG images with nanosvg ?
* Do we want FLTK to read and write SVG-formatted files ?
*/
#cmakedefine FLTK_USE_NANOSVG 1
#cmakedefine FLTK_USE_SVG 1
/*
* Do we have POSIX threading?

View File

@ -287,7 +287,7 @@
#undef HAVE_LIBPNG
#undef HAVE_LIBZ
#undef HAVE_LIBJPEG
#undef FLTK_USE_NANOSVG
#undef FLTK_USE_SVG
/*
* FLTK_USE_CAIRO

View File

@ -789,10 +789,10 @@ AC_SUBST(PNGINC)
AC_SUBST(ZLIB)
AC_SUBST(ZLIBINC)
# Control the usage of the nanosvg lib
AC_ARG_ENABLE(nanosvg, [ --enable-nanosvg use nanosvg to support SVG images [[default=yes]]])
if test x$enable_nanosvg != xno; then
AC_DEFINE(FLTK_USE_NANOSVG)
# Control the usage of the nanosvg lib and SVG output
AC_ARG_ENABLE(svg, [ --enable-svg read/write SVG files [[default=yes]]])
if test x$enable_svg != xno; then
AC_DEFINE(FLTK_USE_SVG)
fi
dnl Restore original LIBS settings...

View File

@ -161,6 +161,7 @@ set (CPPFILES
fl_utf8.cxx
fl_encoding_latin1.cxx
fl_encoding_mac_roman.cxx
drivers/SVG/Fl_SVG_File_Surface.cxx
)
# find all header files in source directory <FL/...>

View File

@ -18,7 +18,7 @@
#include <config.h>
#if defined(FLTK_USE_NANOSVG) || defined(FL_DOXYGEN)
#if defined(FLTK_USE_SVG) || defined(FL_DOXYGEN)
#include <FL/Fl_SVG_Image.H>
#include <FL/fl_utf8.h>
@ -272,7 +272,7 @@ void Fl_SVG_Image::normalize() {
if (!array) resize(w(), h());
}
#endif // FLTK_USE_NANOSVG
#endif // FLTK_USE_SVG
//
// End of "$Id$".

View File

@ -214,7 +214,6 @@ IMGCPPFILES = \
Fl_Image_Reader.cxx \
Fl_SVG_Image.cxx
CFILES = fl_call_main.c flstring.c numericsort.c vsnprintf.c
UTF8CFILES = \
@ -306,7 +305,8 @@ GDICFILES = \
PSCPPFILES = \
drivers/PostScript/Fl_PostScript.cxx \
drivers/PostScript/Fl_PostScript_image.cxx
drivers/PostScript/Fl_PostScript_image.cxx \
drivers/SVG/Fl_SVG_File_Surface.cxx
################################################################
FLTKFLAGS = -DFL_LIBRARY

View File

@ -26,6 +26,7 @@
#include <FL/Fl_Native_File_Chooser.H>
#include "../../Fl_System_Driver.H"
#include <stdarg.h>
#include <time.h>
const char *Fl_PostScript_File_Device::file_chooser_title = "Select a .ps file";
@ -137,7 +138,6 @@ int Fl_PostScript_Graphics_Driver::clocale_printf(const char *format, ...)
// Prolog string
static const char * prolog =
"%%BeginProlog\n"
"/L { /y2 exch def\n"
"/x2 exch def\n"
"/y1 exch def\n"
@ -554,7 +554,7 @@ int Fl_PostScript_Graphics_Driver::start_postscript (int pagecount,
if (lang_level_ == 3 && (layout & Fl_Paged_Device::LANDSCAPE) ) { x = w; w = h; h = x; }
fprintf(output, "<</PageSize[%d %d]>>setpagedevice\n", w, h );
fputs("%%EndFeature\n", output);
fputs("%%EndComments\n", output);
fputs("%%EndComments\n%%BeginProlog\n", output);
fputs(prolog, output);
if (lang_level_ > 1) {
fputs(prolog_2, output);
@ -583,6 +583,41 @@ int Fl_PostScript_Graphics_Driver::start_postscript (int pagecount,
return 0;
}
int Fl_PostScript_Graphics_Driver::start_eps (int width, int height) {
width_ = width;
height_ = height;
fputs("%!PS-Adobe-3.0 EPSF-3.0\n", output);
fputs("%%Creator: (FLTK)\n", output);
fprintf(output,"%%%%BoundingBox: 1 1 %d %d\n", width, height);
if (ps_filename_) fprintf(output,"%%%%Title: (%s)\n", fl_filename_name(ps_filename_));
time_t lt = time(NULL);
fprintf(output,"%%%%CreationDate: %s", ctime(&lt)+4);
lang_level_= 2;
fprintf(output, "%%%%LanguageLevel: 2\n");
fputs("%%Pages: 1\n%%EndComments\n", output);
fputs("%%BeginProlog\n", output);
fputs("%%EndProlog\n",output);
fprintf(output, "save\n");
fputs("/FLTK 20 dict def FLTK begin\n"
"/x1 0 def /x2 0 def /y1 0 def /y2 0 def /x 0 def /y 0 def /dx 0 def /dy 0 def\n"
"/px 0 def /py 0 def /sx 0 def /sy 0 def /inter 0 def\n"
"/pixmap_sx 0 def /pixmap_sy 0 def /pixmap_w 0 def /pixmap_h 0 def\n", output);
fputs(prolog, output);
fputs(prolog_2, output);
fputs(prolog_2_pixmap, output);
fputs("/CS { GS } bind def\n", output);
fputs("/CR { GR } bind def\n", output);
page_policy_ = 1;
reset();
nPages=0;
fprintf(output, "GS\n");
clocale_printf( "%g %g TR\n", (double)0, height_);
fprintf(output, "1 -1 SC\n");
line_style(0);
fprintf(output, "GS GS\n");
return 0;
}
void Fl_PostScript_Graphics_Driver::recover(){
color(cr_,cg_,cb_);
line_style(linestyle_,linewidth_,linedash_);
@ -1386,6 +1421,22 @@ int Fl_PostScript_Graphics_Driver::not_clipped(int x, int y, int w, int h) {
return 0;
}
void Fl_PostScript_Graphics_Driver::ps_origin(int x, int y)
{
clocale_printf("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_PostScript_Graphics_Driver::ps_translate(int x, int y)
{
fprintf(output, "GS %d %d translate GS\n", x, y);
}
void Fl_PostScript_Graphics_Driver::ps_untranslate(void)
{
fprintf(output, "GR GR\n");
}
void Fl_PostScript_File_Device::margins(int *left, int *top, int *right, int *bottom) // to implement
{
Fl_PostScript_Graphics_Driver *ps = driver();
@ -1413,9 +1464,7 @@ void Fl_PostScript_File_Device::origin(int x, int y)
{
x_offset = x;
y_offset = y;
Fl_PostScript_Graphics_Driver *ps = driver();
ps->clocale_printf("GR GR GS %d %d TR %f %f SC %d %d TR %f rotate GS\n",
ps->left_margin, ps->top_margin, ps->scale_x, ps->scale_y, x, y, ps->angle);
driver()->ps_origin(x, y);
}
void Fl_PostScript_File_Device::scale (float s_x, float s_y)
@ -1438,12 +1487,12 @@ void Fl_PostScript_File_Device::rotate (float rot_angle)
void Fl_PostScript_File_Device::translate(int x, int y)
{
fprintf(driver()->output, "GS %d %d translate GS\n", x, y);
driver()->ps_translate(x, y);
}
void Fl_PostScript_File_Device::untranslate(void)
{
fprintf(driver()->output, "GR GR\n");
driver()->ps_untranslate();
}
int Fl_PostScript_File_Device::begin_page (void)
@ -1495,9 +1544,85 @@ void Fl_PostScript_File_Device::end_job (void)
}
/**
\}
\endcond
*/
\}
\endcond
*/
Fl_EPS_File_Surface::Fl_EPS_File_Surface(int width, int height, FILE *eps, Fl_Color background) :
Fl_Widget_Surface(new Fl_PostScript_Graphics_Driver()) {
Fl_PostScript_Graphics_Driver *ps = driver();
ps->output = eps;
if (ps->output) {
float s = Fl::screen_scale(0);
ps->start_eps(width*s, height*s);
if (s != 1) {
ps->clocale_printf("GR GR GS %f %f SC GS\n", s, s);
ps->scale_x = ps->scale_y = s;
}
Fl::get_color(background, ps->bg_r, ps->bg_g, ps->bg_b);
}
}
void Fl_EPS_File_Surface::complete_() {
Fl_PostScript_Graphics_Driver *ps = driver();
if(ps->output) {
fputs("GR\nend %matches begin of FLTK dict\n", ps->output);
fputs("restore\n", ps->output);
fputs("%%EOF\n", ps->output);
ps->reset();
fflush(ps->output);
if(ferror(ps->output)) {
fl_alert ("Error during PostScript data output.");
}
}
while (ps->clip_){
Fl_PostScript_Graphics_Driver::Clip * c= ps->clip_;
ps->clip_= ps->clip_->prev;
delete c;
}
}
Fl_EPS_File_Surface::~Fl_EPS_File_Surface() {
Fl_PostScript_Graphics_Driver *ps = driver();
if(ps->output) complete_();
delete ps;
}
int Fl_EPS_File_Surface::close() {
complete_();
Fl_PostScript_Graphics_Driver *ps = driver();
int retval = fclose(ps->output);
ps->output = NULL;
return retval;
}
int Fl_EPS_File_Surface::printable_rect(int *w, int *h) {
Fl_PostScript_Graphics_Driver *ps = driver();
*w = ps->width_;
*h = ps->height_;
return 0;
}
void Fl_EPS_File_Surface::origin(int x, int y)
{
x_offset = x;
y_offset = y;
driver()->ps_origin(x, y);
}
void Fl_EPS_File_Surface::origin(int *px, int *py) {
Fl_Widget_Surface::origin(px, py);
}
void Fl_EPS_File_Surface::translate(int x, int y)
{
driver()->ps_translate(x, y);
}
void Fl_EPS_File_Surface::untranslate()
{
driver()->ps_untranslate();
}
#endif // !defined(FL_NO_PRINT_SUPPORT)

File diff suppressed because it is too large Load Diff

View File

@ -91,7 +91,7 @@ fl_check_images(const char *name, // I - Filename
return new Fl_JPEG_Image(name);
#endif // HAVE_LIBJPEG
#ifdef FLTK_USE_NANOSVG
#ifdef FLTK_USE_SVG
# if defined(HAVE_LIBZ)
if (header[0] == 0x1f && header[1] == 0x8b) { // denotes gzip'ed data
int fd = fl_open_ext(name, 1, 0);
@ -106,7 +106,7 @@ fl_check_images(const char *name, // I - Filename
if ( (headerlen > 5 && memcmp(header, "<?xml", 5) == 0) ||
memcmp(header, "<svg", 4) == 0)
return new Fl_SVG_Image(name);
#endif // FLTK_USE_NANOSVG
#endif // FLTK_USE_SVG
return 0;
}

View File

@ -59,7 +59,7 @@ CREATE_EXAMPLE(color_chooser color_chooser.cxx fltk ANDROID_OK)
CREATE_EXAMPLE(cursor cursor.cxx fltk ANDROID_OK)
CREATE_EXAMPLE(curve curve.cxx fltk ANDROID_OK)
CREATE_EXAMPLE(demo demo.cxx fltk)
CREATE_EXAMPLE(device device.cxx fltk)
CREATE_EXAMPLE(device device.cxx "fltk;fltk_images")
CREATE_EXAMPLE(doublebuffer doublebuffer.cxx fltk ANDROID_OK)
CREATE_EXAMPLE(editor editor.cxx fltk ANDROID_OK)
CREATE_EXAMPLE(fast_slow fast_slow.fl fltk ANDROID_OK)

View File

@ -370,9 +370,9 @@ demo$(EXEEXT): demo.o
$(OSX_ONLY) mkdir -p demo.app/Contents/Resources
$(OSX_ONLY) cp -f demo.menu demo.app/Contents/Resources/
device$(EXEEXT): device.o $(IMGLIBNAME)
device$(EXEEXT): device.o
echo Linking $@...
$(CXX) $(ARCHFLAGS) $(CXXFLAGS) $(LDFLAGS) device.o -o $@ $(LINKFLTKIMG) $(LDLIBS)
$(CXX) $(ARCHFLAGS) $(CXXFLAGS) $(LDFLAGS) device.o -o $@ $(LINKFLTK) $(IMAGELIBS) $(LDLIBS)
$(OSX_ONLY) ../fltk-config --post $@
doublebuffer$(EXEEXT): doublebuffer.o

View File

@ -3,7 +3,7 @@
//
// Device test program for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2016 by Roman Kantor and others.
// Copyright 1998-2020 by Roman Kantor 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
@ -18,7 +18,6 @@
#include <math.h>
#include <FL/Fl.H>
#include <FL/Fl_Overlay_Window.H>
#include <FL/Fl_Light_Button.H>
#include <FL/Fl_Radio_Round_Button.H>
@ -28,15 +27,12 @@
#include <FL/Fl_Pixmap.H>
#include <FL/Fl_Bitmap.H>
#include <FL/Fl_Round_Button.H>
#include <FL/Fl_Printer.H>
#include <FL/Fl_PostScript.H>
#include <FL/Fl_Copy_Surface.H>
#include <FL/Fl_Image_Surface.H>
#include <FL/Fl_File_Chooser.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Native_File_Chooser.H>
#include <FL/Fl_SVG_File_Surface.H>
#define sorceress_width 75
@ -630,6 +626,59 @@ void copy(Fl_Widget *, void *data) {
} else if (err > 1 && err_message) {fl_alert("%s", err_message); delete[] err_message;}
delete p;
}
if (strcmp(operation, "Fl_EPS_File_Surface") == 0) {
Fl_Native_File_Chooser fnfc;
fnfc.title("Save a .eps file");
fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
fnfc.filter("EPS\t*.eps\n");
fnfc.options(Fl_Native_File_Chooser::SAVEAS_CONFIRM | Fl_Native_File_Chooser::USE_FILTER_EXT);
if (!fnfc.show() ) {
FILE *eps = fl_fopen(fnfc.filename(), "w");
if (eps) {
int ww, wh;
if (target->as_window()) {
ww = target->as_window()->decorated_w();
wh = target->as_window()->decorated_h();
} else {
ww = target->w();
wh = target->h();
}
Fl_EPS_File_Surface p(ww, wh, eps);
if (target->as_window()) p.draw_decorated_window(target->as_window());
else p.draw(target);
//p.close();
}
fclose(eps);
}
}
if (strcmp(operation, "Fl_SVG_File_Surface") == 0) {
Fl_Native_File_Chooser fnfc;
fnfc.title("Save a .svg file");
fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
fnfc.filter("SVG\t*.svg\n");
fnfc.options(Fl_Native_File_Chooser::SAVEAS_CONFIRM | Fl_Native_File_Chooser::USE_FILTER_EXT);
if (!fnfc.show() ) {
FILE *svg = fl_fopen(fnfc.filename(), "w");
if (svg) {
int ww, wh;
if (target->as_window()) {
ww = target->as_window()->decorated_w();
wh = target->as_window()->decorated_h();
} else {
ww = target->w();
wh = target->h();
}
Fl_SVG_File_Surface surface(ww, wh, svg);
if (surface.file()) {
if (target->as_window()) surface.draw_decorated_window(target->as_window());
else surface.draw(target);
surface.close();
}
}
}
}
}
@ -664,59 +713,59 @@ void operation_cb(Fl_Widget* wid, void *data)
int main(int argc, char ** argv) {
//Fl::scheme("plastic");
Fl::scheme("plastic");
Fl_Window * w2 = new Fl_Window(500,560,"Graphics test");
Fl_Window * w2 = new Fl_Window(500,568,"Graphics test");
Fl_Group *c2 =new Fl_Group(3, 43, 494, 514 );
Fl_Group *c2 =new Fl_Group(3, 56, 494, 514 );
new MyWidget(10,140);
new MyWidget2(110,80);
new MyWidget3(220,140);
new MyWidget4(330,70);
new MyWidget5(140,270);
new MyWidget(10,140+16);
new MyWidget2(110,80+16);
new MyWidget3(220,140+16);
new MyWidget4(330,70+16);
new MyWidget5(140,270+16);
make_image();
Fl_RGB_Image *rgb = new Fl_RGB_Image(image, width, height, 4);
My_Button b_rgb(10,245,100,100,"RGB with alpha");
My_Button b_rgb(10,245+16,100,100,"RGB with alpha");
b_rgb.image(rgb);
My_Button b_pixmap(10,345,100,100,"Pixmap");
My_Button b_pixmap(10,345+16,100,100,"Pixmap");
Fl_Pixmap *pixmap = new Fl_Pixmap(porsche_xpm);
b_pixmap.image(pixmap);
My_Button b_bitmap(10,445,100,100,"Bitmap");
My_Button b_bitmap(10,445+16,100,100,"Bitmap");
b_bitmap.labelcolor(FL_GREEN);
b_bitmap.image(new Fl_Bitmap(sorceress_bits,sorceress_width,sorceress_height));
new Fl_Clock(360,230,120,120);
new Fl_Clock(360,230+16,120,120);
Fl_Return_Button * ret = new Fl_Return_Button (360, 360, 120,30, "Return");
ret->deactivate();
Fl_Button but1(360, 390, 30, 30, "@->|");
Fl_Button but1(360, 390+16, 30, 30, "@->|");
but1.labelcolor(FL_DARK3);
Fl_Button but2(390, 390, 30, 30, "@UpArrow");
Fl_Button but2(390, 390+16, 30, 30, "@UpArrow");
but2.labelcolor(FL_DARK3);
Fl_Button but3(420, 390, 30, 30, "@DnArrow");
Fl_Button but3(420, 390+16, 30, 30, "@DnArrow");
but3.labelcolor(FL_DARK3);
Fl_Button but4(450, 390, 30, 30, "@+");
Fl_Button but4(450, 390+16, 30, 30, "@+");
but4.labelcolor(FL_DARK3);
Fl_Button but5(360, 425, 120, 30, "Hello, World");
Fl_Button but5(360, 425+16, 120, 30, "Hello, World");
but5.labelfont(FL_BOLD|FL_ITALIC);
but5.labeltype(FL_SHADOW_LABEL);
but5.box(FL_ROUND_UP_BOX);
Fl_Button but6(360, 460, 120, 30, "Plastic");
Fl_Button but6(360, 460+16, 120, 30, "Plastic");
but6.box(FL_PLASTIC_UP_BOX);
Fl_Group *group;
{ Fl_Group* o = new Fl_Group(360, 495, 120, 40); group=o;
{ Fl_Group* o = new Fl_Group(360, 495+16, 120, 40); group=o;
o->box(FL_UP_BOX);
{ Fl_Group* o = new Fl_Group(365, 500, 110, 30);
{ Fl_Group* o = new Fl_Group(365, 500+16, 110, 30);
o->box(FL_THIN_UP_FRAME);
{ Fl_Round_Button* o = new Fl_Round_Button(365, 500, 40, 30, "rad");
{ Fl_Round_Button* o = new Fl_Round_Button(365, 500+16, 40, 30, "rad");
o->value(1);
}
{ Fl_Check_Button* o = new Fl_Check_Button(410, 500, 60, 30, "check");
{ Fl_Check_Button* o = new Fl_Check_Button(410, 500+16, 60, 30, "check");
o->value(1);
}
@ -725,7 +774,7 @@ int main(int argc, char ** argv) {
o->end();
o->deactivate();
}
Fl_Box tx(120,492,230,50,"Background is not printed because\nencapsulating group, which we are\n printing, has not set the box type");
Fl_Box tx(120,492+16,230,50,"Background is not printed because\nencapsulating group, which we are\n printing, has not set the box type");
tx.box(FL_SHADOW_BOX);
tx.labelsize(12);
@ -734,7 +783,7 @@ int main(int argc, char ** argv) {
c2->end();
Fl_Radio_Round_Button *rb;
Fl_Window *w3 = new Fl_Window(2,5,w2->w()-10,60);
Fl_Window *w3 = new Fl_Window(2,5,w2->w()-10,73);
w3->box(FL_DOWN_BOX);
Fl_Group *g1 = new Fl_Group(w3->x(),w3->y(),w3->w(),w3->h());
rb = new Fl_Radio_Round_Button(5,5,150,12, "Fl_Image_Surface");
@ -742,6 +791,8 @@ int main(int argc, char ** argv) {
rb = new Fl_Radio_Round_Button(5,18,150,12, "Fl_Copy_Surface"); rb->callback(operation_cb, NULL); rb->labelsize(12);
rb = new Fl_Radio_Round_Button(5,31,150,12, "Fl_Printer"); rb->callback(operation_cb, NULL); rb->labelsize(12);
rb = new Fl_Radio_Round_Button(5,44,150,12, "Fl_PostScript_File_Device"); rb->callback(operation_cb, NULL); rb->labelsize(12);
rb = new Fl_Radio_Round_Button(5,57,150,12, "Fl_EPS_File_Surface"); rb->callback(operation_cb, NULL); rb->labelsize(12);
rb = new Fl_Radio_Round_Button(170,57,150,12, "Fl_SVG_File_Surface"); rb->callback(operation_cb, NULL); rb->labelsize(12);
g1->end();
Fl_Group *g2 = new Fl_Group(w3->x(),w3->y(),w3->w(),w3->h());

View File

@ -27,7 +27,8 @@
#include <errno.h>
#include <FL/Fl_File_Chooser.H>
#include <FL/fl_message.H>
#include <FL/Fl_SVG_File_Surface.H>
#include <FL/Fl_Native_File_Chooser.H>
Fl_Box *b;
Fl_Double_Window *w;
Fl_Shared_Image *img;
@ -77,16 +78,17 @@ void file_cb(const char *n) {
void button_cb(Fl_Widget *,void *) {
fl_file_chooser_callback(file_cb);
const char *fname = fl_file_chooser("Image file?","*.{bm,bmp,gif,jpg,pbm,pgm,png,ppm,xbm,xpm"
#ifdef FLTK_USE_NANOSVG
#ifdef FLTK_USE_SVG
",svg"
#ifdef HAVE_LIBZ
",svgz"
#endif
#endif
#endif // HAVE_LIBZ
#endif // FLTK_USE_SVG
"}", name);
puts(fname ? fname : "(null)"); fflush(stdout);
fl_file_chooser_callback(0);
}
void print_cb(Fl_Widget *widget, void *) {
Fl_Printer printer;
int width, height;
@ -101,6 +103,19 @@ void print_cb(Fl_Widget *widget, void *) {
printer.end_page();
printer.end_job();
}
void svg_cb(Fl_Widget *widget, void *) {
Fl_Native_File_Chooser fnfc;
fnfc.title("Pick a .svg file");
fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
fnfc.filter("SVG\t*.svg\n");
fnfc.options(Fl_Native_File_Chooser::SAVEAS_CONFIRM | Fl_Native_File_Chooser::USE_FILTER_EXT);
if (fnfc.show() ) return;
FILE *svg = fl_fopen(fnfc.filename(), "w");
Fl_SVG_File_Surface surf(widget->window()->decorated_w(), widget->window()->decorated_h(), svg);
surf.draw_decorated_window(widget->window());
surf.close();
}
int dvisual = 0;
int arg(int, char **argv, int &i) {
@ -126,6 +141,8 @@ int main(int argc, char **argv) {
window.resizable(b);
Fl_Button print(300,425,50,25,"Print");
print.callback(print_cb);
Fl_Button svg(190,425,100,25,"save as SVG");
svg.callback(svg_cb);
window.show(argc,argv);
return Fl::run();