* - work out why the list boxes don't go all the way to the RHS
* of the dialog box
*
- * - develop a sensible sorting order for the font styles -
- * Regular / Roman / non-bold-or-italic should come at the top!
+ * - construct a stylekey for X11 fonts
*
* - big testing and shakedown!
*/
typedef void (*fontsel_add_entry)(void *ctx, const char *realfontname,
const char *family, const char *charset,
- const char *style, int size, int flags,
+ const char *style, const char *stylekey,
+ int size, int flags,
const struct unifont_vtable *fontclass);
struct unifont_vtable {
*/
if (fontsize)
callback(callback_ctx, fontnames[i], font, charset,
- style, fontsize, flags, &x11font_vtable);
+ style, NULL, fontsize, flags, &x11font_vtable);
} else {
/*
* This isn't an XLFD, so it must be an alias.
* anything but computationally hideous. Ah well.
*/
callback(callback_ctx, fontnames[i], fontnames[i], NULL,
- NULL, 0, FONTFLAG_SERVERALIAS, &x11font_vtable);
+ NULL, NULL, 0, FONTFLAG_SERVERALIAS, &x11font_vtable);
}
}
XFreeFontNames(fontnames);
*/
for (k = 0; k < nsizes; k++) {
char *fullname;
+ char stylekey[128];
pango_font_description_set_size(desc, sizes[k]);
fullname = pango_font_description_to_string(desc);
+ /*
+ * Construct the sorting key for font styles.
+ */
+ {
+ char *p = stylekey;
+ int n;
+
+ n = pango_font_description_get_weight(desc);
+ /* Weight: normal, then lighter, then bolder */
+ if (n <= PANGO_WEIGHT_NORMAL)
+ n = PANGO_WEIGHT_NORMAL - n;
+ p += sprintf(p, "%4d", n);
+
+ n = pango_font_description_get_style(desc);
+ p += sprintf(p, " %2d", n);
+
+ n = pango_font_description_get_stretch(desc);
+ /* Stretch: closer to normal sorts earlier */
+ n = 2 * abs(PANGO_STRETCH_NORMAL - n) +
+ (n < PANGO_STRETCH_NORMAL);
+ p += sprintf(p, " %2d", n);
+
+ n = pango_font_description_get_variant(desc);
+ p += sprintf(p, " %2d", n);
+
+ }
+
/*
* Got everything. Hand off to the callback.
* (The charset string is NULL, because only
* server-side X fonts use it.)
*/
callback(callback_ctx, fullname, familyname, NULL, facename,
+ stylekey,
(sizes == &dummysize ? 0 : PANGO_PIXELS(sizes[k])),
flags, &pangofont_vtable);
*/
struct fontinfo {
char *realname;
- char *family, *charset, *style;
+ char *family, *charset, *style, *stylekey;
int size, flags;
/*
* Fallback sorting key, to permit multiple identical entries
return i;
if ((i = strnullcasecmp(a->charset, b->charset)) != 0)
return i;
+ if ((i = strnullcasecmp(a->stylekey, b->stylekey)) != 0)
+ return i;
if ((i = strnullcasecmp(a->style, b->style)) != 0)
return i;
if (a->size != b->size)
static void unifontsel_add_entry(void *ctx, const char *realfontname,
const char *family, const char *charset,
- const char *style, int size, int flags,
+ const char *style, const char *stylekey,
+ int size, int flags,
const struct unifont_vtable *fontclass)
{
unifontsel_internal *fs = (unifontsel_internal *)ctx;
totalsize = sizeof(fontinfo) + strlen(realfontname) +
(family ? strlen(family) : 0) + (charset ? strlen(charset) : 0) +
- (style ? strlen(style) : 0) + 10;
+ (style ? strlen(style) : 0) + (stylekey ? strlen(stylekey) : 0) + 10;
info = (fontinfo *)smalloc(totalsize);
info->fontclass = fontclass;
p = (char *)info + sizeof(fontinfo);
p += 1+strlen(p);
} else
info->style = NULL;
+ if (stylekey) {
+ info->stylekey = p;
+ strcpy(p, stylekey);
+ p += 1+strlen(p);
+ } else
+ info->stylekey = NULL;
assert(p - (char *)info <= totalsize);
info->size = size;
info->flags = flags;