From 02535d122296b00a99fa30e0253f83c82f177894 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Thu, 22 Sep 2016 07:44:34 +0000 Subject: [PATCH] Rewrite Fl::set_fonts(), Fl::get_font_sizes(), Fl::get_font_name() under the driver model. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11965 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl_Screen_Driver.H | 5 +++++ src/Fl.cxx | 12 ++++++++++++ src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H | 3 +++ src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx | 8 ++++---- .../Quartz/Fl_Quartz_Graphics_Driver_font.cxx | 12 +++++------- src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H | 3 +++ src/drivers/X11/Fl_X11_Screen_Driver.H | 3 +++ src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx | 7 ++++--- .../Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx | 9 +++++---- 9 files changed, 44 insertions(+), 18 deletions(-) diff --git a/FL/Fl_Screen_Driver.H b/FL/Fl_Screen_Driver.H index 853798dac..412af653f 100644 --- a/FL/Fl_Screen_Driver.H +++ b/FL/Fl_Screen_Driver.H @@ -124,6 +124,11 @@ public: static unsigned font_desc_size(); static const char *font_name(int num); static void font_name(int num, const char *name); + // to support Fl::set_fonts(), Fl::get_font_sizes(), Fl::get_font_name() + virtual Fl_Font set_fonts(const char *name) {return 0;} + virtual int get_font_sizes(Fl_Font fnum, int*& sizep) {return 0;} + virtual const char* get_font_name(Fl_Font fnum, int* ap) {return NULL;} + // read raw image from a window or an offscreen buffer #if defined(FL_PORTING) # pragma message "FL_PORTING: implement code to read RGB data from screen" diff --git a/src/Fl.cxx b/src/Fl.cxx index e798166b0..b000893c6 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -2004,6 +2004,18 @@ void fl_open_callback(void (*cb)(const char *)) } /** @} */ +Fl_Font Fl::set_fonts(const char* xstarname) { + return Fl::screen_driver()->set_fonts(xstarname); +} + +const char* Fl::get_font_name(Fl_Font fnum, int* ap) { + return Fl::screen_driver()->get_font_name(fnum, ap); +} + +int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) { + return Fl::screen_driver()->get_font_sizes(fnum, sizep); +} + // // End of "$Id$". // diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H index 29ae7570e..3c639a58e 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H @@ -94,6 +94,9 @@ public: virtual void enable_im(); virtual void disable_im(); virtual void open_display(); + virtual Fl_Font set_fonts(const char *name); + virtual int get_font_sizes(Fl_Font fnum, int*& sizep); + virtual const char* get_font_name(Fl_Font fnum, int* ap); }; diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx index 3f1b31223..495ceb858 100644 --- a/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx +++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx @@ -37,6 +37,7 @@ // Select fonts from the FLTK font table. #include "Fl_GDI_Graphics_Driver.H" +#include "../WinAPI/Fl_WinAPI_Screen_Driver.H" #include "../../flstring.h" #include #include @@ -62,7 +63,7 @@ #define ENDOFBUFFER 127 // sizeof(Fl_Font.fontname)-1 // turn a stored font name into a pretty name: -const char* Fl::get_font_name(Fl_Font fnum, int* ap) { +const char* Fl_WinAPI_Screen_Driver::get_font_name(Fl_Font fnum, int* ap) { Fl_Fontdesc *f = fl_fonts + fnum; if (!f->fontname[0]) { const char* p = f->name; @@ -112,7 +113,7 @@ enumcbw(CONST LOGFONTW *lpelf, return 1; } /* enumcbw */ -Fl_Font Fl::set_fonts(const char* xstarname) { +Fl_Font Fl_WinAPI_Screen_Driver::set_fonts(const char* xstarname) { HDC gc = (HDC)fl_graphics_driver->gc(); if (fl_free_font == FL_FREE_FONT) {// if not already been called if (!gc) gc = fl_GetDC(0); @@ -163,8 +164,7 @@ EnumSizeCbW(CONST LOGFONTW * /*lpelf*/, } -int -Fl::get_font_sizes(Fl_Font fnum, int*& sizep) { +int Fl_WinAPI_Screen_Driver::get_font_sizes(Fl_Font fnum, int*& sizep) { nbSize = 0; Fl_Fontdesc *s = fl_fonts+fnum; if (!s->name) s = fl_fonts; // empty slot in table, use entry 0 diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx index 2d951cc8c..46c1dc925 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx @@ -21,18 +21,16 @@ #include "Fl_Quartz_Graphics_Driver.h" #include "../Darwin/Fl_Darwin_System_Driver.H" +#include "../Cocoa/Fl_Cocoa_Screen_Driver.H" #include "Fl_Font.H" #include #include #include -#include +#include // for fl_utf8toUtf16() #include Fl_Fontdesc* fl_fonts = NULL; -/* from fl_utf.c */ -extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen); - static CGAffineTransform font_mx = { 1, 0, 0, -1, 0, 0 }; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 static CFMutableDictionaryRef attributes = NULL; @@ -49,7 +47,7 @@ static const int CoreText_threshold = 100500; // this represents Mac OS 10.5 #define ENDOFBUFFER sizeof(fl_fonts->fontname)-1 // turn a stored font name into a pretty name: -const char* Fl::get_font_name(Fl_Font fnum, int* ap) { +const char* Fl_Cocoa_Screen_Driver::get_font_name(Fl_Font fnum, int* ap) { if (!fl_fonts) fl_fonts = Fl_Screen_Driver::calc_fl_fonts(); Fl_Fontdesc *f = fl_fonts + fnum; if (!f->fontname[0]) { @@ -121,7 +119,7 @@ static int fl_free_font = FL_FREE_FONT; // and to sort them so the first 4 in a family are normal, bold, italic, // and bold italic. -Fl_Font Fl::set_fonts(const char* xstarname) { +Fl_Font Fl_Cocoa_Screen_Driver::set_fonts(const char* xstarname) { #pragma unused ( xstarname ) if (fl_free_font > FL_FREE_FONT) return (Fl_Font)fl_free_font; // if already called @@ -200,7 +198,7 @@ else { return 0; } -int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) { +int Fl_Cocoa_Screen_Driver::get_font_sizes(Fl_Font fnum, int*& sizep) { static int array[128]; if (!fl_fonts) fl_fonts = Fl_Screen_Driver::calc_fl_fonts(); Fl_Fontdesc *s = fl_fonts+fnum; diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H index 80529138f..0fc1e1cbe 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H @@ -77,6 +77,9 @@ public: virtual void enable_im(); virtual void disable_im(); virtual void open_display(); + virtual Fl_Font set_fonts(const char *name); + virtual int get_font_sizes(Fl_Font fnum, int*& sizep); + virtual const char* get_font_name(Fl_Font fnum, int* ap); }; diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.H b/src/drivers/X11/Fl_X11_Screen_Driver.H index 8f3638718..a38e6ef4f 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.H +++ b/src/drivers/X11/Fl_X11_Screen_Driver.H @@ -87,6 +87,9 @@ public: virtual void disable_im(); virtual void open_display(); virtual void close_display(); + virtual Fl_Font set_fonts(const char *name); + virtual int get_font_sizes(Fl_Font fnum, int*& sizep); + virtual const char* get_font_name(Fl_Font fnum, int* ap); }; diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx index 766fd0673..d1f28e831 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx @@ -19,6 +19,7 @@ // Select fonts from the FLTK font table. #include "../../flstring.h" #include "Fl_Xlib_Graphics_Driver.H" +#include "../X11/Fl_X11_Screen_Driver.H" #include #include #include @@ -93,7 +94,7 @@ static int use_registry(const char *p) { #define ENDOFBUFFER 127 // sizeof(Fl_Font.fontname)-1 // turn a stored (with *'s) X font name into a pretty name: -const char* Fl::get_font_name(Fl_Font fnum, int* ap) { +const char* Fl_X11_Screen_Driver::get_font_name(Fl_Font fnum, int* ap) { Fl_Fontdesc *f = fl_fonts + fnum; if (!f->fontname[0]) { int type = 0; @@ -264,7 +265,7 @@ static int to_canonical(char *to, const char *from, size_t tolen) { static unsigned int fl_free_font = FL_FREE_FONT; -Fl_Font Fl::set_fonts(const char* xstarname) { +Fl_Font Fl_X11_Screen_Driver::set_fonts(const char* xstarname) { if (fl_free_font > (unsigned)FL_FREE_FONT) // already been here return (Fl_Font)fl_free_font; fl_open_display(); @@ -317,7 +318,7 @@ Fl_Font Fl::set_fonts(const char* xstarname) { return (Fl_Font)fl_free_font; } -int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) { +int Fl_X11_Screen_Driver::get_font_sizes(Fl_Font fnum, int*& sizep) { Fl_Fontdesc *s = fl_fonts+fnum; if (!s->name) s = fl_fonts; // empty slot in table, use entry 0 if (!s->xlist) { diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx index befb90ea0..0e5f8cb71 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx @@ -19,6 +19,7 @@ // Select fonts from the FLTK font table. #include "../../flstring.h" #include "Fl_Xlib_Graphics_Driver.H" +#include "../X11/Fl_X11_Screen_Driver.H" #include #include #include @@ -43,7 +44,7 @@ #define USE_OVERLAY 0 // turn a stored font name in "fltk format" into a pretty name: -const char* Fl::get_font_name(Fl_Font fnum, int* ap) { +const char* Fl_X11_Screen_Driver::get_font_name(Fl_Font fnum, int* ap) { Fl_Fontdesc *f = fl_fonts + fnum; if (!f->fontname[0]) { const char* p = f->name; @@ -217,7 +218,7 @@ static int fl_free_font = FL_FREE_FONT; // Also, for now I'm ignoring the "pattern_name" and just getting everything... // AND I don't try and skip the fonts we've already loaded in the defaults. // Blimey! What a hack! -Fl_Font Fl::set_fonts(const char* pattern_name) +Fl_Font Fl_X11_Screen_Driver::set_fonts(const char* pattern_name) { FcFontSet *fnt_set; // Will hold the list of fonts we find FcPattern *fnt_pattern; // Holds the generic "match all names" pattern @@ -363,11 +364,11 @@ static int int_sort(const void *aa, const void *bb) { // Return all the point sizes supported by this font: // Suprisingly enough Xft works exactly like fltk does and returns // the same list. Except there is no way to tell if the font is scalable. -int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) { +int Fl_X11_Screen_Driver::get_font_sizes(Fl_Font fnum, int*& sizep) { Fl_Fontdesc *s = fl_fonts+fnum; if (!s->name) s = fl_fonts; // empty slot in table, use entry 0 - fl_open_display(); + open_display(); XftFontSet* fs = XftListFonts(fl_display, fl_screen, XFT_FAMILY, XftTypeString, s->name+1, (void *)0,