annotate src/ftxfont.c @ 90491:f894dd8d64ea

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Wed, 21 Jun 2006 01:25:10 +0000
parents ddb25860d044
children d0351223b22a
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 /* ftxfont.c -- FreeType font driver on X (without using XFT).
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 <X11/Xlib.h>
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
27
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
28 #include "lisp.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
29 #include "dispextern.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
30 #include "xterm.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 "blockinput.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
33 #include "character.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
34 #include "charset.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
35 #include "fontset.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
36 #include "font.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
37
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
38 /* FTX font driver. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
39
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
40 static Lisp_Object Qftx;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
41
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
42 /* Prototypes for helper function. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
43 static int ftxfont_draw_bitmap P_ ((FRAME_PTR, GC *, struct font *, unsigned,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
44 int, int, XPoint *, int, int *n));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
45 static void ftxfont_draw_backgrond P_ ((FRAME_PTR, struct font *, GC,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
46 int, int, int));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
47
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
48 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
49 ftxfont_draw_bitmap (f, gc, font, code, x, y, p, size, n)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
50 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
51 GC *gc;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
52 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
53 unsigned code;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
54 int x, y;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
55 XPoint *p;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
56 int size, *n;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
57 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
58 struct font_bitmap bitmap;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
59 unsigned char *b;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
60 int i, j;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
61
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
62 if (ftfont_driver.get_bitmap (font, code, &bitmap, 1) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
63 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
64 for (i = 0, b = bitmap.buffer; i < bitmap.rows;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
65 i++, b += bitmap.pitch)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
66 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
67 if (size > 0x100)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
68 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
69 for (j = 0; j < bitmap.width; j++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
70 if (b[j / 8] & (1 << (7 - (j % 8))))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
71 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
72 p[n[0]].x = x + bitmap.left + j;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
73 p[n[0]].y = y - bitmap.top + i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
74 if (++n[0] == 0x400)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
75 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
76 XDrawPoints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
77 gc[0], p, size, CoordModeOrigin);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
78 n[0] = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
79 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
80 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
81 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
82 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
83 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
84 for (j = 0; j < bitmap.width; j++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
85 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
86 int idx = (b[j] >> 5) - 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
87
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
88 if (idx >= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
89 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
90 XPoint *pp = p + size * idx;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
91
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
92 pp[n[idx]].x = x + bitmap.left + j;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
93 pp[n[idx]].y = y - bitmap.top + i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
94 if (++(n[idx]) == 0x100)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
95 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
96 XDrawPoints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
97 gc[idx], pp, size, CoordModeOrigin);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
98 n[idx] = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
99 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
100 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
101 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
102 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
103 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
104
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
105 if (ftfont_driver.free_bitmap)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
106 ftfont_driver.free_bitmap (font, &bitmap);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
107
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
108 return bitmap.advance;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
109 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
110
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
111 static void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
112 ftxfont_draw_backgrond (f, font, gc, x, y, width)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
113 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
114 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
115 GC gc;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
116 int x, y, width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
117 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
118 XGCValues xgcv;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
119
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
120 XGetGCValues (FRAME_X_DISPLAY (f), gc,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
121 GCForeground | GCBackground, &xgcv);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
122 XSetForeground (FRAME_X_DISPLAY (f), gc, xgcv.background);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
123 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
124 x, y - font->ascent, width, font->font.height);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
125 XSetForeground (FRAME_X_DISPLAY (f), gc, xgcv.foreground);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
126 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
127
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
128 /* Prototypes for font-driver methods. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
129 static Lisp_Object ftxfont_list P_ ((Lisp_Object, Lisp_Object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
130 static struct font *ftxfont_open P_ ((FRAME_PTR, Lisp_Object, int));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
131 static void ftxfont_close P_ ((FRAME_PTR, struct font *));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
132 static int ftxfont_prepare_face (FRAME_PTR, struct face *);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
133 static void ftxfont_done_face (FRAME_PTR, struct face *);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
134
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
135 static int ftxfont_draw P_ ((struct glyph_string *, int, int, int, int, int));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
136
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
137 struct font_driver ftxfont_driver;
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 ftxfont_list (frame, spec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
141 Lisp_Object frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
142 Lisp_Object spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
143 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
144 Lisp_Object val = ftfont_driver.list (frame, spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
145
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
146 if (! NILP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
147 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
148 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
149
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
150 for (i = 0; i < ASIZE (val); i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
151 ASET (AREF (val, i), FONT_TYPE_INDEX, Qftx);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
152 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
153 return val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
154 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
155
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
156 static struct font *
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
157 ftxfont_open (f, entity, pixel_size)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
158 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
159 Lisp_Object entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
160 int pixel_size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
161 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
162 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
163 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
164 XFontStruct *xfont = malloc (sizeof (XFontStruct));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
165
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
166 if (! xfont)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
167 return NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
168 font = ftfont_driver.open (f, entity, pixel_size);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
169 if (! font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
170 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
171 free (xfont);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
172 return NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
173 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
174
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
175 xfont->fid = FRAME_FONT (f)->fid;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
176 xfont->ascent = font->ascent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
177 xfont->descent = font->descent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
178 xfont->max_bounds.width = font->font.size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
179 xfont->min_bounds.width = font->min_width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
180 font->font.font = xfont;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
181 font->driver = &ftxfont_driver;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
182
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
183 dpyinfo->n_fonts++;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
184
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
185 /* Set global flag fonts_changed_p to non-zero if the font loaded
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
186 has a character with a smaller width than any other character
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
187 before, or if the font loaded has a smaller height than any other
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
188 font loaded before. If this happens, it will make a glyph matrix
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
189 reallocation necessary. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
190 if (dpyinfo->n_fonts == 1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
191 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
192 dpyinfo->smallest_font_height = font->font.height;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
193 dpyinfo->smallest_char_width = font->min_width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
194 fonts_changed_p = 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
195 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
196 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
197 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
198 if (dpyinfo->smallest_font_height > font->font.height)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
199 dpyinfo->smallest_font_height = font->font.height, fonts_changed_p |= 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
200 if (dpyinfo->smallest_char_width > font->min_width)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
201 dpyinfo->smallest_char_width = font->min_width, fonts_changed_p |= 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
202 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
203
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
204 return font;
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 static void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
208 ftxfont_close (f, font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
209 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
210 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
211 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
212 ftfont_driver.close (f, font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
213 FRAME_X_DISPLAY_INFO (f)->n_fonts--;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
214 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
215
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
216 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
217 ftxfont_prepare_face (f, face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
218 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
219 struct face *face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
220 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
221 GC gc[6];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
222 XColor colors[3];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
223 XGCValues xgcv;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
224 unsigned long mask = GCForeground | GCBackground | GCGraphicsExposures;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
225 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
226
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
227 face->extra = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
228
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
229 /* Here, we create 6 more GCs to simulate anti-aliasing. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
230 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
231 XGetGCValues (FRAME_X_DISPLAY (f), face->gc, mask, &xgcv);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
232 colors[0].pixel = face->foreground;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
233 colors[1].pixel = face->background;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
234 XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), colors, 2);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
235 for (i = 1; i < 7; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
236 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
237 colors[2].red = (colors[0].red * i + colors[1].red * (7 - i)) / 7;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
238 colors[2].green = (colors[0].green * i + colors[1].green * (7 - i)) / 7;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
239 colors[2].blue = (colors[0].blue * i + colors[1].blue * (7 - i)) / 7;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
240 if (! x_alloc_nearest_color (f, FRAME_X_COLORMAP (f), &colors[2]))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
241 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
242 xgcv.foreground = colors[2].pixel;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
243 gc[i - 1] = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
244 mask, &xgcv);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
245 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
246 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
247
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
248 if (i < 7)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
249 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
250 face->extra = malloc (sizeof (GC) * 7);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
251 if (! face->extra)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
252 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
253 for (i = 0; i < 6; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
254 ((GC *) face->extra)[i] = gc[i];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
255 ((GC *) face->extra)[i] = face->gc;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
256 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
257 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
258
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
259 static void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
260 ftxfont_done_face (f, face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
261 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
262 struct face *face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
263 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
264 if (face->extra)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
265 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
266 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
267
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
268 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
269 for (i = 0; i < 7; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
270 XFreeGC (FRAME_X_DISPLAY (f), ((GC *) face->extra)[i]);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
271 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
272 free (face->extra);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
273 face->extra = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
274 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
275 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
276
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
277 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
278 ftxfont_draw (s, from, to, x, y, with_background)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
279 struct glyph_string *s;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
280 int from, to, x, y, with_background;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
281 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
282 FRAME_PTR f = s->f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
283 struct face *face = s->face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
284 struct font *font = (struct font *) face->font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
285 XPoint p[0x700];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
286 int n[7];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
287 unsigned *code;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
288 int len = to - from;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
289 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
290
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
291 n[0] = n[1] = n[2] = n[3] = n[4] = n[5] = n[6] = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
292
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
293 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
294
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
295 if (with_background)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
296 ftxfont_draw_backgrond (f, font, s->gc, x, y, s->width);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
297 code = alloca (sizeof (unsigned) * len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
298 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
299 code[i] = ((XCHAR2B_BYTE1 (s->char2b + from + i) << 8)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
300 | XCHAR2B_BYTE2 (s->char2b + from + i));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
301
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
302 if (! face->extra)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
303 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
304 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
305 x += ftxfont_draw_bitmap (f, &face->gc, font, code[i], x, y,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
306 p, 0x700, n);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
307 if (n[0] > 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
308 XDrawPoints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
309 face->gc, p, n[0], CoordModeOrigin);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
310 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
311 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
312 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
313 GC *gc = face->extra;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
314
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
315 for (i = 0; i < len; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
316 x += ftxfont_draw_bitmap (f, &face->gc, font, code[i], x, y,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
317 p, 0x100, n);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
318 for (i = 0; i < 7; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
319 if (n[i] > 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
320 XDrawPoints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
321 gc[i], p + 0x100 * i, n[i], CoordModeOrigin);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
322 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
323
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
324 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
325
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
326 return len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
327 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
328
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
329
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
330
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
331 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
332 syms_of_ftxfont ()
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
333 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
334 DEFSYM (Qftx, "ftx");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
335
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
336 ftxfont_driver = ftfont_driver;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
337 ftxfont_driver.type = Qftx;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
338 ftxfont_driver.list = ftxfont_list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
339 ftxfont_driver.open = ftxfont_open;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
340 ftxfont_driver.close = ftxfont_close;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
341 ftxfont_driver.prepare_face = ftxfont_prepare_face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
342 ftxfont_driver.done_face = ftxfont_done_face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
343 ftxfont_driver.draw = ftxfont_draw;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
344
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
345 register_font_driver (&ftxfont_driver, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
346 }
90427
ddb25860d044 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 90400
diff changeset
347
ddb25860d044 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 90400
diff changeset
348 /* arch-tag: 59bd3469-5330-413f-b29d-1aa36492abe8
ddb25860d044 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 90400
diff changeset
349 (do not change this comment) */