1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00

Tune the sorting of the style list box for X fonts.

[originally from svn r7942]
This commit is contained in:
Simon Tatham 2008-03-26 21:33:10 +00:00
parent 95a5116dbf
commit f0b78b8869

View File

@ -46,8 +46,6 @@
* - work out why the list boxes don't go all the way to the RHS * - work out why the list boxes don't go all the way to the RHS
* of the dialog box * of the dialog box
* *
* - construct a stylekey for X11 fonts
*
* - big testing and shakedown! * - big testing and shakedown!
*/ */
@ -452,10 +450,11 @@ static void x11font_enum_fonts(GtkWidget *widget,
* we'll be using in the font selector. * we'll be using in the font selector.
*/ */
char *components[14]; char *components[14];
char *p, *font, *style, *charset; char *p, *font, *style, *stylekey, *charset;
int j, thistmpsize, fontsize, flags; int j, weightkey, slantkey, setwidthkey;
int thistmpsize, fontsize, flags;
thistmpsize = 3 * strlen(fontnames[i]) + 256; thistmpsize = 4 * strlen(fontnames[i]) + 256;
if (tmpsize < thistmpsize) { if (tmpsize < thistmpsize) {
tmpsize = thistmpsize; tmpsize = thistmpsize;
tmp = sresize(tmp, tmpsize, char); tmp = sresize(tmp, tmpsize, char);
@ -488,10 +487,8 @@ static void x11font_enum_fonts(GtkWidget *widget,
p += 1 + sprintf(p, "%s-%s", components[12], components[13]); p += 1 + sprintf(p, "%s-%s", components[12], components[13]);
/* /*
* Style is a mixture of the weight, slant, set_width * Style is a mixture of quite a lot of the fields,
* and spacing fields (respectively 2, 3, 4 and 10) * with some strange formatting.
* with some strange formatting. (Again, cribbed
* entirely from the GTK 1.2 font selector.)
*/ */
style = p; style = p;
p += sprintf(p, "%s", components[2][0] ? components[2] : p += sprintf(p, "%s", components[2][0] ? components[2] :
@ -512,6 +509,48 @@ static void x11font_enum_fonts(GtkWidget *widget,
p += sprintf(p, " [M]"); p += sprintf(p, " [M]");
if (!g_strcasecmp(components[10], "c")) if (!g_strcasecmp(components[10], "c"))
p += sprintf(p, " [C]"); p += sprintf(p, " [C]");
if (components[5][0])
p += sprintf(p, " %s", components[5]);
/*
* Style key is the same stuff as above, but with a
* couple of transformations done on it to make it
* sort more sensibly.
*/
p++;
stylekey = p;
if (!g_strcasecmp(components[2], "medium") ||
!g_strcasecmp(components[2], "regular") ||
!g_strcasecmp(components[2], "normal") ||
!g_strcasecmp(components[2], "book"))
weightkey = 0;
else if (!g_strncasecmp(components[2], "demi", 4) ||
!g_strncasecmp(components[2], "semi", 4))
weightkey = 1;
else
weightkey = 2;
if (!g_strcasecmp(components[3], "r"))
slantkey = 0;
else if (!g_strncasecmp(components[3], "r", 1))
slantkey = 2;
else
slantkey = 1;
if (!g_strcasecmp(components[4], "normal"))
setwidthkey = 0;
else
setwidthkey = 1;
p += sprintf(p, "%04d%04d%s%04d%04d%s%04d%04d%s%04d%s%04d%s",
weightkey,
strlen(components[2]), components[2],
slantkey,
strlen(components[3]), components[3],
setwidthkey,
strlen(components[4]), components[4],
strlen(components[10]), components[10],
strlen(components[5]), components[5]);
assert(p - tmp < thistmpsize);
/* /*
* Size is in pixels, for our application, so we * Size is in pixels, for our application, so we
@ -536,7 +575,7 @@ static void x11font_enum_fonts(GtkWidget *widget,
*/ */
if (fontsize) if (fontsize)
callback(callback_ctx, fontnames[i], font, charset, callback(callback_ctx, fontnames[i], font, charset,
style, NULL, fontsize, flags, &x11font_vtable); style, stylekey, fontsize, flags, &x11font_vtable);
} else { } else {
/* /*
* This isn't an XLFD, so it must be an alias. * This isn't an XLFD, so it must be an alias.