Rewrite Fl_Xlib_Graphics_Driver::get_font_name() with less lines of code.

This commit is contained in:
ManoloFLTK 2020-03-20 10:47:19 +01:00
parent 214f14db8a
commit 10a9a0440e

View File

@ -977,45 +977,35 @@ float Fl_Xlib_Graphics_Driver::scale_font_for_PostScript(Fl_Font_Descriptor *des
// of the font name array.
#define ENDOFBUFFER 127 // sizeof(Fl_Font.fontname)-1
#if USE_PANGO
// 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) {
Fl_Fontdesc *f = fl_fonts + fnum;
if (!f->fontname[0]) {
const char* p = f->name;
int type;
#if USE_PANGO
type = 0;
if (strstr(p, " Bold")) type = FL_BOLD;
if (strstr(p, " Italic") || strstr(p, " Oblique")) type += FL_ITALIC;
strlcpy(f->fontname, p, ENDOFBUFFER);
f->fontname[ENDOFBUFFER] = (char)type;
}
if (ap) *ap = f->fontname[ENDOFBUFFER];
return f->fontname;
}
#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]) {
case 'B': type = FL_BOLD; break;
case 'I': type = FL_ITALIC; break;
case 'P': type = FL_BOLD | FL_ITALIC; break;
default: type = 0; break;
case 'B': type = FL_BOLD; break;
case 'I': type = FL_ITALIC; break;
case 'P': type = FL_BOLD | FL_ITALIC; break;
default: type = 0; break;
}
// NOTE: This can cause duplications in fonts that already have Bold or Italic in
// their "name". Maybe we need to find a cleverer way?
strlcpy(f->fontname, p+1, ENDOFBUFFER);
if (type & FL_BOLD) strlcat(f->fontname, " bold", ENDOFBUFFER);
if (type & FL_ITALIC) strlcat(f->fontname, " italic", ENDOFBUFFER);
#endif // USE_PANGO
f->fontname[ENDOFBUFFER] = (char)type;
}
if (ap) *ap = f->fontname[ENDOFBUFFER];
return f->fontname;
}
#endif // USE_PANGO
float Fl_Xlib_Graphics_Driver::scale_bitmap_for_PostScript() {
return 2;