1 /* ftxfont.c -- FreeType font driver on X (without using XFT).
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 National Institute of Advanced Industrial Science and Technology (AIST)
5 Registration Number H13PRO009
7 This file is part of GNU Emacs.
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)
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.
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. */
29 #include "dispextern.h"
32 #include "blockinput.h"
33 #include "character.h"
38 /* FTX font driver. */
40 static Lisp_Object Qftx
;
42 /* Prototypes for helper function. */
43 static int ftxfont_draw_bitmap
P_ ((FRAME_PTR
, GC
*, struct font
*, unsigned,
44 int, int, XPoint
*, int, int *n
));
45 static void ftxfont_draw_backgrond
P_ ((FRAME_PTR
, struct font
*, GC
,
49 ftxfont_draw_bitmap (f
, gc
, font
, code
, x
, y
, p
, size
, n
)
58 struct font_bitmap bitmap
;
62 if (ftfont_driver
.get_bitmap (font
, code
, &bitmap
, 1) < 0)
64 for (i
= 0, b
= bitmap
.buffer
; i
< bitmap
.rows
;
65 i
++, b
+= bitmap
.pitch
)
69 for (j
= 0; j
< bitmap
.width
; j
++)
70 if (b
[j
/ 8] & (1 << (7 - (j
% 8))))
72 p
[n
[0]].x
= x
+ bitmap
.left
+ j
;
73 p
[n
[0]].y
= y
- bitmap
.top
+ i
;
76 XDrawPoints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
77 gc
[0], p
, size
, CoordModeOrigin
);
84 for (j
= 0; j
< bitmap
.width
; j
++)
86 int idx
= (b
[j
] >> 5) - 1;
90 XPoint
*pp
= p
+ size
* idx
;
92 pp
[n
[idx
]].x
= x
+ bitmap
.left
+ j
;
93 pp
[n
[idx
]].y
= y
- bitmap
.top
+ i
;
94 if (++(n
[idx
]) == 0x100)
96 XDrawPoints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
97 gc
[idx
], pp
, size
, CoordModeOrigin
);
105 if (ftfont_driver
.free_bitmap
)
106 ftfont_driver
.free_bitmap (font
, &bitmap
);
108 return bitmap
.advance
;
112 ftxfont_draw_backgrond (f
, font
, gc
, x
, y
, width
)
120 XGetGCValues (FRAME_X_DISPLAY (f
), gc
,
121 GCForeground
| GCBackground
, &xgcv
);
122 XSetForeground (FRAME_X_DISPLAY (f
), gc
, xgcv
.background
);
123 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
124 x
, y
- font
->ascent
, width
, font
->font
.height
);
125 XSetForeground (FRAME_X_DISPLAY (f
), gc
, xgcv
.foreground
);
128 /* Prototypes for font-driver methods. */
129 static Lisp_Object ftxfont_list
P_ ((Lisp_Object
, Lisp_Object
));
130 static struct font
*ftxfont_open
P_ ((FRAME_PTR
, Lisp_Object
, int));
131 static void ftxfont_close
P_ ((FRAME_PTR
, struct font
*));
132 static int ftxfont_prepare_face (FRAME_PTR
, struct face
*);
133 static void ftxfont_done_face (FRAME_PTR
, struct face
*);
135 static int ftxfont_draw
P_ ((struct glyph_string
*, int, int, int, int, int));
137 struct font_driver ftxfont_driver
;
140 ftxfont_list (frame
, spec
)
144 Lisp_Object val
= ftfont_driver
.list (frame
, spec
);
150 for (i
= 0; i
< ASIZE (val
); i
++)
151 ASET (AREF (val
, i
), FONT_TYPE_INDEX
, Qftx
);
157 ftxfont_open (f
, entity
, pixel_size
)
162 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
164 XFontStruct
*xfont
= malloc (sizeof (XFontStruct
));
168 font
= ftfont_driver
.open (f
, entity
, pixel_size
);
175 xfont
->fid
= FRAME_FONT (f
)->fid
;
176 xfont
->ascent
= font
->ascent
;
177 xfont
->descent
= font
->descent
;
178 xfont
->max_bounds
.width
= font
->font
.size
;
179 xfont
->min_bounds
.width
= font
->min_width
;
180 font
->font
.font
= xfont
;
181 font
->driver
= &ftxfont_driver
;
185 /* Set global flag fonts_changed_p to non-zero if the font loaded
186 has a character with a smaller width than any other character
187 before, or if the font loaded has a smaller height than any other
188 font loaded before. If this happens, it will make a glyph matrix
189 reallocation necessary. */
190 if (dpyinfo
->n_fonts
== 1)
192 dpyinfo
->smallest_font_height
= font
->font
.height
;
193 dpyinfo
->smallest_char_width
= font
->min_width
;
198 if (dpyinfo
->smallest_font_height
> font
->font
.height
)
199 dpyinfo
->smallest_font_height
= font
->font
.height
, fonts_changed_p
|= 1;
200 if (dpyinfo
->smallest_char_width
> font
->min_width
)
201 dpyinfo
->smallest_char_width
= font
->min_width
, fonts_changed_p
|= 1;
208 ftxfont_close (f
, font
)
212 ftfont_driver
.close (f
, font
);
213 FRAME_X_DISPLAY_INFO (f
)->n_fonts
--;
217 ftxfont_prepare_face (f
, face
)
224 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
229 /* Here, we create 6 more GCs to simulate anti-aliasing. */
231 XGetGCValues (FRAME_X_DISPLAY (f
), face
->gc
, mask
, &xgcv
);
232 colors
[0].pixel
= face
->foreground
;
233 colors
[1].pixel
= face
->background
;
234 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, 2);
235 for (i
= 1; i
< 7; i
++)
237 colors
[2].red
= (colors
[0].red
* i
+ colors
[1].red
* (7 - i
)) / 7;
238 colors
[2].green
= (colors
[0].green
* i
+ colors
[1].green
* (7 - i
)) / 7;
239 colors
[2].blue
= (colors
[0].blue
* i
+ colors
[1].blue
* (7 - i
)) / 7;
240 if (! x_alloc_nearest_color (f
, FRAME_X_COLORMAP (f
), &colors
[2]))
242 xgcv
.foreground
= colors
[2].pixel
;
243 gc
[i
- 1] = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
250 face
->extra
= malloc (sizeof (GC
) * 7);
253 for (i
= 0; i
< 6; i
++)
254 ((GC
*) face
->extra
)[i
] = gc
[i
];
255 ((GC
*) face
->extra
)[i
] = face
->gc
;
260 ftxfont_done_face (f
, face
)
269 for (i
= 0; i
< 7; i
++)
270 XFreeGC (FRAME_X_DISPLAY (f
), ((GC
*) face
->extra
)[i
]);
278 ftxfont_draw (s
, from
, to
, x
, y
, with_background
)
279 struct glyph_string
*s
;
280 int from
, to
, x
, y
, with_background
;
283 struct face
*face
= s
->face
;
284 struct font
*font
= (struct font
*) face
->font
;
291 n
[0] = n
[1] = n
[2] = n
[3] = n
[4] = n
[5] = n
[6] = 0;
296 ftxfont_draw_backgrond (f
, font
, s
->gc
, x
, y
, s
->width
);
297 code
= alloca (sizeof (unsigned) * len
);
298 for (i
= 0; i
< len
; i
++)
299 code
[i
] = ((XCHAR2B_BYTE1 (s
->char2b
+ from
+ i
) << 8)
300 | XCHAR2B_BYTE2 (s
->char2b
+ from
+ i
));
304 for (i
= 0; i
< len
; i
++)
305 x
+= ftxfont_draw_bitmap (f
, &face
->gc
, font
, code
[i
], x
, y
,
308 XDrawPoints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
309 face
->gc
, p
, n
[0], CoordModeOrigin
);
313 GC
*gc
= face
->extra
;
315 for (i
= 0; i
< len
; i
++)
316 x
+= ftxfont_draw_bitmap (f
, &face
->gc
, font
, code
[i
], x
, y
,
318 for (i
= 0; i
< 7; i
++)
320 XDrawPoints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
321 gc
[i
], p
+ 0x100 * i
, n
[i
], CoordModeOrigin
);
334 DEFSYM (Qftx
, "ftx");
336 ftxfont_driver
= ftfont_driver
;
337 ftxfont_driver
.type
= Qftx
;
338 ftxfont_driver
.list
= ftxfont_list
;
339 ftxfont_driver
.open
= ftxfont_open
;
340 ftxfont_driver
.close
= ftxfont_close
;
341 ftxfont_driver
.prepare_face
= ftxfont_prepare_face
;
342 ftxfont_driver
.done_face
= ftxfont_done_face
;
343 ftxfont_driver
.draw
= ftxfont_draw
;
345 register_font_driver (&ftxfont_driver
, NULL
);