aboutsummaryrefslogtreecommitdiffstats
path: root/src/fontset.c
diff options
context:
space:
mode:
authorKenichi Handa2009-03-13 05:08:56 +0000
committerKenichi Handa2009-03-13 05:08:56 +0000
commita3d16f39799a3f5a2eddc80b50adcda877d7d758 (patch)
tree689a11b15098155dc0fc45b68c5311f34ce4fbc4 /src/fontset.c
parentd102151dabddcce2860f82b5291ab106c27d534f (diff)
downloademacs-a3d16f39799a3f5a2eddc80b50adcda877d7d758.tar.gz
emacs-a3d16f39799a3f5a2eddc80b50adcda877d7d758.zip
(Ffontset_info, check_fontset_name): New arg frame.
Hanlde NAME nil and t correctly. Callers changed. (font_def_arg, add_arg, from_arg, to_arg): Delete them. (set_fontset_font): Change ARG to a vector. Handle range_list in ARG correctly. (Fset_fontset_font): Fix the case that TARGET is both a script name and charset name. Adjusted the arg to set_fontset_font for the above change. (fontset_from_font): Fix previous change. (Ffontset_info): Adjusted for the 2008-07-09 change of fontset entry. If FONTSET is the default fontset, don't set the extra slot of the returning char-table.
Diffstat (limited to 'src/fontset.c')
-rw-r--r--src/fontset.c211
1 files changed, 125 insertions, 86 deletions
diff --git a/src/fontset.c b/src/fontset.c
index e8b2b9747d3..03c50b76c8a 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -1291,25 +1291,39 @@ free_realized_fontsets (base)
1291 1291
1292/* Check validity of NAME as a fontset name and return the 1292/* Check validity of NAME as a fontset name and return the
1293 corresponding fontset. If not valid, signal an error. 1293 corresponding fontset. If not valid, signal an error.
1294 If NAME is t, return Vdefault_fontset. */ 1294
1295 If NAME is t, return Vdefault_fontset. If NAME is nil, return the
1296 fontset of *FRAME.
1297
1298 Set *FRAME to the actual frame. */
1295 1299
1296static Lisp_Object 1300static Lisp_Object
1297check_fontset_name (name) 1301check_fontset_name (name, frame)
1298 Lisp_Object name; 1302 Lisp_Object name, *frame;
1299{ 1303{
1300 int id; 1304 int id;
1301 1305
1306 if (NILP (*frame))
1307 *frame = selected_frame;
1308 CHECK_LIVE_FRAME (*frame);
1309
1302 if (EQ (name, Qt)) 1310 if (EQ (name, Qt))
1303 return Vdefault_fontset; 1311 return Vdefault_fontset;
1304 1312 if (NILP (name))
1305 CHECK_STRING (name); 1313 {
1306 /* First try NAME as literal. */ 1314 id = FRAME_FONTSET (XFRAME (*frame));
1307 id = fs_query_fontset (name, 2); 1315 }
1308 if (id < 0) 1316 else
1309 /* For backward compatibility, try again NAME as pattern. */ 1317 {
1310 id = fs_query_fontset (name, 0); 1318 CHECK_STRING (name);
1311 if (id < 0) 1319 /* First try NAME as literal. */
1312 error ("Fontset `%s' does not exist", SDATA (name)); 1320 id = fs_query_fontset (name, 2);
1321 if (id < 0)
1322 /* For backward compatibility, try again NAME as pattern. */
1323 id = fs_query_fontset (name, 0);
1324 if (id < 0)
1325 error ("Fontset `%s' does not exist", SDATA (name));
1326 }
1313 return FONTSET_FROM_ID (id); 1327 return FONTSET_FROM_ID (id);
1314} 1328}
1315 1329
@@ -1349,46 +1363,57 @@ generate_ascii_font_name (name, ascii_spec)
1349 return make_unibyte_string (xlfd, i); 1363 return make_unibyte_string (xlfd, i);
1350} 1364}
1351 1365
1352/* Variables referred in set_fontset_font. They are set before 1366/* Callback function for map_charset_chars in Fset_fontset_font.
1353 map_charset_chars is called in Fset_fontset_font. */ 1367 ARG is a vector [ FONTSET FONT_DEF ADD ASCII SCRIPT_RANGE_LIST ].
1354static Lisp_Object font_def_arg, add_arg;
1355static int from_arg, to_arg;
1356 1368
1357/* Callback function for map_charset_chars in Fset_fontset_font. In 1369 In FONTSET, set FONT_DEF in a fashion specified by ADD for
1358 FONTSET, set font_def_arg in a fashion specified by add_arg for 1370 characters in RANGE and ranges in SCRIPT_RANGE_LIST before RANGE.
1359 characters in RANGE while ignoring the range between from_arg and 1371 The consumed ranges are poped up from SCRIPT_RANGE_LIST, and the
1360 to_arg. */ 1372 new SCRIPT_RANGE_LIST is stored in ARG.
1373
1374 If ASCII is nil, don't set FONT_DEF for ASCII characters. It is
1375 assured that SCRIPT_RANGE_LIST doesn't contain ASCII in that
1376 case. */
1361 1377
1362static void 1378static void
1363set_fontset_font (fontset, range) 1379set_fontset_font (arg, range)
1364 Lisp_Object fontset, range; 1380 Lisp_Object arg, range;
1365{ 1381{
1366 if (from_arg < to_arg) 1382 Lisp_Object fontset, font_def, add, ascii, script_range_list;
1367 { 1383 int from = XINT (XCAR (range)), to = XINT (XCDR (range));
1368 int from = XINT (XCAR (range)), to = XINT (XCDR (range));
1369 1384
1370 if (from < from_arg) 1385 fontset = AREF (arg, 0);
1371 { 1386 font_def = AREF (arg, 1);
1372 if (to > to_arg) 1387 add = AREF (arg, 2);
1373 { 1388 ascii = AREF (arg, 3);
1374 Lisp_Object range2; 1389 script_range_list = AREF (arg, 4);
1375 1390
1376 range2 = Fcons (make_number (to_arg), XCDR (range)); 1391 if (NILP (ascii) && from < 0x80)
1377 FONTSET_ADD (fontset, range, font_def_arg, add_arg); 1392 {
1378 to = to_arg; 1393 if (to < 0x80)
1379 }
1380 if (to > from_arg)
1381 range = Fcons (XCAR (range), make_number (from_arg));
1382 }
1383 else if (to <= to_arg)
1384 return; 1394 return;
1385 else 1395 from = 0x80;
1386 { 1396 range = Fcons (make_number (0x80), XCDR (range));
1387 if (from < to_arg) 1397 }
1388 range = Fcons (make_number (to_arg), XCDR (range)); 1398
1389 } 1399#define SCRIPT_FROM XINT (XCAR (XCAR (script_range_list)))
1400#define SCRIPT_TO XINT (XCDR (XCAR (script_range_list)))
1401#define POP_SCRIPT_RANGE() script_range_list = XCDR (script_range_list)
1402
1403 for (; CONSP (script_range_list) && SCRIPT_TO < from; POP_SCRIPT_RANGE ())
1404 FONTSET_ADD (fontset, XCAR (script_range_list), font_def, add);
1405 if (CONSP (script_range_list))
1406 {
1407 if (SCRIPT_FROM < from)
1408 range = Fcons (make_number (SCRIPT_FROM), XCDR (range));
1409 while (CONSP (script_range_list) && SCRIPT_TO <= to)
1410 POP_SCRIPT_RANGE ();
1411 if (CONSP (script_range_list) && SCRIPT_FROM <= to)
1412 XSETCAR (XCAR (script_range_list), make_number (to + 1));
1390 } 1413 }
1391 FONTSET_ADD (fontset, range, font_def_arg, add_arg); 1414
1415 FONTSET_ADD (fontset, range, font_def, add);
1416 ASET (arg, 4, script_range_list);
1392} 1417}
1393 1418
1394extern Lisp_Object QCfamily, QCregistry; 1419extern Lisp_Object QCfamily, QCregistry;
@@ -1399,6 +1424,9 @@ DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0,
1399 doc: /* 1424 doc: /*
1400Modify fontset NAME to use FONT-SPEC for TARGET characters. 1425Modify fontset NAME to use FONT-SPEC for TARGET characters.
1401 1426
1427NAME is a fontset name string, nil for the fontset of FRAME, or t for
1428the default fontset.
1429
1402TARGET may be a cons; (FROM . TO), where FROM and TO are characters. 1430TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1403In that case, use FONT-SPEC for all characters in the range FROM and 1431In that case, use FONT-SPEC for all characters in the range FROM and
1404TO (inclusive). 1432TO (inclusive).
@@ -1420,8 +1448,8 @@ FONT-SPEC may one of these:
1420 * A font name string. 1448 * A font name string.
1421 * nil, which explicitly specifies that there's no font for TARGET. 1449 * nil, which explicitly specifies that there's no font for TARGET.
1422 1450
1423Optional 4th argument FRAME, if non-nil, is a frame. This argument is 1451Optional 4th argument FRAME is a frame or nil for the selected frame
1424kept for backward compatibility and has no meaning. 1452that is concerned in the case that NAME is nil.
1425 1453
1426Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC 1454Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1427to the font specifications for TARGET previously set. If it is 1455to the font specifications for TARGET previously set. If it is
@@ -1437,12 +1465,7 @@ appended. By default, FONT-SPEC overrides the previous settings. */)
1437 Lisp_Object fontname; 1465 Lisp_Object fontname;
1438 int ascii_changed = 0; 1466 int ascii_changed = 0;
1439 1467
1440 fontset = check_fontset_name (name); 1468 fontset = check_fontset_name (name, &frame);
1441
1442 /* The arg FRAME is kept for backward compatibility. We only check
1443 the validity. */
1444 if (!NILP (frame))
1445 CHECK_LIVE_FRAME (frame);
1446 1469
1447 fontname = Qnil; 1470 fontname = Qnil;
1448 if (CONSP (font_spec)) 1471 if (CONSP (font_spec))
@@ -1541,7 +1564,7 @@ appended. By default, FONT-SPEC overrides the previous settings. */)
1541 val = Fcons (target, Qnil); 1564 val = Fcons (target, Qnil);
1542 map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table, 1565 map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table,
1543 val); 1566 val);
1544 range_list = XCDR (val); 1567 range_list = Fnreverse (XCDR (val));
1545 } 1568 }
1546 if (CHARSETP (target)) 1569 if (CHARSETP (target))
1547 { 1570 {
@@ -1558,22 +1581,33 @@ appended. By default, FONT-SPEC overrides the previous settings. */)
1558 else 1581 else
1559 error ("Invalid target for setting a font"); 1582 error ("Invalid target for setting a font");
1560 1583
1561 if (NILP (font_spec) && ascii_changed) 1584 if (ascii_changed)
1562 error ("Can't set ASCII font to nil"); 1585 {
1586 Lisp_Object val;
1587
1588 if (NILP (font_spec))
1589 error ("Can't set ASCII font to nil");
1590 val = CHAR_TABLE_REF (fontset, 0);
1591 if (! NILP (val) && EQ (add, Qappend))
1592 /* We are going to change just an additional font for ASCII. */
1593 ascii_changed = 0;
1594 }
1563 1595
1564 if (charset) 1596 if (charset)
1565 { 1597 {
1566 font_def_arg = font_def; 1598 Lisp_Object arg;
1567 add_arg = add; 1599
1568 if (NILP (range_list)) 1600 arg = Fmake_vector (make_number (5), Qnil);
1569 from_arg = to_arg = 0; 1601 ASET (arg, 0, fontset);
1570 else 1602 ASET (arg, 1, font_def);
1571 from_arg = XINT (XCAR (XCAR (range_list))), 1603 ASET (arg, 2, add);
1572 to_arg = XINT (XCDR (XCAR (range_list))); 1604 ASET (arg, 3, ascii_changed ? Qt : Qnil);
1605 ASET (arg, 4, range_list);
1573 1606
1574 map_charset_chars (set_fontset_font, Qnil, fontset, charset, 1607 map_charset_chars (set_fontset_font, Qnil, arg, charset,
1575 CHARSET_MIN_CODE (charset), 1608 CHARSET_MIN_CODE (charset),
1576 CHARSET_MAX_CODE (charset)); 1609 CHARSET_MAX_CODE (charset));
1610 range_list = AREF (arg, 4);
1577 } 1611 }
1578 for (; CONSP (range_list); range_list = XCDR (range_list)) 1612 for (; CONSP (range_list); range_list = XCDR (range_list))
1579 FONTSET_ADD (fontset, XCAR (range_list), font_def, add); 1613 FONTSET_ADD (fontset, XCAR (range_list), font_def, add);
@@ -1729,15 +1763,15 @@ fontset_from_font (font_object)
1729 Vfontset_alias_alist = Fcons (Fcons (name, alias), Vfontset_alias_alist); 1763 Vfontset_alias_alist = Fcons (Fcons (name, alias), Vfontset_alias_alist);
1730 auto_fontset_alist = Fcons (Fcons (font_spec, fontset), auto_fontset_alist); 1764 auto_fontset_alist = Fcons (Fcons (font_spec, fontset), auto_fontset_alist);
1731 font_spec = Fcopy_font_spec (font_spec); 1765 font_spec = Fcopy_font_spec (font_spec);
1732 ASET (font_spec, FONT_REGISTRY_INDEX, Qiso10646_1);
1733 for (i = FONT_WEIGHT_INDEX; i < FONT_EXTRA_INDEX; i++) 1766 for (i = FONT_WEIGHT_INDEX; i < FONT_EXTRA_INDEX; i++)
1734 ASET (font_spec, i, Qnil); 1767 ASET (font_spec, i, Qnil);
1735 Fset_fontset_font (name, Qlatin, font_spec, Qnil, Qnil); 1768 Fset_fontset_font (name, Qlatin, font_spec, Qnil, Qnil);
1736 Fset_fontset_font (name, Qnil, font_spec, Qnil, Qnil); 1769 Fset_fontset_font (name, Qnil, font_spec, Qnil, Qnil);
1737 if (registry != Qiso10646_1) 1770 if (registry != Qiso10646_1)
1738 { 1771 {
1739 ASET (font_spec, FONT_REGISTRY_INDEX, registry); 1772 font_spec = Fcopy_font_spec (font_spec);
1740 Fset_fontset_font (name, Qascii, font_spec, Qnil, Qnil); 1773 ASET (font_spec, FONT_REGISTRY_INDEX, Qiso10646_1);
1774 Fset_fontset_font (name, Qlatin, font_spec, Qnil, Qappend);
1741 } 1775 }
1742 FONTSET_ASCII (fontset) = font_name; 1776 FONTSET_ASCII (fontset) = font_name;
1743 1777
@@ -1876,21 +1910,22 @@ DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0,
1876 1910
1877DEFUN ("fontset-info", Ffontset_info, Sfontset_info, 1, 2, 0, 1911DEFUN ("fontset-info", Ffontset_info, Sfontset_info, 1, 2, 0,
1878 doc: /* Return information about a fontset FONTSET on frame FRAME. 1912 doc: /* Return information about a fontset FONTSET on frame FRAME.
1879The value is a char-table whose elements have this form:
1880 1913
1881 ((FONT-PATTERN OPENED-FONT ...) ...) 1914FONTSET is a fontset name string, nil for the fontset of FRAME, or t
1915for the default fontset. FRAME nil means the selected frame.
1882 1916
1883FONT-PATTERN is a vector: 1917The value is a char-table whose elements have this form:
1884 1918
1885 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ] 1919 ((FONT OPENED-FONT ...) ...)
1886 1920
1887or a string of font name pattern. 1921FONT is a name of font specified for a range of characters.
1888 1922
1889OPENED-FONT is a name of a font actually opened. 1923OPENED-FONT is a name of a font actually opened.
1890 1924
1891The char-table has one extra slot. The value is a char-table 1925The char-table has one extra slot. If FONTSET is not the default
1892containing the information about the derived fonts from the default 1926fontset, the value the extra slot is a char-table containing the
1893fontset. The format is the same as above. */) 1927information about the derived fonts from the default fontset. The
1928format is the same as above. */)
1894 (fontset, frame) 1929 (fontset, frame)
1895 Lisp_Object fontset, frame; 1930 Lisp_Object fontset, frame;
1896{ 1931{
@@ -1901,11 +1936,7 @@ fontset. The format is the same as above. */)
1901 1936
1902 (*check_window_system_func) (); 1937 (*check_window_system_func) ();
1903 1938
1904 fontset = check_fontset_name (fontset); 1939 fontset = check_fontset_name (fontset, &frame);
1905
1906 if (NILP (frame))
1907 frame = selected_frame;
1908 CHECK_LIVE_FRAME (frame);
1909 f = XFRAME (frame); 1940 f = XFRAME (frame);
1910 1941
1911 /* Recode fontsets realized on FRAME from the base fontset FONTSET 1942 /* Recode fontsets realized on FRAME from the base fontset FONTSET
@@ -1933,10 +1964,13 @@ fontset. The format is the same as above. */)
1933 realized[1][j] = Qnil; 1964 realized[1][j] = Qnil;
1934 1965
1935 tables[0] = Fmake_char_table (Qfontset_info, Qnil); 1966 tables[0] = Fmake_char_table (Qfontset_info, Qnil);
1936 tables[1] = Fmake_char_table (Qnil, Qnil);
1937 XCHAR_TABLE (tables[0])->extras[0] = tables[1];
1938 fontsets[0] = fontset; 1967 fontsets[0] = fontset;
1939 fontsets[1] = Vdefault_fontset; 1968 if (fontset != Vdefault_fontset)
1969 {
1970 tables[1] = Fmake_char_table (Qnil, Qnil);
1971 XCHAR_TABLE (tables[0])->extras[0] = tables[1];
1972 fontsets[1] = Vdefault_fontset;
1973 }
1940 1974
1941 /* Accumulate information of the fontset in TABLE. The format of 1975 /* Accumulate information of the fontset in TABLE. The format of
1942 each element is ((FONT-SPEC OPENED-FONT ...) ...). */ 1976 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
@@ -1973,10 +2007,11 @@ fontset. The format is the same as above. */)
1973 val = FONTSET_REF (realized[k][i], c); 2007 val = FONTSET_REF (realized[k][i], c);
1974 else 2008 else
1975 val = FONTSET_FALLBACK (realized[k][i]); 2009 val = FONTSET_FALLBACK (realized[k][i]);
1976 if (! VECTORP (val)) 2010 if (! CONSP (val) || ! VECTORP (XCDR (val)))
1977 continue; 2011 continue;
1978 /* VAL: [int ? [FACE-ID FONT-DEF FONT-OBJECT int] ... ] */ 2012 /* VAL: (int . [[FACE-ID FONT-DEF FONT-OBJECT int] ... ]) */
1979 for (j = 2; j < ASIZE (val); j++) 2013 val = XCDR (val);
2014 for (j = 0; j < ASIZE (val); j++)
1980 { 2015 {
1981 elt = AREF (val, j); 2016 elt = AREF (val, j);
1982 if (FONT_OBJECT_P (RFONT_DEF_OBJECT (elt))) 2017 if (FONT_OBJECT_P (RFONT_DEF_OBJECT (elt)))
@@ -2007,6 +2042,8 @@ fontset. The format is the same as above. */)
2007 } 2042 }
2008 c = to + 1; 2043 c = to + 1;
2009 } 2044 }
2045 if (fontset == Vdefault_fontset)
2046 break;
2010 } 2047 }
2011 2048
2012 return tables[0]; 2049 return tables[0];
@@ -2030,8 +2067,10 @@ patterns. */)
2030 int c; 2067 int c;
2031 Lisp_Object fontset, elt, list, repertory, val; 2068 Lisp_Object fontset, elt, list, repertory, val;
2032 int i, j; 2069 int i, j;
2070 Lisp_Object frame;
2033 2071
2034 fontset = check_fontset_name (name); 2072 frame = Qnil;
2073 fontset = check_fontset_name (name, &frame);
2035 2074
2036 CHECK_CHARACTER (ch); 2075 CHECK_CHARACTER (ch);
2037 c = XINT (ch); 2076 c = XINT (ch);