annotate src/font.c @ 90450:5c96354daf9e

(ftfont_pattern_entity): Fix typo. (ftfont_list): Enforce FC_LANG in PATTERN to cancel the effect of locale.
author Kenichi Handa <handa@m17n.org>
date Wed, 14 Jun 2006 00:38:48 +0000
parents 15dda5f83c27
children 6ffc9b378367
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1 /* font.c -- "Font" primitives.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2 Copyright (C) 2006 Free Software Foundation, Inc.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
3 Copyright (C) 2006
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
4 National Institute of Advanced Industrial Science and Technology (AIST)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
5 Registration Number H13PRO009
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
6
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
7 This file is part of GNU Emacs.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
8
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
9 GNU Emacs is free software; you can redistribute it and/or modify
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
11 the Free Software Foundation; either version 2, or (at your option)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
12 any later version.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
13
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
14 GNU Emacs is distributed in the hope that it will be useful,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
17 GNU General Public License for more details.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
18
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
20 along with GNU Emacs; see the file COPYING. If not, write to
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
22 Boston, MA 02110-1301, USA. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
23
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
24 #include <config.h>
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
25 #include <stdio.h>
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
26 #include <stdlib.h>
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
27 #include <ctype.h>
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
28
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
29 #include "lisp.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
30 #include "buffer.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
31 #include "frame.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
32 #include "dispextern.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
33 #include "charset.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
34 #include "character.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
35 #include "composite.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
36 #include "fontset.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
37 #include "font.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
38
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
39 #define FONT_DEBUG
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
40
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
41 #ifdef FONT_DEBUG
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
42 #undef xassert
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
43 #define xassert(X) do {if (!(X)) abort ();} while (0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
44 #else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
45 #define xassert(X) (void) 0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
46 #endif
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
47
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
48 int enable_font_backend;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
49
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
50 Lisp_Object Qfontp;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
51
90439
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
52 /* Important character set symbols. */
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
53 Lisp_Object Qiso8859_1, Qiso10646_1, Qunicode_bmp;
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
54
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
55 /* Like CHECK_FONT_SPEC but also validate properties of the font-spec,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
56 and set X to the validated result. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
57
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
58 #define CHECK_VALIDATE_FONT_SPEC(x) \
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
59 do { \
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
60 if (! FONT_SPEC_P (x)) x = wrong_type_argument (Qfont, x); \
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
61 x = font_prop_validate (x); \
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
62 } while (0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
63
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
64 /* Number of pt per inch (from the TeXbook). */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
65 #define PT_PER_INCH 72.27
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
66
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
67 /* Return a pixel size corresponding to POINT size (1/10 pt unit) on
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
68 resolution RESY. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
69 #define POINT_TO_PIXEL(POINT, RESY) ((POINT) * (RESY) / PT_PER_INCH / 10 + 0.5)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
70
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
71 #define PIXEL_TO_POINT(PIXEL, RESY) ((PIXEL) * PT_PER_INCH * 10 / (RESY) + 0.5)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
72
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
73 /* Special string of zero length. It is used to specify a NULL name
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
74 in a font properties (e.g. adstyle). We don't use the symbol of
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
75 NULL name because it's confusing (Lisp printer prints nothing for
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
76 it). */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
77 Lisp_Object null_string;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
78
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
79 /* Special vector of zero length. This is repeatedly used by (struct
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
80 font_driver *)->list when a specified font is not found. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
81 Lisp_Object null_vector;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
82
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
83 /* Vector of 3 elements. Each element is an alist for one of font
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
84 style properties (weight, slant, width). The alist contains a
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
85 mapping between symbolic property values (e.g. `medium' for weight)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
86 and numeric property values (e.g. 100). So, it looks like this:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
87 [((thin . 0) ... (heavy . 210))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
88 ((ro . 0) ... (ot . 210))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
89 ((ultracondensed . 50) ... (wide . 200))] */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
90 static Lisp_Object font_style_table;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
91
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
92 /* Alist of font family vs the corresponding aliases.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
93 Each element has this form:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
94 (FAMILY ALIAS1 ALIAS2 ...) */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
95
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
96 static Lisp_Object font_family_alist;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
97
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
98 /* Symbols representing keys of normal font properties. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
99 extern Lisp_Object QCtype, QCfamily, QCweight, QCslant, QCwidth, QCsize, QCname;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
100 Lisp_Object QCfoundry, QCadstyle, QCregistry, QCextra;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
101 /* Symbols representing keys of font extra info. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
102 Lisp_Object QCotf, QClanguage, QCscript;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
103
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
104 /* List of all font drivers. All font-backends (XXXfont.c) call
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
105 add_font_driver in syms_of_XXXfont to register the font-driver
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
106 here. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
107 static struct font_driver_list *font_driver_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
108
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
109 static Lisp_Object prop_name_to_numeric P_ ((enum font_property_index,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
110 Lisp_Object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
111 static Lisp_Object prop_numeric_to_name P_ ((enum font_property_index, int));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
112 static Lisp_Object font_open_entity P_ ((FRAME_PTR, Lisp_Object, int));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
113
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
114 /* Number of registered font drivers. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
115 static int num_font_drivers;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
116
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
117 /* Return a numeric value corresponding to PROP's NAME (symbol). If
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
118 NAME is not registered in font_style_table, return Qnil. PROP must
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
119 be one of FONT_{WEIGHT|SLANT|SWIDTH}_INDEX. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
120
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
121 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
122 prop_name_to_numeric (prop, name)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
123 enum font_property_index prop;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
124 Lisp_Object name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
125 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
126 int table_index = prop - FONT_WEIGHT_INDEX;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
127 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
128
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
129 val = assq_no_quit (name, AREF (font_style_table, table_index));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
130 return (NILP (val) ? Qnil : XCDR (val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
131 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
132
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
133
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
134 /* Return a name (symbol) corresponding to PROP's NUMERIC value. If
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
135 no name is registered for NUMERIC in font_style_table, return a
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
136 symbol of integer name (e.g. `123'). PROP must be one of
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
137 FONT_{WEIGHT|SLANT|SWIDTH}_INDEX. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
138
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
139 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
140 prop_numeric_to_name (prop, numeric)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
141 enum font_property_index prop;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
142 int numeric;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
143 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
144 int table_index = prop - FONT_WEIGHT_INDEX;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
145 Lisp_Object table = AREF (font_style_table, table_index);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
146 char buf[10];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
147
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
148 while (! NILP (table))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
149 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
150 if (XINT (XCDR (XCAR (table))) >= numeric)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
151 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
152 if (XINT (XCDR (XCAR (table))) == numeric)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
153 return XCAR (XCAR (table));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
154 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
155 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
156 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
157 table = XCDR (table);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
158 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
159 sprintf (buf, "%d", numeric);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
160 return intern (buf);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
161 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
162
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
163
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
164 /* Return a symbol whose name is STR (length LEN). If STR contains
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
165 uppercase letters, downcase them in advance. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
166
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
167 Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
168 intern_downcase (str, len)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
169 char *str;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
170 int len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
171 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
172 char *buf;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
173 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
174
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
175 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
176 if (isupper (str[i]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
177 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
178 if (i == len)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
179 return Fintern (make_unibyte_string (str, len), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
180 buf = alloca (len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
181 if (! buf)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
182 return Fintern (null_string, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
183 bcopy (str, buf, len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
184 for (; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
185 if (isascii (buf[i]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
186 buf[i] = tolower (buf[i]);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
187 return Fintern (make_unibyte_string (buf, len), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
188 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
189
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
190 extern Lisp_Object Vface_alternative_font_family_alist;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
191
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
192 static void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
193 build_font_family_alist ()
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
194 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
195 Lisp_Object alist = Vface_alternative_font_family_alist;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
196
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
197 for (; CONSP (alist); alist = XCDR (alist))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
198 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
199 Lisp_Object tail, elt;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
200
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
201 for (tail = XCAR (alist), elt = Qnil ; CONSP (tail); tail = XCDR (tail))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
202 elt = nconc2 (elt, Fcons (Fintern (XCAR (tail), Qnil), Qnil));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
203 font_family_alist = Fcons (elt, font_family_alist);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
204 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
205 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
206
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
207
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
208 /* Font property validater. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
209
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
210 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
211 font_prop_validate_type (prop, val)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
212 enum font_property_index prop;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
213 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
214 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
215 return (SYMBOLP (val) ? val : Qerror);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
216 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
217
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
218 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
219 font_prop_validate_symbol (prop, val)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
220 enum font_property_index prop;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
221 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
222 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
223 if (STRINGP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
224 val = (SCHARS (val) == 0 ? null_string
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
225 : intern_downcase ((char *) SDATA (val), SBYTES (val)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
226 else if (SYMBOLP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
227 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
228 if (SCHARS (SYMBOL_NAME (val)) == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
229 val = null_string;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
230 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
231 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
232 val = Qerror;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
233 return val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
234 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
235
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
236 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
237 font_prop_validate_style (prop, val)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
238 enum font_property_index prop;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
239 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
240 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
241 if (! INTEGERP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
242 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
243 if (STRINGP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
244 val = intern_downcase ((char *) SDATA (val), SBYTES (val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
245 if (! SYMBOLP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
246 val = Qerror;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
247 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
248 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
249 val = prop_name_to_numeric (prop, val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
250 if (NILP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
251 val = Qerror;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
252 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
253 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
254 return val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
255 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
256
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
257 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
258 font_prop_validate_size (prop, val)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
259 enum font_property_index prop;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
260 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
261 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
262 return (NATNUMP (val) || (FLOATP (val) && XFLOAT_DATA (val) >= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
263 ? val : Qerror);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
264 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
265
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
266 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
267 font_prop_validate_extra (prop, val)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
268 enum font_property_index prop;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
269 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
270 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
271 Lisp_Object tail;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
272
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
273 for (tail = val; CONSP (tail); tail = XCDR (tail))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
274 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
275 Lisp_Object key = Fcar (XCAR (tail)), this_val = Fcdr (XCAR (tail));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
276
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
277 if (NILP (this_val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
278 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
279 if (EQ (key, QClanguage))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
280 if (! SYMBOLP (this_val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
281 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
282 for (; CONSP (this_val); this_val = XCDR (this_val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
283 if (! SYMBOLP (XCAR (this_val)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
284 return Qerror;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
285 if (! NILP (this_val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
286 return Qerror;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
287 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
288 if (EQ (key, QCotf))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
289 if (! STRINGP (this_val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
290 return Qerror;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
291 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
292 return (NILP (tail) ? val : Qerror);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
293 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
294
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
295
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
296 struct
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
297 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
298 Lisp_Object *key;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
299 Lisp_Object (*validater) P_ ((enum font_property_index prop,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
300 Lisp_Object val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
301 } font_property_table[FONT_SPEC_MAX] =
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
302 { { &QCtype, font_prop_validate_type },
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
303 { &QCfoundry, font_prop_validate_symbol },
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
304 { &QCfamily, font_prop_validate_symbol },
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
305 { &QCadstyle, font_prop_validate_symbol },
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
306 { &QCregistry, font_prop_validate_symbol },
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
307 { &QCweight, font_prop_validate_style },
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
308 { &QCslant, font_prop_validate_style },
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
309 { &QCwidth, font_prop_validate_style },
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
310 { &QCsize, font_prop_validate_size },
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
311 { &QCextra, font_prop_validate_extra }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
312 };
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
313
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
314 static enum font_property_index
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
315 check_font_prop_name (key)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
316 Lisp_Object key;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
317 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
318 enum font_property_index i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
319
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
320 for (i = FONT_TYPE_INDEX; i < FONT_SPEC_MAX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
321 if (EQ (key, *font_property_table[i].key))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
322 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
323 return i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
324 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
325
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
326 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
327 font_prop_validate (spec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
328 Lisp_Object spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
329 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
330 enum font_property_index i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
331 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
332
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
333 for (i = FONT_TYPE_INDEX; i <= FONT_EXTRA_INDEX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
334 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
335 if (! NILP (AREF (spec, i)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
336 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
337 val = (font_property_table[i].validater) (i, AREF (spec, i));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
338 if (EQ (val, Qerror))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
339 Fsignal (Qerror, list3 (build_string ("invalid font property"),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
340 *font_property_table[i].key,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
341 AREF (spec, i)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
342 ASET (spec, i, val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
343 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
344 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
345 return spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
346 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
347
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
348
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
349 /* Font name parser and unparser */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
350
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
351 /* An enumerator for each field of an XLFD font name. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
352
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
353 enum xlfd_field_index
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
354 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
355 XLFD_FOUNDRY_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
356 XLFD_FAMILY_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
357 XLFD_WEIGHT_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
358 XLFD_SLANT_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
359 XLFD_SWIDTH_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
360 XLFD_ADSTYLE_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
361 XLFD_PIXEL_SIZE_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
362 XLFD_POINT_SIZE_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
363 XLFD_RESX_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
364 XLFD_RESY_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
365 XLFD_SPACING_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
366 XLFD_AVGWIDTH_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
367 XLFD_REGISTRY_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
368 XLFD_ENCODING_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
369 XLFD_LAST_INDEX
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
370 };
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
371
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
372 /* Return a symbol interned by string at STR and bytes LEN.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
373 If LEN == 0, return a null string.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
374 If the string is "*", return Qnil.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
375 It is assured that LEN < 256. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
376
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
377 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
378 intern_font_field (f, xlfd)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
379 char *f[XLFD_LAST_INDEX + 1];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
380 int xlfd;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
381 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
382 char *str = f[xlfd] + 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
383 int len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
384
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
385 if (xlfd != XLFD_RESY_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
386 len = f[xlfd + 1] - f[xlfd] - 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
387 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
388 len = f[XLFD_REGISTRY_INDEX] - f[xlfd] - 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
389
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
390 if (len == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
391 return null_string;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
392 if (*str == '*' && len == 1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
393 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
394 return intern_downcase (str, len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
395 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
396
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
397 /* Parse P pointing the pixel/point size field of the form
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
398 `[A B C D]' which specifies a transformation matrix:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
399
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
400 A B 0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
401 C D 0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
402 0 0 1
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
403
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
404 by which all glyphs of the font are transformed. The spec says
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
405 that scalar value N for the pixel/point size is equivalent to:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
406 A = N * resx/resy, B = C = 0, D = N.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
407
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
408 Return the scalar value N if the form is valid. Otherwise return
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
409 -1. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
410
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
411 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
412 parse_matrix (p)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
413 char *p;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
414 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
415 double matrix[4];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
416 char *end;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
417 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
418
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
419 for (i = 0, p++; i < 4 && *p && *p != ']'; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
420 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
421 if (*p == '~')
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
422 matrix[i] = - strtod (p + 1, &end);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
423 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
424 matrix[i] = strtod (p, &end);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
425 p = end;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
426 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
427 return (i == 4 ? (int) matrix[3] : -1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
428 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
429
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
430 /* Parse NAME (null terminated) as XLFD format, and store information
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
431 in FONT (font-spec or font-entity). If NAME is successfully
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
432 parsed, return 2 (non-scalable font), 1 (scalable vector font), or
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
433 0 (auto-scaled font). Otherwise return -1.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
434
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
435 If FONT is a font-entity, store RESY-SPACING-AVWIDTH information as
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
436 a symbol in FONT_EXTRA_INDEX.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
437
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
438 If MERGE is nonzero, set a property of FONT only when it's nil. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
439
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
440 int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
441 font_parse_xlfd (name, font, merge)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
442 char *name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
443 Lisp_Object font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
444 int merge;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
445 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
446 int len = strlen (name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
447 int i, j;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
448 int pixel_size, resy, avwidth;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
449 double point_size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
450 char *f[XLFD_LAST_INDEX + 1];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
451 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
452 int first_wildcard_field = -1, last_wildcard_field = XLFD_LAST_INDEX;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
453
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
454 if (len > 255)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
455 /* Maximum XLFD name length is 255. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
456 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
457 for (i = 0; *name; name++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
458 if (*name == '-'
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
459 && i < XLFD_LAST_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
460 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
461 f[i] = name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
462 if (name[1] == '*' && (! name[2] || name[2] == '-'))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
463 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
464 if (first_wildcard_field < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
465 first_wildcard_field = i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
466 last_wildcard_field = i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
467 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
468 i++;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
469 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
470
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
471 f[XLFD_LAST_INDEX] = name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
472 if (i < XLFD_LAST_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
473 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
474 /* Not a fully specified XLFD. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
475 if (first_wildcard_field < 0 )
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
476 /* No wild card. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
477 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
478 i--;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
479 if (last_wildcard_field < i)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
480 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
481 /* Shift fields after the last wildcard field. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
482 for (j = XLFD_LAST_INDEX - 1; j > last_wildcard_field; j--, i--)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
483 f[j] = f[i];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
484 /* Make all fields between the first and last wildcard fieled
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
485 also wildcard fields. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
486 for (j--; j > first_wildcard_field; j--)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
487 f[j] = "-*";
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
488 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
489 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
490 f[XLFD_ENCODING_INDEX] = f[XLFD_LAST_INDEX];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
491
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
492 if (! merge || NILP (AREF (font, FONT_FOUNDRY_INDEX)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
493 ASET (font, FONT_FOUNDRY_INDEX, intern_font_field (f, XLFD_FOUNDRY_INDEX));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
494 if (! merge || NILP (AREF (font, FONT_FAMILY_INDEX)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
495 ASET (font, FONT_FAMILY_INDEX, intern_font_field (f, XLFD_FAMILY_INDEX));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
496 if (! merge || NILP (AREF (font, FONT_ADSTYLE_INDEX)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
497 ASET (font, FONT_ADSTYLE_INDEX, intern_font_field (f, XLFD_ADSTYLE_INDEX));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
498 if (! merge || NILP (AREF (font, FONT_REGISTRY_INDEX)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
499 ASET (font, FONT_REGISTRY_INDEX, intern_font_field (f, XLFD_REGISTRY_INDEX));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
500
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
501 for (i = FONT_WEIGHT_INDEX, j = XLFD_WEIGHT_INDEX;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
502 j <= XLFD_SWIDTH_INDEX; i++, j++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
503 if (! merge || NILP (AREF (font, i)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
504 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
505 if (isdigit(f[j][1]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
506 val = make_number (atoi (f[j] + 1));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
507 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
508 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
509 Lisp_Object sym = intern_font_field (f, j);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
510
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
511 val = prop_name_to_numeric (i, sym);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
512 if (NILP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
513 val = sym;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
514 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
515 ASET (font, i, val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
516 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
517
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
518 if (f[XLFD_PIXEL_SIZE_INDEX][1] == '*')
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
519 pixel_size = -1; /* indicates "unspecified" */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
520 else if (f[XLFD_PIXEL_SIZE_INDEX][1] == '[')
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
521 pixel_size = parse_matrix (f[XLFD_PIXEL_SIZE_INDEX] + 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
522 else if (isdigit (f[XLFD_PIXEL_SIZE_INDEX][1]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
523 pixel_size = strtod (f[XLFD_PIXEL_SIZE_INDEX] + 1, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
524 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
525 pixel_size = -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
526
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
527 if (pixel_size < 0 && FONT_ENTITY_P (font))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
528 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
529
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
530 if (f[XLFD_POINT_SIZE_INDEX][1] == '*')
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
531 point_size = -1; /* indicates "unspecified" */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
532 else if (f[XLFD_POINT_SIZE_INDEX][1] == '[')
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
533 point_size = parse_matrix (f[XLFD_POINT_SIZE_INDEX] + 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
534 else if (isdigit (f[XLFD_POINT_SIZE_INDEX][1]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
535 point_size = strtod (f[XLFD_POINT_SIZE_INDEX] + 1, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
536 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
537 point_size = -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
538
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
539 if (f[XLFD_RESY_INDEX][1] == '*')
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
540 resy = -1; /* indicates "unspecified" */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
541 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
542 resy = strtod (f[XLFD_RESY_INDEX] + 1, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
543
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
544 if (f[XLFD_AVGWIDTH_INDEX][1] == '*')
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
545 avwidth = -1; /* indicates "unspecified" */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
546 else if (f[XLFD_AVGWIDTH_INDEX][1] == '~')
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
547 avwidth = - strtod (f[XLFD_AVGWIDTH_INDEX] + 2, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
548 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
549 avwidth = strtod (f[XLFD_AVGWIDTH_INDEX] + 1, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
550
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
551 if (! merge || NILP (AREF (font, FONT_SIZE_INDEX)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
552 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
553 if (pixel_size >= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
554 ASET (font, FONT_SIZE_INDEX, make_number (pixel_size));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
555 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
556 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
557 if (point_size >= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
558 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
559 if (resy > 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
560 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
561 pixel_size = POINT_TO_PIXEL (point_size, resy);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
562 ASET (font, FONT_SIZE_INDEX, make_number (pixel_size));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
563 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
564 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
565 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
566 ASET (font, FONT_SIZE_INDEX, make_float (point_size / 10));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
567 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
568 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
569 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
570 ASET (font, FONT_SIZE_INDEX, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
571 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
572 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
573
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
574 if (FONT_ENTITY_P (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
575 && EQ (AREF (font, FONT_TYPE_INDEX), Qx))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
576 ASET (font, FONT_EXTRA_INDEX, intern_font_field (f, XLFD_RESY_INDEX));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
577
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
578 return (avwidth > 0 ? 2 : resy == 0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
579 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
580
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
581 /* Store XLFD name of FONT (font-spec or font-entity) in NAME (NBYTES
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
582 length), and return the name length. If FONT_SIZE_INDEX of FONT is
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
583 0, use PIXEL_SIZE instead. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
584
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
585 int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
586 font_unparse_xlfd (font, pixel_size, name, nbytes)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
587 Lisp_Object font;
90439
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
588 int pixel_size;
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
589 char *name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
590 int nbytes;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
591 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
592 char *f[XLFD_REGISTRY_INDEX + 1], *pixel_point;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
593 char work[256];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
594 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
595 int i, j, len = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
596
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
597 xassert (FONTP (font));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
598
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
599 for (i = FONT_FOUNDRY_INDEX, j = XLFD_FOUNDRY_INDEX; i <= FONT_REGISTRY_INDEX;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
600 i++, j++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
601 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
602 if (i == FONT_ADSTYLE_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
603 j = XLFD_ADSTYLE_INDEX;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
604 else if (i == FONT_REGISTRY_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
605 j = XLFD_REGISTRY_INDEX;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
606 val = AREF (font, i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
607 if (NILP (val))
90439
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
608 {
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
609 if (j == XLFD_REGISTRY_INDEX)
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
610 f[j] = "*-*", len += 4;
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
611 else
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
612 f[j] = "*", len += 2;
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
613 }
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
614 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
615 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
616 if (SYMBOLP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
617 val = SYMBOL_NAME (val);
90439
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
618 if (j == XLFD_REGISTRY_INDEX
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
619 && ! strchr ((char *) SDATA (val), '-'))
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
620 {
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
621 /* Change "jisx0208*" and "jisx0208" to "jisx0208*-*". */
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
622 if (SDATA (val)[SBYTES (val) - 1] == '*')
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
623 {
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
624 f[j] = alloca (SBYTES (val) + 3);
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
625 sprintf (f[j], "%s-*", SDATA (val));
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
626 len += SBYTES (val) + 3;
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
627 }
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
628 else
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
629 {
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
630 f[j] = alloca (SBYTES (val) + 4);
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
631 sprintf (f[j], "%s*-*", SDATA (val));
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
632 len += SBYTES (val) + 4;
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
633 }
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
634 }
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
635 else
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
636 f[j] = (char *) SDATA (val), len += SBYTES (val) + 1;
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
637 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
638 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
639
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
640 for (i = FONT_WEIGHT_INDEX, j = XLFD_WEIGHT_INDEX; i <= FONT_WIDTH_INDEX;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
641 i++, j++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
642 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
643 val = AREF (font, i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
644 if (NILP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
645 f[j] = "*", len += 2;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
646 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
647 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
648 if (INTEGERP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
649 val = prop_numeric_to_name (i, XINT (val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
650 if (SYMBOLP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
651 val = SYMBOL_NAME (val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
652 xassert (STRINGP (val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
653 f[j] = (char *) SDATA (val), len += SBYTES (val) + 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
654 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
655 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
656
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
657 val = AREF (font, FONT_SIZE_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
658 xassert (NUMBERP (val) || NILP (val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
659 if (INTEGERP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
660 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
661 i = XINT (val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
662 if (i > 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
663 len += sprintf (work, "%d", i) + 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
664 else /* i == 0 */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
665 len += sprintf (work, "%d-*", pixel_size) + 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
666 pixel_point = work;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
667 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
668 else if (FLOATP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
669 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
670 i = XFLOAT_DATA (val) * 10;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
671 len += sprintf (work, "*-%d", i) + 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
672 pixel_point = work;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
673 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
674 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
675 pixel_point = "*-*", len += 4;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
676
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
677 if (FONT_ENTITY_P (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
678 && EQ (AREF (font, FONT_TYPE_INDEX), Qx))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
679 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
680 /* Setup names for RESY-SPACING-AVWIDTH. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
681 val = AREF (font, FONT_EXTRA_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
682 if (SYMBOLP (val) && ! NILP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
683 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
684 val = SYMBOL_NAME (val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
685 f[XLFD_RESY_INDEX] = (char *) SDATA (val), len += SBYTES (val) + 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
686 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
687 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
688 f[XLFD_RESY_INDEX] = "*-*-*", len += 6;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
689 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
690 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
691 f[XLFD_RESY_INDEX] = "*-*-*", len += 6;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
692
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
693 len += 3; /* for "-*" of resx, and terminating '\0'. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
694 if (len >= nbytes)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
695 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
696 return sprintf (name, "-%s-%s-%s-%s-%s-%s-%s-*-%s-%s",
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
697 f[XLFD_FOUNDRY_INDEX], f[XLFD_FAMILY_INDEX],
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
698 f[XLFD_WEIGHT_INDEX], f[XLFD_SLANT_INDEX],
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
699 f[XLFD_SWIDTH_INDEX],
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
700 f[XLFD_ADSTYLE_INDEX], pixel_point,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
701 f[XLFD_RESY_INDEX], f[XLFD_REGISTRY_INDEX]);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
702 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
703
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
704 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
705 font_merge_old_spec (name, family, registry, spec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
706 Lisp_Object name, family, registry, spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
707 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
708 if (STRINGP (name))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
709 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
710 if (font_parse_xlfd ((char *) SDATA (name), spec, 1) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
711 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
712 Lisp_Object extra = Fcons (Fcons (QCname, name), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
713
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
714 ASET (spec, FONT_EXTRA_INDEX, extra);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
715 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
716 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
717 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
718 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
719 if (! NILP (family))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
720 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
721 int len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
722 char *p0, *p1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
723
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
724 xassert (STRINGP (family));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
725 len = SBYTES (family);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
726 p0 = (char *) SDATA (family);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
727 p1 = index (p0, '-');
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
728 if (p1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
729 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
730 if (NILP (AREF (spec, FONT_FOUNDRY_INDEX)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
731 ASET (spec, FONT_FOUNDRY_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
732 intern_downcase (p0, p1 - p0));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
733 if (NILP (AREF (spec, FONT_FAMILY_INDEX)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
734 ASET (spec, FONT_FAMILY_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
735 intern_downcase (p1 + 1, len - (p1 + 1 - p0)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
736 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
737 else if (NILP (AREF (spec, FONT_FAMILY_INDEX)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
738 ASET (spec, FONT_FAMILY_INDEX, intern_downcase (p0, len));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
739 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
740 if (! NILP (registry)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
741 && NILP (AREF (spec, FONT_REGISTRY_INDEX)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
742 ASET (spec, FONT_REGISTRY_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
743 intern_downcase ((char *) SDATA (registry), SBYTES (registry)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
744 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
745 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
746
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
747
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
748 /* OTF handler */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
749
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
750 #ifdef HAVE_LIBOTF
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
751 #include <otf.h>
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
752
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
753 struct otf_list
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
754 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
755 Lisp_Object entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
756 OTF *otf;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
757 struct otf_list *next;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
758 };
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
759
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
760 static struct otf_list *otf_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
761
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
762 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
763 otf_tag_symbol (tag)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
764 OTF_Tag tag;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
765 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
766 char name[5];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
767
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
768 OTF_tag_name (tag, name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
769 return Fintern (make_unibyte_string (name, 4), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
770 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
771
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
772 static OTF *
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
773 otf_open (entity, file)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
774 Lisp_Object entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
775 char *file;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
776 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
777 struct otf_list *list = otf_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
778
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
779 while (list && ! EQ (list->entity, entity))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
780 list = list->next;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
781 if (! list)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
782 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
783 list = malloc (sizeof (struct otf_list));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
784 list->entity = entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
785 list->otf = file ? OTF_open (file) : NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
786 list->next = otf_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
787 otf_list = list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
788 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
789 return list->otf;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
790 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
791
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
792
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
793 /* Return a list describing which scripts/languages FONT supports by
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
794 which GSUB/GPOS features of OpenType tables. See the comment of
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
795 (sturct font_driver).otf_capability. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
796
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
797 Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
798 font_otf_capability (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
799 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
800 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
801 OTF *otf;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
802 Lisp_Object capability = Fcons (Qnil, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
803 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
804
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
805 otf = otf_open (font->entity, font->file_name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
806 if (! otf)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
807 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
808 for (i = 0; i < 2; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
809 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
810 OTF_GSUB_GPOS *gsub_gpos;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
811 Lisp_Object script_list = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
812 int j;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
813
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
814 if (OTF_get_features (otf, i == 0) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
815 continue;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
816 gsub_gpos = i == 0 ? otf->gsub : otf->gpos;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
817 for (j = gsub_gpos->ScriptList.ScriptCount - 1; j >= 0; j--)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
818 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
819 OTF_Script *script = gsub_gpos->ScriptList.Script + j;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
820 Lisp_Object langsys_list = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
821 Lisp_Object script_tag = otf_tag_symbol (script->ScriptTag);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
822 int k;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
823
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
824 for (k = script->LangSysCount; k >= 0; k--)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
825 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
826 OTF_LangSys *langsys;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
827 Lisp_Object feature_list = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
828 Lisp_Object langsys_tag;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
829 int l;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
830
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
831 if (j == script->LangSysCount)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
832 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
833 langsys = &script->DefaultLangSys;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
834 langsys_tag = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
835 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
836 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
837 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
838 langsys = script->LangSys + k;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
839 langsys_tag
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
840 = otf_tag_symbol (script->LangSysRecord[k].LangSysTag);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
841 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
842 for (l = langsys->FeatureCount -1; l >= 0; l--)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
843 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
844 OTF_Feature *feature
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
845 = gsub_gpos->FeatureList.Feature + langsys->FeatureIndex[l];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
846 Lisp_Object feature_tag
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
847 = otf_tag_symbol (feature->FeatureTag);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
848
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
849 feature_list = Fcons (feature_tag, feature_list);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
850 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
851 langsys_list = Fcons (Fcons (langsys_tag, feature_list),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
852 langsys_list);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
853 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
854 script_list = Fcons (Fcons (script_tag, langsys_list),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
855 script_list);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
856 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
857
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
858 if (i == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
859 XSETCAR (capability, script_list);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
860 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
861 XSETCDR (capability, script_list);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
862 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
863
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
864 return capability;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
865 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
866
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
867 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
868 parse_gsub_gpos_spec (spec, script, langsys, features)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
869 Lisp_Object spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
870 char **script, **langsys, **features;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
871 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
872 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
873 int len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
874 char *p;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
875 int asterisk;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
876
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
877 val = XCAR (spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
878 *script = (char *) SDATA (SYMBOL_NAME (val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
879 spec = XCDR (spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
880 val = XCAR (spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
881 *langsys = NILP (val) ? NULL : (char *) SDATA (SYMBOL_NAME (val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
882 spec = XCDR (spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
883 len = XINT (Flength (spec));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
884 *features = p = malloc (6 * len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
885 if (! p)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
886 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
887
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
888 for (asterisk = 0; CONSP (spec); spec = XCDR (spec))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
889 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
890 val = XCAR (spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
891 if (SREF (SYMBOL_NAME (val), 0) == '*')
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
892 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
893 asterisk = 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
894 p += sprintf (p, ",*");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
895 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
896 else if (! asterisk)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
897 p += sprintf (p, ",%s", SDATA (SYMBOL_NAME (val)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
898 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
899 p += sprintf (p, ",~%s", SDATA (SYMBOL_NAME (val)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
900 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
901 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
902 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
903
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
904 #define DEVICE_DELTA(table, size) \
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
905 (((size) >= (table).StartSize && (size) <= (table).EndSize) \
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
906 ? (table).DeltaValue[(size) >= (table).StartSize] \
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
907 : 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
908
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
909 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
910 adjust_anchor (struct font *font, OTF_Anchor *anchor,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
911 unsigned code, int size, int *x, int *y)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
912 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
913 if (anchor->AnchorFormat == 2)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
914 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
915 int x0, y0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
916
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
917 if (font->driver->anchor_point (font, code, anchor->f.f1.AnchorPoint,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
918 &x0, &y0) >= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
919 *x = x0, *y = y0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
920 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
921 else if (anchor->AnchorFormat == 3)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
922 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
923 if (anchor->f.f2.XDeviceTable.offset)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
924 *x += DEVICE_DELTA (anchor->f.f2.XDeviceTable, size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
925 if (anchor->f.f2.YDeviceTable.offset)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
926 *y += DEVICE_DELTA (anchor->f.f2.YDeviceTable, size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
927 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
928 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
929
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
930
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
931 /* Drive FONT's OTF GSUB features according to GSUB_SPEC. See the
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
932 comment of (sturct font_driver).otf_gsub. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
933
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
934 int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
935 font_otf_gsub (font, gsub_spec, gstring_in, from, to, gstring_out, idx)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
936 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
937 Lisp_Object gsub_spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
938 Lisp_Object gstring_in;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
939 int from, to;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
940 Lisp_Object gstring_out;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
941 int idx;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
942 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
943 int len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
944 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
945 OTF *otf;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
946 OTF_GlyphString otf_gstring;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
947 OTF_Glyph *g;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
948 char *script, *langsys, *features;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
949
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
950 otf = otf_open (font->entity, font->file_name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
951 if (! otf)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
952 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
953 if (OTF_get_table (otf, "head") < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
954 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
955 if (OTF_check_table (otf, "GSUB") < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
956 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
957 if (parse_gsub_gpos_spec (gsub_spec, &script, &langsys, &features) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
958 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
959 len = to - from;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
960 otf_gstring.size = otf_gstring.used = len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
961 otf_gstring.glyphs = (OTF_Glyph *) malloc (sizeof (OTF_Glyph) * len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
962 memset (otf_gstring.glyphs, 0, sizeof (OTF_Glyph) * len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
963 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
964 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
965 Lisp_Object g = LGSTRING_GLYPH (gstring_in, from + i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
966
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
967 otf_gstring.glyphs[i].c = XINT (LGLYPH_CHAR (g));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
968 otf_gstring.glyphs[i].glyph_id = XINT (LGLYPH_CODE (g));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
969 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
970
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
971 OTF_drive_gdef (otf, &otf_gstring);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
972 if (OTF_drive_gsub (otf, &otf_gstring, script, langsys, features) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
973 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
974 free (otf_gstring.glyphs);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
975 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
976 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
977 if (ASIZE (gstring_out) < idx + otf_gstring.used)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
978 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
979 free (otf_gstring.glyphs);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
980 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
981 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
982
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
983 for (i = 0, g = otf_gstring.glyphs; i < otf_gstring.used;)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
984 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
985 int i0 = g->f.index.from, i1 = g->f.index.to;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
986 Lisp_Object glyph = LGSTRING_GLYPH (gstring_in, from + i0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
987 Lisp_Object min_idx = AREF (glyph, 0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
988 Lisp_Object max_idx = AREF (glyph, 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
989
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
990 if (i0 < i1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
991 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
992 int min_idx_i = XINT (min_idx), max_idx_i = XINT (max_idx);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
993
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
994 for (i0++; i0 <= i1; i0++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
995 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
996 glyph = LGSTRING_GLYPH (gstring_in, from + i0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
997 if (min_idx_i > XINT (AREF (glyph, 0)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
998 min_idx_i = XINT (AREF (glyph, 0));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
999 if (max_idx_i < XINT (AREF (glyph, 1)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1000 max_idx_i = XINT (AREF (glyph, 1));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1001 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1002 min_idx = make_number (min_idx_i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1003 max_idx = make_number (max_idx_i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1004 i0 = g->f.index.from;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1005 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1006 for (; i < otf_gstring.used && g->f.index.from == i0; i++, g++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1007 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1008 glyph = LGSTRING_GLYPH (gstring_out, idx + i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1009 ASET (glyph, 0, min_idx);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1010 ASET (glyph, 1, max_idx);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1011 LGLYPH_SET_CHAR (glyph, make_number (g->c));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1012 LGLYPH_SET_CODE (glyph, make_number (g->glyph_id));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1013 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1014 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1015
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1016 free (otf_gstring.glyphs);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1017 return i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1018 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1019
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1020 /* Drive FONT's OTF GPOS features according to GPOS_SPEC. See the
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1021 comment of (sturct font_driver).otf_gpos. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1022
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1023 int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1024 font_otf_gpos (font, gpos_spec, gstring, from, to)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1025 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1026 Lisp_Object gpos_spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1027 Lisp_Object gstring;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1028 int from, to;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1029 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1030 int len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1031 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1032 OTF *otf;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1033 OTF_GlyphString otf_gstring;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1034 OTF_Glyph *g;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1035 char *script, *langsys, *features;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1036 Lisp_Object glyph;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1037 int u, size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1038 Lisp_Object base, mark;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1039
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1040 otf = otf_open (font->entity, font->file_name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1041 if (! otf)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1042 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1043 if (OTF_get_table (otf, "head") < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1044 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1045 if (OTF_check_table (otf, "GPOS") < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1046 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1047 if (parse_gsub_gpos_spec (gpos_spec, &script, &langsys, &features) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1048 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1049 len = to - from;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1050 otf_gstring.size = otf_gstring.used = len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1051 otf_gstring.glyphs = (OTF_Glyph *) malloc (sizeof (OTF_Glyph) * len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1052 memset (otf_gstring.glyphs, 0, sizeof (OTF_Glyph) * len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1053 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1054 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1055 glyph = LGSTRING_GLYPH (gstring, from + i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1056 otf_gstring.glyphs[i].glyph_id = XINT (LGLYPH_CODE (glyph));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1057 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1058
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1059 OTF_drive_gdef (otf, &otf_gstring);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1060
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1061 if (OTF_drive_gpos (otf, &otf_gstring, script, langsys, features) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1062 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1063 free (otf_gstring.glyphs);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1064 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1065 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1066
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1067 u = otf->head->unitsPerEm;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1068 size = font->pixel_size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1069 base = mark = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1070 for (i = 0, g = otf_gstring.glyphs; i < otf_gstring.used; i++, g++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1071 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1072 Lisp_Object prev;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1073 int xoff = 0, yoff = 0, width_adjust = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1074
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1075 if (! g->glyph_id)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1076 continue;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1077
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1078 glyph = LGSTRING_GLYPH (gstring, from + i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1079 switch (g->positioning_type)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1080 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1081 case 0:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1082 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1083 case 1: case 2:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1084 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1085 int format = g->f.f1.format;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1086
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1087 if (format & OTF_XPlacement)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1088 xoff = g->f.f1.value->XPlacement * size / u;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1089 if (format & OTF_XPlaDevice)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1090 xoff += DEVICE_DELTA (g->f.f1.value->XPlaDevice, size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1091 if (format & OTF_YPlacement)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1092 yoff = - (g->f.f1.value->YPlacement * size / u);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1093 if (format & OTF_YPlaDevice)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1094 yoff -= DEVICE_DELTA (g->f.f1.value->YPlaDevice, size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1095 if (format & OTF_XAdvance)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1096 width_adjust += g->f.f1.value->XAdvance * size / u;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1097 if (format & OTF_XAdvDevice)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1098 width_adjust += DEVICE_DELTA (g->f.f1.value->XAdvDevice, size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1099 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1100 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1101 case 3:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1102 /* Not yet supported. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1103 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1104 case 4: case 5:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1105 if (NILP (base))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1106 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1107 prev = base;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1108 goto label_adjust_anchor;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1109 default: /* i.e. case 6 */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1110 if (NILP (mark))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1111 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1112 prev = mark;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1113
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1114 label_adjust_anchor:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1115 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1116 int base_x, base_y, mark_x, mark_y, width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1117 unsigned code;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1118
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1119 base_x = g->f.f4.base_anchor->XCoordinate * size / u;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1120 base_y = g->f.f4.base_anchor->YCoordinate * size / u;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1121 mark_x = g->f.f4.mark_anchor->XCoordinate * size / u;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1122 mark_y = g->f.f4.mark_anchor->YCoordinate * size / u;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1123
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1124 code = XINT (LGLYPH_CODE (prev));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1125 if (g->f.f4.base_anchor->AnchorFormat != 1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1126 adjust_anchor (font, g->f.f4.base_anchor,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1127 code, size, &base_x, &base_y);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1128 if (g->f.f4.mark_anchor->AnchorFormat != 1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1129 adjust_anchor (font, g->f.f4.mark_anchor,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1130 code, size, &mark_x, &mark_y);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1131
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1132 if (NILP (LGLYPH_WIDTH (prev)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1133 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1134 width = font->driver->text_extents (font, &code, 1, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1135 LGLYPH_SET_WIDTH (prev, make_number (width));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1136 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1137 xoff = XINT (LGLYPH_XOFF (prev)) + (base_x - width) - mark_x;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1138 yoff = XINT (LGLYPH_YOFF (prev)) + mark_y - base_y;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1139 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1140 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1141 if (g->GlyphClass == OTF_GlyphClass0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1142 base = mark = glyph;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1143 else if (g->GlyphClass == OTF_GlyphClassMark)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1144 mark = glyph;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1145 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1146 base = glyph;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1147
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1148 LGLYPH_SET_XOFF (glyph, make_number (xoff));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1149 LGLYPH_SET_YOFF (glyph, make_number (yoff));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1150 LGLYPH_SET_WADJUST (glyph, make_number (width_adjust));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1151 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1152
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1153 free (otf_gstring.glyphs);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1154 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1155 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1156
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1157 #endif /* HAVE_LIBOTF */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1158
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1159
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1160 /* glyph-string handler */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1161
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1162 /* GSTRING is a vector of this form:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1163 [ [FONT-OBJECT LBEARING RBEARING WITH ASCENT DESCENT] GLYPH ... ]
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1164 and GLYPH is a vector of this form:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1165 [ FROM-IDX TO-IDX C CODE X-OFF Y-OFF WIDTH WADJUST ]
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1166 where
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1167 FROM-IDX and TO-IDX are used internally and should not be touched.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1168 C is a character of the glyph.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1169 CODE is a glyph-code of C in FONT-OBJECT.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1170 X-OFF and Y-OFF are offests to the base position for the glyph.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1171 WIDTH is a normal width of the glyph.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1172 WADJUST is an adjustment to the normal width of the glyph. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1173
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1174 struct font *
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1175 font_prepare_composition (cmp)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1176 struct composition *cmp;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1177 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1178 Lisp_Object gstring
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1179 = AREF (XHASH_TABLE (composition_hash_table)->key_and_value,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1180 cmp->hash_index * 2);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1181 struct font *font = XSAVE_VALUE (LGSTRING_FONT (gstring))->pointer;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1182 int len = LGSTRING_LENGTH (gstring);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1183 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1184
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1185 cmp->font = font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1186 cmp->lbearing = cmp->rbearing = cmp->pixel_width = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1187 cmp->ascent = font->ascent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1188 cmp->descent = font->descent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1189
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1190 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1191 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1192 Lisp_Object g = LGSTRING_GLYPH (gstring, i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1193 unsigned code = XINT (LGLYPH_CODE (g));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1194 struct font_metrics metrics;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1195
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1196 font->driver->text_extents (font, &code, 1, &metrics);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1197 LGLYPH_SET_WIDTH (g, make_number (metrics.width));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1198 metrics.lbearing += XINT (LGLYPH_XOFF (g));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1199 metrics.rbearing += XINT (LGLYPH_XOFF (g));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1200 metrics.ascent += XINT (LGLYPH_YOFF (g));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1201 metrics.descent += XINT (LGLYPH_YOFF (g));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1202
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1203 if (cmp->lbearing > cmp->pixel_width + metrics.lbearing)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1204 cmp->lbearing = cmp->pixel_width + metrics.lbearing;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1205 if (cmp->rbearing < cmp->pixel_width + metrics.rbearing)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1206 cmp->rbearing = cmp->pixel_width + metrics.rbearing;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1207 if (cmp->ascent < metrics.ascent)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1208 cmp->ascent = metrics.ascent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1209 if (cmp->descent < metrics.descent)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1210 cmp->descent = metrics.descent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1211 cmp->pixel_width += metrics.width + XINT (LGLYPH_WADJUST (g));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1212 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1213 LGSTRING_SET_LBEARING (gstring, make_number (cmp->lbearing));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1214 LGSTRING_SET_RBEARING (gstring, make_number (cmp->rbearing));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1215 LGSTRING_SET_WIDTH (gstring, make_number (cmp->pixel_width));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1216 LGSTRING_SET_ASCENT (gstring, make_number (cmp->ascent));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1217 LGSTRING_SET_DESCENT (gstring, make_number (cmp->descent));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1218
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1219 return font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1220 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1221
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1222 int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1223 font_gstring_produce (old, from, to, new, idx, code, n)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1224 Lisp_Object old;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1225 int from, to;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1226 Lisp_Object new;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1227 int idx;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1228 unsigned *code;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1229 int n;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1230 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1231 Lisp_Object min_idx, max_idx;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1232 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1233
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1234 if (idx + n > ASIZE (new))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1235 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1236 if (from == to)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1237 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1238 if (from == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1239 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1240 min_idx = make_number (0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1241 max_idx = make_number (1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1242 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1243 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1244 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1245 min_idx = AREF (AREF (old, from - 1), 0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1246 max_idx = AREF (AREF (old, from - 1), 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1247 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1248 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1249 else if (from + 1 == to)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1250 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1251 min_idx = AREF (AREF (old, from), 0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1252 max_idx = AREF (AREF (old, from), 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1253 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1254 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1255 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1256 int min_idx_i = XINT (AREF (AREF (old, from), 0));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1257 int max_idx_i = XINT (AREF (AREF (old, from), 1));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1258
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1259 for (i = from + 1; i < to; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1260 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1261 if (min_idx_i > XINT (AREF (AREF (old, i), 0)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1262 min_idx_i = XINT (AREF (AREF (old, i), 0));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1263 if (max_idx_i < XINT (AREF (AREF (old, i), 1)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1264 max_idx_i = XINT (AREF (AREF (old, i), 1));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1265 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1266 min_idx = make_number (min_idx_i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1267 max_idx = make_number (max_idx_i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1268 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1269
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1270 for (i = 0; i < n; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1271 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1272 ASET (AREF (new, idx + i), 0, min_idx);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1273 ASET (AREF (new, idx + i), 1, max_idx);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1274 ASET (AREF (new, idx + i), 2, make_number (code[i]));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1275 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1276
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1277 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1278 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1279
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1280 /* Font sorting */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1281
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1282 static unsigned font_score P_ ((Lisp_Object, Lisp_Object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1283 static int font_compare P_ ((const void *, const void *));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1284 static Lisp_Object font_sort_entites P_ ((Lisp_Object, Lisp_Object,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1285 Lisp_Object, Lisp_Object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1286
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1287 /* We sort fonts by scoring each of them against a specified
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1288 font-spec. The score value is 32 bit (`unsigned'), and the smaller
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1289 the value is, the closer the font is to the font-spec.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1290
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1291 Each 1-bit in the highest 4 bits of the score is used for atomic
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1292 properties FOUNDRY, FAMILY, ADSTYLE, and REGISTRY.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1293
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1294 Each 7-bit in the lowest 28 bits are used for numeric properties
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1295 WEIGHT, SLANT, WIDTH, and SIZE. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1296
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1297 /* How many bits to shift to store the difference value of each font
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1298 property in a score. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1299 static int sort_shift_bits[FONT_SIZE_INDEX + 1];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1300
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1301 /* Score font-entity ENTITY against font-spec SPEC. The return value
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1302 indicates how different ENTITY is compared with SPEC. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1303
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1304 static unsigned
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1305 font_score (entity, spec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1306 Lisp_Object entity, spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1307 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1308 unsigned score = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1309 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1310 /* Score atomic fields. Maximum difference is 1. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1311 for (i = FONT_FOUNDRY_INDEX; i <= FONT_REGISTRY_INDEX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1312 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1313 Lisp_Object val = AREF (spec, i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1314
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1315 if (! NILP (val)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1316 && ! EQ (val, AREF (entity, i)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1317 score |= 1 << sort_shift_bits[i];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1318 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1319
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1320 /* Score numeric fields. Maximum difference is 127. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1321 for (i = FONT_WEIGHT_INDEX; i <= FONT_SIZE_INDEX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1322 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1323 Lisp_Object spec_val = AREF (spec, i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1324 Lisp_Object entity_val = AREF (entity, i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1325
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1326 if (! NILP (spec_val) && ! EQ (spec_val, entity_val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1327 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1328 if (! INTEGERP (entity_val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1329 score |= 127 << sort_shift_bits[i];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1330 else if (i < FONT_SIZE_INDEX
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1331 || XINT (entity_val) != 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1332 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1333 int diff = XINT (entity_val) - XINT (spec_val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1334
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1335 if (diff < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1336 diff = - diff;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1337 score |= min (diff, 127) << sort_shift_bits[i];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1338 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1339 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1340 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1341
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1342 return score;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1343 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1344
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1345
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1346 /* The comparison function for qsort. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1347
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1348 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1349 font_compare (d1, d2)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1350 const void *d1, *d2;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1351 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1352 return (*(unsigned *) d1 < *(unsigned *) d2
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1353 ? -1 : *(unsigned *) d1 > *(unsigned *) d2);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1354 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1355
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1356
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1357 /* The structure for elements being sorted by qsort. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1358 struct font_sort_data
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1359 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1360 unsigned score;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1361 Lisp_Object entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1362 };
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1363
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1364
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1365 /* Sort font-entities in vector VEC by closeness to font-spec PREFER.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1366 If PREFER specifies a point-size, calculate the corresponding
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1367 pixel-size from the Y-resolution of FRAME before sorting. If SPEC
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1368 is not nil, it is a font-spec to get the font-entities in VEC. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1369
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1370 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1371 font_sort_entites (vec, prefer, frame, spec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1372 Lisp_Object vec, prefer, frame, spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1373 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1374 Lisp_Object size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1375 int len, i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1376 struct font_sort_data *data;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1377 int prefer_is_copy = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1378 USE_SAFE_ALLOCA;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1379
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1380 len = ASIZE (vec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1381 if (len <= 1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1382 return vec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1383
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1384 size = AREF (spec, FONT_SIZE_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1385 if (FLOATP (size))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1386 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1387 double point_size = XFLOAT_DATA (size) * 10;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1388 int pixel_size = POINT_TO_PIXEL (point_size, XFRAME (frame)->resy);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1389
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1390 prefer = Fcopy_sequence (prefer);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1391 ASET (prefer, FONT_SIZE_INDEX, make_number (pixel_size));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1392 prefer_is_copy = 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1393 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1394
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1395 if (! NILP (spec))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1396 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1397 /* As it is assured that all fonts in VEC match with SPEC, we
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1398 should ignore properties specified in SPEC. So, set the
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1399 corresponding properties in PREFER nil. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1400 for (i = FONT_WEIGHT_INDEX; i <= FONT_SIZE_INDEX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1401 if (! NILP (AREF (spec, i)) && ! NILP (AREF (prefer, i)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1402 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1403 if (i <= FONT_SIZE_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1404 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1405 if (! prefer_is_copy)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1406 prefer = Fcopy_sequence (prefer);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1407 for (; i <= FONT_SIZE_INDEX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1408 if (! NILP (AREF (spec, i)) && ! NILP (AREF (prefer, i)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1409 ASET (prefer, i, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1410 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1411 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1412
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1413 /* Scoring and sorting. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1414 SAFE_ALLOCA (data, struct font_sort_data *, (sizeof *data) * len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1415 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1416 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1417 data[i].entity = AREF (vec, i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1418 data[i].score = font_score (data[i].entity, prefer);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1419 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1420 qsort (data, len, sizeof *data, font_compare);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1421 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1422 ASET (vec, i, data[i].entity);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1423 SAFE_FREE ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1424
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1425 return vec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1426 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1427
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1428
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1429 /* API of Font Service Layer. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1430
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1431 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1432 font_update_sort_order (order)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1433 int *order;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1434 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1435 int i, shift_bits = 21;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1436
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1437 for (i = 0; i < 4; i++, shift_bits -= 7)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1438 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1439 int xlfd_idx = order[i];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1440
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1441 if (xlfd_idx == XLFD_WEIGHT_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1442 sort_shift_bits[FONT_WEIGHT_INDEX] = shift_bits;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1443 else if (xlfd_idx == XLFD_SLANT_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1444 sort_shift_bits[FONT_SLANT_INDEX] = shift_bits;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1445 else if (xlfd_idx == XLFD_SWIDTH_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1446 sort_shift_bits[FONT_WIDTH_INDEX] = shift_bits;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1447 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1448 sort_shift_bits[FONT_SIZE_INDEX] = shift_bits;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1449 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1450 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1451
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1452 Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1453 font_symbolic_weight (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1454 Lisp_Object font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1455 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1456 Lisp_Object weight = AREF (font, FONT_WEIGHT_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1457
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1458 if (INTEGERP (weight))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1459 weight = prop_numeric_to_name (FONT_WEIGHT_INDEX, XINT (weight));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1460 return weight;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1461 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1462
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1463 Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1464 font_symbolic_slant (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1465 Lisp_Object font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1466 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1467 Lisp_Object slant = AREF (font, FONT_SLANT_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1468
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1469 if (INTEGERP (slant))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1470 slant = prop_numeric_to_name (FONT_SLANT_INDEX, XINT (slant));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1471 return slant;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1472 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1473
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1474 Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1475 font_symbolic_width (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1476 Lisp_Object font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1477 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1478 Lisp_Object width = AREF (font, FONT_WIDTH_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1479
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1480 if (INTEGERP (width))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1481 width = prop_numeric_to_name (FONT_WIDTH_INDEX, XINT (width));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1482 return width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1483 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1484
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1485 Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1486 font_find_object (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1487 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1488 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1489 Lisp_Object tail, elt;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1490
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1491 for (tail = AREF (font->entity, FONT_OBJLIST_INDEX); CONSP (tail);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1492 tail = XCDR (tail))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1493 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1494 elt = XCAR (tail);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1495 if (font == XSAVE_VALUE (elt)->pointer
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1496 && XSAVE_VALUE (elt)->integer > 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1497 return elt;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1498 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1499 abort ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1500 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1501 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1502
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1503 static Lisp_Object scratch_font_spec, scratch_font_prefer;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1504
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1505 /* Return a vector of font-entities matching with SPEC on frame F. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1506
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1507 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1508 font_list_entities (frame, spec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1509 Lisp_Object frame, spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1510 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1511 FRAME_PTR f = XFRAME (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1512 struct font_driver_list *driver_list = f->font_driver_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1513 Lisp_Object ftype, family, alternate_familes;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1514 Lisp_Object *vec = alloca (sizeof (Lisp_Object) * num_font_drivers);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1515 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1516
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1517 if (! vec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1518 return null_vector;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1519
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1520 family = AREF (spec, FONT_FAMILY_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1521 if (NILP (family))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1522 alternate_familes = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1523 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1524 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1525 if (NILP (font_family_alist)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1526 && !NILP (Vface_alternative_font_family_alist))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1527 build_font_family_alist ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1528 alternate_familes = assq_no_quit (family, font_family_alist);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1529 if (! NILP (alternate_familes))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1530 alternate_familes = XCDR (alternate_familes);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1531 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1532 xassert (ASIZE (spec) == FONT_SPEC_MAX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1533 ftype = AREF (spec, FONT_TYPE_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1534
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1535 for (i = 0; driver_list; driver_list = driver_list->next)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1536 if (NILP (ftype) || EQ (driver_list->driver->type, ftype))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1537 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1538 Lisp_Object cache = driver_list->driver->get_cache (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1539 Lisp_Object tail = alternate_familes;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1540 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1541
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1542 xassert (CONSP (cache));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1543 ASET (spec, FONT_TYPE_INDEX, driver_list->driver->type);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1544 ASET (spec, FONT_FAMILY_INDEX, family);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1545
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1546 while (1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1547 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1548 val = assoc_no_quit (spec, XCDR (cache));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1549 if (CONSP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1550 val = XCDR (val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1551 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1552 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1553 val = driver_list->driver->list (frame, spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1554 if (VECTORP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1555 XSETCDR (cache, Fcons (Fcons (Fcopy_sequence (spec), val),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1556 XCDR (cache)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1557 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1558 if (VECTORP (val) && ASIZE (val) > 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1559 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1560 vec[i++] = val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1561 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1562 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1563 if (NILP (tail))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1564 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1565 ASET (spec, FONT_FAMILY_INDEX, XCAR (tail));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1566 tail = XCDR (tail);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1567 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1568 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1569 ASET (spec, FONT_TYPE_INDEX, ftype);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1570 ASET (spec, FONT_FAMILY_INDEX, family);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1571 return (i > 0 ? Fvconcat (i, vec) : null_vector);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1572 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1573
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1574 static int num_fonts;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1575
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1576 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1577 font_open_entity (f, entity, pixel_size)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1578 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1579 Lisp_Object entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1580 int pixel_size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1581 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1582 struct font_driver_list *driver_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1583 Lisp_Object objlist, size, val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1584 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1585
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1586 size = AREF (entity, FONT_SIZE_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1587 xassert (NATNUMP (size));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1588 if (XINT (size) != 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1589 pixel_size = XINT (size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1590
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1591 for (objlist = AREF (entity, FONT_OBJLIST_INDEX); CONSP (objlist);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1592 objlist = XCDR (objlist))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1593 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1594 font = XSAVE_VALUE (XCAR (objlist))->pointer;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1595 if (font->pixel_size == pixel_size)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1596 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1597 XSAVE_VALUE (XCAR (objlist))->integer++;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1598 return XCAR (objlist);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1599 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1600 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1601
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1602 xassert (FONT_ENTITY_P (entity));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1603 val = AREF (entity, FONT_TYPE_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1604 for (driver_list = f->font_driver_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1605 driver_list && ! EQ (driver_list->driver->type, val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1606 driver_list = driver_list->next);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1607 if (! driver_list)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1608 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1609
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1610 font = driver_list->driver->open (f, entity, pixel_size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1611 if (! font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1612 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1613 val = make_save_value (font, 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1614 ASET (entity, FONT_OBJLIST_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1615 Fcons (val, AREF (entity, FONT_OBJLIST_INDEX)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1616 num_fonts++;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1617 return val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1618 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1619
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1620 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1621 font_close_object (f, font_object)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1622 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1623 Lisp_Object font_object;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1624 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1625 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1626 Lisp_Object objlist = AREF (font->entity, FONT_OBJLIST_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1627 Lisp_Object tail, prev = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1628
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1629 for (prev = Qnil, tail = objlist; CONSP (tail);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1630 prev = tail, tail = XCDR (tail))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1631 if (EQ (font_object, XCAR (tail)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1632 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1633 struct Lisp_Save_Value *p = XSAVE_VALUE (font_object);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1634
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1635 xassert (p->integer > 0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1636 p->integer--;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1637 if (p->integer == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1638 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1639 if (font->driver->close)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1640 font->driver->close (f, p->pointer);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1641 p->pointer = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1642 if (NILP (prev))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1643 ASET (font->entity, FONT_OBJLIST_INDEX, XCDR (objlist));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1644 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1645 XSETCDR (prev, XCDR (objlist));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1646 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1647 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1648 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1649 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1650
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1651 int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1652 font_has_char (f, font_entity, c)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1653 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1654 Lisp_Object font_entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1655 int c;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1656 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1657 Lisp_Object type = AREF (font_entity, FONT_TYPE_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1658 struct font_driver_list *driver_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1659
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1660 for (driver_list = f->font_driver_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1661 driver_list && ! EQ (driver_list->driver->type, type);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1662 driver_list = driver_list->next);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1663 if (! driver_list)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1664 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1665 return driver_list->driver->has_char (font_entity, c);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1666 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1667
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1668 unsigned
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1669 font_encode_char (font_object, c)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1670 Lisp_Object font_object;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1671 int c;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1672 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1673 struct font *font = XSAVE_VALUE (font_object)->pointer;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1674
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1675 return font->driver->encode_char (font, c);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1676 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1677
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1678 char *
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1679 font_get_name (font_object)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1680 Lisp_Object font_object;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1681 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1682 struct font *font = XSAVE_VALUE (font_object)->pointer;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1683
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1684 return (font->font.full_name ? font->font.full_name
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1685 : font->file_name ? font->file_name
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1686 : "");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1687 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1688
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1689 Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1690 font_get_frame (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1691 Lisp_Object font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1692 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1693 if (FONT_OBJECT_P (font))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1694 font = ((struct font *) XSAVE_VALUE (font)->pointer)->entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1695 xassert (FONT_ENTITY_P (font));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1696 return AREF (font, FONT_FRAME_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1697 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1698
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1699 extern Lisp_Object Qunspecified, Qignore_defface;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1700
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1701 Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1702 font_find_for_lface (f, lface, spec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1703 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1704 Lisp_Object *lface;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1705 Lisp_Object spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1706 {
90439
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1707 Lisp_Object attrs[LFACE_FONT_INDEX + 1];
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1708 Lisp_Object frame, val, entities;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1709 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1710 unsigned char try_unspecified[FONT_SPEC_MAX];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1711
90439
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1712 for (i = 0; i <= LFACE_FONT_INDEX; i++)
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1713 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1714 val = lface[i];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1715 if (EQ (val, Qunspecified) || EQ (val, Qignore_defface))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1716 val = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1717 attrs[i] = val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1718 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1719 if (NILP (spec))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1720 for (i = 0; i < FONT_SPEC_MAX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1721 ASET (scratch_font_spec, i, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1722 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1723 for (i = 0; i < FONT_SPEC_MAX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1724 ASET (scratch_font_spec, i, AREF (spec, i));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1725
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1726 /* If SPEC doesn't specify a specific property, it can be tried with
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1727 nil even if FACE specifies it. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1728 for (i = FONT_FOUNDRY_INDEX; i <= FONT_SIZE_INDEX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1729 try_unspecified[i] = NILP (AREF (scratch_font_spec, i));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1730
90448
15dda5f83c27 (font_find_for_lface): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 90439
diff changeset
1731 if (NILP (spec) && STRINGP (attrs[LFACE_FONT_INDEX]))
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1732 font_merge_old_spec (attrs[LFACE_FONT_INDEX], Qnil, Qnil,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1733 scratch_font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1734 if (NILP (AREF (scratch_font_spec, FONT_FAMILY_INDEX))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1735 && ! NILP (attrs[LFACE_FAMILY_INDEX]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1736 font_merge_old_spec (Qnil, attrs[LFACE_FAMILY_INDEX], Qnil,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1737 scratch_font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1738 if (NILP (AREF (scratch_font_spec, FONT_REGISTRY_INDEX)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1739 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1740 ASET (scratch_font_spec, FONT_REGISTRY_INDEX, intern ("iso8859-1"));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1741 try_unspecified[FONT_REGISTRY_INDEX] = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1742 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1743
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1744 for (i = FONT_FAMILY_INDEX; i <= FONT_SIZE_INDEX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1745 if (try_unspecified[i]
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1746 && NILP (AREF (scratch_font_spec, i)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1747 try_unspecified[i] = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1748
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1749 XSETFRAME (frame, f);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1750 entities = font_list_entities (frame, scratch_font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1751 while (ASIZE (entities) == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1752 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1753 if (try_unspecified[FONT_WEIGHT_INDEX]
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1754 || try_unspecified[FONT_SLANT_INDEX]
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1755 || try_unspecified[FONT_WIDTH_INDEX]
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1756 || try_unspecified[FONT_SIZE_INDEX])
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1757 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1758 for (i = FONT_WEIGHT_INDEX; i <= FONT_SIZE_INDEX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1759 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1760 try_unspecified[i] = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1761 ASET (scratch_font_spec, i, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1762 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1763 entities = font_list_entities (frame, scratch_font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1764 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1765 else if (try_unspecified[FONT_FOUNDRY_INDEX])
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1766 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1767 try_unspecified[FONT_FOUNDRY_INDEX] = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1768 ASET (scratch_font_spec, FONT_FOUNDRY_INDEX, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1769 entities = font_list_entities (frame, scratch_font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1770 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1771 else if (try_unspecified[FONT_FAMILY_INDEX])
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1772 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1773 try_unspecified[FONT_FAMILY_INDEX] = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1774 ASET (scratch_font_spec, FONT_FAMILY_INDEX, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1775 entities = font_list_entities (frame, scratch_font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1776 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1777 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1778 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1779 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1780
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1781 if (ASIZE (entities) > 1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1782 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1783 Lisp_Object prefer = scratch_font_prefer;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1784
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1785 for (i = 0; i < FONT_WEIGHT_INDEX; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1786 ASET (prefer, i, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1787 if (! NILP (attrs[LFACE_WEIGHT_INDEX]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1788 ASET (prefer, FONT_WEIGHT_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1789 font_prop_validate_style (FONT_WEIGHT_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1790 attrs[LFACE_WEIGHT_INDEX]));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1791 if (! NILP (attrs[LFACE_SLANT_INDEX]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1792 ASET (prefer, FONT_SLANT_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1793 font_prop_validate_style (FONT_SLANT_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1794 attrs[LFACE_SLANT_INDEX]));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1795 if (! NILP (attrs[LFACE_SWIDTH_INDEX]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1796 ASET (prefer, FONT_WIDTH_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1797 font_prop_validate_style (FONT_WIDTH_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1798 attrs[LFACE_SWIDTH_INDEX]));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1799 if (! NILP (attrs[LFACE_HEIGHT_INDEX]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1800 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1801 int size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1802
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1803 val = attrs[LFACE_HEIGHT_INDEX];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1804 size = POINT_TO_PIXEL (XINT (val), f->resy);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1805 ASET (prefer, FONT_SIZE_INDEX, make_number (size));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1806 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1807 font_sort_entites (entities, prefer, frame, spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1808 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1809
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1810 return AREF (entities, 0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1811 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1812
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1813 Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1814 font_open_for_lface (f, lface, entity)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1815 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1816 Lisp_Object *lface;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1817 Lisp_Object entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1818 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1819 int pt = XINT (lface[LFACE_HEIGHT_INDEX]);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1820 int size = POINT_TO_PIXEL (pt, f->resy);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1821
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1822 return font_open_entity (f, entity, size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1823 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1824
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1825 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1826 font_load_for_face (f, face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1827 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1828 struct face *face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1829 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1830 Lisp_Object entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1831
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1832 face->font_info_id = -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1833 face->font_info = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1834 face->font = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1835 face->font_name = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1836
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1837 entity = font_find_for_lface (f, face->lface, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1838 if (! NILP (entity))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1839 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1840 Lisp_Object font_object = font_open_for_lface (f, face->lface, entity);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1841
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1842 if (! NILP (font_object))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1843 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1844 struct font *font = XSAVE_VALUE (font_object)->pointer;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1845
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1846 face->font = font->font.font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1847 face->font_info = (struct font_info *) font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1848 face->font_info_id = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1849 face->font_name = font->font.full_name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1850 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1851 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1852 if (! face->font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1853 add_to_log ("Unable to load font for a face%s", null_string, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1854 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1855
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1856 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1857 font_prepare_for_face (f, face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1858 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1859 struct face *face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1860 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1861 struct font *font = (struct font *) face->font_info;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1862
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1863 if (font->driver->prepare_face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1864 font->driver->prepare_face (f, face);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1865 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1866
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1867 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1868 font_done_for_face (f, face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1869 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1870 struct face *face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1871 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1872 struct font *font = (struct font *) face->font_info;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1873
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1874 if (font->driver->done_face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1875 font->driver->done_face (f, face);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1876 face->extra = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1877 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1878
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1879 Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1880 font_open_by_name (f, name)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1881 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1882 char *name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1883 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1884 Lisp_Object spec = Ffont_spec (0, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1885 Lisp_Object frame;
90439
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1886 struct font_driver_list *dlist;
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1887
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1888 XSETFRAME (frame, f);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1889 ASET (spec, FONT_EXTRA_INDEX,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1890 Fcons (Fcons (QCname, make_unibyte_string (name, strlen (name))),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1891 Qnil));
90439
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1892
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1893 for (dlist = f->font_driver_list; dlist; dlist = dlist->next)
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1894 if (dlist->driver->parse_name
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1895 && dlist->driver->parse_name (f, name, spec) >= 0)
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1896 {
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1897 Lisp_Object entities = font_list_entities (frame, spec);
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1898 Lisp_Object font_object;
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1899 int pixel_size;
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1900
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1901 if (ASIZE (entities) == 0)
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1902 continue;
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1903 pixel_size = XINT (AREF (AREF (entities, 0), FONT_SIZE_INDEX));
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1904 if (pixel_size == 0 && INTEGERP (AREF (spec, FONT_SIZE_INDEX)))
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1905 pixel_size = XINT (AREF (spec, FONT_SIZE_INDEX));
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1906 font_object = font_open_entity (f, AREF (entities, 0), pixel_size);
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1907 if (! NILP (font_object))
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1908 return font_object;
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1909 }
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
1910 return Qnil;
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1911 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1912
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1913
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1914 /* Register font-driver DRIVER. This function is used in two ways.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1915
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1916 The first is with frame F non-NULL. In this case, DRIVER is
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1917 registered to be used for drawing characters on F. All frame
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1918 creaters (e.g. Fx_create_frame) must call this function at least
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1919 once with an available font-driver.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1920
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1921 The second is with frame F NULL. In this case, DRIVER is globally
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1922 registered in the variable `font_driver_list'. All font-driver
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1923 implementations must call this function in its syms_of_XXXX
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1924 (e.g. syms_of_xfont). */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1925
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1926 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1927 register_font_driver (driver, f)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1928 struct font_driver *driver;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1929 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1930 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1931 struct font_driver_list *root = f ? f->font_driver_list : font_driver_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1932 struct font_driver_list *prev, *list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1933
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1934 if (f && ! driver->draw)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1935 error ("Unsable font driver for a frame: %s",
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1936 SDATA (SYMBOL_NAME (driver->type)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1937
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1938 for (prev = NULL, list = root; list; prev = list, list = list->next)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1939 if (list->driver->type == driver->type)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1940 error ("Duplicated font driver: %s", SDATA (SYMBOL_NAME (driver->type)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1941
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1942 list = malloc (sizeof (struct font_driver_list));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1943 list->driver = driver;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1944 list->next = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1945 if (prev)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1946 prev->next = list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1947 else if (f)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1948 f->font_driver_list = list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1949 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1950 font_driver_list = list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1951 num_font_drivers++;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1952 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1953
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1954 /* Free font-driver list on frame F. It doesn't free font-drivers
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1955 themselves. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1956
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1957 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1958 free_font_driver_list (f)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1959 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1960 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1961 while (f->font_driver_list)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1962 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1963 struct font_driver_list *next = f->font_driver_list->next;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1964
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1965 free (f->font_driver_list);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1966 f->font_driver_list = next;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1967 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1968 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1969
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1970
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1971 /* Lisp API */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1972
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1973 DEFUN ("fontp", Ffontp, Sfontp, 1, 1, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1974 doc: /* Return t if object is a font-spec or font-entity. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1975 (object)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1976 Lisp_Object object;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1977 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1978 return (FONTP (object) ? Qt : Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1979 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1980
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1981 DEFUN ("font-spec", Ffont_spec, Sfont_spec, 0, MANY, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1982 doc: /* Return a newly created font-spec with specified arguments as properties.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1983 usage: (font-spec &rest properties) */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1984 (nargs, args)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1985 int nargs;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1986 Lisp_Object *args;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1987 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1988 Lisp_Object spec = Fmake_vector (make_number (FONT_SPEC_MAX), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1989 Lisp_Object extra = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1990 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1991
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1992 for (i = 0; i < nargs; i += 2)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1993 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1994 enum font_property_index prop;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1995 Lisp_Object key = args[i], val = args[i + 1];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1996
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1997 prop = check_font_prop_name (key);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1998 if (prop < FONT_EXTRA_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1999 ASET (spec, prop, (font_property_table[prop].validater) (prop, val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2000 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2001 extra = Fcons (Fcons (key, val), extra);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2002 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2003 ASET (spec, FONT_EXTRA_INDEX, extra);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2004 return spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2005 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2006
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2007
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2008 DEFUN ("font-get", Ffont_get, Sfont_get, 2, 2, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2009 doc: /* Return the value of FONT's PROP property.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2010 FONT may be a font-spec or font-entity.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2011 If FONT is font-entity and PROP is :extra, always nil is returned. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2012 (font, prop)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2013 Lisp_Object font, prop;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2014 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2015 enum font_property_index idx;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2016
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2017 CHECK_FONT (font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2018 idx = check_font_prop_name (prop);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2019 if (idx < FONT_EXTRA_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2020 return AREF (font, idx);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2021 if (FONT_ENTITY_P (font))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2022 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2023 return Fcdr (Fassoc (AREF (font, FONT_EXTRA_INDEX), prop));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2024 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2025
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2026
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2027 DEFUN ("font-put", Ffont_put, Sfont_put, 3, 3, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2028 doc: /* Set one property of FONT-SPEC: give property PROP value VALUE. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2029 (font_spec, prop, val)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2030 Lisp_Object font_spec, prop, val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2031 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2032 enum font_property_index idx;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2033 Lisp_Object extra, slot;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2034
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2035 CHECK_FONT_SPEC (font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2036 idx = check_font_prop_name (prop);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2037 if (idx < FONT_EXTRA_INDEX)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2038 return ASET (font_spec, idx, val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2039 extra = AREF (font_spec, FONT_EXTRA_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2040 slot = Fassoc (extra, prop);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2041 if (NILP (slot))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2042 extra = Fcons (Fcons (prop, val), extra);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2043 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2044 Fsetcdr (slot, val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2045 return val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2046 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2047
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2048 DEFUN ("list-fonts", Flist_fonts, Slist_fonts, 1, 4, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2049 doc: /* List available fonts matching FONT-SPEC on the current frame.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2050 Optional 2nd argument FRAME specifies the target frame.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2051 Optional 3rd argument NUM, if non-nil, limits the number of returned fonts.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2052 Optional 4th argument PREFER, if non-nil, is a font-spec to sort fonts
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2053 by closeness to PREFER. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2054 (font_spec, frame, num, prefer)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2055 Lisp_Object font_spec, frame, num, prefer;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2056 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2057 Lisp_Object vec, list, tail;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2058 int n = 0, i, len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2059
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2060 if (NILP (frame))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2061 frame = selected_frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2062 CHECK_LIVE_FRAME (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2063 CHECK_VALIDATE_FONT_SPEC (font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2064 if (! NILP (num))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2065 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2066 CHECK_NUMBER (num);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2067 n = XINT (num);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2068 if (n <= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2069 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2070 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2071 if (! NILP (prefer))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2072 CHECK_FONT (prefer);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2073
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2074 vec = font_list_entities (frame, font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2075 len = ASIZE (vec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2076 if (len == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2077 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2078 if (len == 1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2079 return Fcons (AREF (vec, 0), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2080
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2081 if (! NILP (prefer))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2082 vec = font_sort_entites (vec, prefer, frame, font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2083
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2084 list = tail = Fcons (AREF (vec, 0), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2085 if (n == 0 || n > len)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2086 n = len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2087 for (i = 1; i < n; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2088 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2089 Lisp_Object val = Fcons (AREF (vec, i), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2090
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2091 XSETCDR (tail, val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2092 tail = val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2093 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2094 return list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2095 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2096
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2097 DEFUN ("list-families", Flist_families, Slist_families, 0, 1, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2098 doc: /* List available font families on the current frame.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2099 Optional 2nd argument FRAME specifies the target frame. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2100 (frame)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2101 Lisp_Object frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2102 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2103 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2104 struct font_driver_list *driver_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2105 Lisp_Object list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2106
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2107 if (NILP (frame))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2108 frame = selected_frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2109 CHECK_LIVE_FRAME (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2110 f = XFRAME (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2111 list = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2112 for (driver_list = f->font_driver_list; driver_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2113 driver_list = driver_list->next)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2114 if (driver_list->driver->list_family)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2115 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2116 Lisp_Object val = driver_list->driver->list_family (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2117
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2118 if (NILP (list))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2119 list = val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2120 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2121 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2122 Lisp_Object tail = list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2123
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2124 for (; CONSP (val); val = XCDR (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2125 if (NILP (Fmemq (XCAR (val), tail)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2126 list = Fcons (XCAR (val), list);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2127 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2128 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2129 return list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2130 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2131
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2132 DEFUN ("find-font", Ffind_font, Sfind_font, 1, 2, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2133 doc: /* Return a font-entity matching with FONT-SPEC on the current frame.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2134 Optional 2nd argument FRAME, if non-nil, specifies the target frame. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2135 (font_spec, frame)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2136 Lisp_Object font_spec, frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2137 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2138 Lisp_Object val = Flist_fonts (font_spec, frame, make_number (1), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2139
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2140 if (CONSP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2141 val = XCAR (val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2142 return val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2143 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2144
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2145 DEFUN ("font-xlfd-name", Ffont_xlfd_name, Sfont_xlfd_name, 1, 1, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2146 doc: /* Return XLFD name of FONT.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2147 FONT is a font-spec, font-entity, or font-object.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2148 If the name is too long for XLFD (maximum 255 chars), return nil. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2149 (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2150 Lisp_Object font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2151 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2152 char name[256];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2153 int pixel_size = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2154
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2155 if (FONT_SPEC_P (font))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2156 CHECK_VALIDATE_FONT_SPEC (font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2157 else if (FONT_ENTITY_P (font))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2158 CHECK_FONT (font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2159 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2160 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2161 struct font *fontp;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2162
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2163 CHECK_FONT_GET_OBJECT (font, fontp);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2164 font = fontp->entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2165 pixel_size = fontp->pixel_size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2166 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2167
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2168 if (font_unparse_xlfd (font, pixel_size, name, 256) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2169 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2170 return build_string (name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2171 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2172
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2173 DEFUN ("clear-font-cache", Fclear_font_cache, Sclear_font_cache, 0, 0, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2174 doc: /* Clear font cache. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2175 ()
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2176 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2177 Lisp_Object list, frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2178
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2179 FOR_EACH_FRAME (list, frame)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2180 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2181 FRAME_PTR f = XFRAME (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2182 struct font_driver_list *driver_list = f->font_driver_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2183
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2184 for (; driver_list; driver_list = driver_list->next)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2185 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2186 Lisp_Object cache = driver_list->driver->get_cache (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2187 Lisp_Object tail, elt;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2188
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2189 for (tail = XCDR (cache); CONSP (tail); tail = XCDR (tail))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2190 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2191 elt = XCAR (tail);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2192 if (CONSP (elt) && FONT_SPEC_P (XCAR (elt)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2193 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2194 Lisp_Object vec = XCDR (elt);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2195 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2196
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2197 for (i = 0; i < ASIZE (vec); i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2198 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2199 Lisp_Object entity = AREF (vec, i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2200 Lisp_Object objlist = AREF (entity, FONT_OBJLIST_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2201
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2202 for (; CONSP (objlist); objlist = XCDR (objlist))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2203 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2204 Lisp_Object val = XCAR (objlist);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2205 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2206 struct font *font = p->pointer;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2207
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2208 xassert (font
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2209 && driver_list->driver == font->driver);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2210 driver_list->driver->close (f, font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2211 p->pointer = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2212 p->integer = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2213 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2214 if (driver_list->driver->free_entity)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2215 driver_list->driver->free_entity (entity);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2216 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2217 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2218 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2219 XSETCDR (cache, Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2220 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2221 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2222
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2223 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2224 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2225
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2226 DEFUN ("internal-set-font-style-table", Finternal_set_font_style_table,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2227 Sinternal_set_font_style_table, 2, 2, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2228 doc: /* Set font style table for PROP to TABLE.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2229 PROP must be `:weight', `:slant', or `:width'.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2230 TABLE must be an alist of symbols vs the corresponding numeric values
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2231 sorted by numeric values. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2232 (prop, table)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2233 Lisp_Object prop, table;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2234 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2235 int table_index;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2236 int numeric;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2237 Lisp_Object tail, val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2238
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2239 CHECK_SYMBOL (prop);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2240 table_index = (EQ (prop, QCweight) ? 0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2241 : EQ (prop, QCslant) ? 1
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2242 : EQ (prop, QCwidth) ? 2
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2243 : 3);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2244 if (table_index >= ASIZE (font_style_table))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2245 error ("Invalid font style property: %s", SDATA (SYMBOL_NAME (prop)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2246 table = Fcopy_sequence (table);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2247 numeric = -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2248 for (tail = table; ! NILP (tail); tail = Fcdr (tail))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2249 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2250 prop = Fcar (Fcar (tail));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2251 val = Fcdr (Fcar (tail));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2252 CHECK_SYMBOL (prop);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2253 CHECK_NATNUM (val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2254 if (numeric > XINT (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2255 error ("Numeric values not sorted for %s", SDATA (SYMBOL_NAME (prop)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2256 numeric = XINT (val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2257 XSETCAR (tail, Fcons (prop, val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2258 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2259 ASET (font_style_table, table_index, table);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2260 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2261 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2262
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2263 DEFUN ("font-make-gstring", Ffont_make_gstring, Sfont_make_gstring, 2, 2, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2264 doc: /* Return a newly created glyph-string for FONT-OBJECT with NUM glyphs.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2265 FONT-OBJECT may be nil if it is not yet known. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2266 (font_object, num)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2267 Lisp_Object font_object, num;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2268 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2269 Lisp_Object gstring, g;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2270 int len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2271 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2272
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2273 if (! NILP (font_object))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2274 CHECK_FONT_OBJECT (font_object);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2275 CHECK_NATNUM (num);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2276
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2277 len = XINT (num) + 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2278 gstring = Fmake_vector (make_number (len), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2279 g = Fmake_vector (make_number (6), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2280 ASET (g, 0, font_object);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2281 ASET (gstring, 0, g);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2282 for (i = 1; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2283 ASET (gstring, i, Fmake_vector (make_number (8), make_number (0)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2284 return gstring;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2285 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2286
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2287 DEFUN ("font-fill-gstring", Ffont_fill_gstring, Sfont_fill_gstring, 4, 5, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2288 doc: /* Fillin glyph-string GSTRING by characters for FONT-OBJECT.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2289 START and END specifies the region to extract characters.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2290 If optional 3rd argument OBJECT is non-nil, it is a buffer or a string from
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2291 where to extract characters.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2292 FONT-OBJECT may be nil if GSTRING already already contains one. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2293 (gstring, font_object, start, end, object)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2294 Lisp_Object gstring, font_object, start, end, object;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2295 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2296 int len, i, c;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2297 unsigned code;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2298 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2299
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2300 CHECK_VECTOR (gstring);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2301 if (NILP (font_object))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2302 font_object = Faref (Faref (gstring, make_number (0)), make_number (0));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2303 CHECK_FONT_GET_OBJECT (font_object, font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2304
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2305 if (STRINGP (object))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2306 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2307 const unsigned char *p;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2308
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2309 CHECK_NATNUM (start);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2310 CHECK_NATNUM (end);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2311 if (XINT (start) > XINT (end)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2312 || XINT (end) > ASIZE (object)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2313 || XINT (end) - XINT (start) >= XINT (Flength (gstring)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2314 args_out_of_range (start, end);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2315
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2316 len = XINT (end) - XINT (start);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2317 p = SDATA (object) + string_char_to_byte (object, XINT (start));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2318 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2319 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2320 Lisp_Object g = LGSTRING_GLYPH (gstring, i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2321
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2322 c = STRING_CHAR_ADVANCE (p);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2323 code = font->driver->encode_char (font, c);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2324 if (code > MOST_POSITIVE_FIXNUM)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2325 error ("Glyph code 0x%X is too large", code);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2326 ASET (g, 0, make_number (i));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2327 ASET (g, 1, make_number (i + 1));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2328 LGLYPH_SET_CHAR (g, make_number (c));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2329 LGLYPH_SET_CODE (g, make_number (code));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2330 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2331 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2332 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2333 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2334 int pos, pos_byte;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2335
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2336 if (! NILP (object))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2337 Fset_buffer (object);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2338 validate_region (&start, &end);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2339 if (XINT (end) - XINT (start) > len)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2340 args_out_of_range (start, end);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2341 len = XINT (end) - XINT (start);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2342 pos = XINT (start);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2343 pos_byte = CHAR_TO_BYTE (pos);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2344 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2345 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2346 Lisp_Object g = LGSTRING_GLYPH (gstring, i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2347
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2348 FETCH_CHAR_ADVANCE (c, pos, pos_byte);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2349 code = font->driver->encode_char (font, c);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2350 if (code > MOST_POSITIVE_FIXNUM)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2351 error ("Glyph code 0x%X is too large", code);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2352 ASET (g, 0, make_number (i));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2353 ASET (g, 1, make_number (i + 1));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2354 LGLYPH_SET_CHAR (g, make_number (c));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2355 LGLYPH_SET_CODE (g, make_number (code));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2356 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2357 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2358 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2359 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2360
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2361
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2362 #ifdef FONT_DEBUG
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2363
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2364 DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2365 doc: /* Open FONT-ENTITY. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2366 (font_entity, size, frame)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2367 Lisp_Object font_entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2368 Lisp_Object size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2369 Lisp_Object frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2370 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2371 int isize;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2372
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2373 CHECK_FONT_ENTITY (font_entity);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2374 if (NILP (size))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2375 size = AREF (font_entity, FONT_SIZE_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2376 CHECK_NUMBER (size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2377 if (NILP (frame))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2378 frame = selected_frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2379 CHECK_LIVE_FRAME (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2380
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2381 isize = XINT (size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2382 if (isize < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2383 isize = POINT_TO_PIXEL (- isize, XFRAME (frame)->resy);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2384
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2385 return font_open_entity (XFRAME (frame), font_entity, isize);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2386 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2387
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2388 DEFUN ("close-font", Fclose_font, Sclose_font, 1, 2, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2389 doc: /* Close FONT-OBJECT. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2390 (font_object, frame)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2391 Lisp_Object font_object, frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2392 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2393 CHECK_FONT_OBJECT (font_object);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2394 if (NILP (frame))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2395 frame = selected_frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2396 CHECK_LIVE_FRAME (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2397 font_close_object (XFRAME (frame), font_object);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2398 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2399 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2401 DEFUN ("query-font", Fquery_font, Squery_font, 1, 1, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2402 doc: /* Return information about FONT-OBJECT. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2403 (font_object)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2404 Lisp_Object font_object;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2405 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2406 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2407 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2408
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2409 CHECK_FONT_GET_OBJECT (font_object, font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2410
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2411 val = Fmake_vector (make_number (9), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2412 ASET (val, 0, Ffont_xlfd_name (font_object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2413 if (font->file_name)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2414 ASET (val, 1, make_unibyte_string (font->file_name,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2415 strlen (font->file_name)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2416 ASET (val, 2, make_number (font->pixel_size));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2417 ASET (val, 3, make_number (font->font.size));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2418 ASET (val, 4, make_number (font->ascent));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2419 ASET (val, 5, make_number (font->descent));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2420 ASET (val, 6, make_number (font->font.space_width));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2421 ASET (val, 7, make_number (font->font.average_width));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2422 if (font->driver->otf_capability)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2423 ASET (val, 8, font->driver->otf_capability (font));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2424 return val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2425 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2426
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2427 DEFUN ("get-font-glyphs", Fget_font_glyphs, Sget_font_glyphs, 2, 2, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2428 doc: /* Return a vector of glyphs of FONT-OBJECT for drawing STRING.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2429 Each element is a vector [GLYPH-CODE LBEARING RBEARING WIDTH ASCENT DESCENT]. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2430 (font_object, string)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2431 Lisp_Object font_object, string;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2432 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2433 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2434 int i, len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2435 Lisp_Object vec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2436
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2437 CHECK_FONT_GET_OBJECT (font_object, font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2438 CHECK_STRING (string);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2439 len = SCHARS (string);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2440 vec = Fmake_vector (make_number (len), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2441 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2442 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2443 Lisp_Object ch = Faref (string, make_number (i));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2444 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2445 int c = XINT (ch);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2446 unsigned code;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2447 struct font_metrics metrics;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2448
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2449 code = font->driver->encode_char (font, c);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2450 if (code == FONT_INVALID_CODE)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2451 continue;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2452 val = Fmake_vector (make_number (6), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2453 if (code <= MOST_POSITIVE_FIXNUM)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2454 ASET (val, 0, make_number (code));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2455 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2456 ASET (val, 0, Fcons (make_number (code >> 16),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2457 make_number (code & 0xFFFF)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2458 font->driver->text_extents (font, &code, 1, &metrics);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2459 ASET (val, 1, make_number (metrics.lbearing));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2460 ASET (val, 2, make_number (metrics.rbearing));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2461 ASET (val, 3, make_number (metrics.width));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2462 ASET (val, 4, make_number (metrics.ascent));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2463 ASET (val, 5, make_number (metrics.descent));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2464 ASET (vec, i, val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2465 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2466 return vec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2467 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2468
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2469 #if 0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2470 DEFUN ("draw-string", Fdraw_string, Sdraw_string, 2, 2, 0,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2471 doc: /* Draw STRING by FONT-OBJECT on the top left corner of the current frame.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2472 The value is a number of glyphs drawn.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2473 Type C-l to recover what previously shown. */)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2474 (font_object, string)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2475 Lisp_Object font_object, string;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2476 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2477 Lisp_Object frame = selected_frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2478 FRAME_PTR f = XFRAME (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2479 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2480 struct face *face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2481 int i, len, width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2482 unsigned *code;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2483
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2484 CHECK_FONT_GET_OBJECT (font_object, font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2485 CHECK_STRING (string);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2486 len = SCHARS (string);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2487 code = alloca (sizeof (unsigned) * len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2488 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2489 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2490 Lisp_Object ch = Faref (string, make_number (i));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2491 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2492 int c = XINT (ch);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2493
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2494 code[i] = font->driver->encode_char (font, c);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2495 if (code[i] == FONT_INVALID_CODE)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2496 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2497 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2498 face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2499 face->fontp = font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2500 if (font->driver->prepare_face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2501 font->driver->prepare_face (f, face);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2502 width = font->driver->text_extents (font, code, i, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2503 len = font->driver->draw_text (f, face, 0, font->ascent, code, i, width);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2504 if (font->driver->done_face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2505 font->driver->done_face (f, face);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2506 face->fontp = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2507 return make_number (len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2508 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2509 #endif
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2510
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2511 #endif /* FONT_DEBUG */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2512
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2513
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2514 extern void syms_of_ftfont P_ (());
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2515 extern void syms_of_xfont P_ (());
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2516 extern void syms_of_xftfont P_ (());
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2517 extern void syms_of_ftxfont P_ (());
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2518 extern void syms_of_bdffont P_ (());
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2519 extern void syms_of_w32font P_ (());
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2520 extern void syms_of_atmfont P_ (());
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2521
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2522 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2523 syms_of_font ()
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2524 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2525 sort_shift_bits[FONT_SLANT_INDEX] = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2526 sort_shift_bits[FONT_WEIGHT_INDEX] = 7;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2527 sort_shift_bits[FONT_SIZE_INDEX] = 14;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2528 sort_shift_bits[FONT_WIDTH_INDEX] = 21;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2529 sort_shift_bits[FONT_ADSTYLE_INDEX] = 28;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2530 sort_shift_bits[FONT_FOUNDRY_INDEX] = 29;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2531 sort_shift_bits[FONT_FAMILY_INDEX] = 30;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2532 sort_shift_bits[FONT_REGISTRY_INDEX] = 31;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2533 /* Note that sort_shift_bits[FONT_SLANT_TYPE] is never used. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2534
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2535 staticpro (&font_style_table);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2536 font_style_table = Fmake_vector (make_number (3), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2537
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2538 staticpro (&font_family_alist);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2539 font_family_alist = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2540
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2541 DEFSYM (Qfontp, "fontp");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2542
90439
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
2543 DEFSYM (Qiso8859_1, "iso8859-1");
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
2544 DEFSYM (Qiso10646_1, "iso10646-1");
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
2545 DEFSYM (Qunicode_bmp, "unicode-bmp");
fb253905e9c3 * font.c (Qiso8859_1, Qiso10646_1, Qunicode_bmp): Moved from
Kenichi Handa <handa@m17n.org>
parents: 90427
diff changeset
2546
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2547 DEFSYM (QCotf, ":otf");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2548 DEFSYM (QClanguage, ":language");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2549 DEFSYM (QCscript, ":script");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2550
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2551 DEFSYM (QCfoundry, ":foundry");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2552 DEFSYM (QCadstyle, ":adstyle");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2553 DEFSYM (QCregistry, ":registry");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2554 DEFSYM (QCextra, ":extra");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2555
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2556 staticpro (&null_string);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2557 null_string = build_string ("");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2558 staticpro (&null_vector);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2559 null_vector = Fmake_vector (make_number (0), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2560
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2561 staticpro (&scratch_font_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2562 scratch_font_spec = Ffont_spec (0, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2563 staticpro (&scratch_font_prefer);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2564 scratch_font_prefer = Ffont_spec (0, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2565
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2566 defsubr (&Sfontp);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2567 defsubr (&Sfont_spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2568 defsubr (&Sfont_get);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2569 defsubr (&Sfont_put);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2570 defsubr (&Slist_fonts);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2571 defsubr (&Slist_families);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2572 defsubr (&Sfind_font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2573 defsubr (&Sfont_xlfd_name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2574 defsubr (&Sclear_font_cache);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2575 defsubr (&Sinternal_set_font_style_table);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2576 defsubr (&Sfont_make_gstring);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2577 defsubr (&Sfont_fill_gstring);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2578
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2579 #ifdef FONT_DEBUG
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2580 defsubr (&Sopen_font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2581 defsubr (&Sclose_font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2582 defsubr (&Squery_font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2583 defsubr (&Sget_font_glyphs);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2584 #if 0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2585 defsubr (&Sdraw_string);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2586 #endif
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2587 #endif /* FONT_DEBUG */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2588
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2589 #ifdef HAVE_FREETYPE
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2590 syms_of_ftfont ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2591 #ifdef HAVE_X_WINDOWS
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2592 syms_of_xfont ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2593 syms_of_ftxfont ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2594 #ifdef HAVE_XFT
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2595 syms_of_xftfont ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2596 #endif /* HAVE_XFT */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2597 #endif /* HAVE_X_WINDOWS */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2598 #else /* not HAVE_FREETYPE */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2599 #ifdef HAVE_X_WINDOWS
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2600 syms_of_xfont ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2601 #endif /* HAVE_X_WINDOWS */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2602 #endif /* not HAVE_FREETYPE */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2603 #ifdef HAVE_BDFFONT
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2604 syms_of_bdffont ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2605 #endif /* HAVE_BDFFONT */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2606 #ifdef WINDOWSNT
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2607 syms_of_w32font ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2608 #endif /* WINDOWSNT */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2609 #ifdef MAC_OS
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2610 syms_of_atmfont ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2611 #endif /* MAC_OS */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2612 }
90427
ddb25860d044 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 90400
diff changeset
2613
ddb25860d044 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 90400
diff changeset
2614 /* arch-tag: 74c9475d-5976-4c93-a327-942ae3072846
ddb25860d044 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 90400
diff changeset
2615 (do not change this comment) */