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
This commit is contained in:
Manolo Gouy 2016-09-22 07:44:34 +00:00
parent 145cca26bd
commit 02535d1222
9 changed files with 44 additions and 18 deletions

View File

@ -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"

View File

@ -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$".
//

View File

@ -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);
};

View File

@ -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 <FL/Fl.H>
#include <FL/fl_draw.H>
@ -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

View File

@ -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 <math.h>
#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/fl_utf8.h>
#include <FL/fl_utf8.h> // for fl_utf8toUtf16()
#include <FL/Fl_Screen_Driver.H>
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;

View File

@ -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);
};

View File

@ -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);
};

View File

@ -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 <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/x.H>
@ -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) {

View File

@ -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 <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/x.H>
@ -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,