The attribute argument to Fl::get_font_name() was set correctly only
the first time it was called for a given font, otherwise it was left unchanged. Warning: only the X11 version has been tested! The Win32, Xft, and Mac versions (which are all identical to each other) probably work but I did not test them. Try the "fonts" demo. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2948 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
eca1c6cc4c
commit
5eb2576cfc
@ -1,5 +1,5 @@
|
||||
//
|
||||
// "$Id: fl_set_fonts_mac.cxx,v 1.1.2.8 2003/01/30 21:44:16 easysw Exp $"
|
||||
// "$Id: fl_set_fonts_mac.cxx,v 1.1.2.9 2003/03/09 00:22:17 spitzak Exp $"
|
||||
//
|
||||
// MacOS font utilities for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
@ -28,6 +28,12 @@
|
||||
// and to sort them so the first 4 in a family are normal, bold, italic,
|
||||
// and bold italic.
|
||||
|
||||
// Bug: older versions calculated the value for *ap as a side effect of
|
||||
// making the name, and then forgot about it. To avoid having to change
|
||||
// the header files I decided to store this value in the last character
|
||||
// of the font name array.
|
||||
#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) {
|
||||
Fl_Fontdesc *f = fl_fonts + fnum;
|
||||
@ -41,12 +47,12 @@ const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
|
||||
case 'P': type = FL_BOLD | FL_ITALIC; break;
|
||||
default: type = 0; break;
|
||||
}
|
||||
if (ap) *ap = type;
|
||||
if (!type) return p+1;
|
||||
strlcpy(f->fontname, p+1, sizeof(f->fontname));
|
||||
if (type & FL_BOLD) strlcat(f->fontname, " bold", sizeof(f->fontname));
|
||||
if (type & FL_ITALIC) strlcat(f->fontname, " italic", sizeof(f->fontname));
|
||||
strlcpy(f->fontname, p+1, ENDOFBUFFER);
|
||||
if (type & FL_BOLD) strlcat(f->fontname, " bold", ENDOFBUFFER);
|
||||
if (type & FL_ITALIC) strlcat(f->fontname, " italic", ENDOFBUFFER);
|
||||
f->fontname[ENDOFBUFFER] = (char)type;
|
||||
}
|
||||
if (ap) *ap = f->fontname[ENDOFBUFFER];
|
||||
return f->fontname;
|
||||
}
|
||||
|
||||
@ -156,5 +162,5 @@ int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id: fl_set_fonts_mac.cxx,v 1.1.2.8 2003/01/30 21:44:16 easysw Exp $".
|
||||
// End of "$Id: fl_set_fonts_mac.cxx,v 1.1.2.9 2003/03/09 00:22:17 spitzak Exp $".
|
||||
//
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// "$Id: fl_set_fonts_win32.cxx,v 1.5.2.5.2.9 2003/01/30 21:44:16 easysw Exp $"
|
||||
// "$Id: fl_set_fonts_win32.cxx,v 1.5.2.5.2.10 2003/03/09 00:22:18 spitzak Exp $"
|
||||
//
|
||||
// WIN32 font utilities for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
@ -28,6 +28,12 @@
|
||||
// and to sort them so the first 4 in a family are normal, bold, italic,
|
||||
// and bold italic.
|
||||
|
||||
// Bug: older versions calculated the value for *ap as a side effect of
|
||||
// making the name, and then forgot about it. To avoid having to change
|
||||
// the header files I decided to store this value in the last character
|
||||
// of the font name array.
|
||||
#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) {
|
||||
Fl_Fontdesc *f = fl_fonts + fnum;
|
||||
@ -41,12 +47,12 @@ const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
|
||||
case 'P': type = FL_BOLD | FL_ITALIC; break;
|
||||
default: type = 0; break;
|
||||
}
|
||||
if (ap) *ap = type;
|
||||
if (!type) return p+1;
|
||||
strlcpy(f->fontname, p+1, sizeof(f->fontname));
|
||||
if (type & FL_BOLD) strlcat(f->fontname, " bold", sizeof(f->fontname));
|
||||
if (type & FL_ITALIC) strlcat(f->fontname, " italic", sizeof(f->fontname));
|
||||
strlcpy(f->fontname, p+1, ENDOFBUFFER);
|
||||
if (type & FL_BOLD) strlcat(f->fontname, " bold", ENDOFBUFFER);
|
||||
if (type & FL_ITALIC) strlcat(f->fontname, " italic", ENDOFBUFFER);
|
||||
f->fontname[ENDOFBUFFER] = (char)type;
|
||||
}
|
||||
if (ap) *ap = f->fontname[ENDOFBUFFER];
|
||||
return f->fontname;
|
||||
}
|
||||
|
||||
@ -137,5 +143,5 @@ Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
|
||||
|
||||
|
||||
//
|
||||
// End of "$Id: fl_set_fonts_win32.cxx,v 1.5.2.5.2.9 2003/01/30 21:44:16 easysw Exp $".
|
||||
// End of "$Id: fl_set_fonts_win32.cxx,v 1.5.2.5.2.10 2003/03/09 00:22:18 spitzak Exp $".
|
||||
//
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// "$Id: fl_set_fonts_x.cxx,v 1.1.2.6 2003/01/30 21:44:17 easysw Exp $"
|
||||
// "$Id: fl_set_fonts_x.cxx,v 1.1.2.7 2003/03/09 00:22:20 spitzak Exp $"
|
||||
//
|
||||
// X11 font utilities for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
@ -79,10 +79,17 @@ static int use_registry(const char *p) {
|
||||
return *p && *p!='*' && strcmp(p,fl_encoding);
|
||||
}
|
||||
|
||||
// Bug: older versions calculated the value for *ap as a side effect of
|
||||
// making the name, and then forgot about it. To avoid having to change
|
||||
// the header files I decided to store this value in the last character
|
||||
// of the font name array.
|
||||
#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) {
|
||||
Fl_Fontdesc *f = fl_fonts + fnum;
|
||||
if (!f->fontname[0]) {
|
||||
int type = 0;
|
||||
const char* p = f->name;
|
||||
if (!p) {
|
||||
if (ap) *ap = 0;
|
||||
@ -91,70 +98,65 @@ const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
|
||||
char *o = f->fontname;
|
||||
|
||||
if (*p != '-') { // non-standard font, just replace * with spaces:
|
||||
if (ap) {
|
||||
int type = 0;
|
||||
if (strstr(p,"bold")) type = FL_BOLD;
|
||||
if (strstr(p,"ital")) type |= FL_ITALIC;
|
||||
*ap = type;
|
||||
}
|
||||
if (strstr(p,"bold")) type = FL_BOLD;
|
||||
if (strstr(p,"ital")) type |= FL_ITALIC;
|
||||
for (;*p; p++) {
|
||||
if (*p == '*' || *p == ' ' || *p == '-') {
|
||||
do p++; while (*p == '*' || *p == ' ' || *p == '-');
|
||||
if (!*p) break;
|
||||
if (o < (f->fontname + sizeof(f->fontname) - 1)) *o++ = ' ';
|
||||
if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ = ' ';
|
||||
}
|
||||
if (o < (f->fontname + sizeof(f->fontname) - 1)) *o++ = *p;
|
||||
if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ = *p;
|
||||
}
|
||||
*o = 0;
|
||||
return f->fontname;
|
||||
|
||||
} else { // standard dash-seperated font:
|
||||
|
||||
// get the family:
|
||||
const char *x = fl_font_word(p,2); if (*x) x++; if (*x=='*') x++;
|
||||
if (!*x) {
|
||||
if (ap) *ap = 0;
|
||||
return p;
|
||||
}
|
||||
const char *e = fl_font_word(x,1);
|
||||
if ((e - x) < (int)(ENDOFBUFFER - 1)) {
|
||||
// MRS: we want strncpy here, not strlcpy...
|
||||
strncpy(o,x,e-x);
|
||||
o += e-x;
|
||||
} else {
|
||||
strlcpy(f->fontname, x, ENDOFBUFFER);
|
||||
o = f->fontname+ENDOFBUFFER-1;
|
||||
}
|
||||
|
||||
// collect all the attribute words:
|
||||
for (int n = 3; n <= 6; n++) {
|
||||
// get the next word:
|
||||
if (*e) e++; x = e; e = fl_font_word(x,1);
|
||||
int t = attribute(n,x);
|
||||
if (t < 0) {
|
||||
if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ = ' ';
|
||||
if ((e - x) < (int)(ENDOFBUFFER - (o - f->fontname) - 1)) {
|
||||
// MRS: we want strncpy here, not strlcpy...
|
||||
strncpy(o,x,e-x);
|
||||
o += e-x;
|
||||
} else {
|
||||
strlcpy(o,x, ENDOFBUFFER - (o - f->fontname) - 1);
|
||||
o = f->fontname+ENDOFBUFFER-1;
|
||||
}
|
||||
} else type |= t;
|
||||
}
|
||||
|
||||
// skip over the '*' for the size and get the registry-encoding:
|
||||
x = fl_font_word(e,2);
|
||||
if (*x) {x++; *o++ = '('; while (*x) *o++ = *x++; *o++ = ')';}
|
||||
|
||||
*o = 0;
|
||||
if (type & FL_BOLD) strlcat(f->fontname, " bold", ENDOFBUFFER);
|
||||
if (type & FL_ITALIC) strlcat(f->fontname, " italic", ENDOFBUFFER);
|
||||
}
|
||||
|
||||
// get the family:
|
||||
const char *x = fl_font_word(p,2); if (*x) x++; if (*x=='*') x++;
|
||||
if (!*x) {
|
||||
if (ap) *ap = 0;
|
||||
return p;
|
||||
}
|
||||
const char *e = fl_font_word(x,1);
|
||||
if ((e - x) < (int)(sizeof(f->fontname) - 1)) {
|
||||
// MRS: we want strncpy here, not strlcpy...
|
||||
strncpy(o,x,e-x);
|
||||
o += e-x;
|
||||
} else {
|
||||
strlcpy(f->fontname,x,sizeof(f->fontname));
|
||||
return f->fontname;
|
||||
}
|
||||
|
||||
// collect all the attribute words:
|
||||
int type = 0;
|
||||
for (int n = 3; n <= 6; n++) {
|
||||
// get the next word:
|
||||
if (*e) e++; x = e; e = fl_font_word(x,1);
|
||||
int t = attribute(n,x);
|
||||
if (t < 0) {
|
||||
if (o < (f->fontname + sizeof(f->fontname) - 1)) *o++ = ' ';
|
||||
if ((e - x) < (int)(sizeof(f->fontname) - (o - f->fontname) - 1)) {
|
||||
// MRS: we want strncpy here, not strlcpy...
|
||||
strncpy(o,x,e-x);
|
||||
o += e-x;
|
||||
} else {
|
||||
strlcpy(o,x,sizeof(f->fontname) - (o - f->fontname) - 1);
|
||||
return f->fontname;
|
||||
}
|
||||
} else type |= t;
|
||||
}
|
||||
|
||||
// skip over the '*' for the size and get the registry-encoding:
|
||||
x = fl_font_word(e,2);
|
||||
if (*x) {x++; *o++ = '('; while (*x) *o++ = *x++; *o++ = ')';}
|
||||
|
||||
*o = 0;
|
||||
if (type & FL_BOLD) strlcat(f->fontname, " bold", sizeof(f->fontname));
|
||||
if (type & FL_ITALIC) strlcat(f->fontname, " italic", sizeof(f->fontname));
|
||||
|
||||
if (ap) *ap = type;
|
||||
f->fontname[ENDOFBUFFER] = (char)type;
|
||||
}
|
||||
|
||||
if (ap) *ap = f->fontname[ENDOFBUFFER];
|
||||
return f->fontname;
|
||||
}
|
||||
|
||||
@ -342,5 +344,5 @@ int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id: fl_set_fonts_x.cxx,v 1.1.2.6 2003/01/30 21:44:17 easysw Exp $".
|
||||
// End of "$Id: fl_set_fonts_x.cxx,v 1.1.2.7 2003/03/09 00:22:20 spitzak Exp $".
|
||||
//
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// "$Id: fl_set_fonts_xft.cxx,v 1.1.2.3 2003/01/30 21:44:17 easysw Exp $"
|
||||
// "$Id: fl_set_fonts_xft.cxx,v 1.1.2.4 2003/03/09 00:22:20 spitzak Exp $"
|
||||
//
|
||||
// More font utilities for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
@ -30,6 +30,12 @@
|
||||
// and to sort them so the first 4 in a family are normal, bold, italic,
|
||||
// and bold italic.
|
||||
|
||||
// Bug: older versions calculated the value for *ap as a side effect of
|
||||
// making the name, and then forgot about it. To avoid having to change
|
||||
// the header files I decided to store this value in the last character
|
||||
// of the font name array.
|
||||
#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) {
|
||||
Fl_Fontdesc *f = fl_fonts + fnum;
|
||||
@ -42,12 +48,12 @@ const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
|
||||
case 'P': type = FL_BOLD | FL_ITALIC; break;
|
||||
default: type = 0; break;
|
||||
}
|
||||
if (ap) {*ap = type; return p+1;}
|
||||
if (!type) {return p+1;}
|
||||
strlcpy(f->fontname, p+1, sizeof(f->fontname));
|
||||
if (type & FL_BOLD) strlcat(f->fontname, " bold", sizeof(f->fontname));
|
||||
if (type & FL_ITALIC) strlcat(f->fontname, " italic", sizeof(f->fontname));
|
||||
strlcpy(f->fontname, p+1, ENDOFBUFFER);
|
||||
if (type & FL_BOLD) strlcat(f->fontname, " bold", ENDOFBUFFER);
|
||||
if (type & FL_ITALIC) strlcat(f->fontname, " italic", ENDOFBUFFER);
|
||||
f->fontname[ENDOFBUFFER] = (char)type;
|
||||
}
|
||||
if (ap) *ap = f->fontname[ENDOFBUFFER];
|
||||
return f->fontname;
|
||||
}
|
||||
|
||||
@ -118,5 +124,5 @@ int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id: fl_set_fonts_xft.cxx,v 1.1.2.3 2003/01/30 21:44:17 easysw Exp $".
|
||||
// End of "$Id: fl_set_fonts_xft.cxx,v 1.1.2.4 2003/03/09 00:22:20 spitzak Exp $".
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user