Complete removal of platform-dependent code from fl_set_font.cxx

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11512 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-04-02 15:37:03 +00:00
parent 7a8f307fca
commit 6b6c71265f
6 changed files with 88 additions and 37 deletions

View File

@ -114,6 +114,10 @@ public:
virtual int text_display_can_leak() { return 0; }
// an implementation which returns NULL may be enough
static struct Fl_Fontdesc *calc_fl_fonts();
// API to the platform-dependent Fl_Fontdesc structure
static unsigned font_desc_size();
static const char *font_name(int num);
static void font_name(int num, const char *name);
};

View File

@ -19,6 +19,7 @@
#include "../../config_lib.h"
#include "Fl_Cocoa_Screen_Driver.H"
#include "../Quartz/Fl_Font.H"
#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/Fl_Graphics_Driver.H>
@ -301,6 +302,29 @@ int Fl_Cocoa_Screen_Driver::compose(int &del) {
return 1;
}
unsigned Fl_Screen_Driver::font_desc_size() {
return (unsigned)sizeof(Fl_Fontdesc);
}
const char *Fl_Screen_Driver::font_name(int num) {
if (!fl_fonts) fl_fonts = Fl_Screen_Driver::calc_fl_fonts();
return fl_fonts[num].name;
}
void Fl_Screen_Driver::font_name(int num, const char *name) {
Fl_Fontdesc *s = fl_fonts + num;
if (s->name) {
if (!strcmp(s->name, name)) {s->name = name; return;}
for (Fl_Font_Descriptor* f = s->first; f;) {
Fl_Font_Descriptor* n = f->next; delete f; f = n;
}
s->first = 0;
}
s->name = name;
s->fontname[0] = 0;
s->first = 0;
}
//
// End of "$Id$".
//

View File

@ -63,8 +63,6 @@ struct Fl_Fontdesc {
const char *name;
char fontname[128]; // "Pretty" font name
Fl_Font_Descriptor *first; // linked list of sizes of this style
char **xlist; // matched X font names
int n; // size of xlist, negative = don't free xlist!
};
extern FL_EXPORT Fl_Fontdesc *fl_fonts; // the table

View File

@ -19,6 +19,7 @@
#include "../../config_lib.h"
#include "Fl_WinAPI_Screen_Driver.H"
#include "../GDI/Fl_Font.H"
#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/Fl_Graphics_Driver.H>
@ -530,6 +531,28 @@ struct Fl_Fontdesc *Fl_Screen_Driver::calc_fl_fonts() {
return NULL;
}
unsigned Fl_Screen_Driver::font_desc_size() {
return (unsigned)sizeof(Fl_Fontdesc);
}
const char *Fl_Screen_Driver::font_name(int num) {
return fl_fonts[num].name;
}
void Fl_Screen_Driver::font_name(int num, const char *name) {
Fl_Fontdesc *s = fl_fonts + num;
if (s->name) {
if (!strcmp(s->name, name)) {s->name = name; return;}
for (Fl_Font_Descriptor* f = s->first; f;) {
Fl_Font_Descriptor* n = f->next; delete f; f = n;
}
s->first = 0;
}
s->name = name;
s->fontname[0] = 0;
s->first = 0;
}
//
// End of "$Id$".
//

View File

@ -19,6 +19,7 @@
#include "../../config_lib.h"
#include "Fl_X11_Screen_Driver.H"
#include "../xlib/Fl_Font.H"
#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/fl_ask.H>
@ -640,6 +641,30 @@ struct Fl_Fontdesc *Fl_Screen_Driver::calc_fl_fonts() {
return NULL;
}
unsigned Fl_Screen_Driver::font_desc_size() {
return (unsigned)sizeof(Fl_Fontdesc);
}
const char *Fl_Screen_Driver::font_name(int num) {
return fl_fonts[num].name;
}
void Fl_Screen_Driver::font_name(int num, const char *name) {
Fl_Fontdesc *s = fl_fonts + num;
if (s->name) {
if (!strcmp(s->name, name)) {s->name = name; return;}
if (s->xlist && s->n >= 0) XFreeFontNames(s->xlist);
for (Fl_Font_Descriptor* f = s->first; f;) {
Fl_Font_Descriptor* n = f->next; delete f; f = n;
}
s->first = 0;
}
s->name = name;
s->fontname[0] = 0;
s->xlist = 0;
s->first = 0;
}
//
// End of "$Id$".
//

