summaryrefslogtreecommitdiff
path: root/FL
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-10-28 17:19:05 +0100
committerGitHub <noreply@github.com>2020-10-28 17:19:05 +0100
commit8accc6e8409819316fa296642c1d23e5638fcb2d (patch)
tree33c6237919989f120f2179cb1e7b410cb7cdd01e /FL
parentf718943e6fbcf89297e61466068405452d7f8ae6 (diff)
Pango ps (#148)
Use cairo-PostScript to output PostScript when pango is available. This allows to draw in vectorial form any script. Before, only the Latin script could be drawn to PostScript in vectorial form.
Diffstat (limited to 'FL')
-rw-r--r--FL/Fl_PostScript.H271
1 files changed, 47 insertions, 224 deletions
diff --git a/FL/Fl_PostScript.H b/FL/Fl_PostScript.H
index 489916d6b..dc31cb116 100644
--- a/FL/Fl_PostScript.H
+++ b/FL/Fl_PostScript.H
@@ -15,7 +15,7 @@
//
/** \file Fl_PostScript.H
- \brief declaration of classes Fl_PostScript_Graphics_Driver, Fl_PostScript_File_Device.
+ \brief declaration of classes Fl_PostScript_File_Device and Fl_EPS_File_Surface.
*/
#ifndef Fl_PostScript_H
@@ -25,204 +25,23 @@
#include <FL/fl_draw.H>
#include <stdarg.h>
-/* Signature of Fl_PostScript::close_command() functions passed as parameters. */
+/** Signature of Fl_PostScript::close_command() functions passed as parameters. */
extern "C" {
- typedef int (Fl_PostScript_Close_Command)(FILE *);
+ typedef int (*Fl_PostScript_Close_Command)(FILE *);
}
-/**
- \cond DriverDev
- \addtogroup DriverDeveloper
- \{
- */
-
-/**
- PostScript graphical backend.
- */
-class FL_EXPORT Fl_PostScript_Graphics_Driver : public Fl_Graphics_Driver {
-private:
- void transformed_draw_extra(const char* str, int n, double x, double y, int w, bool rtl);
- void *prepare_rle85();
- void write_rle85(uchar b, void *data);
- void close_rle85(void *data);
- void *prepare85();
- void write85(void *data, const uchar *p, int len);
- void close85(void *data);
- int scale_for_image_(Fl_Image *img, int XP, int YP, int WP, int HP,int cx, int cy);
-protected:
- uchar **mask_bitmap() {return &mask;}
-public:
- Fl_PostScript_Graphics_Driver();
-#ifndef FL_DOXYGEN
- enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS};
-
- class Clip {
- public:
- int x, y, w, h;
- Clip *prev;
- };
- Clip * clip_;
-
- int lang_level_;
- 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 enough
- void concat(); // transform ror scalable dradings...
- void reconcat(); //invert
- void recover(); //recovers the state after grestore (such as line styles...)
- void reset();
-
- uchar * mask;
- int mx; // width of mask;
- int my; // mask lines
- //Fl_Color bg_;
- Fl_PostScript_Close_Command* close_cmd_;
- int page_policy_;
- int nPages;
- int orientation_;
-
- float scale_x;
- float scale_y;
- float angle;
- int left_margin;
- int top_margin;
-
- FILE *output;
- double pw_, ph_;
-
- uchar bg_r, bg_g, bg_b;
- int start_postscript (int pagecount, enum Fl_Paged_Device::Page_Format format, enum Fl_Paged_Device::Page_Layout layout);
- /* int alpha_mask(const uchar * data, int w, int h, int D, int LD=0);
- */
- 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);
-
- enum Fl_Paged_Device::Page_Format page_format_;
- char *ps_filename_;
-
- void page_policy(int p);
- int page_policy(){return page_policy_;};
- void close_command(Fl_PostScript_Close_Command* cmd){close_cmd_=cmd;};
- FILE * file() {return output;};
- //void orientation (int o);
- //Fl_PostScript_Graphics_Driver(FILE *o, int lang_level, int pages = 0); // ps (also multi-page) constructor
- //Fl_PostScript_Graphics_Driver(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);
-#endif // FL_DOXYGEN
-
- // implementation of drawing methods
- void color(Fl_Color c);
- void color(uchar r, uchar g, uchar b);
-
- 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 draw_image(const uchar* d, int x,int y,int w,int h, int delta=3, int ldelta=0);
- void draw_image_mono(const uchar* d, int x,int y,int w,int h, int delta=1, int ld=0);
- void draw_image(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=3);
- void draw_image_mono(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=1);
-
- void draw(const char* s, int nBytes, int x, int y) {transformed_draw(s,nBytes,x,y); };
- void draw(const char* s, int nBytes, float x, float y) {transformed_draw(s,nBytes,x,y); };
- void draw(int angle, const char *str, int n, int x, int y);
- void rtl_draw(const char* s, int n, int x, int y);
- void font(int face, int size);
- double width(const char *, int);
- double width(unsigned int u);
- void text_extents(const char *c, int n, int &dx, int &dy, int &w, int &h);
- int height();
- int descent();
- void draw_pixmap(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
- void draw_bitmap(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
- void draw_rgb(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
- /** Shields output PostScript data from modifications of the current locale.
- It typically avoids PostScript errors caused if the current locale uses comma instead of dot
- as "decimal point".
- \param format directives controlling output PostScript data
- \return value returned by vfprintf() call
- */
- int clocale_printf(const char *format, ...);
- ~Fl_PostScript_Graphics_Driver();
- // ---
- 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();
-};
-
-/**
- \}
- \endcond
- */
+class Fl_PostScript_Graphics_Driver;
/**
To send graphical output to a PostScript file.
This class is used exactly as the Fl_Printer class except for the begin_job() call,
two variants of which are usable and allow to specify what page format and layout are desired.
- PostScript text uses vectorial fonts when using the FLTK standard fonts
- and the latin alphabet or a few other characters listed in the following table.
+ <b>Processing of text</b>: Text uses vectorial fonts under the X11 + pango platform.
+ 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.
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.
<table>
@@ -241,37 +60,31 @@ public:
<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>
- <br> All other unicode characters or all other fonts (FL_FREE_FONT and above) are output as a bitmap.
- <br> FLTK standard fonts are output using the corresponding PostScript standard fonts.
-
+
*/
class FL_EXPORT Fl_PostScript_File_Device : public Fl_Paged_Device {
protected:
/**
\brief Returns the PostScript driver of this drawing surface.
*/
- Fl_PostScript_Graphics_Driver *driver();
+ inline Fl_PostScript_Graphics_Driver *driver() { return (Fl_PostScript_Graphics_Driver*)Fl_Surface_Device::driver(); }
public:
- /**
- @brief The constructor.
- */
- Fl_PostScript_File_Device();
- /**
- @brief The destructor.
- */
+ /** The constructor. */
+ Fl_PostScript_File_Device();
+ /** The destructor. */
~Fl_PostScript_File_Device();
/** Don't use with this class. */
int begin_job(int pagecount, int* from, int* to, char **perr_message);
- /**
- @brief Begins the session where all graphics requests will go to a local PostScript file.
- *
- Opens a file dialog entitled with Fl_PostScript_File_Device::file_chooser_title to select an output PostScript file.
+ /** 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.
@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.
*/
- int begin_job(int pagecount = 0, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
+ int begin_job(int pagecount = 0, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4,
enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT);
/** Synonym of begin_job().
For API compatibility with FLTK 1.3.x */
@@ -279,9 +92,9 @@ public:
enum Fl_Paged_Device::Page_Layout layout = Fl_Paged_Device::PORTRAIT) {
return begin_job(pagecount, format, layout);
}
- /**
- @brief Begins the session where all graphics requests will go to FILE pointer.
- *
+ /** 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.
@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.
@@ -308,11 +121,14 @@ public:
void translate(int x, int y);
void untranslate(void);
int end_page (void);
+ /** Finishes all PostScript output.
+ This also closes the underlying \p fclose(file()) unless close_command() was used to set another function.
+ */
void end_job(void);
- /** \brief Label of the PostScript file chooser window */
+ /** Label of the PostScript file chooser window */
static const char *file_chooser_title;
/** Returns the underlying FILE* receiving all PostScript data */
- FILE *file() { return driver()->file(); }
+ FILE *file();
};
/** Encapsulated PostScript drawing surface.
@@ -329,13 +145,10 @@ public:
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(); }
@@ -343,27 +156,37 @@ 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.
+ \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.
*/
- Fl_EPS_File_Surface(int width, int height, FILE *eps, Fl_Color background = FL_WHITE);
+ Fl_EPS_File_Surface(int width, int height, FILE *eps_output,
+ Fl_Color background = FL_WHITE, Fl_PostScript_Close_Command closef = NULL);
/**
Destructor.
- The underlying FILE pointer remains open after destruction of the Fl_EPS_File_Surface object
- unless close() was called.
+ 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().
*/
~Fl_EPS_File_Surface();
virtual int printable_rect(int *w, int *h);
/** Returns the underlying FILE pointer */
- FILE *file() { return driver() ? driver()->output : NULL; }
+ FILE *file();
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. */
+ /** 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. */
int close();
};