Mercurial > emacs
comparison src/font.h @ 90400:80fff33f74f5
New file.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 06 Jun 2006 03:47:13 +0000 |
parents | |
children | ddb25860d044 |
comparison
equal
deleted
inserted
replaced
90399:a5812696f7bf | 90400:80fff33f74f5 |
---|---|
1 /* font.h -- Interface definition for font handling. | |
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 #ifndef EMACS_FONT_H | |
25 #define EMACS_FONT_H | |
26 | |
27 #include "ccl.h" | |
28 | |
29 /* We have three types of Lisp objects related to font. | |
30 | |
31 FONT-SPEC | |
32 | |
33 Vector (length FONT_SPEC_MAX) of font properties. Some | |
34 properties can be left unspecified (i.e. nil). Emacs asks | |
35 font-drivers to find a font by FONT-SPEC. A fontset entry | |
36 specifies requisite properties whereas a face specifies just | |
37 preferable properties. This object is fully modifiable by | |
38 Lisp. | |
39 | |
40 FONT-ENTITY | |
41 | |
42 Vector (length FONT_ENTITY_MAX) of fully specified font | |
43 properties that a font-driver returns upon a request of | |
44 FONT-SPEC. | |
45 | |
46 Note: Only the method `list' of a font-driver can create this | |
47 object, and should never be modified by Lisp. In that sense, | |
48 it may be cleaner to implement it as a Lisp object of a new | |
49 type (e.g. struct Lisp_Font). | |
50 | |
51 FONT-OBJECT | |
52 | |
53 Lisp object of type Lisp_Misc_Save_Value encapsulating a | |
54 pointer to "struct font". This corresponds to an opened font. | |
55 | |
56 Note: The note for FONT-ENTITY also applies to this. | |
57 */ | |
58 | |
59 | |
60 struct font_driver; | |
61 struct font; | |
62 | |
63 /* An enumerator for each font property. This is used as an index to | |
64 the vector of FONT-SPEC and FONT-ENTITY. | |
65 | |
66 Note: The order is important and should not be changed. */ | |
67 | |
68 enum font_property_index | |
69 { | |
70 /* FONT-TYPE is a symbol indicating a font backend; currently `x', | |
71 `xft', `ftx', `freetype' are available. For windows, we need | |
72 `bdf' and `windows'. For Mac OS X, we need `atm'. */ | |
73 FONT_TYPE_INDEX, | |
74 | |
75 /* FONT-FOUNDRY is a foundry name (symbol). */ | |
76 FONT_FOUNDRY_INDEX, | |
77 | |
78 /* FONT-FAMILY is a family name (symbol). */ | |
79 FONT_FAMILY_INDEX, | |
80 | |
81 /* FONT-ADSTYLE is an additional style name (symbol). */ | |
82 FONT_ADSTYLE_INDEX, | |
83 | |
84 /* FONT-REGISTRY is a combination of a charset-registry and | |
85 charset0encoding name (symbol). */ | |
86 FONT_REGISTRY_INDEX, | |
87 | |
88 /* FONT-WEIGHT is a numeric value of weight (e.g. medium, bold) of | |
89 the font. The value is what defined by FC_WEIGHT_* in | |
90 fontconfig. */ | |
91 FONT_WEIGHT_INDEX, | |
92 | |
93 /* FONT-SLANT is a numeric value of slant (e.g. r, i, o) of the | |
94 font. The value is what defined by FC_SLANT_* in | |
95 fontconfig plus 100. */ | |
96 FONT_SLANT_INDEX, | |
97 | |
98 /* FONT-WIDTH is a numeric value of setwidth (e.g. normal, | |
99 condensed) of the font. The value is what defined by | |
100 FC_WIDTH_* in fontconfig. */ | |
101 FONT_WIDTH_INDEX, | |
102 | |
103 /* FONT-SIZE is a size of the font. If integer, it is a pixel | |
104 size. For a font-spec, the value can be float specifying a | |
105 point size. For a font-entity, the value can be zero meaning | |
106 that the font is scalable. */ | |
107 FONT_SIZE_INDEX, | |
108 | |
109 /* In a font-spec, the value is an alist of extra information of a | |
110 font such as name, OpenType features, and language coverage. | |
111 In a font-entity, the value is an extra infomation for | |
112 identifying a font (font-driver dependent). */ | |
113 FONT_EXTRA_INDEX, /* alist alist */ | |
114 | |
115 /* This value is the length of font-spec vector. */ | |
116 FONT_SPEC_MAX, | |
117 | |
118 /* The followings are used only for a font-entity. */ | |
119 | |
120 /* Frame on which the font is found. The value is nil if the font | |
121 can be opend on any frame. */ | |
122 FONT_FRAME_INDEX = FONT_SPEC_MAX, | |
123 | |
124 /* List of font-objects opened from the font-entity. */ | |
125 FONT_OBJLIST_INDEX, | |
126 | |
127 /* This value is the length of font-entity vector. */ | |
128 FONT_ENTITY_MAX | |
129 }; | |
130 | |
131 extern Lisp_Object QCotf, QClanguage, QCscript; | |
132 | |
133 extern Lisp_Object null_string; | |
134 extern Lisp_Object null_vector; | |
135 | |
136 /* Structure for an opened font. We can safely cast this structure to | |
137 "struft font_info". */ | |
138 | |
139 struct font | |
140 { | |
141 struct font_info font; | |
142 | |
143 /* From which font-entity the font is opened. */ | |
144 Lisp_Object entity; | |
145 | |
146 /* By which pixel size the font is opened. */ | |
147 int pixel_size; | |
148 | |
149 /* Font-driver for the font. */ | |
150 struct font_driver *driver; | |
151 | |
152 /* File name of the font, or NULL if the font is not associated with | |
153 a file. */ | |
154 char *file_name; | |
155 | |
156 /* Charset to encode a character code into a glyph code of the | |
157 font. */ | |
158 int encoding_charset; | |
159 | |
160 /* Charset to check if a character code is supported by the font. | |
161 -1 means that the contents of the font must be looked up to | |
162 determine it. | |
163 */ | |
164 int repertory_charet; | |
165 | |
166 /* Minimum glyph width (in pixels). */ | |
167 int min_width; | |
168 | |
169 /* Ascent and descent of the font (in pixels). */ | |
170 int ascent, descent; | |
171 | |
172 /* There will be more to this structure, but they are private to a | |
173 font-driver. */ | |
174 }; | |
175 | |
176 struct font_metrics | |
177 { | |
178 short lbearing, rbearing, width, ascent, descent; | |
179 }; | |
180 | |
181 struct font_bitmap | |
182 { | |
183 int rows; | |
184 int width; | |
185 int pitch; | |
186 unsigned char *buffer; | |
187 int left; | |
188 int top; | |
189 int advance; | |
190 void *extra; | |
191 }; | |
192 | |
193 /* Predicates to check various font-related objects. */ | |
194 | |
195 #define FONTP(x) \ | |
196 (VECTORP (x) && (ASIZE (x) == FONT_SPEC_MAX || ASIZE (x) == FONT_ENTITY_MAX)) | |
197 #define FONT_SPEC_P(x) \ | |
198 (VECTORP (x) && ASIZE (x) == FONT_SPEC_MAX) | |
199 #define FONT_ENTITY_P(x) \ | |
200 (VECTORP (x) && ASIZE (x) == FONT_ENTITY_MAX) | |
201 #define FONT_OBJECT_P(x) \ | |
202 (XTYPE (x) == Lisp_Misc && XMISCTYPE (x) == Lisp_Misc_Save_Value) | |
203 | |
204 | |
205 /* Check macros for various font-related objects. */ | |
206 | |
207 #define CHECK_FONT(x) \ | |
208 do { if (! FONTP (x)) x = wrong_type_argument (Qfont, x); } while (0) | |
209 #define CHECK_FONT_SPEC(x) \ | |
210 do { if (! FONT_SPEC_P (x)) x = wrong_type_argument (Qfont, x); } while (0) | |
211 #define CHECK_FONT_ENTITY(x) \ | |
212 do { if (! FONT_ENTITY_P (x)) x = wrong_type_argument (Qfont, x); } while (0) | |
213 #define CHECK_FONT_OBJECT(x) \ | |
214 do { if (! FONT_OBJECT_P (x)) x = wrong_type_argument (Qfont, x); } while (0) | |
215 | |
216 #define CHECK_FONT_GET_OBJECT(x, font) \ | |
217 do { \ | |
218 if (! FONT_OBJECT_P (x)) x = wrong_type_argument (Qfont, x); \ | |
219 if (! XSAVE_VALUE (x)->pointer) error ("Font already closed"); \ | |
220 font = XSAVE_VALUE (x)->pointer; \ | |
221 } while (0) | |
222 | |
223 struct face; | |
224 struct composition; | |
225 | |
226 /* Macros for lispy glyph-string. */ | |
227 #define LGSTRING_FONT(lgs) AREF (AREF ((lgs), 0), 0) | |
228 #define LGSTRING_LBEARING(lgs) AREF (AREF ((lgs), 0), 1) | |
229 #define LGSTRING_RBEARING(lgs) AREF (AREF ((lgs), 0), 2) | |
230 #define LGSTRING_WIDTH(lgs) AREF (AREF ((lgs), 0), 3) | |
231 #define LGSTRING_ASCENT(lgs) AREF (AREF ((lgs), 0), 4) | |
232 #define LGSTRING_DESCENT(lgs) AREF (AREF ((lgs), 0), 5) | |
233 #define LGSTRING_SET_FONT(lgs, val) ASET (AREF ((lgs), 0), 0, (val)) | |
234 #define LGSTRING_SET_LBEARING(lgs, val) ASET (AREF ((lgs), 0), 1, (val)) | |
235 #define LGSTRING_SET_RBEARING(lgs, val) ASET (AREF ((lgs), 0), 2, (val)) | |
236 #define LGSTRING_SET_WIDTH(lgs, val) ASET (AREF ((lgs), 0), 3, (val)) | |
237 #define LGSTRING_SET_ASCENT(lgs, val) ASET (AREF ((lgs), 0), 4, (val)) | |
238 #define LGSTRING_SET_DESCENT(lgs, val) ASET (AREF ((lgs), 0), 5, (val)) | |
239 | |
240 #define LGSTRING_LENGTH(lgs) (ASIZE ((lgs)) - 1) | |
241 #define LGSTRING_GLYPH(lgs, idx) AREF ((lgs), (idx) + 1) | |
242 | |
243 #define LGLYPH_CHAR(g) AREF ((g), 2) | |
244 #define LGLYPH_CODE(g) AREF ((g), 3) | |
245 #define LGLYPH_XOFF(g) AREF ((g), 4) | |
246 #define LGLYPH_YOFF(g) AREF ((g), 5) | |
247 #define LGLYPH_WIDTH(g) AREF ((g), 6) | |
248 #define LGLYPH_WADJUST(g) AREF ((g), 7) | |
249 #define LGLYPH_SET_CHAR(g, val) ASET ((g), 2, (val)) | |
250 #define LGLYPH_SET_CODE(g, val) ASET ((g), 3, (val)) | |
251 #define LGLYPH_SET_XOFF(g, val) ASET ((g), 4, (val)) | |
252 #define LGLYPH_SET_YOFF(g, val) ASET ((g), 5, (val)) | |
253 #define LGLYPH_SET_WIDTH(g, val) ASET ((g), 6, (val)) | |
254 #define LGLYPH_SET_WADJUST(g, val) ASET ((g), 7, (val)) | |
255 | |
256 #define FONT_INVALID_CODE 0xFFFFFFFF | |
257 | |
258 struct font_driver | |
259 { | |
260 /* Symbol indicating the type of the font-driver. */ | |
261 Lisp_Object type; | |
262 | |
263 /* Return a cache of font-entities on FRAME. The cache must be a | |
264 cons whose cdr part is the actual cache area. */ | |
265 Lisp_Object (*get_cache) P_ ((Lisp_Object frame)); | |
266 | |
267 /* Parse font name NAME, store the font properties in SPEC, and | |
268 return 0. If the font-driver can't parse NAME, return -1. */ | |
269 int (*parse_name) P_ ((FRAME_PTR f, char *name, Lisp_Object spec)); | |
270 | |
271 /* List fonts matching with FONT_SPEC on FRAME. The value is a | |
272 vector of font-entities. This is the sole API that allocates | |
273 font-entities. */ | |
274 Lisp_Object (*list) P_ ((Lisp_Object frame, Lisp_Object font_spec)); | |
275 | |
276 /* List available families. The value is a list of family names | |
277 (symbols). The method can be NULL if the driver doesn't support | |
278 this facility. */ | |
279 Lisp_Object (*list_family) P_ ((Lisp_Object frame)); | |
280 | |
281 /* Free FONT_EXTRA_INDEX field of FONT_ENTITY. This method can be | |
282 NULL if FONT_EXTRA_INDEX of FONT_ENTITY is a normal Lisp object | |
283 (i.e. not Lisp_Save_Value). */ | |
284 void (*free_entity) P_ ((Lisp_Object font_entity)); | |
285 | |
286 /* Open a font specified by FONT_ENTITY on frame F. If the font is | |
287 scalable, open it with PIXEL_SIZE. */ | |
288 struct font *(*open) P_ ((FRAME_PTR f, Lisp_Object font_entity, | |
289 int pixel_size)); | |
290 | |
291 /* Close FONT on frame F. */ | |
292 void (*close) P_ ((FRAME_PTR f, struct font *font)); | |
293 | |
294 /* Prepare FACE for displaying characters by FONT on frame F. If | |
295 successful, return 0. Otherwise, return -1. This method can be | |
296 NULL if there's nothing to do. */ | |
297 int (*prepare_face) P_ ((FRAME_PTR f, struct face *face)); | |
298 | |
299 /* Done FACE for displaying characters by FACE->font on frame F. | |
300 This method can be NULL if there's nothing to do. */ | |
301 void (*done_face) P_ ((FRAME_PTR f, struct face *face)); | |
302 | |
303 /* If FONT_ENTITY has a glyph for character C, return 1. If not, | |
304 return 0. If a font must be opened to check it, return -1. This | |
305 method can be NULL if the driver always requires a font to be | |
306 opened for this check. In that case, we must open a font and use | |
307 `encode_char' method. */ | |
308 int (*has_char) P_ ((Lisp_Object entity, int c)); | |
309 | |
310 /* Return a glyph code of FONT for characer C. If FONT doesn't have | |
311 such a glyph, return FONT_INVALID_CODE. */ | |
312 unsigned (*encode_char) P_ ((struct font *font, int c)); | |
313 | |
314 /* Perform the size computation of glyphs of FONT and fillin members | |
315 of METRICS. The glyphs are specified by their glyph codes in | |
316 CODE (length NGLYPHS). */ | |
317 int (*text_extents) P_ ((struct font *font, | |
318 unsigned *code, int nglyphs, | |
319 struct font_metrics *metrics)); | |
320 | |
321 /* Draw glyphs between FROM and TO of S->char2b at (X Y) pixel | |
322 position of frame F with S->FACE and S->GC. If WITH_BACKGROUND | |
323 is nonzero, fill the background in advance. It is assured that | |
324 WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */ | |
325 int (*draw) P_ ((struct glyph_string *s, int from, int to, | |
326 int x, int y, int with_background)); | |
327 | |
328 /* Store bitmap data for glyph-code CODE of FONT in BITMAP. This | |
329 method can be NULL if the driver doesn't support this facility. | |
330 It is intended that this method is callled from the other | |
331 font-driver for actual drawing. */ | |
332 int (*get_bitmap) P_ ((struct font *font, unsigned code, | |
333 struct font_bitmap *bitmap, | |
334 int bits_per_pixel)); | |
335 | |
336 /* Free bitmap data in BITMAP. This method can be NULL if no data | |
337 have to be freed. */ | |
338 void (*free_bitmap) P_ ((struct font *font, struct font_bitmap *bitmap)); | |
339 | |
340 /* Return an outline data for glyph-code CODE of FONT. The format | |
341 of the outline data depends on the font-driver. This method can | |
342 be NULL if the driver doesn't support this facility. */ | |
343 void *(*get_outline) P_ ((struct font *font, unsigned code)); | |
344 | |
345 /* Free OUTLINE (that is obtained by the above method). */ | |
346 void (*free_outline) P_ ((struct font *font, void *outline)); | |
347 | |
348 /* Get coordinates of the INDEXth anchor point of the glyph whose | |
349 code is CODE. Store the coordinates in *X and *Y. Return 0 if | |
350 the operations was successfull. Otherwise return -1. This | |
351 method can be NULL if the driver doesn't support this | |
352 facility. */ | |
353 int (*anchor_point) P_ ((struct font *font, unsigned code, int index, | |
354 int *x, int *y)); | |
355 | |
356 /* Return a list describing which scripts/languages FONT | |
357 supports by which GSUB/GPOS features of OpenType tables. */ | |
358 Lisp_Object (*otf_capability) P_ ((struct font *font)); | |
359 | |
360 /* Drive FONT's OTF GSUB features according to GSUB_SPEC. | |
361 | |
362 GSUB_SPEC is in this format (all elements are symbols): | |
363 (SCRIPT LANGSYS GSUB-FEATURE ...) | |
364 If one of GSUB-FEATURE is nil, apply all gsub features except for | |
365 already applied and listed later. For instance, if the font has | |
366 GSUB features nukt, haln, rphf, blwf, and half, | |
367 (deva nil nukt haln nil rphf) | |
368 applies nukt and haln in this order, then applies blwf and half | |
369 in the order apearing in the font. The features are of the | |
370 default langsys of `deva' script. | |
371 | |
372 This method applies the specified features to the codes in the | |
373 elements of GSTRING-IN (between FROMth and TOth). The output | |
374 codes are stored in GSTRING-OUT at the IDXth element and the | |
375 following elements. | |
376 | |
377 Return the number of output codes. If none of the features are | |
378 applicable to the input data, return 0. If GSTRING-OUT is too | |
379 short, return -1. */ | |
380 int (*otf_gsub) P_ ((struct font *font, Lisp_Object gsub_spec, | |
381 Lisp_Object gstring_in, int from, int to, | |
382 Lisp_Object gstring_out, int idx)); | |
383 | |
384 /* Drive FONT's OTF GPOS features according to GPOS_SPEC. | |
385 | |
386 GPOS_SPEC is in this format (all elements are symbols): | |
387 (SCRIPT LANGSYS GPOS-FEATURE ...) | |
388 The meaning is the same as GSUB_SPEC above. | |
389 | |
390 This method applies the specified features to the codes in the | |
391 elements of GSTRING (between FROMth and TOth). The resulting | |
392 positioning information (x-offset and y-offset) is stored in the | |
393 slots of the elements. | |
394 | |
395 Return 1 if at least one glyph has nonzero x-offset or y-offset. | |
396 Otherwise return 0. */ | |
397 int (*otf_gpos) P_ ((struct font *font, Lisp_Object gpos_spec, | |
398 Lisp_Object gstring, int from, int to)); | |
399 }; | |
400 | |
401 | |
402 struct font_driver_list | |
403 { | |
404 struct font_driver *driver; | |
405 struct font_driver_list *next; | |
406 }; | |
407 | |
408 extern int enable_font_backend; | |
409 | |
410 EXFUN (Ffont_spec, MANY); | |
411 | |
412 extern Lisp_Object font_symbolic_weight P_ ((Lisp_Object font)); | |
413 extern Lisp_Object font_symbolic_slant P_ ((Lisp_Object font)); | |
414 extern Lisp_Object font_symbolic_width P_ ((Lisp_Object font)); | |
415 | |
416 extern Lisp_Object font_find_object P_ ((struct font *font)); | |
417 extern char *font_get_name P_ ((Lisp_Object)); | |
418 extern Lisp_Object font_get_frame P_ ((Lisp_Object font)); | |
419 extern int font_has_char P_ ((FRAME_PTR, Lisp_Object, int)); | |
420 extern unsigned font_encode_char P_ ((Lisp_Object, int)); | |
421 | |
422 extern int font_set_lface_from_name P_ ((FRAME_PTR f, | |
423 Lisp_Object lface, | |
424 Lisp_Object fontname, | |
425 int force_p, int may_fail_p)); | |
426 extern Lisp_Object font_find_for_lface P_ ((FRAME_PTR f, Lisp_Object *lface, | |
427 Lisp_Object spec)); | |
428 extern Lisp_Object font_open_for_lface P_ ((FRAME_PTR f, Lisp_Object *lface, | |
429 Lisp_Object entity)); | |
430 extern void font_load_for_face P_ ((FRAME_PTR f, struct face *face)); | |
431 extern void font_prepare_for_face P_ ((FRAME_PTR f, struct face *face)); | |
432 extern Lisp_Object font_open_by_name P_ ((FRAME_PTR f, char *name)); | |
433 | |
434 extern Lisp_Object intern_downcase P_ ((char *str, int len)); | |
435 extern void font_update_sort_order P_ ((int *order)); | |
436 | |
437 extern void font_parse_old_font_spec P_ ((Lisp_Object, Lisp_Object, | |
438 Lisp_Object, Lisp_Object)); | |
439 | |
440 | |
441 extern int font_parse_xlfd P_ ((char *name, Lisp_Object font, int merge)); | |
442 extern int font_unparse_xlfd P_ ((Lisp_Object font, int pixel_size, | |
443 char *name, int bytes)); | |
444 extern void register_font_driver P_ ((struct font_driver *driver, FRAME_PTR f)); | |
445 extern void free_font_driver_list P_ ((FRAME_PTR f)); | |
446 | |
447 extern struct font *font_prepare_composition P_ ((struct composition *cmp)); | |
448 | |
449 | |
450 #ifdef HAVE_LIBOTF | |
451 /* This can be used as `otf_capability' method of a font-driver. */ | |
452 extern Lisp_Object font_otf_capability P_ ((struct font *font)); | |
453 /* This can be used as `otf_gsub' method of a font-driver. */ | |
454 extern int font_otf_gsub P_ ((struct font *font, Lisp_Object gsub_spec, | |
455 Lisp_Object gstring_in, int from, int to, | |
456 Lisp_Object gstring_out, int idx)); | |
457 /* This can be used as `otf_gpos' method of a font-driver. */ | |
458 extern int font_otf_gpos P_ ((struct font *font, Lisp_Object gpos_spec, | |
459 Lisp_Object gstring, int from, int to)); | |
460 #endif /* HAVE_LIBOTF */ | |
461 | |
462 #ifdef HAVE_FREETYPE | |
463 extern struct font_driver ftfont_driver; | |
464 #endif /* HAVE_FREETYPE */ | |
465 #ifdef HAVE_X_WINDOWS | |
466 extern struct font_driver xfont_driver; | |
467 extern struct font_driver ftxfont_driver; | |
468 #ifdef HAVE_XFT | |
469 extern struct font_driver xftfont_driver; | |
470 #endif /* HAVE_XFT */ | |
471 #endif /* HAVE_X_WINDOWS */ | |
472 #ifdef WINDOWSNT | |
473 extern struct font_driver w32font_driver; | |
474 #endif /* WINDOWSNT */ | |
475 #ifdef MAC_OS | |
476 extern struct font_driver atmfont_driver; | |
477 #endif /* MAC_OS */ | |
478 | |
479 #endif /* not EMACS_FONT_H */ |