View File

@ -24,74 +24,51 @@
#include <FL/fl_draw.H>
#include <FL/Fl_Screen_Driver.H>
#include "flstring.h"
#if defined(__APPLE__)
#include "drivers/Quartz/Fl_Font.H"
#elif defined(WIN32)
#include "drivers/GDI/Fl_Font.H"
#elif USE_X11
#include "drivers/Xlib/Fl_Font.H"
#endif
#include <stdlib.h>
struct Fl_Fontdesc;
extern FL_EXPORT Fl_Fontdesc *fl_fonts; // the table
static int table_size;
/**
Changes a face. The string pointer is simply stored,
the string is not copied, so the string must be in static memory.
*/
void Fl::set_font(Fl_Font fnum, const char* name) {
unsigned width = Fl_Screen_Driver::font_desc_size();
if (!fl_fonts) fl_fonts = Fl_Screen_Driver::calc_fl_fonts();
while (fnum >= table_size) {
int i = table_size;
if (!i) { // don't realloc the built-in table
table_size = 2*FL_FREE_FONT;
i = FL_FREE_FONT;
Fl_Fontdesc* t = (Fl_Fontdesc*)malloc(table_size*sizeof(Fl_Fontdesc));
memcpy(t, fl_fonts, FL_FREE_FONT*sizeof(Fl_Fontdesc));
Fl_Fontdesc* t = (Fl_Fontdesc*)malloc(table_size*width);
memcpy(t, fl_fonts, FL_FREE_FONT*width);
fl_fonts = t;
} else {
table_size = 2*table_size;
fl_fonts=(Fl_Fontdesc*)realloc(fl_fonts, table_size*sizeof(Fl_Fontdesc));
fl_fonts=(Fl_Fontdesc*)realloc(fl_fonts, table_size*width);
}
for (; i < table_size; i++) {
fl_fonts[i].fontname[0] = 0;
fl_fonts[i].name = 0;
#if defined(USE_X11)
fl_fonts[i].xlist = 0;
fl_fonts[i].n = 0;
#endif // !WIN32 && !__APPLE__ // PORTME: Fl_Graphics_Driver - platform fonts
memset((char*)fl_fonts + i * width, 0, width);
}
}
Fl_Fontdesc* s = fl_fonts+fnum;
if (s->name) {
if (!strcmp(s->name, name)) {s->name = name; return;}
#if defined(USE_X11)
if (s->xlist && s->n >= 0) XFreeFontNames(s->xlist);
#endif
for (Fl_Font_Descriptor* f = s->first; f;) {
Fl_Font_Descriptor* n = f->next; delete f; f = n;
}
s->first = 0;
}
s->name = name;
s->fontname[0] = 0;
#if defined(USE_X11)
s->xlist = 0;
#endif
s->first = 0;
Fl_Screen_Driver::font_name(fnum, name);
Fl_Display_Device::display_device()->driver()->font(-1, 0);
}
/** Copies one face to another. */
void Fl::set_font(Fl_Font fnum, Fl_Font from) {
Fl::set_font(fnum, get_font(from));
}
/**
Gets the string for this face. This string is different for each
face. Under X this value is passed to XListFonts to get all the sizes
of this face.
*/
const char* Fl::get_font(Fl_Font fnum) {
if (!fl_fonts) fl_fonts = Fl_Screen_Driver::calc_fl_fonts();
return fl_fonts[fnum].name;
return Fl_Screen_Driver::font_name(fnum);
}
//