2010-05-27 21:20:18 +04:00
|
|
|
|
//
|
|
|
|
|
// Support for graphics output to PostScript file for the Fast Light Tool Kit (FLTK).
|
|
|
|
|
//
|
2020-06-27 10:56:00 +03:00
|
|
|
|
// Copyright 2010-2020 by Bill Spitzak and others.
|
2010-05-27 21:20:18 +04:00
|
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
|
// 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:
|
2010-05-27 21:20:18 +04:00
|
|
|
|
//
|
2020-04-05 17:53:10 +03:00
|
|
|
|
// https://www.fltk.org/COPYING.php
|
2010-05-27 21:20:18 +04:00
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
|
// Please see the following page on how to report bugs and issues:
|
2010-05-27 21:20:18 +04:00
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
|
// https://www.fltk.org/bugs.php
|
2010-05-27 21:20:18 +04:00
|
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
|
/** \file Fl_PostScript.H
|
2020-10-28 19:19:05 +03:00
|
|
|
|
\brief declaration of classes Fl_PostScript_File_Device and Fl_EPS_File_Surface.
|
2010-05-27 21:20:18 +04:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef Fl_PostScript_H
|
|
|
|
|
#define Fl_PostScript_H
|
|
|
|
|
|
|
|
|
|
#include <FL/Fl_Paged_Device.H>
|
|
|
|
|
#include <FL/fl_draw.H>
|
2014-09-08 16:35:23 +04:00
|
|
|
|
#include <stdarg.h>
|
2010-05-27 21:20:18 +04:00
|
|
|
|
|
2020-11-01 11:26:29 +03:00
|
|
|
|
/** Signature of functions FLTK may use to close FILE variables after PostScript/EPS output.
|
|
|
|
|
A non-null return value indicates output error.
|
|
|
|
|
\see Fl_PostScript_File_Device::close_command() and Fl_EPS_File_Surface::Fl_EPS_File_Surface().
|
|
|
|
|
*/
|
2015-02-02 12:46:32 +03:00
|
|
|
|
extern "C" {
|
2020-10-28 19:19:05 +03:00
|
|
|
|
typedef int (*Fl_PostScript_Close_Command)(FILE *);
|
2015-02-02 12:46:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 19:19:05 +03:00
|
|
|
|
class Fl_PostScript_Graphics_Driver;
|
2018-06-23 19:47:40 +03:00
|
|
|
|
|
2010-05-27 21:20:18 +04:00
|
|
|
|
/**
|
2015-02-26 18:38:54 +03:00
|
|
|
|
To send graphical output to a PostScript file.
|
2018-05-09 17:16:35 +03:00
|
|
|
|
This class is used exactly as the Fl_Printer class except for the begin_job() call,
|
2015-02-26 18:38:54 +03:00
|
|
|
|
two variants of which are usable and allow to specify what page format and layout are desired.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
|
2022-03-10 17:05:26 +03:00
|
|
|
|
<b>Processing of text</b>: Text uses vectorial fonts under the X11 + Pango and the Wayland platforms.
|
2020-10-28 19:19:05 +03:00
|
|
|
|
With other platforms, only text restricted to the Latin alphabet (and a few other characters
|
|
|
|
|
listed in the table below) and to FLTK standard fonts is vectorized. All other unicode characters
|
|
|
|
|
or all other fonts (FL_FREE_FONT and above) are output as a bitmap.
|
|
|
|
|
FLTK standard fonts are output using the corresponding PostScript standard fonts.
|
2019-04-12 12:29:08 +03:00
|
|
|
|
The latin alphabet means all unicode characters between U+0020 and U+017F, or, in other words,
|
|
|
|
|
the ASCII, Latin-1 Supplement and Latin Extended-A charts.
|
2022-03-10 17:05:26 +03:00
|
|
|
|
<br><b>Processing of transparent Fl_RGB_Image objects</b>: Under the X11 + Pango and the Wayland platforms,
|
2020-11-01 11:26:29 +03:00
|
|
|
|
these objects are output with their exact transparency. With other platforms, these objects
|
|
|
|
|
are drawn blended to white color. Class Fl_EPS_File_Surface 's constructor allows to set another
|
|
|
|
|
background color for blending.
|
|
|
|
|
<center>Extra characters supported by standard PostScript fonts</center>
|
2019-04-12 12:29:08 +03:00
|
|
|
|
<table>
|
|
|
|
|
<tr> <th>Char</th><th>Codepoint</th><th>Name</th> <th>Char</th><th>Codepoint</th><th>Name</th> <th>Char</th><th>Codepoint</th><th>Name</th></tr>
|
|
|
|
|
<tr><td>ƒ</td><td>U+0192</td><td>florin</td><td>‚</td><td>U+201A</td><td>quotesinglbase</td><td>™</td><td>U+2122</td><td>trademark</td></tr>
|
|
|
|
|
<tr><td>ˆ</td><td>U+02C6</td><td>circumflex</td><td>“</td><td>U+201C</td><td>quotedblleft</td><td>∂</td><td>U+2202</td><td>partialdiff</td></tr>
|
|
|
|
|
<tr><td>ˇ</td><td>U+02C7</td><td>caron</td><td>”</td><td>U+201D</td><td>quotedblright</td><td>Δ</td><td>U+2206</td><td>Delta</td></tr>
|
|
|
|
|
<tr><td>˘</td><td>U+02D8</td><td>breve</td><td>„</td><td>U+201E</td><td>quotedblbase</td><td>∑</td><td>U+2211</td><td>summation</td></tr>
|
|
|
|
|
<tr><td>˙</td><td>U+02D9</td><td>dotaccent</td><td>†</td><td>U+2020</td><td>dagger</td><td>√</td><td>U+221A</td><td>radical</td></tr>
|
|
|
|
|
<tr><td>˚</td><td>U+02DA</td><td>ring</td><td>‡</td><td>U+2021</td><td>daggerdbl</td><td>∞</td><td>U+221E</td><td>infinity</td></tr>
|
|
|
|
|
<tr><td>˛</td><td>U+02DB</td><td>ogonek</td><td>•</td><td>U+2022</td><td>bullet</td><td>≠</td><td>U+2260</td><td>notequal</td></tr>
|
|
|
|
|
<tr><td>˜</td><td>U+02DC</td><td>tilde</td><td>…</td><td>U+2026</td><td>ellipsis</td><td>≤</td><td>U+2264</td><td>lessequal</td></tr>
|
|
|
|
|
<tr><td>˝</td><td>U+02DD</td><td>hungarumlaut</td><td>‰</td><td>U+2030</td><td>perthousand</td><td>≥</td><td>U+2265</td><td>greaterequal</td></tr>
|
|
|
|
|
<tr><td>–</td><td>U+2013</td><td>endash</td><td>‹</td><td>U+2039</td><td>guilsinglleft</td><td>◊</td><td>U+25CA</td><td>lozenge</td></tr>
|
|
|
|
|
<tr><td>—</td><td>U+2014</td><td>emdash</td><td>›</td><td>U+203A</td><td>guilsinglright</td><td>fi</td><td>U+FB01</td><td>fi</td></tr>
|
|
|
|
|
<tr><td>‘</td><td>U+2018</td><td>quoteleft</td><td>/</td><td>U+2044</td><td>fraction</td><td>fl</td><td>U+FB02</td><td>fl</td></tr>
|
|
|
|
|
<tr><td>’</td><td>U+2019</td><td>quoteright</td><td>€</td><td>U+20AC</td><td>Euro</td><td></td><td>U+F8FF</td><td>apple (Mac OS only)</td></tr>
|
|
|
|
|
</table>
|
2020-11-17 18:11:03 +03:00
|
|
|
|
|
2010-05-27 21:20:18 +04:00
|
|
|
|
*/
|
2011-05-20 20:39:06 +04:00
|
|
|
|
class FL_EXPORT Fl_PostScript_File_Device : public Fl_Paged_Device {
|
2022-07-24 09:46:52 +03:00
|
|
|
|
private:
|
|
|
|
|
// memorize the display's current font to restore it when the object ceases being current
|
|
|
|
|
Fl_Font display_font_;
|
|
|
|
|
Fl_Fontsize display_size_;
|
2010-05-27 21:20:18 +04:00
|
|
|
|
protected:
|
2016-04-23 20:55:08 +03:00
|
|
|
|
/**
|
|
|
|
|
\brief Returns the PostScript driver of this drawing surface.
|
|
|
|
|
*/
|
2020-10-28 19:19:05 +03:00
|
|
|
|
inline Fl_PostScript_Graphics_Driver *driver() { return (Fl_PostScript_Graphics_Driver*)Fl_Surface_Device::driver(); }
|
2010-05-27 21:20:18 +04:00
|
|
|
|
public:
|
2020-10-28 19:19:05 +03:00
|
|
|
|
/** The constructor. */
|
|
|
|
|
Fl_PostScript_File_Device();
|
|
|
|
|
/** The destructor. */
|
2010-05-27 21:20:18 +04:00
|
|
|
|
~Fl_PostScript_File_Device();
|
2016-04-23 20:52:34 +03:00
|
|
|
|
/** Don't use with this class. */
|
2022-12-30 21:14:36 +03:00
|
|
|
|
int begin_job(int pagecount, int* from, int* to, char **perr_message) FL_OVERRIDE;
|
2020-10-28 19:19:05 +03:00
|
|
|
|
/** Begins the session where all graphics requests will go to a local PostScript file.
|
|
|
|
|
Opens a file dialog to select an output PostScript file.
|
|
|
|
|
This member function makes end_job() close the resulting PostScript file and display an
|
|
|
|
|
alert message with fl_alert() in case of any output error.
|
2016-04-23 20:52:34 +03:00
|
|
|
|
@param pagecount The total number of pages to be created. Use 0 if this number is unknown when this function is called.
|
|
|
|
|
@param format Desired page format.
|
|
|
|
|
@param layout Desired page layout.
|
|
|
|
|
@return 0 if OK, 1 if user cancelled the file dialog, 2 if fopen failed on user-selected output file.
|
|
|
|
|
*/
|
2020-10-28 19:19:05 +03:00
|
|
|
|
int begin_job(int pagecount = 0, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
|
2020-07-01 19:03:10 +03:00
|
|
|
|
enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT);
|
2018-05-09 17:16:35 +03:00
|
|
|
|
/** Synonym of begin_job().
|
|
|
|
|
For API compatibility with FLTK 1.3.x */
|
2019-10-22 14:16:14 +03:00
|
|
|
|
int start_job(int pagecount = 0, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
|
2018-05-09 17:16:35 +03:00
|
|
|
|
enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT) {
|
|
|
|
|
return begin_job(pagecount, format, layout);
|
|
|
|
|
}
|
2020-10-28 19:19:05 +03:00
|
|
|
|
/** Begins the session where all graphics requests will go to FILE pointer.
|
|
|
|
|
This member function prevents end_job() from closing \p ps_output, so the user can check with \p ferror(ps_output)
|
|
|
|
|
for output errors.
|
2016-04-23 20:52:34 +03:00
|
|
|
|
@param ps_output A writable FILE pointer that will receive PostScript output and that should not be closed
|
|
|
|
|
until after end_job() has been called.
|
|
|
|
|
@param pagecount The total number of pages to be created. Use 0 if this number is unknown when this function is called.
|
|
|
|
|
@param format Desired page format.
|
|
|
|
|
@param layout Desired page layout.
|
|
|
|
|
@return always 0.
|
|
|
|
|
*/
|
2019-10-22 14:16:14 +03:00
|
|
|
|
int begin_job(FILE *ps_output, int pagecount = 0, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
|
2020-07-01 19:03:10 +03:00
|
|
|
|
enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT);
|
2018-05-09 17:16:35 +03:00
|
|
|
|
/** Synonym of begin_job().
|
|
|
|
|
For API compatibility with FLTK 1.3.x */
|
2019-10-22 14:16:14 +03:00
|
|
|
|
int start_job(FILE *ps_output, int pagecount = 0, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
|
2018-05-09 17:16:35 +03:00
|
|
|
|
enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT) {
|
|
|
|
|
return begin_job(ps_output, pagecount, format, layout);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 21:14:36 +03:00
|
|
|
|
int begin_page (void) FL_OVERRIDE;
|
|
|
|
|
int printable_rect(int *w, int *h) FL_OVERRIDE;
|
|
|
|
|
void margins(int *left, int *top, int *right, int *bottom) FL_OVERRIDE;
|
|
|
|
|
void origin(int *x, int *y) FL_OVERRIDE;
|
|
|
|
|
void origin(int x, int y) FL_OVERRIDE;
|
|
|
|
|
void scale (float scale_x, float scale_y = 0.) FL_OVERRIDE;
|
|
|
|
|
void rotate(float angle) FL_OVERRIDE;
|
|
|
|
|
void translate(int x, int y) FL_OVERRIDE;
|
|
|
|
|
void untranslate(void) FL_OVERRIDE;
|
|
|
|
|
int end_page (void) FL_OVERRIDE;
|
2020-11-01 11:26:29 +03:00
|
|
|
|
/** Completes all PostScript output.
|
|
|
|
|
This also closes with \p fclose() the underlying file() unless close_command() was used to set another function.
|
2020-10-28 19:19:05 +03:00
|
|
|
|
*/
|
2022-12-30 21:14:36 +03:00
|
|
|
|
void end_job(void) FL_OVERRIDE;
|
2020-10-28 19:19:05 +03:00
|
|
|
|
/** Label of the PostScript file chooser window */
|
2016-04-23 20:52:34 +03:00
|
|
|
|
static const char *file_chooser_title;
|
2020-07-06 22:01:28 +03:00
|
|
|
|
/** Returns the underlying FILE* receiving all PostScript data */
|
2020-10-28 19:19:05 +03:00
|
|
|
|
FILE *file();
|
2020-11-01 11:26:29 +03:00
|
|
|
|
/** Sets the function end_job() calls to close the file() */
|
|
|
|
|
void close_command(Fl_PostScript_Close_Command cmd);
|
2022-12-30 21:14:36 +03:00
|
|
|
|
void set_current() FL_OVERRIDE;
|
|
|
|
|
void end_current() FL_OVERRIDE;
|
2010-05-27 21:20:18 +04:00
|
|
|
|
};
|
|
|
|
|
|
2020-06-27 10:56:00 +03:00
|
|
|
|
/** 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
|
|
|
|
|
}
|
|
|
|
|
\endcode
|
|
|
|
|
*/
|
|
|
|
|
class FL_EXPORT Fl_EPS_File_Surface : public Fl_Widget_Surface {
|
|
|
|
|
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
|
2020-10-28 19:19:05 +03:00
|
|
|
|
\param eps_output 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.
|
|
|
|
|
Under the X11 + pango platform, transparent RGB images are correctly blended to their background,
|
|
|
|
|
thus this parameter has no effect.
|
|
|
|
|
\param closef If not NULL, the destructor or close() will call \p closef(eps_output) after all
|
|
|
|
|
EPS data has been sent. If NULL, \p fclose(eps_output) is called instead. This allows to close the FILE
|
|
|
|
|
pointer by, e.g., \p pclose, or, using a function such as \p "int keep_open(FILE*){return 0;}", to keep it open after
|
|
|
|
|
completion of all output to \p eps_output. Function \p closef should return non zero to indicate an error.
|
2020-06-27 10:56:00 +03:00
|
|
|
|
*/
|
2020-10-28 19:19:05 +03:00
|
|
|
|
Fl_EPS_File_Surface(int width, int height, FILE *eps_output,
|
|
|
|
|
Fl_Color background = FL_WHITE, Fl_PostScript_Close_Command closef = NULL);
|
2020-06-27 10:56:00 +03:00
|
|
|
|
/**
|
|
|
|
|
Destructor.
|
2020-10-28 19:19:05 +03:00
|
|
|
|
By default, the destructor closes with function \p fclose() the underlying FILE. See the constructor for how
|
|
|
|
|
to close it differently or to keep it open. Use close() before object destruction to receive the status code
|
|
|
|
|
of output operations. If close() is not used and if EPS output results in error, the destructor displays an alert message
|
|
|
|
|
with fl_alert().
|
2020-06-27 10:56:00 +03:00
|
|
|
|
*/
|
|
|
|
|
~Fl_EPS_File_Surface();
|
2022-12-30 21:14:36 +03:00
|
|
|
|
int printable_rect(int *w, int *h) FL_OVERRIDE;
|
2020-06-27 10:56:00 +03:00
|
|
|
|
/** Returns the underlying FILE pointer */
|
2020-10-28 19:19:05 +03:00
|
|
|
|
FILE *file();
|
2022-12-30 21:14:36 +03:00
|
|
|
|
void origin(int x, int y) FL_OVERRIDE;
|
|
|
|
|
void origin(int *px, int *py) FL_OVERRIDE;
|
|
|
|
|
void translate(int x, int y) FL_OVERRIDE;
|
|
|
|
|
void untranslate() FL_OVERRIDE;
|
2020-10-28 19:19:05 +03:00
|
|
|
|
/** Completes all EPS output.
|
|
|
|
|
The only operation possible with the Fl_EPS_File_Surface object after calling close() is its destruction.
|
|
|
|
|
\return The status code of output operations to the FILE object. 0 indicates success. */
|
2020-06-27 10:56:00 +03:00
|
|
|
|
int close();
|
|
|
|
|
};
|
|
|
|
|
|
2010-05-27 21:20:18 +04:00
|
|
|
|
#endif // Fl_PostScript_H
|