aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2006-06-06 03:51:41 +0000
committerKenichi Handa2006-06-06 03:51:41 +0000
commit8aa07a8dcccb408b9e7560ba1be254dea946ce5d (patch)
tree31fca387c42d476a61ab0c74c1894b59885d3f6a
parent7f907f7cdce2a7a05b324d2112acdf0b4e5c4dc5 (diff)
downloademacs-8aa07a8dcccb408b9e7560ba1be254dea946ce5d.tar.gz
emacs-8aa07a8dcccb408b9e7560ba1be254dea946ce5d.zip
Include "font.h".
(fontset_font, fontset_ascii, face_for_char) (make_fontset_for_ascii_face, Ffont_info) (Finternal_char_font) [USE_FONT_BACKEND]: If enable_font_backend is nonzero, use font-backend mechanism. (find_font_encoding): Make it non-static. (new_fontset_from_font, fontset_ascii_font) [USE_FONT_BACKEND]: New functions.
-rw-r--r--src/fontset.c222
1 files changed, 217 insertions, 5 deletions
diff --git a/src/fontset.c b/src/fontset.c
index 9cebcfe1160..6e3e8b69961 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -3,7 +3,7 @@
3 Copyright (C) 1995, 1997, 1998, 2000, 2003, 2004, 2005 3 Copyright (C) 1995, 1997, 1998, 2000, 2003, 2004, 2005
4 National Institute of Advanced Industrial Science and Technology (AIST) 4 National Institute of Advanced Industrial Science and Technology (AIST)
5 Registration Number H14PRO021 5 Registration Number H14PRO021
6 Copyright (C) 2003 6 Copyright (C) 2003, 2006
7 National Institute of Advanced Industrial Science and Technology (AIST) 7 National Institute of Advanced Industrial Science and Technology (AIST)
8 Registration Number H13PRO009 8 Registration Number H13PRO009
9 9
@@ -54,6 +54,10 @@ Boston, MA 02110-1301, USA. */
54#include "macterm.h" 54#include "macterm.h"
55#endif 55#endif
56 56
57#ifdef USE_FONT_BACKEND
58#include "font.h"
59#endif /* USE_FONT_BACKEND */
60
57#undef xassert 61#undef xassert
58#ifdef FONTSET_DEBUG 62#ifdef FONTSET_DEBUG
59#define xassert(X) do {if (!(X)) abort ();} while (0) 63#define xassert(X) do {if (!(X)) abort ();} while (0)
@@ -263,7 +267,7 @@ static Lisp_Object make_fontset P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
263static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object)); 267static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object));
264static void accumulate_script_ranges P_ ((Lisp_Object, Lisp_Object, 268static void accumulate_script_ranges P_ ((Lisp_Object, Lisp_Object,
265 Lisp_Object)); 269 Lisp_Object));
266static Lisp_Object find_font_encoding P_ ((Lisp_Object)); 270Lisp_Object find_font_encoding P_ ((Lisp_Object));
267 271
268static void set_fontset_font P_ ((Lisp_Object, Lisp_Object)); 272static void set_fontset_font P_ ((Lisp_Object, Lisp_Object));
269 273
@@ -564,6 +568,11 @@ fontset_font (fontset, c, face, id)
564 { 568 {
565 Lisp_Object tmp; 569 Lisp_Object tmp;
566 570
571#ifdef USE_FONT_BACKEND
572 if (enable_font_backend)
573 tmp = Fmake_vector (make_number (5), Qnil);
574 else
575#endif /* USE_FONT_BACKEND */
567 tmp = Fmake_vector (make_number (4), Qnil); 576 tmp = Fmake_vector (make_number (4), Qnil);
568 ASET (tmp, 2, AREF (elt, i)); 577 ASET (tmp, 2, AREF (elt, i));
569 ASET (vec, 3 + i, tmp); 578 ASET (vec, 3 + i, tmp);
@@ -619,6 +628,61 @@ fontset_font (fontset, c, face, id)
619 628
620 font_def = AREF (elt, 2); 629 font_def = AREF (elt, 2);
621 /* FONT_DEF == [ FONT-SPEC ENCODING REPERTORY ] */ 630 /* FONT_DEF == [ FONT-SPEC ENCODING REPERTORY ] */
631
632#ifdef USE_FONT_BACKEND
633 if (enable_font_backend)
634 {
635 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF FONT-ENTITY FONT-OBJECT ] */
636 Lisp_Object font_entity = AREF (elt, 3);
637 Lisp_Object font_object = AREF (elt, 4);
638 int has_char;
639
640 if (NILP (font_entity))
641 {
642 Lisp_Object tmp = AREF (font_def, 0);
643 Lisp_Object spec = Ffont_spec (0, NULL);
644 Lisp_Object script;
645
646 if (STRINGP (tmp))
647 font_merge_old_spec (tmp, Qnil, Qnil, spec);
648 else
649 {
650 Lisp_Object family = AREF (tmp, 0);
651 Lisp_Object registry = AREF (tmp, 5);;
652
653 font_merge_old_spec (Qnil, family, registry, spec);
654 }
655 script = CHAR_TABLE_REF (Vchar_script_table, c);
656 if (! NILP (script))
657 ASET (spec, FONT_EXTRA_INDEX,
658 Fcons (Fcons (QCscript, script), Qnil));
659 font_entity = font_find_for_lface (f, face->lface, spec);
660 ASET (elt, 3, font_entity);
661 }
662 if (NILP (font_entity))
663 {
664 ASET (elt, 1, make_number (-1));
665 continue;
666 }
667 has_char = font_has_char (f, font_entity, c);
668 if (has_char == 0)
669 continue;
670 if (NILP (font_object))
671 font_object = font_open_for_lface (f, face->lface, font_entity);
672 if (NILP (font_object))
673 {
674 ASET (elt, 1, make_number (-1));
675 continue;
676 }
677 ASET (elt, 1, make_number (0));
678 ASET (elt, 4, font_object);
679 if (has_char < 0
680 && font_encode_char (font_object, c) == FONT_INVALID_CODE)
681 continue;
682 }
683 else
684#endif /* USE_FONT_BACKEND */
685
622 if (INTEGERP (AREF (font_def, 2))) 686 if (INTEGERP (AREF (font_def, 2)))
623 { 687 {
624 /* The repertory is specified by charset ID. */ 688 /* The repertory is specified by charset ID. */
@@ -700,6 +764,11 @@ fontset_font (fontset, c, face, id)
700 { 764 {
701 Lisp_Object tmp; 765 Lisp_Object tmp;
702 766
767#ifdef USE_FONT_BACKEND
768 if (enable_font_backend)
769 tmp = Fmake_vector (make_number (5), Qnil);
770 else
771#endif /* USE_FONT_BACKEND */
703 tmp = Fmake_vector (make_number (4), Qnil); 772 tmp = Fmake_vector (make_number (4), Qnil);
704 ASET (tmp, 2, AREF (elt, i)); 773 ASET (tmp, 2, AREF (elt, i));
705 ASET (vec, 3 + i, tmp); 774 ASET (vec, 3 + i, tmp);
@@ -817,6 +886,10 @@ fontset_ascii (id)
817 886
818 fontset= FONTSET_FROM_ID (id); 887 fontset= FONTSET_FROM_ID (id);
819 elt = FONTSET_ASCII (fontset); 888 elt = FONTSET_ASCII (fontset);
889#ifdef USE_FONT_BACKEND
890 if (CONSP (elt))
891 elt = XCAR (elt);
892#endif /* USE_FONT_BACKEND */
820 /* It is assured that ELT is always a string (i.e. fontname 893 /* It is assured that ELT is always a string (i.e. fontname
821 pattern). */ 894 pattern). */
822 return elt; 895 return elt;
@@ -906,6 +979,17 @@ face_for_char (f, face, c, pos, object)
906 rfont_def = fontset_font (fontset, c, face, id); 979 rfont_def = fontset_font (fontset, c, face, id);
907 if (VECTORP (rfont_def)) 980 if (VECTORP (rfont_def))
908 { 981 {
982#ifdef USE_FONT_BACKEND
983 if (enable_font_backend
984 && NILP (AREF (rfont_def, 0)))
985 {
986 struct font *font = XSAVE_VALUE (AREF (rfont_def, 4))->pointer;
987
988 face_id = face_for_font (f, font, face);
989 ASET (rfont_def, 0, make_number (face_id));
990 }
991 else
992#endif /* USE_FONT_BACKEND */
909 if (NILP (AREF (rfont_def, 0))) 993 if (NILP (AREF (rfont_def, 0)))
910 { 994 {
911 /* We have not yet made a realized face that uses this font. */ 995 /* We have not yet made a realized face that uses this font. */
@@ -958,11 +1042,24 @@ make_fontset_for_ascii_face (f, base_fontset_id, face)
958 1042
959 elt = FONTSET_REF (base_fontset, 0); 1043 elt = FONTSET_REF (base_fontset, 0);
960 xassert (VECTORP (elt) && ASIZE (elt) > 0); 1044 xassert (VECTORP (elt) && ASIZE (elt) > 0);
961 rfont_def = Fmake_vector (make_number (4), Qnil); 1045#ifdef USE_FONT_BACKEND
1046 rfont_def = Fmake_vector (make_number (5), Qnil);
1047 if (enable_font_backend && face->font_info)
1048 {
1049 struct font *font = (struct font *) face->font_info;
1050
1051 ASET (rfont_def, 3, font->entity);
1052 ASET (rfont_def, 4, font_find_object (font));
1053 }
1054#else /* not USE_FONT_BACKEND */
1055 {
1056 rfont_def = Fmake_vector (make_number (4), Qnil);
1057 ASET (rfont_def, 3, build_string (face->font_name));
1058 }
1059#endif /* not USE_FONT_BACKEND */
962 ASET (rfont_def, 0, make_number (face->id)); 1060 ASET (rfont_def, 0, make_number (face->id));
963 ASET (rfont_def, 1, make_number (face->font_info_id)); 1061 ASET (rfont_def, 1, make_number (face->font_info_id));
964 ASET (rfont_def, 2, AREF (elt, 0)); 1062 ASET (rfont_def, 2, AREF (elt, 0));
965 ASET (rfont_def, 3, build_string (face->font_name));
966 elt = Fmake_vector (make_number (4), Qnil); 1063 elt = Fmake_vector (make_number (4), Qnil);
967 ASET (elt, 0, make_number (charset_ordered_list_tick)); 1064 ASET (elt, 0, make_number (charset_ordered_list_tick));
968 ASET (elt, 1, make_number (charset_ascii)); 1065 ASET (elt, 1, make_number (charset_ascii));
@@ -1010,6 +1107,8 @@ fs_load_font (f, fontname, charset)
1010 charset_symbol = find_font_encoding (fullname); 1107 charset_symbol = find_font_encoding (fullname);
1011 if (CONSP (charset_symbol)) 1108 if (CONSP (charset_symbol))
1012 charset_symbol = XCAR (charset_symbol); 1109 charset_symbol = XCAR (charset_symbol);
1110 if (NILP (charset_symbol))
1111 charset_symbol = Qascii;
1013 charset = XINT (CHARSET_SYMBOL_ID (charset_symbol)); 1112 charset = XINT (CHARSET_SYMBOL_ID (charset_symbol));
1014 } 1113 }
1015 fontp->charset = charset; 1114 fontp->charset = charset;
@@ -1040,7 +1139,7 @@ fs_load_font (f, fontname, charset)
1040 of the font. REPERTORY is a charset symbol or nil. */ 1139 of the font. REPERTORY is a charset symbol or nil. */
1041 1140
1042 1141
1043static Lisp_Object 1142Lisp_Object
1044find_font_encoding (fontname) 1143find_font_encoding (fontname)
1045 Lisp_Object fontname; 1144 Lisp_Object fontname;
1046{ 1145{
@@ -1489,6 +1588,9 @@ appended. By default, FONT-SPEC overrides the previous settings. */)
1489 encoding = find_font_encoding (font_spec); 1588 encoding = find_font_encoding (font_spec);
1490 else 1589 else
1491 encoding = find_font_encoding (concat2 (family, registry)); 1590 encoding = find_font_encoding (concat2 (family, registry));
1591 if (NILP (encoding))
1592 encoding = Qascii;
1593
1492 if (SYMBOLP (encoding)) 1594 if (SYMBOLP (encoding))
1493 { 1595 {
1494 CHECK_CHARSET (encoding); 1596 CHECK_CHARSET (encoding);
@@ -1698,6 +1800,79 @@ new_fontset_from_font_name (Lisp_Object fontname)
1698 return id; 1800 return id;
1699} 1801}
1700 1802
1803#ifdef USE_FONT_BACKEND
1804int
1805new_fontset_from_font (f, font_object)
1806 FRAME_PTR f;
1807 Lisp_Object font_object;
1808{
1809 Lisp_Object xlfd = Ffont_xlfd_name (font_object);
1810 int id = new_fontset_from_font_name (xlfd);
1811 Lisp_Object fontset = FONTSET_FROM_ID (id);
1812
1813 if (STRINGP (FONTSET_ASCII (fontset)))
1814 FONTSET_ASCII (fontset) = Fcons (FONTSET_ASCII (fontset),
1815 Fcons (font_object, Qnil));
1816 else
1817 {
1818 Lisp_Object val = XCDR (FONTSET_ASCII (fontset));
1819
1820 for (; ! NILP (val); val = XCDR (val))
1821 if (EQ (XCAR (val), font_object))
1822 break;
1823 if (NILP (val))
1824 {
1825 val = FONTSET_ASCII (fontset);
1826 XSETCDR (val, Fcons (font_object, XCDR (val)));
1827 }
1828 }
1829 return id;
1830}
1831
1832struct font *
1833fontset_ascii_font (f, id)
1834 FRAME_PTR f;
1835 int id;
1836{
1837 Lisp_Object fontset = FONTSET_FROM_ID (id);
1838 Lisp_Object ascii_slot = FONTSET_ASCII (fontset);
1839 Lisp_Object val, font_object;
1840
1841 if (CONSP (ascii_slot))
1842 {
1843 Lisp_Object ascii_font_name = XCAR (ascii_slot);
1844
1845 font_object = Qnil;
1846 for (val = XCDR (ascii_slot); ! NILP (val); val = XCDR (val))
1847 {
1848 Lisp_Object frame = font_get_frame (XCAR (val));
1849
1850 if (NILP (frame) || XFRAME (frame) == f)
1851 {
1852 font_object = XCAR (val);
1853 if (XSAVE_VALUE (font_object)->integer == 0)
1854 {
1855 font_object = font_open_by_name (f, SDATA (ascii_font_name));
1856 XSETCAR (val, font_object);
1857 }
1858 break;
1859 }
1860 }
1861 if (NILP (font_object))
1862 {
1863 font_object = font_open_by_name (f, SDATA (ascii_font_name));
1864 XSETCDR (ascii_slot, Fcons (font_object, XCDR (ascii_slot)));
1865 }
1866 }
1867 else
1868 {
1869 font_object = font_open_by_name (f, SDATA (ascii_slot));
1870 FONTSET_ASCII (fontset) = Fcons (ascii_slot, Fcons (font_object, Qnil));
1871 }
1872 return XSAVE_VALUE (font_object)->pointer;
1873}
1874
1875#endif /* USE_FONT_BACKEND */
1701 1876
1702DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0, 1877DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0,
1703 doc: /* Return information about a font named NAME on frame FRAME. 1878 doc: /* Return information about a font named NAME on frame FRAME.
@@ -1719,6 +1894,7 @@ If the named font is not yet loaded, return nil. */)
1719 FRAME_PTR f; 1894 FRAME_PTR f;
1720 struct font_info *fontp; 1895 struct font_info *fontp;
1721 Lisp_Object info; 1896 Lisp_Object info;
1897 Lisp_Object font_object;
1722 1898
1723 (*check_window_system_func) (); 1899 (*check_window_system_func) ();
1724 1900
@@ -1732,6 +1908,17 @@ If the named font is not yet loaded, return nil. */)
1732 if (!query_font_func) 1908 if (!query_font_func)
1733 error ("Font query function is not supported"); 1909 error ("Font query function is not supported");
1734 1910
1911#ifdef USE_FONT_BACKEND
1912 if (enable_font_backend)
1913 {
1914 font_object = font_open_by_name (f, SDATA (name));
1915 if (NILP (font_object))
1916 fontp = NULL;
1917 else
1918 fontp = (struct font_info *) XSAVE_VALUE (font_object)->pointer;
1919 }
1920 else
1921#endif /* USE_FONT_BACKEND */
1735 fontp = (*query_font_func) (f, SDATA (name)); 1922 fontp = (*query_font_func) (f, SDATA (name));
1736 if (!fontp) 1923 if (!fontp)
1737 return Qnil; 1924 return Qnil;
@@ -1746,6 +1933,10 @@ If the named font is not yet loaded, return nil. */)
1746 XVECTOR (info)->contents[5] = make_number (fontp->relative_compose); 1933 XVECTOR (info)->contents[5] = make_number (fontp->relative_compose);
1747 XVECTOR (info)->contents[6] = make_number (fontp->default_ascent); 1934 XVECTOR (info)->contents[6] = make_number (fontp->default_ascent);
1748 1935
1936#ifdef USE_FONT_BACKEND
1937 if (! NILP (font_object))
1938 font_close_object (f, font_object);
1939#endif /* USE_FONT_BACKEND */
1749 return info; 1940 return info;
1750} 1941}
1751 1942
@@ -1831,6 +2022,27 @@ DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0,
1831 id = XINT (CHARSET_SYMBOL_ID (charset)); 2022 id = XINT (CHARSET_SYMBOL_ID (charset));
1832 else 2023 else
1833 id = -1; 2024 id = -1;
2025#ifdef USE_FONT_BACKEND
2026 if (enable_font_backend)
2027 {
2028 rfont_def = fontset_font (FONTSET_FROM_ID (face->fontset), c, face, id);
2029 if (VECTORP (rfont_def) && ! NILP (AREF (rfont_def, 4)))
2030 {
2031 Lisp_Object font_object = AREF (rfont_def, 4);
2032 struct font *font = XSAVE_VALUE (font_object)->pointer;
2033 unsigned code = font->driver->encode_char (font, c);
2034 Lisp_Object fontname = Ffont_xlfd_name (font_object);
2035
2036 if (code == FONT_INVALID_CODE)
2037 return Fcons (fontname, Qnil);
2038 if (code <= MOST_POSITIVE_FIXNUM)
2039 return Fcons (fontname, make_number (code));
2040 return Fcons (fontname, Fcons (make_number (code >> 16),
2041 make_number (code & 0xFFFF)));
2042 }
2043 return Qnil;
2044 }
2045#endif /* USE_FONT_BACKEND */
1834 rfont_def = fontset_font (FONTSET_FROM_ID (face->fontset), c, face, id); 2046 rfont_def = fontset_font (FONTSET_FROM_ID (face->fontset), c, face, id);
1835 if (VECTORP (rfont_def) && STRINGP (AREF (rfont_def, 3))) 2047 if (VECTORP (rfont_def) && STRINGP (AREF (rfont_def, 3)))
1836 { 2048 {