From beb210d4d4ea2550fcc9de5a610b8fe6d9afc631 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Wed, 2 Dec 1998 15:51:38 +0000 Subject: [PATCH] Font changes from Bill. git-svn-id: file:///fltk/svn/fltk/trunk@109 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/fl_draw.H | 8 ++- FL/x.H | 5 +- src/Fl_Font.H | 40 +++++------ src/fl_font.cxx | 134 +++++++++++++++++-------------------- src/fl_font_win32.cxx | 29 ++++---- src/fl_set_font.cxx | 19 +++--- src/fl_set_fonts.cxx | 7 +- src/fl_set_fonts_win32.cxx | 22 +++--- src/gl_draw.cxx | 43 +++++------- 9 files changed, 143 insertions(+), 164 deletions(-) diff --git a/FL/fl_draw.H b/FL/fl_draw.H index e0531dbe5..c4b1fb7b4 100644 --- a/FL/fl_draw.H +++ b/FL/fl_draw.H @@ -1,5 +1,5 @@ // -// "$Id: fl_draw.H,v 1.4 1998/12/02 15:39:28 mike Exp $" +// "$Id: fl_draw.H,v 1.5 1998/12/02 15:51:33 mike Exp $" // // Portable drawing function header file for the Fast Light Tool Kit (FLTK). // @@ -121,8 +121,10 @@ double fl_width(uchar); // draw using current font: void fl_draw(const char*, int x, int y); void fl_draw(const char*, int n, int x, int y); -void fl_draw(const char*, int x, int y, int w, int h, Fl_Align); void fl_measure(const char*, int& x, int& y); +void fl_draw(const char*, int,int,int,int, Fl_Align); +void fl_draw(const char*, int,int,int,int, Fl_Align, + void (*callthis)(const char *, int n, int x, int y)); // boxtypes: void fl_frame(const char* s, int x, int y, int w, int h); @@ -156,5 +158,5 @@ int fl_add_symbol(const char* name, void (*drawit)(Fl_Color), int scalable); #endif // -// End of "$Id: fl_draw.H,v 1.4 1998/12/02 15:39:28 mike Exp $". +// End of "$Id: fl_draw.H,v 1.5 1998/12/02 15:51:33 mike Exp $". // diff --git a/FL/x.H b/FL/x.H index c6c06aa46..c5a82637e 100644 --- a/FL/x.H +++ b/FL/x.H @@ -1,5 +1,5 @@ // -// "$Id: x.H,v 1.6 1998/11/05 16:04:41 mike Exp $" +// "$Id: x.H,v 1.7 1998/12/02 15:51:34 mike Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -56,6 +56,7 @@ extern Colormap fl_colormap; // drawing functions: extern GC fl_gc; extern Window fl_window; +extern XFontStruct* fl_xfont; ulong fl_xpixel(Fl_Color i); ulong fl_xpixel(uchar r, uchar g, uchar b); void fl_clip_region(Region); @@ -116,5 +117,5 @@ extern int fl_background_pixel; // hack into Fl_X::make_xid() #endif // -// End of "$Id: x.H,v 1.6 1998/11/05 16:04:41 mike Exp $". +// End of "$Id: x.H,v 1.7 1998/12/02 15:51:34 mike Exp $". // diff --git a/src/Fl_Font.H b/src/Fl_Font.H index 3e2c1202f..ea937e53c 100644 --- a/src/Fl_Font.H +++ b/src/Fl_Font.H @@ -1,5 +1,5 @@ // -// "$Id: Fl_Font.H,v 1.3 1998/10/21 14:20:03 mike Exp $" +// "$Id: Fl_Font.H,v 1.4 1998/12/02 15:51:35 mike Exp $" // // Font definitions for the Fast Light Tool Kit (FLTK). // @@ -25,47 +25,42 @@ // Two internal fltk data structures: // -// Fl_Fontdesc: an entry into the fl_font() table. This entry may contain -// several "fonts" according to the system, for instance under X all the -// sizes are different X fonts, but only one fl_font. +// Fl_Fontdesc: an entry into the fl_font() table. There is one of these +// for each fltk font number. // -// Fl_XFont: a structure for an actual system font, with junk to help -// choose it and info on character sizes. Each Fl_Font has a linked -// list of these. These are created the first time each system font -// is used. +// Fl_FontSize: a structure for an actual system font, with junk to +// help choose it and info on character sizes. Each Fl_Fontdesc has a +// linked list of these. These are created the first time each system +// font/size combination is used. #ifndef FL_FONT_ #define FL_FONT_ -class Fl_XFont { +class Fl_FontSize { public: - Fl_XFont *next; // linked list of sizes of this style + Fl_FontSize *next; // linked list for this Fl_Fontdesc #ifndef WIN32 - XFontStruct* font; // X font information, 0 for display list - XCharStruct* per_char;// modified from XFontStruct to have 0x20-0xff in it - XCharStruct* free_this; // pointer saved for delete[] - Fl_XFont(const char*, int); + XFontStruct* font; // X font information + Fl_FontSize(const char* xfontname); #else HFONT fid; int width[256]; TEXTMETRIC metr; - Fl_XFont(const char*, int, int); + Fl_FontSize(const char* fontname, int size); #endif - int number; // which slot in FL's font table int minsize; // smallest point size that should use this int maxsize; // largest point size that should use this #if HAVE_GL unsigned int listbase;// base of display list, 0 = none #endif - ~Fl_XFont(); + ~Fl_FontSize(); }; -extern Fl_XFont *fl_current_xfont; -extern Fl_XFont *fl_fixed_xfont; +extern Fl_FontSize *fl_fontsize; // the currently selected one struct Fl_Fontdesc { const char *name; - Fl_XFont *first; // linked list of sizes of this style + Fl_FontSize *first; // linked list of sizes of this style #ifndef WIN32 char **xlist; // matched X font names int n; // size of xlist, negative = don't free xlist! @@ -80,11 +75,8 @@ const char* fl_font_word(const char *p, int n); char *fl_find_fontsize(char *name); #endif -void fl_draw(const char *, int x, int y, int w, int h, Fl_Align, - void (*callthis)(const char *, int n, int x, int y)); - #endif // -// End of "$Id: Fl_Font.H,v 1.3 1998/10/21 14:20:03 mike Exp $". +// End of "$Id: Fl_Font.H,v 1.4 1998/12/02 15:51:35 mike Exp $". // diff --git a/src/fl_font.cxx b/src/fl_font.cxx index d8b0a6ac3..8fa805f8f 100644 --- a/src/fl_font.cxx +++ b/src/fl_font.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_font.cxx,v 1.4 1998/12/02 15:39:36 mike Exp $" +// "$Id: fl_font.cxx,v 1.5 1998/12/02 15:51:35 mike Exp $" // // Font selection code for the Fast Light Tool Kit (FLTK). // @@ -39,41 +39,20 @@ #include #include -Fl_XFont::Fl_XFont(const char *name, int num) - : number(num) -{ +Fl_FontSize::Fl_FontSize(const char* name) { font = XLoadQueryFont(fl_display, name); if (!font) { Fl::warning("bad font: %s", name); font = XLoadQueryFont(fl_display, "fixed"); // if fixed fails we crash } - XCharStruct *p = font->per_char; - if (!p) { - free_this = per_char = 0; - } else if (font->min_char_or_byte2>0x20 || font->max_char_or_byte2<0xff) { - // fill in short fonts so fl_width does not crash: - XCharStruct *q = free_this = new XCharStruct[0xff-0x20+1]; - per_char = q - 0x20; - unsigned int i = 0x20; - for (; imin_char_or_byte2; i++, q++) - q->width = font->min_bounds.width; - for (; i<=font->max_char_or_byte2; i++) - *q++ = *p++; - for (; i<=0xff; i++) - q->width = font->min_bounds.width; - } else { - free_this = 0; - per_char = p - font->min_char_or_byte2; - } #if HAVE_GL listbase = 0; #endif } -Fl_XFont *fl_current_xfont; -Fl_XFont *fl_fixed_xfont; +Fl_FontSize* fl_current_xfont; -Fl_XFont::~Fl_XFont() { +Fl_FontSize::~Fl_FontSize() { #if HAVE_GL // Delete list created by gl_draw(). This is not done by this code // as it will link in GL unnecessarily. There should be some kind @@ -86,7 +65,6 @@ Fl_XFont::~Fl_XFont() { // } #endif if (this == fl_current_xfont) fl_current_xfont = 0; - delete[] free_this; XFreeFont(fl_display, font); } @@ -113,28 +91,28 @@ static Fl_Fontdesc built_in_table[] = { {"-*-*zapf dingbats-*"} }; -Fl_Fontdesc *fl_fonts = built_in_table; +Fl_Fontdesc* fl_fonts = built_in_table; #define MAXSIZE 32767 // return dash number N, or pointer to ending null if none: -const char* fl_font_word(const char *p, int n) { +const char* fl_font_word(const char* p, int n) { while (*p) {if (*p=='-') {if (!--n) break;} p++;} return p; } // return a pointer to a number we think is "point size": -char *fl_find_fontsize(char* name) { - char *c = name; +char* fl_find_fontsize(char* name) { + char* c = name; // for standard x font names, try after 7th dash: if (*c == '-') { c = (char*)fl_font_word(c,7); if (*c++ && isdigit(*c)) return c; return 0; // malformed x font name? } - char *r = 0; + char* r = 0; // find last set of digits: - for (c++; *c; c++) + for (c++;* c; c++) if (isdigit(*c) && !isdigit(*(c-1))) r = c; return r; } @@ -148,42 +126,39 @@ int fl_correct_encoding(const char* name) { return (*c++ && !strcmp(c,fl_encoding)); } -// locate or create an Fl_XFont for a given Fl_Fontdesc and size: -static Fl_XFont *find(int fnum, int size) { - Fl_Fontdesc *s = fl_fonts+fnum; +// locate or create an Fl_FontSize for a given Fl_Fontdesc and size: +static Fl_FontSize* find(int fnum, int size) { + Fl_Fontdesc* s = fl_fonts+fnum; if (!s->name) s = fl_fonts; // use font 0 if still undefined - Fl_XFont *f; + Fl_FontSize* f; for (f = s->first; f; f = f->next) if (f->minsize <= size && f->maxsize >= size) return f; fl_open_display(); if (!s->xlist) { s->xlist = XListFonts(fl_display, s->name, 100, &(s->n)); if (!s->xlist) { // use fixed if no matching font... - if (!fl_fixed_xfont) { - fl_fixed_xfont = new Fl_XFont("fixed",fnum); - fl_fixed_xfont->minsize = 0; - fl_fixed_xfont->maxsize = 32767; - } - s->first = fl_fixed_xfont; - return fl_fixed_xfont; + s->first = new Fl_FontSize("fixed"); + s->first->minsize = 0; + s->first->maxsize = 32767; + return s->first; } } // search for largest <= font size: - char *name = s->xlist[0]; int ptsize = 0; // best one found so far + char* name = s->xlist[0]; int ptsize = 0; // best one found so far int matchedlength = 32767; char namebuffer[1024]; // holds scalable font name int found_encoding = 0; int m = s->n; if (m<0) m = -m; for (int n=0; n < m; n++) { - char *thisname = s->xlist[n]; + char* thisname = s->xlist[n]; if (fl_correct_encoding(thisname)) { if (!found_encoding) ptsize = 0; // force it to choose this found_encoding = 1; } else { if (found_encoding) continue; } - char *c = fl_find_fontsize(thisname); + char* c = fl_find_fontsize(thisname); int thissize = c ? atoi(c) : MAXSIZE; int thislength = strlen(thisname); if (thissize == size && thislength < matchedlength) { @@ -227,7 +202,7 @@ static Fl_XFont *find(int fnum, int size) { } // okay, we definately have some name, make the font: - f = new Fl_XFont(name,fnum); + f = new Fl_FontSize(name); if (ptsize < size) {f->minsize = ptsize; f->maxsize = size;} else {f->minsize = size; f->maxsize = ptsize;} f->next = s->first; @@ -241,64 +216,81 @@ static Fl_XFont *find(int fnum, int size) { int fl_font_; int fl_size_; +XFontStruct* fl_xfont; static GC font_gc; void fl_font(int fnum, int size) { if (fnum == fl_font_ && size == fl_size_) return; fl_font_ = fnum; fl_size_ = size; - Fl_XFont *f = find(fnum, size); - if (f != fl_current_xfont) {fl_current_xfont = f; font_gc = 0;} + Fl_FontSize* f = find(fnum, size); + if (f != fl_current_xfont) { + fl_current_xfont = f; + fl_xfont = f->font; + font_gc = 0; + } } int fl_height() { - return (fl_current_xfont->font->ascent + fl_current_xfont->font->descent); + return (fl_xfont->ascent + fl_xfont->descent); } int fl_descent() { - return fl_current_xfont->font->descent; + return fl_xfont->descent; } -double fl_width(const char *c) { - XCharStruct *p = fl_current_xfont->per_char; - if (!p) return strlen(c)*fl_current_xfont->font->min_bounds.width; +double fl_width(const char* c) { + XCharStruct* p = fl_xfont->per_char; + if (!p) return strlen(c)*fl_xfont->min_bounds.width; + int a = fl_xfont->min_char_or_byte2; + int b = fl_xfont->max_char_or_byte2 - a; int w = 0; - while (*c) - if (*c >= ' ') - w += p[(uchar)(*c++)].width; - else - c ++; - + while (*c) { + int x = *(uchar*)c++ - a; + if (x >= 0 && x <= b) w += p[x].width; + else w += fl_xfont->min_bounds.width; + } return w; } -double fl_width(const char *c, int n) { - XCharStruct *p = fl_current_xfont->per_char; - if (!p) return n*fl_current_xfont->font->min_bounds.width; +double fl_width(const char* c, int n) { + XCharStruct* p = fl_xfont->per_char; + if (!p) return n*fl_xfont->min_bounds.width; + int a = fl_xfont->min_char_or_byte2; + int b = fl_xfont->max_char_or_byte2 - a; int w = 0; - while (n--) w += p[(uchar)(*c++)].width; + while (n--) { + int x = *(uchar*)c++ - a; + if (x >= 0 && x <= b) w += p[x].width; + else w += fl_xfont->min_bounds.width; + } return w; } double fl_width(uchar c) { - XCharStruct *p = fl_current_xfont->per_char; - if (!p) return fl_current_xfont->font->min_bounds.width; - return p[c].width; + XCharStruct* p = fl_xfont->per_char; + if (p) { + int a = fl_xfont->min_char_or_byte2; + int b = fl_xfont->max_char_or_byte2 - a; + int x = c-a; + if (x >= 0 && x <= b) return p[c].width; + } + return fl_xfont->min_bounds.width; } -void fl_draw(const char *str, int n, int x, int y) { +void fl_draw(const char* str, int n, int x, int y) { if (font_gc != fl_gc) { font_gc = fl_gc; - XSetFont(fl_display, fl_gc, fl_current_xfont->font->fid); + XSetFont(fl_display, fl_gc, fl_xfont->fid); } XDrawString(fl_display, fl_window, fl_gc, x, y, str, n); } -void fl_draw(const char *str, int x, int y) { +void fl_draw(const char* str, int x, int y) { fl_draw(str, strlen(str), x, y); } #endif // -// End of "$Id: fl_font.cxx,v 1.4 1998/12/02 15:39:36 mike Exp $". +// End of "$Id: fl_font.cxx,v 1.5 1998/12/02 15:51:35 mike Exp $". // diff --git a/src/fl_font_win32.cxx b/src/fl_font_win32.cxx index c37acac17..8138b069e 100644 --- a/src/fl_font_win32.cxx +++ b/src/fl_font_win32.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_font_win32.cxx,v 1.6 1998/12/02 15:39:36 mike Exp $" +// "$Id: fl_font_win32.cxx,v 1.7 1998/12/02 15:51:36 mike Exp $" // // WIN32 font selection routines for the Fast Light Tool Kit (FLTK). // @@ -33,7 +33,7 @@ #include #include -Fl_XFont::Fl_XFont(const char *name, int size, int num) { +Fl_FontSize::Fl_FontSize(const char* name, int size) { int weight = FW_NORMAL; int italic = 0; switch (*name++) { @@ -68,13 +68,12 @@ Fl_XFont::Fl_XFont(const char *name, int size, int num) { #if HAVE_GL listbase = 0; #endif - number = num; minsize = maxsize = size; } -Fl_XFont *fl_current_xfont; +Fl_FontSize* fl_current_xfont; -Fl_XFont::~Fl_XFont() { +Fl_FontSize::~Fl_FontSize() { #if HAVE_GL // Delete list created by gl_draw(). This is not done by this code // as it will link in GL unnecessarily. There should be some kind @@ -113,15 +112,15 @@ static Fl_Fontdesc built_in_table[] = { {" Wingdings"}, }; -Fl_Fontdesc *fl_fonts = built_in_table; +Fl_Fontdesc* fl_fonts = built_in_table; -static Fl_XFont *find(int fnum, int size) { - Fl_Fontdesc *s = fl_fonts+fnum; +static Fl_FontSize* find(int fnum, int size) { + Fl_Fontdesc* s = fl_fonts+fnum; if (!s->name) s = fl_fonts; // use 0 if fnum undefined - Fl_XFont *f; + Fl_FontSize* f; for (f = s->first; f; f = f->next) if (f->minsize <= size && f->maxsize >= size) return f; - f = new Fl_XFont(s->name, size, fnum); + f = new Fl_FontSize(s->name, size); f->next = s->first; s->first = f; return f; @@ -148,13 +147,13 @@ int fl_descent() { return fl_current_xfont->metr.tmDescent; } -double fl_width(const char *c) { +double fl_width(const char* c) { double w = 0.0; while (*c) w += fl_current_xfont->width[uchar(*c++)]; return w; } -double fl_width(const char *c, int n) { +double fl_width(const char* c, int n) { double w = 0.0; while (n--) w += fl_current_xfont->width[uchar(*c++)]; return w; @@ -164,16 +163,16 @@ double fl_width(uchar c) { return fl_current_xfont->width[c]; } -void fl_draw(const char *str, int n, int x, int y) { +void fl_draw(const char* str, int n, int x, int y) { SetTextColor(fl_gc, fl_RGB()); SelectObject(fl_gc, fl_current_xfont->fid); TextOut(fl_gc, x, y, str, n); } -void fl_draw(const char *str, int x, int y) { +void fl_draw(const char* str, int x, int y) { fl_draw(str, strlen(str), x, y); } // -// End of "$Id: fl_font_win32.cxx,v 1.6 1998/12/02 15:39:36 mike Exp $". +// End of "$Id: fl_font_win32.cxx,v 1.7 1998/12/02 15:51:36 mike Exp $". // diff --git a/src/fl_set_font.cxx b/src/fl_set_font.cxx index a720b1a5a..5da1fb4ed 100644 --- a/src/fl_set_font.cxx +++ b/src/fl_set_font.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_set_font.cxx,v 1.3 1998/10/21 14:20:58 mike Exp $" +// "$Id: fl_set_font.cxx,v 1.4 1998/12/02 15:51:36 mike Exp $" // // Font utilities for the Fast Light Tool Kit (FLTK). // @@ -35,13 +35,13 @@ static int table_size; -void Fl::set_font(Fl_Font fnum, const char *name) { +void Fl::set_font(Fl_Font fnum, const char* name) { if (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)); + Fl_Fontdesc* t = (Fl_Fontdesc*)malloc(table_size*sizeof(Fl_Fontdesc)); memcpy(t, fl_fonts, FL_FREE_FONT*sizeof(Fl_Fontdesc)); fl_fonts = t; } else { @@ -50,17 +50,14 @@ void Fl::set_font(Fl_Font fnum, const char *name) { } for (; i < table_size; i++) fl_fonts[i].name = 0; } - Fl_Fontdesc *s = fl_fonts+fnum; + Fl_Fontdesc* s = fl_fonts+fnum; if (s->name) { if (!strcmp(s->name, name)) {s->name = name; return;} #ifndef WIN32 if (s->xlist && s->n >= 0) XFreeFontNames(s->xlist); #endif - for (Fl_XFont *f = s->first; f;) { -#ifndef WIN32 - if (f == fl_fixed_xfont) break; -#endif - Fl_XFont *n = f->next; delete f; f = n; + for (Fl_FontSize* f = s->first; f;) { + Fl_FontSize* n = f->next; delete f; f = n; } s->first = 0; } @@ -71,8 +68,8 @@ void Fl::set_font(Fl_Font fnum, const char *name) { s->first = 0; } -const char *Fl::get_font(Fl_Font fnum) {return fl_fonts[fnum].name;} +const char* Fl::get_font(Fl_Font fnum) {return fl_fonts[fnum].name;} // -// End of "$Id: fl_set_font.cxx,v 1.3 1998/10/21 14:20:58 mike Exp $". +// End of "$Id: fl_set_font.cxx,v 1.4 1998/12/02 15:51:36 mike Exp $". // diff --git a/src/fl_set_fonts.cxx b/src/fl_set_fonts.cxx index 649eca17f..0ea1abf19 100644 --- a/src/fl_set_fonts.cxx +++ b/src/fl_set_fonts.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_set_fonts.cxx,v 1.3 1998/10/21 14:20:58 mike Exp $" +// "$Id: fl_set_fonts.cxx,v 1.4 1998/12/02 15:51:37 mike Exp $" // // More font utilities for the Fast Light Tool Kit (FLTK). // @@ -137,6 +137,9 @@ const char* Fl::get_font_name(Fl_Font fnum, int* ap) { if (*x) {x++; *o++ = '('; while (*x) *o++ = *x++; *o++ = ')';} *o = 0; + if (type & FL_BOLD) {strcpy(o, " bold"); o += 5;} + if (type & FL_ITALIC) {strcpy(o, " italic"); o += 7;} + if (ap) *ap = type; return buffer; @@ -322,5 +325,5 @@ int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) { #endif // -// End of "$Id: fl_set_fonts.cxx,v 1.3 1998/10/21 14:20:58 mike Exp $". +// End of "$Id: fl_set_fonts.cxx,v 1.4 1998/12/02 15:51:37 mike Exp $". // diff --git a/src/fl_set_fonts_win32.cxx b/src/fl_set_fonts_win32.cxx index 80aeb2342..71fa41630 100755 --- a/src/fl_set_fonts_win32.cxx +++ b/src/fl_set_fonts_win32.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_set_fonts_win32.cxx,v 1.3 1998/10/21 14:20:59 mike Exp $" +// "$Id: fl_set_fonts_win32.cxx,v 1.4 1998/12/02 15:51:37 mike Exp $" // // WIN32 font utilities for the Fast Light Tool Kit (FLTK). // @@ -39,13 +39,19 @@ const char* Fl::get_font_name(Fl_Font fnum, int* ap) { const char* p = fl_fonts[fnum].name; if (!p || !*p) {if (ap) *ap = 0; return "";} - if (ap) switch (*p) { - case 'B': *ap = FL_BOLD; break; - case 'I': *ap = FL_ITALIC; break; - case 'P': *ap = FL_BOLD | FL_ITALIC; break; - default: *ap = 0; break; + int type; + switch (*p) { + case 'B': type = FL_BOLD; break; + case 'I': type = FL_ITALIC; break; + case 'P': type = FL_BOLD | FL_ITALIC; break; + default: type = 0; break; } - return p+1; + if (!type) return p+1; + static char *buffer; if (!buffer) buffer = new char[128]; + strcpy(buffer, p+1); + if (type & FL_BOLD) strcat(buffer, " bold"); + if (type & FL_ITALIC) strcat(buffer, " italic"); + return buffer; } static int fl_free_font = FL_FREE_FONT; @@ -81,5 +87,5 @@ int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) { } // -// End of "$Id: fl_set_fonts_win32.cxx,v 1.3 1998/10/21 14:20:59 mike Exp $". +// End of "$Id: fl_set_fonts_win32.cxx,v 1.4 1998/12/02 15:51:37 mike Exp $". // diff --git a/src/gl_draw.cxx b/src/gl_draw.cxx index 2dcae667c..37617e85f 100644 --- a/src/gl_draw.cxx +++ b/src/gl_draw.cxx @@ -1,5 +1,5 @@ // -// "$Id: gl_draw.cxx,v 1.4 1998/11/24 13:18:16 mike Exp $" +// "$Id: gl_draw.cxx,v 1.5 1998/12/02 15:51:38 mike Exp $" // // OpenGL drawing support routines for the Fast Light Tool Kit (FLTK). // @@ -32,20 +32,11 @@ #include #include #include +#include #include "Fl_Gl_Choice.H" #include "Fl_Font.H" #include -// stuff from fl_draw.H: -void fl_font(int fontid, int size); -int fl_height(); // using "size" should work ok -int fl_descent(); -void fl_measure(const char*, int& x, int& y); -double fl_width(const char*); -double fl_width(const char*, int n); -double fl_width(uchar); -unsigned long fl_xpixel(uchar i); - void gl_font(int fontid, int size) {fl_font(fontid, size);} int gl_height() {return fl_height();} int gl_descent() {return fl_descent();} @@ -54,26 +45,22 @@ double gl_width(const char* s, int n) {return fl_width(s,n);} double gl_width(uchar c) {return fl_width(c);} void gl_draw(const char* str, int n) { + if (!fl_fontsize->listbase) { #ifdef WIN32 - if (!fl_current_xfont->listbase) { - int base = fl_current_xfont->metr.tmFirstChar; - int size = fl_current_xfont->metr.tmLastChar-base+1; - HFONT oldFid = (HFONT)SelectObject(fl_gc, fl_current_xfont->fid); - fl_current_xfont->listbase = glGenLists(size)-base; - wglUseFontBitmaps(fl_gc, base, size, fl_current_xfont->listbase+base); + int base = fl_fontsize->metr.tmFirstChar; + int size = fl_fontsize->metr.tmLastChar-base+1; + HFONT oldFid = (HFONT)SelectObject(fl_gc, fl_fontsize->fid); + fl_fontsize->listbase = glGenLists(size)-base; + wglUseFontBitmaps(fl_gc, base, size, fl_fontsize->listbase+base); SelectObject(fl_gc, oldFid); - } #else - if (!fl_current_xfont->listbase) { - int base = fl_current_xfont->font->min_char_or_byte2; - int size = fl_current_xfont->font->max_char_or_byte2-base+1; -// int base = 0; int size = 256; - fl_current_xfont->listbase = glGenLists(size)-base; - glXUseXFont(fl_current_xfont->font->fid, base, size, - fl_current_xfont->listbase+base); - } + int base = fl_xfont->min_char_or_byte2; + int size = fl_xfont->max_char_or_byte2-base+1; + fl_fontsize->listbase = glGenLists(size)-base; + glXUseXFont(fl_xfont->fid, base, size, fl_fontsize->listbase+base); #endif - glListBase(fl_current_xfont->listbase); + } + glListBase(fl_fontsize->listbase); glCallLists(n, GL_UNSIGNED_BYTE, str); } @@ -152,5 +139,5 @@ void gl_draw_image(const uchar* b, int x, int y, int w, int h, int d, int ld) { #endif // -// End of "$Id: gl_draw.cxx,v 1.4 1998/11/24 13:18:16 mike Exp $". +// End of "$Id: gl_draw.cxx,v 1.5 1998/12/02 15:51:38 mike Exp $". //