summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2013-10-30 12:03:49 +0000
committerManolo Gouy <Manolo>2013-10-30 12:03:49 +0000
commit830f9eec89a7e02574d405a037d8fd0357a79943 (patch)
tree9d2f5aeb9bb0560c5f2abfa1889b824dfde7ae33 /src
parent8550d28608bb41690441726a8c4d5582c6350e18 (diff)
Improved the ordering of font names consistently grouping them by family.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10013 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/fl_set_fonts_mac.cxx42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/fl_set_fonts_mac.cxx b/src/fl_set_fonts_mac.cxx
index 52b4a2910..07756090b 100644
--- a/src/fl_set_fonts_mac.cxx
+++ b/src/fl_set_fonts_mac.cxx
@@ -20,10 +20,6 @@
// #inclde <SFNTTypes.h>
-// This function fills in the fltk font table with all the fonts that
-// are found on the X server. It tries to place the fonts into families
-// 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
@@ -52,7 +48,7 @@ const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
if (!p || !*p) {if (ap) *ap = 0; return "";}
int type = 0;
if (strstr(f->name, "Bold")) type |= FL_BOLD;
- if (strstr(f->name, "Italic")) type |= FL_ITALIC;
+ if (strstr(f->name, "Italic") || strstr(f->name, "Oblique")) type |= FL_ITALIC;
f->fontname[ENDOFBUFFER] = (char)type;
}
if (ap) *ap = f->fontname[ENDOFBUFFER];
@@ -62,12 +58,46 @@ const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
static int name_compare(const void *a, const void *b)
{
- return strcmp(*(char**)a, *(char**)b);
+ /* Compare PostScript font names.
+ First compare font family names ignoring bold, italic and oblique qualifiers.
+ When families are identical, order them according to regular, bold, italic, bolditalic.
+ */
+ char *n1 = *(char**)a;
+ char *n2 = *(char**)b;
+ int derived1 = 0;
+ int derived2 = 0;
+ while (true) {
+ if (*n1 == '-') {
+ if (memcmp(n1, "-BoldItalic", 11) == 0) { n1 += 11; derived1 = 3; }
+ else if (memcmp(n1, "-BoldOblique", 12) == 0) { n1 += 12; derived1 = 3; }
+ else if (memcmp(n1, "-Bold", 5) == 0) {n1 += 5; derived1 = 1; }
+ else if (memcmp(n1, "-Italic", 7) == 0) {n1 += 7; derived1 = 2; }
+ else if (memcmp(n1, "-Oblique", 8) == 0) {n1 += 8; derived1 = 2; }
+ }
+ if (*n2 == '-') {
+ if (memcmp(n2, "-BoldItalic", 11) == 0) {n2 += 11; derived2 = 3; }
+ else if (memcmp(n2, "-BoldOblique", 12) == 0) {n2 += 12; derived2 = 3; }
+ else if (memcmp(n2, "-Bold", 5) == 0) {n2 += 5; derived2 = 1; }
+ else if (memcmp(n2, "-Italic", 7) == 0) {n2 += 7; derived2 = 2; }
+ else if (memcmp(n2, "-Oblique", 8) == 0) {n2 += 8; derived2 = 2; }
+ }
+ if (*n1 < *n2) return -1;
+ if (*n1 > *n2) return +1;
+ if (*n1 == 0) {
+ return derived1 - derived2;
+ }
+ n1++; n2++;
+ }
}
#endif
static int fl_free_font = FL_FREE_FONT;
+// This function fills in the fltk font table with all the fonts that
+// are found on the X server. It tries to place the fonts into families
+// and to sort them so the first 4 in a family are normal, bold, italic,
+// and bold italic.
+
Fl_Font Fl::set_fonts(const char* xstarname) {
#pragma unused ( xstarname )
if (fl_free_font > FL_FREE_FONT) return (Fl_Font)fl_free_font; // if already called