diff options
| author | Kenichi Handa | 2009-03-11 07:51:33 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2009-03-11 07:51:33 +0000 |
| commit | d64905422625b01c4f6ffcb4276c6021070d6899 (patch) | |
| tree | a0016b117e58c5cf96cb8a35bebc265426cb8c8f /src | |
| parent | e97389b933292a7faac01726865b2fc914123b16 (diff) | |
| download | emacs-d64905422625b01c4f6ffcb4276c6021070d6899.tar.gz emacs-d64905422625b01c4f6ffcb4276c6021070d6899.zip | |
(Fset_fontset_font): When a font for ASCII is changed,
modify the default font of frames that use this fontset.
(num_auto_fontsets): New variable.
(fontset_from_font): Use num_auto_fontsets to decide a fontset
name. Be sure to set FONTSET_ASCII to the correct font name.
(update_auto_fontset_alist): New function.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fontset.c | 123 |
1 files changed, 95 insertions, 28 deletions
diff --git a/src/fontset.c b/src/fontset.c index efccc780ed4..e8b2b9747d3 100644 --- a/src/fontset.c +++ b/src/fontset.c | |||
| @@ -1392,6 +1392,8 @@ set_fontset_font (fontset, range) | |||
| 1392 | } | 1392 | } |
| 1393 | 1393 | ||
| 1394 | extern Lisp_Object QCfamily, QCregistry; | 1394 | extern Lisp_Object QCfamily, QCregistry; |
| 1395 | static void update_auto_fontset_alist P_ ((Lisp_Object, Lisp_Object)); | ||
| 1396 | |||
| 1395 | 1397 | ||
| 1396 | DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0, | 1398 | DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0, |
| 1397 | doc: /* | 1399 | doc: /* |
| @@ -1432,6 +1434,8 @@ appended. By default, FONT-SPEC overrides the previous settings. */) | |||
| 1432 | Lisp_Object font_def, registry, family; | 1434 | Lisp_Object font_def, registry, family; |
| 1433 | Lisp_Object range_list; | 1435 | Lisp_Object range_list; |
| 1434 | struct charset *charset = NULL; | 1436 | struct charset *charset = NULL; |
| 1437 | Lisp_Object fontname; | ||
| 1438 | int ascii_changed = 0; | ||
| 1435 | 1439 | ||
| 1436 | fontset = check_fontset_name (name); | 1440 | fontset = check_fontset_name (name); |
| 1437 | 1441 | ||
| @@ -1440,23 +1444,28 @@ appended. By default, FONT-SPEC overrides the previous settings. */) | |||
| 1440 | if (!NILP (frame)) | 1444 | if (!NILP (frame)) |
| 1441 | CHECK_LIVE_FRAME (frame); | 1445 | CHECK_LIVE_FRAME (frame); |
| 1442 | 1446 | ||
| 1447 | fontname = Qnil; | ||
| 1443 | if (CONSP (font_spec)) | 1448 | if (CONSP (font_spec)) |
| 1444 | { | 1449 | { |
| 1445 | Lisp_Object spec = Ffont_spec (0, NULL); | 1450 | Lisp_Object spec = Ffont_spec (0, NULL); |
| 1446 | 1451 | ||
| 1447 | font_parse_family_registry (XCAR (font_spec), XCDR (font_spec), spec); | 1452 | font_parse_family_registry (XCAR (font_spec), XCDR (font_spec), spec); |
| 1448 | font_spec = spec; | 1453 | font_spec = spec; |
| 1454 | fontname = Ffont_xlfd_name (font_spec, Qnil); | ||
| 1449 | } | 1455 | } |
| 1450 | else if (STRINGP (font_spec)) | 1456 | else if (STRINGP (font_spec)) |
| 1451 | { | 1457 | { |
| 1452 | Lisp_Object args[2]; | 1458 | Lisp_Object args[2]; |
| 1453 | extern Lisp_Object QCname; | 1459 | extern Lisp_Object QCname; |
| 1454 | 1460 | ||
| 1461 | fontname = font_spec; | ||
| 1455 | args[0] = QCname; | 1462 | args[0] = QCname; |
| 1456 | args[1] = font_spec; | 1463 | args[1] = font_spec; |
| 1457 | font_spec = Ffont_spec (2, args); | 1464 | font_spec = Ffont_spec (2, args); |
| 1458 | } | 1465 | } |
| 1459 | else if (! NILP (font_spec) && ! FONT_SPEC_P (font_spec)) | 1466 | else if (FONT_SPEC_P (font_spec)) |
| 1467 | fontname = Ffont_xlfd_name (font_spec, Qnil); | ||
| 1468 | else if (! NILP (font_spec)) | ||
| 1460 | Fsignal (Qfont, list2 (build_string ("Invalid font-spec"), font_spec)); | 1469 | Fsignal (Qfont, list2 (build_string ("Invalid font-spec"), font_spec)); |
| 1461 | 1470 | ||
| 1462 | if (! NILP (font_spec)) | 1471 | if (! NILP (font_spec)) |
| @@ -1497,7 +1506,11 @@ appended. By default, FONT-SPEC overrides the previous settings. */) | |||
| 1497 | font_def = Qnil; | 1506 | font_def = Qnil; |
| 1498 | 1507 | ||
| 1499 | if (CHARACTERP (target)) | 1508 | if (CHARACTERP (target)) |
| 1500 | range_list = Fcons (Fcons (target, target), Qnil); | 1509 | { |
| 1510 | if (XFASTINT (target) < 0x80) | ||
| 1511 | error ("Can't set a font for partial ASCII range."); | ||
| 1512 | range_list = Fcons (Fcons (target, target), Qnil); | ||
| 1513 | } | ||
| 1501 | else if (CONSP (target)) | 1514 | else if (CONSP (target)) |
| 1502 | { | 1515 | { |
| 1503 | Lisp_Object from, to; | 1516 | Lisp_Object from, to; |
| @@ -1506,6 +1519,12 @@ appended. By default, FONT-SPEC overrides the previous settings. */) | |||
| 1506 | to = Fcdr (target); | 1519 | to = Fcdr (target); |
| 1507 | CHECK_CHARACTER (from); | 1520 | CHECK_CHARACTER (from); |
| 1508 | CHECK_CHARACTER (to); | 1521 | CHECK_CHARACTER (to); |
| 1522 | if (XFASTINT (from) < 0x80) | ||
| 1523 | { | ||
| 1524 | if (XFASTINT (from) != 0 || XFASTINT (to) < 0x7F) | ||
| 1525 | error ("Can't set a font for partial ASCII range."); | ||
| 1526 | ascii_changed = 1; | ||
| 1527 | } | ||
| 1509 | range_list = Fcons (target, Qnil); | 1528 | range_list = Fcons (target, Qnil); |
| 1510 | } | 1529 | } |
| 1511 | else if (SYMBOLP (target) && !NILP (target)) | 1530 | else if (SYMBOLP (target) && !NILP (target)) |
| @@ -1517,35 +1536,18 @@ appended. By default, FONT-SPEC overrides the previous settings. */) | |||
| 1517 | script_list = XCHAR_TABLE (Vchar_script_table)->extras[0]; | 1536 | script_list = XCHAR_TABLE (Vchar_script_table)->extras[0]; |
| 1518 | if (! NILP (Fmemq (target, script_list))) | 1537 | if (! NILP (Fmemq (target, script_list))) |
| 1519 | { | 1538 | { |
| 1539 | if (EQ (target, Qlatin)) | ||
| 1540 | ascii_changed = 1; | ||
| 1520 | val = Fcons (target, Qnil); | 1541 | val = Fcons (target, Qnil); |
| 1521 | map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table, | 1542 | map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table, |
| 1522 | val); | 1543 | val); |
| 1523 | range_list = XCDR (val); | 1544 | range_list = XCDR (val); |
| 1524 | if (EQ (target, Qlatin) && NILP (FONTSET_ASCII (fontset))) | ||
| 1525 | { | ||
| 1526 | if (VECTORP (font_spec)) | ||
| 1527 | val = generate_ascii_font_name (FONTSET_NAME (fontset), | ||
| 1528 | font_spec); | ||
| 1529 | else | ||
| 1530 | val = font_spec; | ||
| 1531 | FONTSET_ASCII (fontset) = val; | ||
| 1532 | } | ||
| 1533 | } | 1545 | } |
| 1534 | if (CHARSETP (target)) | 1546 | if (CHARSETP (target)) |
| 1535 | { | 1547 | { |
| 1536 | if (EQ (target, Qascii) && NILP (FONTSET_ASCII (fontset))) | 1548 | CHECK_CHARSET_GET_CHARSET (target, charset); |
| 1537 | { | 1549 | if (charset->ascii_compatible_p) |
| 1538 | if (VECTORP (font_spec)) | 1550 | ascii_changed = 1; |
| 1539 | font_spec = generate_ascii_font_name (FONTSET_NAME (fontset), | ||
| 1540 | font_spec); | ||
| 1541 | FONTSET_ASCII (fontset) = font_spec; | ||
| 1542 | range_list = Fcons (Fcons (make_number (0), make_number (127)), | ||
| 1543 | Qnil); | ||
| 1544 | } | ||
| 1545 | else | ||
| 1546 | { | ||
| 1547 | CHECK_CHARSET_GET_CHARSET (target, charset); | ||
| 1548 | } | ||
| 1549 | } | 1551 | } |
| 1550 | else if (NILP (range_list)) | 1552 | else if (NILP (range_list)) |
| 1551 | error ("Invalid script or charset name: %s", | 1553 | error ("Invalid script or charset name: %s", |
| @@ -1556,6 +1558,8 @@ appended. By default, FONT-SPEC overrides the previous settings. */) | |||
| 1556 | else | 1558 | else |
| 1557 | error ("Invalid target for setting a font"); | 1559 | error ("Invalid target for setting a font"); |
| 1558 | 1560 | ||
| 1561 | if (NILP (font_spec) && ascii_changed) | ||
| 1562 | error ("Can't set ASCII font to nil"); | ||
| 1559 | 1563 | ||
| 1560 | if (charset) | 1564 | if (charset) |
| 1561 | { | 1565 | { |
| @@ -1579,6 +1583,34 @@ appended. By default, FONT-SPEC overrides the previous settings. */) | |||
| 1579 | font. */ | 1583 | font. */ |
| 1580 | free_realized_fontsets (fontset); | 1584 | free_realized_fontsets (fontset); |
| 1581 | 1585 | ||
| 1586 | if (ascii_changed) | ||
| 1587 | { | ||
| 1588 | Lisp_Object tail, frame, alist; | ||
| 1589 | int fontset_id = XINT (FONTSET_ID (fontset)); | ||
| 1590 | |||
| 1591 | alist = Qnil; | ||
| 1592 | FONTSET_ASCII (fontset) = fontname; | ||
| 1593 | name = FONTSET_NAME (fontset); | ||
| 1594 | FOR_EACH_FRAME (tail, frame) | ||
| 1595 | { | ||
| 1596 | FRAME_PTR f = XFRAME (frame); | ||
| 1597 | Lisp_Object font_object; | ||
| 1598 | |||
| 1599 | if (FRAME_INITIAL_P(f) || FRAME_TERMCAP_P (f)) | ||
| 1600 | continue; | ||
| 1601 | if (fontset_id != FRAME_FONTSET (f)) | ||
| 1602 | continue; | ||
| 1603 | font_object = font_open_by_spec (f, font_spec); | ||
| 1604 | if (! NILP (font_object)) | ||
| 1605 | { | ||
| 1606 | update_auto_fontset_alist (font_object, fontset); | ||
| 1607 | if (NILP (alist)) | ||
| 1608 | alist = Fcons (Fcons (Qfont, name), Qnil); | ||
| 1609 | Fmodify_frame_parameters (frame, alist); | ||
| 1610 | } | ||
| 1611 | } | ||
| 1612 | } | ||
| 1613 | |||
| 1582 | return Qnil; | 1614 | return Qnil; |
| 1583 | } | 1615 | } |
| 1584 | 1616 | ||
| @@ -1657,12 +1689,18 @@ FONT-SPEC is a vector, a cons, or a string. See the documentation of | |||
| 1657 | (FONT-SPEC . FONTSET-ID). */ | 1689 | (FONT-SPEC . FONTSET-ID). */ |
| 1658 | static Lisp_Object auto_fontset_alist; | 1690 | static Lisp_Object auto_fontset_alist; |
| 1659 | 1691 | ||
| 1692 | /* Number of automatically created fontsets. */ | ||
| 1693 | static int num_auto_fontsets; | ||
| 1694 | |||
| 1695 | /* Retun a fontset synthesized from FONT-OBJECT. */ | ||
| 1696 | |||
| 1660 | int | 1697 | int |
| 1661 | fontset_from_font (font_object) | 1698 | fontset_from_font (font_object) |
| 1662 | Lisp_Object font_object; | 1699 | Lisp_Object font_object; |
| 1663 | { | 1700 | { |
| 1664 | Lisp_Object font_name = font_get_name (font_object); | 1701 | Lisp_Object font_name = font_get_name (font_object); |
| 1665 | Lisp_Object font_spec = Fcopy_font_spec (font_object); | 1702 | Lisp_Object font_spec = Fcopy_font_spec (font_object); |
| 1703 | Lisp_Object registry = AREF (font_spec, FONT_REGISTRY_INDEX); | ||
| 1666 | Lisp_Object fontset_spec, alias, name, fontset; | 1704 | Lisp_Object fontset_spec, alias, name, fontset; |
| 1667 | Lisp_Object val; | 1705 | Lisp_Object val; |
| 1668 | int i; | 1706 | int i; |
| @@ -1670,14 +1708,13 @@ fontset_from_font (font_object) | |||
| 1670 | val = assoc_no_quit (font_spec, auto_fontset_alist); | 1708 | val = assoc_no_quit (font_spec, auto_fontset_alist); |
| 1671 | if (CONSP (val)) | 1709 | if (CONSP (val)) |
| 1672 | return XINT (FONTSET_ID (XCDR (val))); | 1710 | return XINT (FONTSET_ID (XCDR (val))); |
| 1673 | if (NILP (auto_fontset_alist)) | 1711 | if (num_auto_fontsets++ == 0) |
| 1674 | alias = intern ("fontset-startup"); | 1712 | alias = intern ("fontset-startup"); |
| 1675 | else | 1713 | else |
| 1676 | { | 1714 | { |
| 1677 | char temp[32]; | 1715 | char temp[32]; |
| 1678 | int len = XINT (Flength (auto_fontset_alist)); | ||
| 1679 | 1716 | ||
| 1680 | sprintf (temp, "fontset-auto%d", len); | 1717 | sprintf (temp, "fontset-auto%d", num_auto_fontsets - 1); |
| 1681 | alias = intern (temp); | 1718 | alias = intern (temp); |
| 1682 | } | 1719 | } |
| 1683 | fontset_spec = Fcopy_font_spec (font_spec); | 1720 | fontset_spec = Fcopy_font_spec (font_spec); |
| @@ -1691,13 +1728,18 @@ fontset_from_font (font_object) | |||
| 1691 | alias = Fdowncase (AREF (font_object, FONT_NAME_INDEX)); | 1728 | alias = Fdowncase (AREF (font_object, FONT_NAME_INDEX)); |
| 1692 | Vfontset_alias_alist = Fcons (Fcons (name, alias), Vfontset_alias_alist); | 1729 | Vfontset_alias_alist = Fcons (Fcons (name, alias), Vfontset_alias_alist); |
| 1693 | auto_fontset_alist = Fcons (Fcons (font_spec, fontset), auto_fontset_alist); | 1730 | auto_fontset_alist = Fcons (Fcons (font_spec, fontset), auto_fontset_alist); |
| 1694 | FONTSET_ASCII (fontset) = font_name; | ||
| 1695 | font_spec = Fcopy_font_spec (font_spec); | 1731 | font_spec = Fcopy_font_spec (font_spec); |
| 1696 | ASET (font_spec, FONT_REGISTRY_INDEX, Qiso10646_1); | 1732 | ASET (font_spec, FONT_REGISTRY_INDEX, Qiso10646_1); |
| 1697 | for (i = FONT_WEIGHT_INDEX; i < FONT_EXTRA_INDEX; i++) | 1733 | for (i = FONT_WEIGHT_INDEX; i < FONT_EXTRA_INDEX; i++) |
| 1698 | ASET (font_spec, i, Qnil); | 1734 | ASET (font_spec, i, Qnil); |
| 1699 | Fset_fontset_font (name, Qlatin, font_spec, Qnil, Qnil); | 1735 | Fset_fontset_font (name, Qlatin, font_spec, Qnil, Qnil); |
| 1700 | Fset_fontset_font (name, Qnil, font_spec, Qnil, Qnil); | 1736 | Fset_fontset_font (name, Qnil, font_spec, Qnil, Qnil); |
| 1737 | if (registry != Qiso10646_1) | ||
| 1738 | { | ||
| 1739 | ASET (font_spec, FONT_REGISTRY_INDEX, registry); | ||
| 1740 | Fset_fontset_font (name, Qascii, font_spec, Qnil, Qnil); | ||
| 1741 | } | ||
| 1742 | FONTSET_ASCII (fontset) = font_name; | ||
| 1701 | 1743 | ||
| 1702 | #ifdef HAVE_NS | 1744 | #ifdef HAVE_NS |
| 1703 | nsfont_make_fontset_for_font(name, font_object); | 1745 | nsfont_make_fontset_for_font(name, font_object); |
| @@ -1706,6 +1748,31 @@ fontset_from_font (font_object) | |||
| 1706 | return XINT (FONTSET_ID (fontset)); | 1748 | return XINT (FONTSET_ID (fontset)); |
| 1707 | } | 1749 | } |
| 1708 | 1750 | ||
| 1751 | |||
| 1752 | /* Update auto_fontset_alist for FONTSET. When an ASCII font of | ||
| 1753 | FONTSET is changed, we delete an entry of FONTSET if any from | ||
| 1754 | auto_fontset_alist so that FONTSET is not re-used by | ||
| 1755 | fontset_from_font. */ | ||
| 1756 | |||
| 1757 | static void | ||
| 1758 | update_auto_fontset_alist (font_object, fontset) | ||
| 1759 | Lisp_Object font_object, fontset; | ||
| 1760 | { | ||
| 1761 | Lisp_Object prev, tail; | ||
| 1762 | |||
| 1763 | for (prev = Qnil, tail = auto_fontset_alist; CONSP (tail); | ||
| 1764 | prev = tail, tail = XCDR (tail)) | ||
| 1765 | if (EQ (fontset, XCDR (XCAR (tail)))) | ||
| 1766 | { | ||
| 1767 | if (NILP (prev)) | ||
| 1768 | auto_fontset_alist = XCDR (tail); | ||
| 1769 | else | ||
| 1770 | XSETCDR (prev, XCDR (tail)); | ||
| 1771 | break; | ||
| 1772 | } | ||
| 1773 | } | ||
| 1774 | |||
| 1775 | |||
| 1709 | /* Return a cons (FONT-OBJECT . GLYPH-CODE). | 1776 | /* Return a cons (FONT-OBJECT . GLYPH-CODE). |
| 1710 | FONT-OBJECT is the font for the character at POSITION in the current | 1777 | FONT-OBJECT is the font for the character at POSITION in the current |
| 1711 | buffer. This is computed from all the text properties and overlays | 1778 | buffer. This is computed from all the text properties and overlays |