Author: ianmacarthur Date: 2013-04-12 02:52:31 -0700 (Fri, 12 Apr 2013) New Revision: 9874 Log: fl_set_fonts_xft had a lower case, rather than upper case "S" in the switch so would not detect the SuperBold font style correctly.
Also, do a bit of defensive clipping of the generated font name, in case we run off the end of the name buffer (if the input font name is infeasibly long...!) Modified: branches/branch-1.3/src/fl_set_fonts_xft.cxx Modified: branches/branch-1.3/src/fl_set_fonts_xft.cxx =================================================================== --- branches/branch-1.3/src/fl_set_fonts_xft.cxx 2013-04-10 21:19:10 UTC (rev 9873) +++ branches/branch-1.3/src/fl_set_fonts_xft.cxx 2013-04-12 09:52:31 UTC (rev 9874) @@ -102,12 +102,16 @@ nm2 = strchr(nm1, ','); } raw[0] = ' '; raw[1] = 0; // Default start of "raw name" text - strncat(raw, nm1, LOCAL_RAW_NAME_MAX); + strncat(raw, nm1, LOCAL_RAW_NAME_MAX-1); // only copy MAX-1 chars, we have already set cell 0 + // Ensure raw is terminated, just in case the given name is infeasibly long... + raw[LOCAL_RAW_NAME_MAX-1] = 0; #else // keep the first remaining name entry char *nm2 = strchr(pretty, ','); if(nm2) *nm2 = 0; // terminate name after first entry raw[0] = ' '; raw[1] = 0; // Default start of "raw name" text - strncat(raw, pretty, LOCAL_RAW_NAME_MAX-1); + strncat(raw, pretty, LOCAL_RAW_NAME_MAX-1); // only copy MAX-1 chars, we have already set cell 0 + // Ensure raw is terminated, just in case the given name is infeasibly long... + raw[LOCAL_RAW_NAME_MAX-1] = 0; #endif // At this point, the name is "marked" as regular... if (style) @@ -153,14 +157,14 @@ mods |= ITALIC; } goto NEXT_STYLE; - - case 's': + + case 'S': if (strncasecmp(style, "SuperBold", 9) == 0) { mods |= BOLD; } goto NEXT_STYLE; - + default: // find the next gap goto NEXT_STYLE; } // switch end @@ -202,17 +206,17 @@ { FcFontSet *fnt_set; // Will hold the list of fonts we find FcPattern *fnt_pattern; // Holds the generic "match all names" pattern - FcObjectSet *fnt_obj_set = 0; // Holds the generic "match all objects" - + FcObjectSet *fnt_obj_set = 0; // Holds the generic "match all objects" + int j; // loop iterator variable int font_count; // Total number of fonts found to process char **full_list; // The list of font names we build if (fl_free_font > FL_FREE_FONT) // already been here return (Fl_Font)fl_free_font; - + fl_open_display(); // Just in case... - + // Make sure fontconfig is ready... is this necessary? The docs say it is // safe to call it multiple times, so just go for it anyway! if (!FcInit()) @@ -228,10 +232,10 @@ // "pattern_name"? fnt_pattern = FcPatternCreate(); fnt_obj_set = FcObjectSetBuild(FC_FAMILY, FC_STYLE, (void *)0); - + // Hopefully, this is a set of all the fonts... fnt_set = FcFontList(0, fnt_pattern, fnt_obj_set); - + // We don't need the fnt_pattern and fnt_obj_set any more, release them FcPatternDestroy(fnt_pattern); FcObjectSetDestroy(fnt_obj_set); @@ -242,22 +246,22 @@ char *stop; char *start; char *first; - + font_count = fnt_set->nfont; // How many fonts? - + // Allocate array of char*'s to hold the name strings full_list = (char **)malloc(sizeof(char *) * font_count); - + // iterate through all the font patterns and get the names out... for (j = 0; j < font_count; j++) { // NOTE: FcChar8 is a typedef of "unsigned char"... FcChar8 *font; // String to hold the font's name - + // Convert from fontconfig internal pattern to human readable name // NOTE: This WILL malloc storage, so we need to free it later... font = FcNameUnparse(fnt_set->fonts[j]); - + // The returned strings look like this... // Century Schoolbook:style=Bold Italic,fed kursiv,Fett Kursiv,... // So the bit we want is up to the first comma - BUT some strings have @@ -300,13 +304,13 @@ if (reg) reg[1]='.'; } } - + // Release the fnt_set - we don't need it any more FcFontSetDestroy(fnt_set); - + // Sort the list into alphabetic order qsort(full_list, font_count, sizeof(*full_list), name_sort); - + // Now let us add the names we got to fltk's font list... for (j = 0; j < font_count; j++) { @@ -321,7 +325,7 @@ stored_name = strdup(xft_name); Fl::set_font((Fl_Font)(j + FL_FREE_FONT), stored_name); fl_free_font ++; - + free(full_list[j]); // release that name from our internal array } } _______________________________________________ fltk-commit mailing list fltk-commit@easysw.com http://lists.easysw.com/mailman/listinfo/fltk-commit