summaryrefslogtreecommitdiff
path: root/src/drivers/PostScript
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/PostScript')
-rw-r--r--src/drivers/PostScript/Fl_PostScript.cxx22
-rw-r--r--src/drivers/PostScript/Fl_PostScript_Graphics_Driver.H16
-rw-r--r--src/drivers/PostScript/Fl_PostScript_image.cxx122
3 files changed, 150 insertions, 10 deletions
diff --git a/src/drivers/PostScript/Fl_PostScript.cxx b/src/drivers/PostScript/Fl_PostScript.cxx
index 38407d5c4..e930bbee7 100644
--- a/src/drivers/PostScript/Fl_PostScript.cxx
+++ b/src/drivers/PostScript/Fl_PostScript.cxx
@@ -1,7 +1,7 @@
//
// Classes Fl_PostScript_File_Device and Fl_PostScript_Graphics_Driver for the Fast Light Tool Kit (FLTK).
//
-// Copyright 2010-2020 by Bill Spitzak and others.
+// Copyright 2010-2022 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
@@ -1499,8 +1499,24 @@ int Fl_PostScript_Graphics_Driver::start_eps(int width, int height) {
return 0;
}
-PangoFontDescription* Fl_PostScript_Graphics_Driver::pango_font_description(Fl_Font fnum) {
- return Fl_Graphics_Driver::default_driver().pango_font_description(fnum);
+
+void Fl_PostScript_Graphics_Driver::transformed_draw(const char* str, int n, double x, double y) {
+ if (!n) return;
+ PangoFontDescription *pfd = Fl_Graphics_Driver::default_driver().pango_font_description(font());
+ pango_layout_set_font_description(pango_layout_, pfd);
+ int pwidth, pheight;
+ cairo_save(cairo_);
+ pango_layout_set_text(pango_layout_, str, n);
+ pango_layout_get_size(pango_layout_, &pwidth, &pheight);
+ if (pwidth > 0) {
+ double s = width(str, n);
+ cairo_translate(cairo_, x, y - height() + descent());
+ s = (s/pwidth) * PANGO_SCALE;
+ cairo_scale(cairo_, s, s);
+ pango_cairo_show_layout(cairo_, pango_layout_);
+ }
+ cairo_restore(cairo_);
+ check_status();
}
#endif // USE_PANGO
diff --git a/src/drivers/PostScript/Fl_PostScript_Graphics_Driver.H b/src/drivers/PostScript/Fl_PostScript_Graphics_Driver.H
index eb2060cc9..9ff238738 100644
--- a/src/drivers/PostScript/Fl_PostScript_Graphics_Driver.H
+++ b/src/drivers/PostScript/Fl_PostScript_Graphics_Driver.H
@@ -1,7 +1,7 @@
//
// Support for graphics output to PostScript file for the Fast Light Tool Kit (FLTK).
//
-// Copyright 2010-2020 by Bill Spitzak and others.
+// Copyright 2010-2022 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
@@ -70,17 +70,27 @@ public:
int height();
int descent();
void text_extents(const char *c, int n, int &dx, int &dy, int &w, int &h);
+ // draw text at width measured on display
+ void transformed_draw(const char* s, int n, double x, double y);
+ 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) {Fl_Cairo_Graphics_Driver::draw(angle, str, n, x, y);}
+
void color(Fl_Color c);
void color(uchar r, uchar g, uchar b) {Fl_Cairo_Graphics_Driver::color(r,g,b);}
Fl_Color color();
void point(int x, int y);
int not_clipped(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);
- virtual PangoFontDescription* pango_font_description(Fl_Font fnum);
virtual int has_feature(driver_feature feature_mask) { return feature_mask & PRINTER; }
+ // draw image classes without caching them
+ void draw_rgb_bitmap_(Fl_Image *img,int XP, int YP, int WP, int HP, int cx, int cy);
+ 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);
};
-#else // USE_PANGO
+#else // ! USE_PANGO
class FL_EXPORT Fl_PostScript_Graphics_Driver : public Fl_Graphics_Driver {
private:
diff --git a/src/drivers/PostScript/Fl_PostScript_image.cxx b/src/drivers/PostScript/Fl_PostScript_image.cxx
index 38b129e44..f2a41a2d4 100644
--- a/src/drivers/PostScript/Fl_PostScript_image.cxx
+++ b/src/drivers/PostScript/Fl_PostScript_image.cxx
@@ -1,7 +1,7 @@
//
// Postscript image drawing implementation for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2021 by Bill Spitzak and others.
+// Copyright 1998-2022 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
@@ -25,8 +25,10 @@
#include <stdlib.h> // abs(int)
#include <string.h> // memcpy()
-#if ! USE_PANGO
-#include <stdio.h> // fprintf()
+#if USE_PANGO
+# include <cairo/cairo.h>
+#else
+# include <stdio.h> // fprintf()
#endif
struct callback_data {
@@ -66,7 +68,119 @@ void Fl_PostScript_Graphics_Driver::draw_image(const uchar *data, int ix, int iy
draw_image(draw_image_cb, &cb_data, ix, iy, iw, ih, abs(D));
}
-#if ! USE_PANGO
+#if USE_PANGO
+
+static void destroy_BGRA(void *data) {
+ delete[] (uchar*)data;
+}
+
+
+void Fl_PostScript_Graphics_Driver::draw_pixmap(Fl_Pixmap *pxm,int XP, int YP, int WP, int HP, int cx, int cy) {
+ Fl_RGB_Image *rgb = new Fl_RGB_Image(pxm);
+ draw_rgb_bitmap_(rgb, XP, YP, WP, HP, cx, cy);
+ delete rgb;
+}
+
+
+void Fl_PostScript_Graphics_Driver::draw_rgb(Fl_RGB_Image *rgb,int XP, int YP, int WP, int HP, int cx, int cy) {
+ draw_rgb_bitmap_(rgb, XP, YP, WP, HP, cx, cy);
+}
+
+
+void Fl_PostScript_Graphics_Driver::draw_bitmap(Fl_Bitmap *bitmap,int XP, int YP, int WP, int HP, int cx, int cy) {
+ draw_rgb_bitmap_(bitmap, XP, YP, WP, HP, cx, cy);
+}
+
+
+void Fl_PostScript_Graphics_Driver::draw_rgb_bitmap_(Fl_Image *img,int XP, int YP, int WP, int HP, int cx, int cy)
+{
+ cairo_surface_t *surf;
+ cairo_format_t format = (img->d() >= 1 ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_A1);
+ int stride = cairo_format_stride_for_width(format, img->data_w());
+ uchar *BGRA = new uchar[stride * img->data_h()];
+ memset(BGRA, 0, stride * img->data_h());
+ if (img->d() >= 1) { // process Fl_RGB_Image of all depths
+ Fl_RGB_Image *rgb = (Fl_RGB_Image*)img;
+ int lrgb = rgb->ld() ? rgb->ld() : rgb->data_w() * rgb->d();
+ uchar A = 0xff, R,G,B, *q;
+ const uchar *r;
+ float f = 1;
+ if (rgb->d() >= 3) { // color images
+ for (int j = 0; j < rgb->data_h(); j++) {
+ r = rgb->array + j * lrgb;
+ q = BGRA + j * stride;
+ for (int i = 0; i < rgb->data_w(); i++) {
+ R = *r;
+ G = *(r+1);
+ B = *(r+2);
+ if (rgb->d() == 4) {
+ A = *(r+3);
+ f = float(A)/0xff;
+ }
+ *q = B * f;
+ *(q+1) = G * f;
+ *(q+2) = R * f;
+ *(q+3) = A;
+ r += rgb->d(); q += 4;
+ }
+ }
+ } else if (rgb->d() == 1 || rgb->d() == 2) { // B&W
+ for (int j = 0; j < rgb->data_h(); j++) {
+ r = rgb->array + j * lrgb;
+ q = BGRA + j * stride;
+ for (int i = 0; i < rgb->data_w(); i++) {
+ G = *r;
+ if (rgb->d() == 2) {
+ A = *(r+1);
+ f = float(A)/0xff;
+ }
+ *(q) = G * f;
+ *(q+1) = G * f;
+ *(q+2) = G * f;
+ *(q+3) = A;
+ r += rgb->d(); q += 4;
+ }
+ }
+ }
+ } else {
+ Fl_Bitmap *bm = (Fl_Bitmap*)img;
+ uchar *r, p;
+ unsigned *q;
+ for (int j = 0; j < bm->data_h(); j++) {
+ r = (uchar*)bm->array + j * ((bm->data_w() + 7)/8);
+ q = (unsigned*)(BGRA + j * stride);
+ unsigned k = 0, mask32 = 1;
+ p = *r;
+ for (int i = 0; i < bm->data_w(); i++) {
+ if (p&1) (*q) |= mask32;
+ k++;
+ if (k % 8 != 0) p >>= 1; else p = *(++r);
+ if (k % 32 != 0) mask32 <<= 1; else {q++; mask32 = 1;}
+ }
+ }
+ }
+ surf = cairo_image_surface_create_for_data(BGRA, format, img->data_w(), img->data_h(), stride);
+ if (cairo_surface_status(surf) == CAIRO_STATUS_SUCCESS) {
+ static cairo_user_data_key_t key = {};
+ (void)cairo_surface_set_user_data(surf, &key, BGRA, destroy_BGRA);
+ cairo_pattern_t *pat = cairo_pattern_create_for_surface(surf);
+ cairo_save(cairo_);
+ cairo_rectangle(cairo_, XP-0.5, YP-0.5, WP+1, HP+1);
+ cairo_clip(cairo_);
+ if (img->d() >= 1) cairo_set_source(cairo_, pat);
+ cairo_matrix_t matrix;
+ cairo_matrix_init_scale(&matrix, double(img->data_w())/(img->w()+1), double(img->data_h())/(img->h()+1));
+ cairo_matrix_translate(&matrix, -XP+0.5+cx, -YP+0.5+cy);
+ cairo_pattern_set_matrix(pat, &matrix);
+ cairo_mask(cairo_, pat);
+ cairo_pattern_destroy(pat);
+ cairo_surface_destroy(surf);
+ cairo_restore(cairo_);
+ check_status();
+ }
+}
+
+#else // USE_PANGO
//
// Implementation of the /ASCII85Encode PostScript filter