From d36013aed9c2e5951fc710b5118ee767d0e1d651 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Thu, 10 Feb 2011 18:41:12 +0000 Subject: [PATCH] Allow to use non-standard fonts with the PostScript backend: in that case all characters are reproduced using a bitmap. Fixed the bitmap-based text output for the X11-no-Xft case. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8411 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_PostScript.cxx | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Fl_PostScript.cxx b/src/Fl_PostScript.cxx index 6aea75ba7..75cc987fe 100644 --- a/src/Fl_PostScript.cxx +++ b/src/Fl_PostScript.cxx @@ -926,10 +926,10 @@ static const char *_fontNames[] = { }; void Fl_PostScript_Graphics_Driver::font(int f, int s) { - if (f >= FL_FREE_FONT) - f = FL_COURIER; - fprintf(output, "/%s SF\n" , _fontNames[f]); - fprintf(output,"%i FS\n", s); + if (f < FL_FREE_FONT) { + fprintf(output, "/%s SF\n" , _fontNames[f]); + fprintf(output,"%i FS\n", s); + } Fl_Display_Device::display_device()->driver()->font(f,s); // Use display fonts for font measurement Fl_Graphics_Driver::font(f, s); } @@ -994,11 +994,16 @@ static uchar *calc_mask(uchar *img, int w, int h, Fl_Color bg) // write to PostScript a bitmap image of a UTF8 string static void transformed_draw_extra(const char* str, int n, double x, double y, int w, FILE *output) { - const float scale = 3; // scale for bitmask computation + // scale for bitmask computation +#if defined(USE_X11) && !USE_XFT + const float scale = 1; // don't scale because we can't expect to have scalable fonts +#else + const float scale = 3; +#endif Fl_Fontsize old_size = fl_size(); - fl_font(fl_font(), (Fl_Fontsize)(scale * old_size) ); + Fl_Font fontnum = fl_font(); w = (int)(w *scale + 0.5); - int h = fl_height(); + int h = (int)(fl_height() * scale); // create an offscreen image of the string Fl_Color text_color = fl_color(); Fl_Color bg_color = fl_contrast(FL_WHITE, text_color); @@ -1008,11 +1013,20 @@ static void transformed_draw_extra(const char* str, int n, double x, double y, i // color offscreen background with a shade contrasting with the text color fl_rectf(0, 0, w+2, (int)(h+3*scale) ); fl_color(text_color); +#if defined(USE_X11) && !USE_XFT + // force seeing this font as new so it's applied to the offscreen graphics context + fl_graphics_driver->font_descriptor(NULL); + fl_graphics_driver->Fl_Graphics_Driver::font(fontnum, 0); +#endif + fl_font(fontnum, (Fl_Fontsize)(scale * old_size) ); fl_draw(str, n, 1, (int)(h * 0.8) ); // draw string in offscreen +#ifdef WIN32 + fl_font(0, FL_NORMAL_SIZE); // TODO: find something better +#endif // read (most of) the offscreen image uchar *img = fl_read_image(NULL, 1, 1, w, h, 0); fl_end_offscreen(); - fl_font(fl_font(), old_size); + fl_font(fontnum, old_size); fl_delete_offscreen(off); // compute the mask of what is not the background uchar *mask = calc_mask(img, w, h, bg_color); @@ -1063,6 +1077,10 @@ void Fl_PostScript_Graphics_Driver::transformed_draw(const char* str, int n, dou // compute display width of string int width = (int)fl_width(str, n); if (width == 0) return; + if (fl_font() >= FL_FREE_FONT) { + transformed_draw_extra(str, n, x, y, width, output); + return; + } fprintf(output, "%d <", width); // transforms UTF8 encoding to our custom PostScript encoding as follows: // extract each unicode character