aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Rumney2007-12-20 10:40:31 +0000
committerJason Rumney2007-12-20 10:40:31 +0000
commit9ba6fd4149ba78a15150320494478fc1cbe79921 (patch)
tree4ee16f9588471a08e2c9ed00ddbeea71f7965207 /src
parent9e1a29952aff42067a7b586977b6f089e8579f04 (diff)
downloademacs-9ba6fd4149ba78a15150320494478fc1cbe79921.tar.gz
emacs-9ba6fd4149ba78a15150320494478fc1cbe79921.zip
(font_parse_fcname): Default weight and slant to normal.
(font_score): Prefer normal fonts if weight or slant unspecified. (font_score) [WINDOWSNT]: Scale weight difference down to closer match freetype scores.
Diffstat (limited to 'src')
-rw-r--r--src/font.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/font.c b/src/font.c
index 3b07e3db59c..51f9ffa0a24 100644
--- a/src/font.c
+++ b/src/font.c
@@ -1248,6 +1248,8 @@ font_parse_fcname (name, font)
1248 char *p0, *p1; 1248 char *p0, *p1;
1249 int len = strlen (name); 1249 int len = strlen (name);
1250 char *copy; 1250 char *copy;
1251 int weight_set = 0;
1252 int slant_set = 0;
1251 1253
1252 if (len == 0) 1254 if (len == 0)
1253 return -1; 1255 return -1;
@@ -1301,12 +1303,14 @@ font_parse_fcname (name, font)
1301 || memcmp (p0 + 1, "black", 5) == 0) 1303 || memcmp (p0 + 1, "black", 5) == 0)
1302 { 1304 {
1303 ASET (font, FONT_WEIGHT_INDEX, val); 1305 ASET (font, FONT_WEIGHT_INDEX, val);
1306 weight_set = 1;
1304 } 1307 }
1305 else if (memcmp (p0 + 1, "roman", 5) == 0 1308 else if (memcmp (p0 + 1, "roman", 5) == 0
1306 || memcmp (p0 + 1, "italic", 6) == 0 1309 || memcmp (p0 + 1, "italic", 6) == 0
1307 || memcmp (p0 + 1, "oblique", 7) == 0) 1310 || memcmp (p0 + 1, "oblique", 7) == 0)
1308 { 1311 {
1309 ASET (font, FONT_SLANT_INDEX, val); 1312 ASET (font, FONT_SLANT_INDEX, val);
1313 slant_set = 1;
1310 } 1314 }
1311 else if (memcmp (p0 + 1, "charcell", 8) == 0 1315 else if (memcmp (p0 + 1, "charcell", 8) == 0
1312 || memcmp (p0 + 1, "mono", 4) == 0 1316 || memcmp (p0 + 1, "mono", 4) == 0
@@ -1338,6 +1342,11 @@ font_parse_fcname (name, font)
1338 { 1342 {
1339 if (prop >= 0 && prop < FONT_EXTRA_INDEX) 1343 if (prop >= 0 && prop < FONT_EXTRA_INDEX)
1340 { 1344 {
1345 if (prop == FONT_WEIGHT_INDEX)
1346 weight_set = 1;
1347 else if (prop == FONT_SLANT_INDEX)
1348 slant_set = 1;
1349
1341 ASET (font, prop, val); 1350 ASET (font, prop, val);
1342 } 1351 }
1343 else 1352 else
@@ -1347,6 +1356,11 @@ font_parse_fcname (name, font)
1347 p0 = p1; 1356 p0 = p1;
1348 } 1357 }
1349 1358
1359 if (!weight_set)
1360 ASET (font, FONT_WEIGHT_INDEX, build_string ("normal"));
1361 if (!slant_set)
1362 ASET (font, FONT_SLANT_INDEX, build_string ("normal"));
1363
1350 return 0; 1364 return 0;
1351} 1365}
1352 1366
@@ -1910,14 +1924,22 @@ font_score (entity, spec_prop)
1910 for (i = FONT_WEIGHT_INDEX; i <= FONT_SIZE_INDEX; i++) 1924 for (i = FONT_WEIGHT_INDEX; i <= FONT_SIZE_INDEX; i++)
1911 { 1925 {
1912 Lisp_Object entity_val = AREF (entity, i); 1926 Lisp_Object entity_val = AREF (entity, i);
1927 Lisp_Object spec_val = spec_prop[i];
1928
1929 /* If weight and slant are unspecified, score normal lower (low wins). */
1930 if (NILP (spec_val))
1931 {
1932 if (i == FONT_WEIGHT_INDEX || i == FONT_SLANT_INDEX)
1933 spec_val = prop_name_to_numeric (i, build_string ("normal"));
1934 }
1913 1935
1914 if (! NILP (spec_prop[i]) && ! EQ (spec_prop[i], entity_val)) 1936 if (! NILP (spec_val) && ! EQ (spec_val, entity_val))
1915 { 1937 {
1916 if (! INTEGERP (entity_val)) 1938 if (! INTEGERP (entity_val))
1917 score |= 127 << sort_shift_bits[i]; 1939 score |= 127 << sort_shift_bits[i];
1918 else 1940 else
1919 { 1941 {
1920 int diff = XINT (entity_val) - XINT (spec_prop[i]); 1942 int diff = XINT (entity_val) - XINT (spec_val);
1921 1943
1922 if (diff < 0) 1944 if (diff < 0)
1923 diff = - diff; 1945 diff = - diff;
@@ -1927,6 +1949,19 @@ font_score (entity, spec_prop)
1927 && diff > FONT_PIXEL_SIZE_QUANTUM) 1949 && diff > FONT_PIXEL_SIZE_QUANTUM)
1928 score |= min (diff, 127) << sort_shift_bits[i]; 1950 score |= min (diff, 127) << sort_shift_bits[i];
1929 } 1951 }
1952#ifdef WINDOWSNT
1953 else if (i == FONT_WEIGHT_INDEX)
1954 {
1955 /* Windows uses a much wider range for weight (100-900)
1956 compared with freetype (0-210), so scale down the
1957 difference. A more general way of doing this
1958 would be to look up the values of regular and bold
1959 and/or light and calculate the scale factor from them,
1960 but the lookup would be expensive, and if only Windows
1961 needs it, not worth the effort. */
1962 score |= min (diff / 4, 127) << sort_shift_bits[i];
1963 }
1964#endif
1930 else 1965 else
1931 score |= min (diff, 127) << sort_shift_bits[i]; 1966 score |= min (diff, 127) << sort_shift_bits[i];
1932 } 1967 }