comparison src/fontset.c @ 91169:8eb408860621

Include "font.h" unconditionally. (generate_ascii_font_name): Use font_parse_xlfd and font_unparse_xlfd. (Fset_fontset_font): Accept a font-spec object.
author Kenichi Handa <handa@m17n.org>
date Mon, 03 Dec 2007 13:51:16 +0000
parents d54684fee154
children 3ce31df2ea58
comparison
equal deleted inserted replaced
91168:4323f9b78ae1 91169:8eb408860621
55 #ifdef MAC_OS 55 #ifdef MAC_OS
56 #include "macterm.h" 56 #include "macterm.h"
57 #endif 57 #endif
58 #include "termhooks.h" 58 #include "termhooks.h"
59 59
60 #ifdef USE_FONT_BACKEND
61 #include "font.h" 60 #include "font.h"
62 #endif /* USE_FONT_BACKEND */
63 61
64 #undef xassert 62 #undef xassert
65 #ifdef FONTSET_DEBUG 63 #ifdef FONTSET_DEBUG
66 #define xassert(X) do {if (!(X)) abort ();} while (0) 64 #define xassert(X) do {if (!(X)) abort ();} while (0)
67 #undef INLINE 65 #undef INLINE
94 and parent are always nil. 92 and parent are always nil.
95 93
96 An element of a base fontset is a vector of FONT-DEFs which itself 94 An element of a base fontset is a vector of FONT-DEFs which itself
97 is a vector [ FONT-SPEC ENCODING REPERTORY ]. 95 is a vector [ FONT-SPEC ENCODING REPERTORY ].
98 96
99 FONT-SPEC is: 97 FONT-SPEC is a font-spec created by `font-spec' or
100 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ] 98 ( FAMILY . REGISTRY )
101 or 99 or
102 FONT-NAME 100 FONT-NAME
103 where FAMILY, WEIGHT, SLANT, SWIDTH, ADSTYLE, REGISTRY, and 101 where FAMILY, REGISTRY, and FONT-NAME are strings.
104 FONT-NAME are strings.
105
106 Note: Currently WEIGHT through ADSTYLE are ignored.
107 102
108 ENCODING is a charset ID that can convert characters to glyph codes 103 ENCODING is a charset ID that can convert characters to glyph codes
109 of the corresponding font. 104 of the corresponding font.
110 105
111 REPERTORY is a charset ID, a char-table, or nil. If REPERTORY is a 106 REPERTORY is a charset ID, a char-table, or nil. If REPERTORY is a
1503 } 1498 }
1504 } 1499 }
1505 1500
1506 1501
1507 /* Return an ASCII font name generated from fontset name NAME and 1502 /* Return an ASCII font name generated from fontset name NAME and
1508 ASCII font specification ASCII_SPEC. NAME is a string conforming 1503 font-spec ASCII_SPEC. NAME is a string conforming to XLFD. */
1509 to XLFD. ASCII_SPEC is a vector:
1510 [FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY]. */
1511 1504
1512 static INLINE Lisp_Object 1505 static INLINE Lisp_Object
1513 generate_ascii_font_name (name, ascii_spec) 1506 generate_ascii_font_name (name, ascii_spec)
1514 Lisp_Object name, ascii_spec; 1507 Lisp_Object name, ascii_spec;
1515 { 1508 {
1509 Lisp_Object font_spec = Ffont_spec (0, NULL);
1516 Lisp_Object vec; 1510 Lisp_Object vec;
1517 int i; 1511 int i;
1518 1512 char xlfd[256];
1519 vec = split_font_name_into_vector (name); 1513
1520 for (i = FONT_SPEC_FAMILY_INDEX; i <= FONT_SPEC_ADSTYLE_INDEX; i++) 1514 if (font_parse_xlfd (SDATA (name), font_spec) < 0)
1515 error ("Not an XLFD font name: %s", SDATA (name));
1516 for (i = FONT_FOUNDRY_INDEX; i <= FONT_WIDTH_INDEX; i++)
1521 if (! NILP (AREF (ascii_spec, i))) 1517 if (! NILP (AREF (ascii_spec, i)))
1522 ASET (vec, 1 + i, AREF (ascii_spec, i)); 1518 ASET (font_spec, i, AREF (ascii_spec, i));
1523 if (! NILP (AREF (ascii_spec, FONT_SPEC_REGISTRY_INDEX))) 1519 i = font_unparse_xlfd (font_spec, 0, xlfd, 256);
1524 ASET (vec, 12, AREF (ascii_spec, FONT_SPEC_REGISTRY_INDEX)); 1520 if (i < 0)
1525 return build_font_name_from_vector (vec); 1521 error ("Not an XLFD font name: %s", SDATA (name));
1522 return make_unibyte_string (xlfd, i);
1526 } 1523 }
1527 1524
1528 /* Variables referred in set_fontset_font. They are set before 1525 /* Variables referred in set_fontset_font. They are set before
1529 map_charset_chars is called in Fset_fontset_font. */ 1526 map_charset_chars is called in Fset_fontset_font. */
1530 static Lisp_Object font_def_arg, add_arg; 1527 static Lisp_Object font_def_arg, add_arg;
1615 if (!NILP (frame)) 1612 if (!NILP (frame))
1616 CHECK_LIVE_FRAME (frame); 1613 CHECK_LIVE_FRAME (frame);
1617 1614
1618 if (VECTORP (font_spec)) 1615 if (VECTORP (font_spec))
1619 { 1616 {
1620 #ifdef USE_FONT_BACKEND 1617 if (! FONT_SPEC_P (font_spec))
1621 if (enable_font_backend && FONT_SPEC_P (font_spec)) 1618 Fsignal (Qfont, list2 (build_string ("invalid font-spec"), font_spec));
1622 { 1619 family = Ffont_get (font_spec, QCfamily);
1623 family = Ffont_get (font_spec, QCfamily); 1620 if (! NILP (family) && SYMBOLP (family))
1624 if (! NILP (family)) 1621 family = SYMBOL_NAME (family);
1625 family = SYMBOL_NAME (family); 1622 registry = Ffont_get (font_spec, QCregistry);
1626 registry = Ffont_get (font_spec, QCregistry); 1623 if (! NILP (registry) && SYMBOLP (registry))
1627 if (! NILP (registry)) 1624 registry = SYMBOL_NAME (registry);
1628 registry = SYMBOL_NAME (registry);
1629 }
1630 else
1631 #endif
1632 {
1633 /* FONT_SPEC should have this form:
1634 [ FAMILY WEIGHT SLANT WIDTH ADSTYLE REGISTRY ]
1635 This is a feature not yet documented because WEIGHT thru
1636 ADSTYLE are ignored for the moment. */
1637 int j;
1638
1639 if (ASIZE (font_spec) != FONT_SPEC_MAX_INDEX)
1640 args_out_of_range (make_number (FONT_SPEC_MAX_INDEX),
1641 make_number (ASIZE (font_spec)));
1642
1643 font_spec = Fcopy_sequence (font_spec);
1644 for (j = 0; j < FONT_SPEC_MAX_INDEX - 1; j++)
1645 if (! NILP (AREF (font_spec, j)))
1646 {
1647 CHECK_STRING (AREF (font_spec, j));
1648 ASET (font_spec, j, Fdowncase (AREF (font_spec, j)));
1649 }
1650 family = AREF (font_spec, FONT_SPEC_FAMILY_INDEX);
1651 /* REGISTRY should not be omitted. */
1652 CHECK_STRING (AREF (font_spec, FONT_SPEC_REGISTRY_INDEX));
1653 registry = AREF (font_spec, FONT_SPEC_REGISTRY_INDEX);
1654 }
1655 } 1625 }
1656 else if (CONSP (font_spec)) 1626 else if (CONSP (font_spec))
1657 { 1627 {
1628 Lisp_Object args[4];
1629 int i= 0;
1630
1658 family = XCAR (font_spec); 1631 family = XCAR (font_spec);
1659 registry = XCDR (font_spec); 1632 registry = XCDR (font_spec);
1660 1633
1661 if (! NILP (family)) 1634 if (! NILP (family))
1662 { 1635 {
1663 CHECK_STRING (family); 1636 CHECK_STRING (family);
1664 family = Fdowncase (family); 1637 args[i++] = QCfamily;
1638 args[i++] = family;
1665 } 1639 }
1666 CHECK_STRING (registry); 1640 CHECK_STRING (registry);
1667 registry = Fdowncase (registry); 1641 args[i++] = QCregistry;
1668 font_spec = Fmake_vector (make_number (FONT_SPEC_MAX_INDEX), Qnil); 1642 args[i++] = registry;
1669 ASET (font_spec, FONT_SPEC_FAMILY_INDEX, family); 1643 font_spec = Ffont_spec (i, args);
1670 ASET (font_spec, FONT_SPEC_REGISTRY_INDEX, registry);
1671 } 1644 }
1672 else 1645 else
1673 { 1646 {
1674 CHECK_STRING (font_spec); 1647 CHECK_STRING (font_spec);
1675 font_spec = Fdowncase (font_spec); 1648 font_spec = Fdowncase (font_spec);