diff options
| author | Manolo Gouy <Manolo> | 2017-08-13 11:50:47 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2017-08-13 11:50:47 +0000 |
| commit | 67a63d40e03b41337c50a21b8e6bd05f47347438 (patch) | |
| tree | 44adf86c9f5c4845dcab05883f5f5f0cf384ea78 /src/drivers/Xlib | |
| parent | 44a3f9fce9085bfdb8057f7e3299ee88622ece7c (diff) | |
Fl_Xlib_Graphics_Driver::set_fonts() with Pango: account better for variety of possible font styles.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12377 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Xlib')
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx index c3f6efa2b..184eff1f7 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx @@ -1343,18 +1343,34 @@ Fl_Font Fl_Xlib_Graphics_Driver::set_fonts(const char* pattern_name) int l = strlen(fam_name); pango_font_family_list_faces(families[fam], &faces, &n_faces); for (int j = 0; j < n_faces; j++) { - char prefix = ' ', *q; - char *p = (char*)pango_font_face_get_face_name(faces[j]); + char prefix = ' '; + char *p = strdup(pango_font_face_get_face_name(faces[j])); + int lp = strlen(p); // build the font's FLTK name - if (strcmp(p, "Regular") == 0) p = NULL; - else if (strcmp(p, "Bold Italic") == 0 || strcmp(p, "Bold Oblique") == 0) {p = NULL; prefix = 'P';} - else if ((q=strstr(p, "Italic")) || (q=strstr(p, "Oblique")) ) {*q = 0; prefix = 'I';} - else if ((q=strstr(p, "Bold")) ) {*q = 0; prefix = 'B';} + if (strcmp(p, "Regular") == 0) *p = 0; + else if (strcmp(p + lp - 12, "Bold Oblique") == 0 ) { + *(p+lp-12) = 0; prefix = 'P'; + } + else if (strcmp(p + lp - 11, "Bold Italic") == 0 ) { + *(p+lp-11) = 0; prefix = 'P'; + } + else if (strcmp(p + lp - 6, "Italic") == 0 ) { + *(p+lp-6) = 0; prefix = 'I'; + } + else if (strcmp(p + lp - 7, "Oblique") == 0 ) { + *(p+lp-7) = 0; prefix = 'I'; + } + else if (strcmp(p + lp - 4, "Bold") == 0 ) { + *(p+lp-4) = 0; prefix = 'B'; + } + char *q = p + strlen(p) - 1; + while (*q == ' ' && q > p) q--; int lq = l+2; - if (p) lq += strlen(p) + 1; + if (*p) lq += strlen(p) + 1; q = new char[lq]; sprintf(q, "%c%s", prefix, fam_name); - if (p && *p) sprintf(q + strlen(q), " %s", p); + if (*p) sprintf(q + strlen(q), " %s", p); + free(p); Fl::set_font((Fl_Font)(count++ + FL_FREE_FONT), q); } /*g_*/free(faces); // glib source code shows that g_free is equivalent to free |
