Mercurial > emacs
comparison src/fontset.c @ 89610:3aa74296be55
(fontset_face): Create a fallback fontset on demand
(make_fontset): Don't create a fallback fontset here.
(free_face_fontset): Free a fallback fontset (if any) too.
(n_auto_fontsets): Delete this variable.
(auto_fontset_alist): New variable.
(new_fontset_from_font_name): Check auto_fontset_alist.
(dump_fontset) [FONTSET_DEBUG]: Fully re-written.
(Ffontset_list_all) [FONTSET_DEBUG]: New function.
(syms_of_fontset): Initialize and staticpro auto_fontset_alist.
Defsubr Sfontset_list_all.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 29 Oct 2003 11:51:42 +0000 |
parents | 9090f7eba02c |
children | 355fc0282e50 |
comparison
equal
deleted
inserted
replaced
89609:6955c3d5b912 | 89610:3aa74296be55 |
---|---|
625 return XINT (AREF (elt, 0)); | 625 return XINT (AREF (elt, 0)); |
626 } | 626 } |
627 | 627 |
628 try_default: | 628 try_default: |
629 if (! EQ (base_fontset, Vdefault_fontset)) | 629 if (! EQ (base_fontset, Vdefault_fontset)) |
630 return fontset_face (FONTSET_FALLBACK (fontset), c, face); | 630 { |
631 if (NILP (FONTSET_FALLBACK (fontset))) | |
632 FONTSET_FALLBACK (fontset) | |
633 = make_fontset (FONTSET_FRAME (fontset), Qnil, Vdefault_fontset); | |
634 return fontset_face (FONTSET_FALLBACK (fontset), c, face); | |
635 } | |
631 | 636 |
632 /* We have tried all the fonts for C, but none of them can be opened | 637 /* We have tried all the fonts for C, but none of them can be opened |
633 nor can display C. */ | 638 nor can display C. */ |
634 if (NILP (FONTSET_NOFONT_FACE (fontset))) | 639 if (NILP (FONTSET_NOFONT_FACE (fontset))) |
635 { | 640 { |
689 FONTSET_BASE (fontset) = base; | 694 FONTSET_BASE (fontset) = base; |
690 } | 695 } |
691 | 696 |
692 ASET (Vfontset_table, id, fontset); | 697 ASET (Vfontset_table, id, fontset); |
693 next_fontset_id = id + 1; | 698 next_fontset_id = id + 1; |
694 if (! NILP (base) && ! EQ (base, Vdefault_fontset)) | |
695 FONTSET_FALLBACK (fontset) = make_fontset (frame, Qnil, Vdefault_fontset); | |
696 return fontset; | 699 return fontset; |
697 } | 700 } |
698 | 701 |
699 | 702 |
700 | 703 |
735 void | 738 void |
736 free_face_fontset (f, face) | 739 free_face_fontset (f, face) |
737 FRAME_PTR f; | 740 FRAME_PTR f; |
738 struct face *face; | 741 struct face *face; |
739 { | 742 { |
743 Lisp_Object fontset; | |
744 | |
745 fontset = AREF (Vfontset_table, face->fontset); | |
746 xassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset)); | |
747 xassert (f == XFRAME (FONTSET_FRAME (fontset))); | |
740 ASET (Vfontset_table, face->fontset, Qnil); | 748 ASET (Vfontset_table, face->fontset, Qnil); |
741 if (face->fontset < next_fontset_id) | 749 if (face->fontset < next_fontset_id) |
742 next_fontset_id = face->fontset; | 750 next_fontset_id = face->fontset; |
751 if (! NILP (FONTSET_FALLBACK (fontset))) | |
752 { | |
753 int id = FONTSET_ID (FONTSET_FALLBACK (fontset)); | |
754 | |
755 fontset = AREF (Vfontset_table, id); | |
756 xassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset)); | |
757 xassert (f == XFRAME (FONTSET_FRAME (fontset))); | |
758 ASET (Vfontset_table, id, Qnil); | |
759 if (id < next_fontset_id) | |
760 next_fontset_id = face->fontset; | |
761 } | |
743 } | 762 } |
744 | 763 |
745 | 764 |
746 /* Return 1 iff FACE is suitable for displaying character C. | 765 /* Return 1 iff FACE is suitable for displaying character C. |
747 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P | 766 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P |
1413 } | 1432 } |
1414 return name; | 1433 return name; |
1415 } | 1434 } |
1416 | 1435 |
1417 | 1436 |
1418 /* Number of fontsets created from a fontname automatically. */ | 1437 /* Alist of automatically created fontsets. Each element is a cons |
1419 static int n_auto_fontsets; | 1438 (FONTNAME . FONTSET-ID). */ |
1439 static Lisp_Object auto_fontset_alist; | |
1420 | 1440 |
1421 int | 1441 int |
1422 new_fontset_from_font_name (Lisp_Object fontname) | 1442 new_fontset_from_font_name (Lisp_Object fontname) |
1423 { | 1443 { |
1444 Lisp_Object val; | |
1424 Lisp_Object name; | 1445 Lisp_Object name; |
1425 Lisp_Object vec; | 1446 Lisp_Object vec; |
1447 int id; | |
1426 | 1448 |
1427 fontname = Fdowncase (fontname); | 1449 fontname = Fdowncase (fontname); |
1450 val = Fassoc (fontname, auto_fontset_alist); | |
1451 if (CONSP (val)) | |
1452 return XINT (XCDR (val)); | |
1453 | |
1428 vec = split_font_name_into_vector (fontname); | 1454 vec = split_font_name_into_vector (fontname); |
1429 if ( NILP (vec)) | 1455 if ( NILP (vec)) |
1430 vec = Fmake_vector (make_number (14), build_string ("")); | 1456 vec = Fmake_vector (make_number (14), build_string ("")); |
1431 ASET (vec, 12, build_string ("fontset")); | 1457 ASET (vec, 12, build_string ("fontset")); |
1432 if (n_auto_fontsets == 0) | 1458 if (NILP (auto_fontset_alist)) |
1433 { | 1459 { |
1434 ASET (vec, 13, build_string ("startup")); | 1460 ASET (vec, 13, build_string ("startup")); |
1435 name = build_font_name_from_vector (vec); | 1461 name = build_font_name_from_vector (vec); |
1436 n_auto_fontsets++; | |
1437 } | 1462 } |
1438 else | 1463 else |
1439 { | 1464 { |
1440 char temp[20]; | 1465 char temp[20]; |
1441 | 1466 int len = Flength (auto_fontset_alist); |
1442 do { | 1467 |
1443 sprintf (temp, "auto%d", n_auto_fontsets); | 1468 sprintf (temp, "auto%d", len); |
1444 ASET (vec, 13, build_string (temp)); | 1469 ASET (vec, 13, build_string (temp)); |
1445 name = build_font_name_from_vector (vec); | 1470 name = build_font_name_from_vector (vec); |
1446 n_auto_fontsets++; | 1471 } |
1447 } while (fs_query_fontset (name, 0) >= 0); | 1472 name = Fnew_fontset (name, Fcons (Fcons (Qascii, Fcons (fontname, Qnil)), |
1448 } | 1473 Qnil)); |
1449 name = Fnew_fontset (name, | 1474 id = fs_query_fontset (name, 0); |
1450 Fcons (Fcons (Qascii, Fcons (fontname, Qnil)), Qnil)); | 1475 auto_fontset_alist |
1451 Vfontset_alias_alist = Fcons (Fcons (name, fontname), Vfontset_alias_alist); | 1476 = Fcons (Fcons (fontname, make_number (id)), auto_fontset_alist); |
1452 return fs_query_fontset (name, 0); | 1477 return id; |
1453 } | 1478 } |
1454 | 1479 |
1455 | 1480 |
1456 DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0, | 1481 DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0, |
1457 doc: /* Return information about a font named NAME on frame FRAME. | 1482 doc: /* Return information about a font named NAME on frame FRAME. |
1716 } | 1741 } |
1717 | 1742 |
1718 return list; | 1743 return list; |
1719 } | 1744 } |
1720 | 1745 |
1746 | |
1747 #ifdef FONTSET_DEBUG | |
1748 | |
1749 Lisp_Object | |
1750 dump_fontset (fontset) | |
1751 Lisp_Object fontset; | |
1752 { | |
1753 Lisp_Object vec; | |
1754 | |
1755 vec = Fmake_vector (make_number (3), Qnil); | |
1756 ASET (vec, 0, FONTSET_ID (fontset)); | |
1757 | |
1758 if (BASE_FONTSET_P (fontset)) | |
1759 { | |
1760 ASET (vec, 1, FONTSET_NAME (fontset)); | |
1761 } | |
1762 else | |
1763 { | |
1764 Lisp_Object frame; | |
1765 | |
1766 frame = FONTSET_FRAME (fontset); | |
1767 if (FRAMEP (frame)) | |
1768 { | |
1769 FRAME_PTR f = XFRAME (frame); | |
1770 | |
1771 if (FRAME_LIVE_P (f)) | |
1772 ASET (vec, 1, f->name); | |
1773 else | |
1774 ASET (vec, 1, Qt); | |
1775 } | |
1776 if (!NILP (FONTSET_FALLBACK (fontset))) | |
1777 ASET (vec, 2, FONTSET_ID (FONTSET_FALLBACK (fontset))); | |
1778 } | |
1779 return vec; | |
1780 } | |
1781 | |
1782 DEFUN ("fontset-list-all", Ffontset_list_all, Sfontset_list_all, 0, 0, 0, | |
1783 doc: /* Return a brief summary of all fontsets for debug use. */) | |
1784 () | |
1785 { | |
1786 Lisp_Object val; | |
1787 int i; | |
1788 | |
1789 for (i = 0, val = Qnil; i < ASIZE (Vfontset_table); i++) | |
1790 if (! NILP (AREF (Vfontset_table, i))) | |
1791 val = Fcons (dump_fontset (AREF (Vfontset_table, i)), val); | |
1792 return (Fnreverse (val)); | |
1793 } | |
1794 #endif /* FONTSET_DEBUG */ | |
1795 | |
1721 void | 1796 void |
1722 syms_of_fontset () | 1797 syms_of_fontset () |
1723 { | 1798 { |
1724 if (!load_font_func) | 1799 if (!load_font_func) |
1725 /* Window system initializer should have set proper functions. */ | 1800 /* Window system initializer should have set proper functions. */ |
1760 FONTSET_ASCII (Vdefault_fontset) = default_ascii_font; | 1835 FONTSET_ASCII (Vdefault_fontset) = default_ascii_font; |
1761 } | 1836 } |
1762 AREF (Vfontset_table, 0) = Vdefault_fontset; | 1837 AREF (Vfontset_table, 0) = Vdefault_fontset; |
1763 next_fontset_id = 1; | 1838 next_fontset_id = 1; |
1764 | 1839 |
1840 auto_fontset_alist = Qnil; | |
1841 staticpro (&auto_fontset_alist); | |
1842 | |
1765 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist, | 1843 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist, |
1766 doc: /* | 1844 doc: /* |
1767 Alist of fontname patterns vs the corresponding encoding and repertory info. | 1845 Alist of fontname patterns vs the corresponding encoding and repertory info. |
1768 Each element looks like (REGEXP . (ENCODING . REPERTORY)), | 1846 Each element looks like (REGEXP . (ENCODING . REPERTORY)), |
1769 where ENCODING is a charset or a char-table, | 1847 where ENCODING is a charset or a char-table, |
1825 defsubr (&Sfont_info); | 1903 defsubr (&Sfont_info); |
1826 defsubr (&Sinternal_char_font); | 1904 defsubr (&Sinternal_char_font); |
1827 defsubr (&Sfontset_info); | 1905 defsubr (&Sfontset_info); |
1828 defsubr (&Sfontset_font); | 1906 defsubr (&Sfontset_font); |
1829 defsubr (&Sfontset_list); | 1907 defsubr (&Sfontset_list); |
1830 } | 1908 #ifdef FONTSET_DEBUG |
1831 | 1909 defsubr (&Sfontset_list_all); |
1832 Lisp_Object | 1910 #endif |
1833 dump_fontset (fontset) | 1911 } |
1834 Lisp_Object fontset; | |
1835 { | |
1836 Lisp_Object val; | |
1837 | |
1838 if (NILP (FONTSET_FALLBACK (fontset))) | |
1839 val = Fcons (Fcons (intern ("fallback-id"), Qnil), Qnil); | |
1840 else | |
1841 val = Fcons (Fcons (intern ("fallback-id"), | |
1842 FONTSET_ID (FONTSET_FALLBACK (fontset))), | |
1843 Qnil); | |
1844 if (NILP (FONTSET_BASE (fontset))) | |
1845 val = Fcons (Fcons (intern ("base"), Qnil), val); | |
1846 else | |
1847 val = Fcons (Fcons (intern ("base"), | |
1848 FONTSET_NAME (FONTSET_BASE (fontset))), | |
1849 val); | |
1850 val = Fcons (Fcons (intern ("name"), FONTSET_NAME (fontset)), val); | |
1851 val = Fcons (Fcons (intern ("id"), FONTSET_ID (fontset)), val); | |
1852 return val; | |
1853 } |