Rewrite Fl_Xlib_Graphics_Driver::get_font_name() with less lines of code.
This commit is contained in:
parent
214f14db8a
commit
10a9a0440e
@ -977,45 +977,35 @@ float Fl_Xlib_Graphics_Driver::scale_font_for_PostScript(Fl_Font_Descriptor *des
|
|||||||
// of the font name array.
|
// of the font name array.
|
||||||
#define ENDOFBUFFER 127 // sizeof(Fl_Font.fontname)-1
|
#define ENDOFBUFFER 127 // sizeof(Fl_Font.fontname)-1
|
||||||
|
|
||||||
#if USE_PANGO
|
|
||||||
// turn a stored font name in "fltk format" into a pretty name:
|
// turn a stored font name in "fltk format" into a pretty name:
|
||||||
const char* Fl_Xlib_Graphics_Driver::get_font_name(Fl_Font fnum, int* ap) {
|
const char* Fl_Xlib_Graphics_Driver::get_font_name(Fl_Font fnum, int* ap) {
|
||||||
Fl_Fontdesc *f = fl_fonts + fnum;
|
Fl_Fontdesc *f = fl_fonts + fnum;
|
||||||
if (!f->fontname[0]) {
|
if (!f->fontname[0]) {
|
||||||
const char* p = f->name;
|
const char* p = f->name;
|
||||||
int type;
|
int type;
|
||||||
|
#if USE_PANGO
|
||||||
type = 0;
|
type = 0;
|
||||||
if (strstr(p, " Bold")) type = FL_BOLD;
|
if (strstr(p, " Bold")) type = FL_BOLD;
|
||||||
if (strstr(p, " Italic") || strstr(p, " Oblique")) type += FL_ITALIC;
|
if (strstr(p, " Italic") || strstr(p, " Oblique")) type += FL_ITALIC;
|
||||||
strlcpy(f->fontname, p, ENDOFBUFFER);
|
strlcpy(f->fontname, p, ENDOFBUFFER);
|
||||||
f->fontname[ENDOFBUFFER] = (char)type;
|
|
||||||
}
|
|
||||||
if (ap) *ap = f->fontname[ENDOFBUFFER];
|
|
||||||
return f->fontname;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
const char* Fl_Xlib_Graphics_Driver::get_font_name(Fl_Font fnum, int* ap) {
|
|
||||||
Fl_Fontdesc *f = fl_fonts + fnum;
|
|
||||||
if (!f->fontname[0]) {
|
|
||||||
const char* p = f->name;
|
|
||||||
int type;
|
|
||||||
switch (p[0]) {
|
switch (p[0]) {
|
||||||
case 'B': type = FL_BOLD; break;
|
case 'B': type = FL_BOLD; break;
|
||||||
case 'I': type = FL_ITALIC; break;
|
case 'I': type = FL_ITALIC; break;
|
||||||
case 'P': type = FL_BOLD | FL_ITALIC; break;
|
case 'P': type = FL_BOLD | FL_ITALIC; break;
|
||||||
default: type = 0; break;
|
default: type = 0; break;
|
||||||
}
|
}
|
||||||
// NOTE: This can cause duplications in fonts that already have Bold or Italic in
|
// NOTE: This can cause duplications in fonts that already have Bold or Italic in
|
||||||
// their "name". Maybe we need to find a cleverer way?
|
// their "name". Maybe we need to find a cleverer way?
|
||||||
strlcpy(f->fontname, p+1, ENDOFBUFFER);
|
strlcpy(f->fontname, p+1, ENDOFBUFFER);
|
||||||
if (type & FL_BOLD) strlcat(f->fontname, " bold", ENDOFBUFFER);
|
if (type & FL_BOLD) strlcat(f->fontname, " bold", ENDOFBUFFER);
|
||||||
if (type & FL_ITALIC) strlcat(f->fontname, " italic", ENDOFBUFFER);
|
if (type & FL_ITALIC) strlcat(f->fontname, " italic", ENDOFBUFFER);
|
||||||
|
#endif // USE_PANGO
|
||||||
f->fontname[ENDOFBUFFER] = (char)type;
|
f->fontname[ENDOFBUFFER] = (char)type;
|
||||||
}
|
}
|
||||||
if (ap) *ap = f->fontname[ENDOFBUFFER];
|
if (ap) *ap = f->fontname[ENDOFBUFFER];
|
||||||
return f->fontname;
|
return f->fontname;
|
||||||
}
|
}
|
||||||
#endif // USE_PANGO
|
|
||||||
|
|
||||||
float Fl_Xlib_Graphics_Driver::scale_bitmap_for_PostScript() {
|
float Fl_Xlib_Graphics_Driver::scale_bitmap_for_PostScript() {
|
||||||
return 2;
|
return 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user