Mercurial > emacs
annotate src/ftxfont.c @ 91060:cd41c7f74f39
(obj): Sync with src/Makefile.in
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Sat, 20 Oct 2007 23:08:16 +0000 |
parents | c443c8a56b84 |
children | 5ed0717083a1 |
rev | line source |
---|---|
90400 | 1 /* ftxfont.c -- FreeType font driver on X (without using XFT). |
2 Copyright (C) 2006 Free Software Foundation, Inc. | |
3 Copyright (C) 2006 | |
4 National Institute of Advanced Industrial Science and Technology (AIST) | |
5 Registration Number H13PRO009 | |
6 | |
7 This file is part of GNU Emacs. | |
8 | |
9 GNU Emacs is free software; you can redistribute it and/or modify | |
10 it under the terms of the GNU General Public License as published by | |
11 the Free Software Foundation; either version 2, or (at your option) | |
12 any later version. | |
13 | |
14 GNU Emacs is distributed in the hope that it will be useful, | |
15 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 GNU General Public License for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
20 along with GNU Emacs; see the file COPYING. If not, write to | |
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
22 Boston, MA 02110-1301, USA. */ | |
23 | |
24 #include <config.h> | |
25 #include <stdio.h> | |
26 #include <X11/Xlib.h> | |
27 | |
28 #include "lisp.h" | |
29 #include "dispextern.h" | |
30 #include "xterm.h" | |
31 #include "frame.h" | |
32 #include "blockinput.h" | |
33 #include "character.h" | |
34 #include "charset.h" | |
35 #include "fontset.h" | |
36 #include "font.h" | |
37 | |
38 /* FTX font driver. */ | |
39 | |
40 static Lisp_Object Qftx; | |
41 | |
42 /* Prototypes for helper function. */ | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
43 static int ftxfont_create_gcs P_ ((FRAME_PTR, GC *, |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
44 unsigned long, unsigned long)); |
90400 | 45 static int ftxfont_draw_bitmap P_ ((FRAME_PTR, GC *, struct font *, unsigned, |
46 int, int, XPoint *, int, int *n)); | |
47 static void ftxfont_draw_backgrond P_ ((FRAME_PTR, struct font *, GC, | |
48 int, int, int)); | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
49 static Font ftxfont_default_fid P_ ((FRAME_PTR)); |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
50 |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
51 /* Create 6 GCs for antialiasing by interpolating colors FOREGROUND |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
52 and BACKGROUND. GCS[0] is closest to BACKGROUND, and GCS[5] is |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
53 closest to FOREGROUND. */ |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
54 |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
55 static int |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
56 ftxfont_create_gcs (f, gcs, foreground, background) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
57 FRAME_PTR f; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
58 GC *gcs; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
59 unsigned long foreground, background; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
60 { |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
61 XColor colors[3]; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
62 XGCValues xgcv; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
63 int i; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
64 |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
65 colors[0].pixel = foreground; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
66 colors[1].pixel = background; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
67 |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
68 BLOCK_INPUT; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
69 XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), colors, 2); |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
70 for (i = 1; i < 7; i++) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
71 { |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
72 colors[2].red = (colors[0].red * i + colors[1].red * (8 - i)) / 8; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
73 colors[2].green = (colors[0].green * i + colors[1].green * (8 - i)) / 8; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
74 colors[2].blue = (colors[0].blue * i + colors[1].blue * (8 - i)) / 8; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
75 if (! x_alloc_nearest_color (f, FRAME_X_COLORMAP (f), &colors[2])) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
76 break; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
77 xgcv.foreground = colors[2].pixel; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
78 gcs[i - 1] = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
79 GCForeground, &xgcv); |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
80 } |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
81 UNBLOCK_INPUT; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
82 |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
83 if (i < 7) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
84 { |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
85 BLOCK_INPUT; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
86 for (i--; i >= 0; i--) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
87 XFreeGC (FRAME_X_DISPLAY (f), gcs[i]); |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
88 UNBLOCK_INPUT; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
89 return -1; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
90 } |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
91 return 0; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
92 } |
90400 | 93 |
94 static int | |
95 ftxfont_draw_bitmap (f, gc, font, code, x, y, p, size, n) | |
96 FRAME_PTR f; | |
97 GC *gc; | |
98 struct font *font; | |
99 unsigned code; | |
100 int x, y; | |
101 XPoint *p; | |
102 int size, *n; | |
103 { | |
104 struct font_bitmap bitmap; | |
105 unsigned char *b; | |
106 int i, j; | |
107 | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
108 if (ftfont_driver.get_bitmap (font, code, &bitmap, size > 0x100 ? 1 : 8) < 0) |
90400 | 109 return 0; |
110 for (i = 0, b = bitmap.buffer; i < bitmap.rows; | |
111 i++, b += bitmap.pitch) | |
112 { | |
113 if (size > 0x100) | |
114 { | |
115 for (j = 0; j < bitmap.width; j++) | |
116 if (b[j / 8] & (1 << (7 - (j % 8)))) | |
117 { | |
118 p[n[0]].x = x + bitmap.left + j; | |
119 p[n[0]].y = y - bitmap.top + i; | |
120 if (++n[0] == 0x400) | |
121 { | |
122 XDrawPoints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
123 gc[0], p, size, CoordModeOrigin); | |
124 n[0] = 0; | |
125 } | |
126 } | |
127 } | |
128 else | |
129 { | |
130 for (j = 0; j < bitmap.width; j++) | |
131 { | |
132 int idx = (b[j] >> 5) - 1; | |
133 | |
134 if (idx >= 0) | |
135 { | |
136 XPoint *pp = p + size * idx; | |
137 | |
138 pp[n[idx]].x = x + bitmap.left + j; | |
139 pp[n[idx]].y = y - bitmap.top + i; | |
140 if (++(n[idx]) == 0x100) | |
141 { | |
142 XDrawPoints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
143 gc[idx], pp, size, CoordModeOrigin); | |
144 n[idx] = 0; | |
145 } | |
146 } | |
147 } | |
148 } | |
149 } | |
150 | |
151 if (ftfont_driver.free_bitmap) | |
152 ftfont_driver.free_bitmap (font, &bitmap); | |
153 | |
154 return bitmap.advance; | |
155 } | |
156 | |
157 static void | |
158 ftxfont_draw_backgrond (f, font, gc, x, y, width) | |
159 FRAME_PTR f; | |
160 struct font *font; | |
161 GC gc; | |
162 int x, y, width; | |
163 { | |
164 XGCValues xgcv; | |
165 | |
166 XGetGCValues (FRAME_X_DISPLAY (f), gc, | |
167 GCForeground | GCBackground, &xgcv); | |
168 XSetForeground (FRAME_X_DISPLAY (f), gc, xgcv.background); | |
169 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
170 x, y - font->ascent, width, y + font->descent); |
90400 | 171 XSetForeground (FRAME_X_DISPLAY (f), gc, xgcv.foreground); |
172 } | |
173 | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
174 /* Return the default Font ID on frame F. */ |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
175 |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
176 static Font |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
177 ftxfont_default_fid (f) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
178 FRAME_PTR f; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
179 { |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
180 static int fid_known; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
181 static Font fid; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
182 |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
183 if (! fid_known) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
184 { |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
185 fid = XLoadFont (FRAME_X_DISPLAY (f), "fixed"); |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
186 if (! fid) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
187 { |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
188 fid = XLoadFont (FRAME_X_DISPLAY (f), "*"); |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
189 if (! fid) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
190 abort (); |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
191 } |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
192 fid_known = 1; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
193 } |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
194 return fid; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
195 } |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
196 |
90400 | 197 /* Prototypes for font-driver methods. */ |
198 static Lisp_Object ftxfont_list P_ ((Lisp_Object, Lisp_Object)); | |
90560
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
199 static Lisp_Object ftxfont_match P_ ((Lisp_Object, Lisp_Object)); |
90400 | 200 static struct font *ftxfont_open P_ ((FRAME_PTR, Lisp_Object, int)); |
201 static void ftxfont_close P_ ((FRAME_PTR, struct font *)); | |
202 static int ftxfont_prepare_face (FRAME_PTR, struct face *); | |
203 static void ftxfont_done_face (FRAME_PTR, struct face *); | |
204 | |
205 static int ftxfont_draw P_ ((struct glyph_string *, int, int, int, int, int)); | |
206 | |
207 struct font_driver ftxfont_driver; | |
208 | |
209 static Lisp_Object | |
210 ftxfont_list (frame, spec) | |
211 Lisp_Object frame; | |
212 Lisp_Object spec; | |
213 { | |
214 Lisp_Object val = ftfont_driver.list (frame, spec); | |
215 | |
216 if (! NILP (val)) | |
217 { | |
218 int i; | |
219 | |
220 for (i = 0; i < ASIZE (val); i++) | |
221 ASET (AREF (val, i), FONT_TYPE_INDEX, Qftx); | |
222 } | |
223 return val; | |
224 } | |
225 | |
90560
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
226 static Lisp_Object |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
227 ftxfont_match (frame, spec) |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
228 Lisp_Object frame; |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
229 Lisp_Object spec; |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
230 { |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
231 Lisp_Object entity = ftfont_driver.match (frame, spec); |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
232 |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
233 if (VECTORP (entity)) |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
234 ASET (entity, FONT_TYPE_INDEX, Qftx); |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
235 return entity; |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
236 } |
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
237 |
90400 | 238 static struct font * |
239 ftxfont_open (f, entity, pixel_size) | |
240 FRAME_PTR f; | |
241 Lisp_Object entity; | |
242 int pixel_size; | |
243 { | |
244 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
245 struct font *font; | |
246 XFontStruct *xfont = malloc (sizeof (XFontStruct)); | |
247 | |
248 if (! xfont) | |
249 return NULL; | |
250 font = ftfont_driver.open (f, entity, pixel_size); | |
251 if (! font) | |
252 { | |
253 free (xfont); | |
254 return NULL; | |
255 } | |
256 | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
257 xfont->fid = ftxfont_default_fid (f); |
90400 | 258 xfont->ascent = font->ascent; |
259 xfont->descent = font->descent; | |
260 xfont->max_bounds.width = font->font.size; | |
261 xfont->min_bounds.width = font->min_width; | |
262 font->font.font = xfont; | |
263 font->driver = &ftxfont_driver; | |
264 | |
265 dpyinfo->n_fonts++; | |
266 | |
267 /* Set global flag fonts_changed_p to non-zero if the font loaded | |
268 has a character with a smaller width than any other character | |
269 before, or if the font loaded has a smaller height than any other | |
270 font loaded before. If this happens, it will make a glyph matrix | |
271 reallocation necessary. */ | |
272 if (dpyinfo->n_fonts == 1) | |
273 { | |
274 dpyinfo->smallest_font_height = font->font.height; | |
275 dpyinfo->smallest_char_width = font->min_width; | |
276 fonts_changed_p = 1; | |
277 } | |
278 else | |
279 { | |
280 if (dpyinfo->smallest_font_height > font->font.height) | |
281 dpyinfo->smallest_font_height = font->font.height, fonts_changed_p |= 1; | |
282 if (dpyinfo->smallest_char_width > font->min_width) | |
283 dpyinfo->smallest_char_width = font->min_width, fonts_changed_p |= 1; | |
284 } | |
285 | |
286 return font; | |
287 } | |
288 | |
289 static void | |
290 ftxfont_close (f, font) | |
291 FRAME_PTR f; | |
292 struct font *font; | |
293 { | |
294 ftfont_driver.close (f, font); | |
295 FRAME_X_DISPLAY_INFO (f)->n_fonts--; | |
296 } | |
297 | |
298 static int | |
299 ftxfont_prepare_face (f, face) | |
300 FRAME_PTR f; | |
301 struct face *face; | |
302 { | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
303 struct font *font = (struct font *) face->font_info; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
304 GC gcs[6]; |
90400 | 305 int i; |
306 | |
307 face->extra = NULL; | |
308 | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
309 if (! font->scalable) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
310 return 0; |
90400 | 311 |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
312 if (ftxfont_create_gcs (f, gcs, face->foreground, face->background) < 0) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
313 /* Give up antialiasing. */ |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
314 return 0; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
315 |
90400 | 316 face->extra = malloc (sizeof (GC) * 7); |
317 if (! face->extra) | |
318 return -1; | |
319 for (i = 0; i < 6; i++) | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
320 ((GC *) face->extra)[i] = gcs[i]; |
90400 | 321 ((GC *) face->extra)[i] = face->gc; |
322 return 0; | |
323 } | |
324 | |
325 static void | |
326 ftxfont_done_face (f, face) | |
327 FRAME_PTR f; | |
328 struct face *face; | |
329 { | |
330 if (face->extra) | |
331 { | |
332 int i; | |
333 | |
334 BLOCK_INPUT; | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
335 for (i = 0; i < 6; i++) |
90400 | 336 XFreeGC (FRAME_X_DISPLAY (f), ((GC *) face->extra)[i]); |
337 UNBLOCK_INPUT; | |
338 free (face->extra); | |
339 face->extra = NULL; | |
340 } | |
341 } | |
342 | |
343 static int | |
344 ftxfont_draw (s, from, to, x, y, with_background) | |
345 struct glyph_string *s; | |
346 int from, to, x, y, with_background; | |
347 { | |
348 FRAME_PTR f = s->f; | |
349 struct face *face = s->face; | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
350 struct font *font = (struct font *) face->font_info; |
90400 | 351 XPoint p[0x700]; |
352 int n[7]; | |
353 unsigned *code; | |
354 int len = to - from; | |
355 int i; | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
356 GC *gcs; |
90400 | 357 |
358 n[0] = n[1] = n[2] = n[3] = n[4] = n[5] = n[6] = 0; | |
359 | |
360 BLOCK_INPUT; | |
361 | |
362 if (with_background) | |
363 ftxfont_draw_backgrond (f, font, s->gc, x, y, s->width); | |
364 code = alloca (sizeof (unsigned) * len); | |
365 for (i = 0; i < len; i++) | |
366 code[i] = ((XCHAR2B_BYTE1 (s->char2b + from + i) << 8) | |
367 | XCHAR2B_BYTE2 (s->char2b + from + i)); | |
368 | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
369 gcs = face->extra; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
370 if (gcs && face->gc != s->gc) |
90400 | 371 { |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
372 /* We are drawing for cursor or for mouse highlighting, and |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
373 can't use the prepared GCs. */ |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
374 XGCValues xgcv; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
375 unsigned long mask = GCForeground | GCBackground; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
376 |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
377 gcs = alloca (sizeof (GC) * 7); |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
378 XGetGCValues (FRAME_X_DISPLAY (f), s->gc, mask, &xgcv); |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
379 if (ftxfont_create_gcs (f, gcs, xgcv.foreground, xgcv.background) < 0) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
380 gcs = NULL; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
381 gcs[6] = s->gc; |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
382 } |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
383 |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
384 if (! gcs) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
385 { |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
386 /* We are drawing with a bitmap font which doesn't use |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
387 antialiasing. */ |
90400 | 388 for (i = 0; i < len; i++) |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
389 x += ftxfont_draw_bitmap (f, &s->gc, font, code[i], x, y, |
90400 | 390 p, 0x700, n); |
391 if (n[0] > 0) | |
392 XDrawPoints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
393 s->gc, p, n[0], CoordModeOrigin); |
90400 | 394 } |
395 else | |
396 { | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
397 /* We are drawing with a scalable font which use |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
398 antialiasing. */ |
90400 | 399 for (i = 0; i < len; i++) |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
400 x += ftxfont_draw_bitmap (f, gcs, font, code[i], x, y, |
90400 | 401 p, 0x100, n); |
402 for (i = 0; i < 7; i++) | |
403 if (n[i] > 0) | |
404 XDrawPoints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
90554
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
405 gcs[i], p + 0x100 * i, n[i], CoordModeOrigin); |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
406 if (face->gc != s->gc) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
407 for (i = 0; i < 6; i++) |
d0351223b22a
(ftxfont_create_gcs): New function.
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
408 XFreeGC (FRAME_X_DISPLAY (f), gcs[i]); |
90400 | 409 } |
410 | |
411 UNBLOCK_INPUT; | |
412 | |
413 return len; | |
414 } | |
415 | |
416 | |
417 | |
418 void | |
419 syms_of_ftxfont () | |
420 { | |
421 DEFSYM (Qftx, "ftx"); | |
422 | |
423 ftxfont_driver = ftfont_driver; | |
424 ftxfont_driver.type = Qftx; | |
425 ftxfont_driver.list = ftxfont_list; | |
90560
c443c8a56b84
(ftxfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90554
diff
changeset
|
426 ftxfont_driver.match = ftxfont_match; |
90400 | 427 ftxfont_driver.open = ftxfont_open; |
428 ftxfont_driver.close = ftxfont_close; | |
429 ftxfont_driver.prepare_face = ftxfont_prepare_face; | |
430 ftxfont_driver.done_face = ftxfont_done_face; | |
431 ftxfont_driver.draw = ftxfont_draw; | |
432 | |
433 register_font_driver (&ftxfont_driver, NULL); | |
434 } | |
90427 | 435 |
436 /* arch-tag: 59bd3469-5330-413f-b29d-1aa36492abe8 | |
437 (do not change this comment) */ |