*** empty log message ***
[bpt/emacs.git] / src / font.h
CommitLineData
c2f5bfd6
KH
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
7This file is part of GNU Emacs.
8
9GNU Emacs is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2, or (at your option)
12any later version.
13
14GNU Emacs is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with GNU Emacs; see the file COPYING. If not, write to
21the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22Boston, 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
60struct font_driver;
61struct 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
68enum 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
a46bb06e 131extern Lisp_Object QCspacing, QCdpi, QCscalable, QCotf, QClanguage, QCscript;
c2f5bfd6 132
3223c449
KH
133/* Important character set symbols. */
134extern Lisp_Object Qiso8859_1, Qiso10646_1, Qunicode_bmp;
135
c2f5bfd6
KH
136extern Lisp_Object null_string;
137extern Lisp_Object null_vector;
138
139/* Structure for an opened font. We can safely cast this structure to
140 "struft font_info". */
141
142struct font
143{
144 struct font_info font;
145
146 /* From which font-entity the font is opened. */
147 Lisp_Object entity;
148
149 /* By which pixel size the font is opened. */
150 int pixel_size;
151
152 /* Font-driver for the font. */
153 struct font_driver *driver;
154
155 /* File name of the font, or NULL if the font is not associated with
156 a file. */
157 char *file_name;
158
159 /* Charset to encode a character code into a glyph code of the
160 font. */
161 int encoding_charset;
162
163 /* Charset to check if a character code is supported by the font.
164 -1 means that the contents of the font must be looked up to
165 determine it.
166 */
e2a3f5b2 167 int repertory_charset;
c2f5bfd6
KH
168
169 /* Minimum glyph width (in pixels). */
170 int min_width;
171
172 /* Ascent and descent of the font (in pixels). */
173 int ascent, descent;
174
175 /* There will be more to this structure, but they are private to a
176 font-driver. */
177};
178
f8657b39
KH
179enum font_spacing
180 {
181 FONT_SPACING_PROPORTIONAL = 0,
182 FONT_SPACING_DUAL = 90,
183 FONT_SPACING_MONO = 100,
184 FONT_SPACING_CHARCELL = 110
185 };
186
c2f5bfd6
KH
187struct font_metrics
188{
189 short lbearing, rbearing, width, ascent, descent;
190};
191
192struct font_bitmap
193{
194 int rows;
195 int width;
196 int pitch;
197 unsigned char *buffer;
198 int left;
199 int top;
200 int advance;
201 void *extra;
202};
203
204/* Predicates to check various font-related objects. */
205
206#define FONTP(x) \
207 (VECTORP (x) && (ASIZE (x) == FONT_SPEC_MAX || ASIZE (x) == FONT_ENTITY_MAX))
208#define FONT_SPEC_P(x) \
209 (VECTORP (x) && ASIZE (x) == FONT_SPEC_MAX)
210#define FONT_ENTITY_P(x) \
211 (VECTORP (x) && ASIZE (x) == FONT_ENTITY_MAX)
212#define FONT_OBJECT_P(x) \
213 (XTYPE (x) == Lisp_Misc && XMISCTYPE (x) == Lisp_Misc_Save_Value)
214
215
216/* Check macros for various font-related objects. */
217
218#define CHECK_FONT(x) \
219 do { if (! FONTP (x)) x = wrong_type_argument (Qfont, x); } while (0)
220#define CHECK_FONT_SPEC(x) \
221 do { if (! FONT_SPEC_P (x)) x = wrong_type_argument (Qfont, x); } while (0)
222#define CHECK_FONT_ENTITY(x) \
223 do { if (! FONT_ENTITY_P (x)) x = wrong_type_argument (Qfont, x); } while (0)
224#define CHECK_FONT_OBJECT(x) \
225 do { if (! FONT_OBJECT_P (x)) x = wrong_type_argument (Qfont, x); } while (0)
226
227#define CHECK_FONT_GET_OBJECT(x, font) \
228 do { \
229 if (! FONT_OBJECT_P (x)) x = wrong_type_argument (Qfont, x); \
230 if (! XSAVE_VALUE (x)->pointer) error ("Font already closed"); \
231 font = XSAVE_VALUE (x)->pointer; \
232 } while (0)
233
f8657b39
KH
234/* Ignore the difference of font pixel sizes less than or equal to
235 this value. */
236#define FONT_PIXEL_SIZE_QUANTUM 1
237
c2f5bfd6
KH
238struct face;
239struct composition;
240
241/* Macros for lispy glyph-string. */
242#define LGSTRING_FONT(lgs) AREF (AREF ((lgs), 0), 0)
243#define LGSTRING_LBEARING(lgs) AREF (AREF ((lgs), 0), 1)
244#define LGSTRING_RBEARING(lgs) AREF (AREF ((lgs), 0), 2)
245#define LGSTRING_WIDTH(lgs) AREF (AREF ((lgs), 0), 3)
246#define LGSTRING_ASCENT(lgs) AREF (AREF ((lgs), 0), 4)
247#define LGSTRING_DESCENT(lgs) AREF (AREF ((lgs), 0), 5)
248#define LGSTRING_SET_FONT(lgs, val) ASET (AREF ((lgs), 0), 0, (val))
249#define LGSTRING_SET_LBEARING(lgs, val) ASET (AREF ((lgs), 0), 1, (val))
250#define LGSTRING_SET_RBEARING(lgs, val) ASET (AREF ((lgs), 0), 2, (val))
251#define LGSTRING_SET_WIDTH(lgs, val) ASET (AREF ((lgs), 0), 3, (val))
252#define LGSTRING_SET_ASCENT(lgs, val) ASET (AREF ((lgs), 0), 4, (val))
253#define LGSTRING_SET_DESCENT(lgs, val) ASET (AREF ((lgs), 0), 5, (val))
254
255#define LGSTRING_LENGTH(lgs) (ASIZE ((lgs)) - 1)
256#define LGSTRING_GLYPH(lgs, idx) AREF ((lgs), (idx) + 1)
257
258#define LGLYPH_CHAR(g) AREF ((g), 2)
259#define LGLYPH_CODE(g) AREF ((g), 3)
260#define LGLYPH_XOFF(g) AREF ((g), 4)
261#define LGLYPH_YOFF(g) AREF ((g), 5)
262#define LGLYPH_WIDTH(g) AREF ((g), 6)
263#define LGLYPH_WADJUST(g) AREF ((g), 7)
264#define LGLYPH_SET_CHAR(g, val) ASET ((g), 2, (val))
265#define LGLYPH_SET_CODE(g, val) ASET ((g), 3, (val))
266#define LGLYPH_SET_XOFF(g, val) ASET ((g), 4, (val))
267#define LGLYPH_SET_YOFF(g, val) ASET ((g), 5, (val))
268#define LGLYPH_SET_WIDTH(g, val) ASET ((g), 6, (val))
269#define LGLYPH_SET_WADJUST(g, val) ASET ((g), 7, (val))
270
271#define FONT_INVALID_CODE 0xFFFFFFFF
272
217caa37
KH
273/* Font driver. Members specified as "optional" can be NULL. */
274
c2f5bfd6
KH
275struct font_driver
276{
277 /* Symbol indicating the type of the font-driver. */
278 Lisp_Object type;
279
280 /* Return a cache of font-entities on FRAME. The cache must be a
281 cons whose cdr part is the actual cache area. */
282 Lisp_Object (*get_cache) P_ ((Lisp_Object frame));
283
c2f5bfd6
KH
284 /* List fonts matching with FONT_SPEC on FRAME. The value is a
285 vector of font-entities. This is the sole API that allocates
286 font-entities. */
287 Lisp_Object (*list) P_ ((Lisp_Object frame, Lisp_Object font_spec));
288
217caa37
KH
289 /* Optional.
290 List available families. The value is a list of family names
291 (symbols). */
c2f5bfd6
KH
292 Lisp_Object (*list_family) P_ ((Lisp_Object frame));
293
217caa37
KH
294 /* Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value).
295 Free FONT_EXTRA_INDEX field of FONT_ENTITY. */
c2f5bfd6
KH
296 void (*free_entity) P_ ((Lisp_Object font_entity));
297
298 /* Open a font specified by FONT_ENTITY on frame F. If the font is
299 scalable, open it with PIXEL_SIZE. */
300 struct font *(*open) P_ ((FRAME_PTR f, Lisp_Object font_entity,
301 int pixel_size));
302
303 /* Close FONT on frame F. */
304 void (*close) P_ ((FRAME_PTR f, struct font *font));
305
217caa37
KH
306 /* Optional (if FACE->extra is not used).
307 Prepare FACE for displaying characters by FONT on frame F by
308 storing some data in FACE->extra. If successful, return 0.
309 Otherwise, return -1. */
c2f5bfd6
KH
310 int (*prepare_face) P_ ((FRAME_PTR f, struct face *face));
311
217caa37
KH
312 /* Optional.
313 Done FACE for displaying characters by FACE->font on frame F. */
c2f5bfd6
KH
314 void (*done_face) P_ ((FRAME_PTR f, struct face *face));
315
217caa37
KH
316 /* Optional.
317 If FONT_ENTITY has a glyph for character C (Unicode code point),
318 return 1. If not, return 0. If a font must be opened to check
319 it, return -1. */
c2f5bfd6
KH
320 int (*has_char) P_ ((Lisp_Object entity, int c));
321
217caa37
KH
322 /* Return a glyph code of FONT for characer C (Unicode code point).
323 If FONT doesn't have such a glyph, return FONT_INVALID_CODE. */
c2f5bfd6
KH
324 unsigned (*encode_char) P_ ((struct font *font, int c));
325
326 /* Perform the size computation of glyphs of FONT and fillin members
327 of METRICS. The glyphs are specified by their glyph codes in
328 CODE (length NGLYPHS). */
329 int (*text_extents) P_ ((struct font *font,
330 unsigned *code, int nglyphs,
331 struct font_metrics *metrics));
332
217caa37
KH
333 /* Optional.
334 Draw glyphs between FROM and TO of S->char2b at (X Y) pixel
c2f5bfd6
KH
335 position of frame F with S->FACE and S->GC. If WITH_BACKGROUND
336 is nonzero, fill the background in advance. It is assured that
337 WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */
338 int (*draw) P_ ((struct glyph_string *s, int from, int to,
339 int x, int y, int with_background));
340
217caa37
KH
341 /* Optional.
342 Store bitmap data for glyph-code CODE of FONT in BITMAP. It is
343 intended that this method is callled from the other font-driver
344 for actual drawing. */
c2f5bfd6
KH
345 int (*get_bitmap) P_ ((struct font *font, unsigned code,
346 struct font_bitmap *bitmap,
347 int bits_per_pixel));
348
217caa37
KH
349 /* Optional.
350 Free bitmap data in BITMAP. */
c2f5bfd6
KH
351 void (*free_bitmap) P_ ((struct font *font, struct font_bitmap *bitmap));
352
217caa37
KH
353 /* Optional.
354 Return an outline data for glyph-code CODE of FONT. The format
355 of the outline data depends on the font-driver. */
c2f5bfd6
KH
356 void *(*get_outline) P_ ((struct font *font, unsigned code));
357
217caa37
KH
358 /* Optional.
359 Free OUTLINE (that is obtained by the above method). */
c2f5bfd6
KH
360 void (*free_outline) P_ ((struct font *font, void *outline));
361
217caa37
KH
362 /* Optional.
363 Get coordinates of the INDEXth anchor point of the glyph whose
c2f5bfd6 364 code is CODE. Store the coordinates in *X and *Y. Return 0 if
217caa37 365 the operations was successfull. Otherwise return -1. */
c2f5bfd6
KH
366 int (*anchor_point) P_ ((struct font *font, unsigned code, int index,
367 int *x, int *y));
368
217caa37
KH
369 /* Optional.
370 Return a list describing which scripts/languages FONT
c2f5bfd6
KH
371 supports by which GSUB/GPOS features of OpenType tables. */
372 Lisp_Object (*otf_capability) P_ ((struct font *font));
373
217caa37
KH
374 /* Optional.
375 Drive FONT's OTF GSUB features according to GSUB_SPEC.
c2f5bfd6
KH
376
377 GSUB_SPEC is in this format (all elements are symbols):
378 (SCRIPT LANGSYS GSUB-FEATURE ...)
379 If one of GSUB-FEATURE is nil, apply all gsub features except for
380 already applied and listed later. For instance, if the font has
381 GSUB features nukt, haln, rphf, blwf, and half,
382 (deva nil nukt haln nil rphf)
383 applies nukt and haln in this order, then applies blwf and half
384 in the order apearing in the font. The features are of the
385 default langsys of `deva' script.
386
387 This method applies the specified features to the codes in the
388 elements of GSTRING-IN (between FROMth and TOth). The output
389 codes are stored in GSTRING-OUT at the IDXth element and the
390 following elements.
391
392 Return the number of output codes. If none of the features are
393 applicable to the input data, return 0. If GSTRING-OUT is too
394 short, return -1. */
395 int (*otf_gsub) P_ ((struct font *font, Lisp_Object gsub_spec,
396 Lisp_Object gstring_in, int from, int to,
397 Lisp_Object gstring_out, int idx));
398
217caa37
KH
399 /* Optional.
400 Drive FONT's OTF GPOS features according to GPOS_SPEC.
c2f5bfd6
KH
401
402 GPOS_SPEC is in this format (all elements are symbols):
403 (SCRIPT LANGSYS GPOS-FEATURE ...)
404 The meaning is the same as GSUB_SPEC above.
405
406 This method applies the specified features to the codes in the
407 elements of GSTRING (between FROMth and TOth). The resulting
408 positioning information (x-offset and y-offset) is stored in the
409 slots of the elements.
410
411 Return 1 if at least one glyph has nonzero x-offset or y-offset.
412 Otherwise return 0. */
413 int (*otf_gpos) P_ ((struct font *font, Lisp_Object gpos_spec,
414 Lisp_Object gstring, int from, int to));
415};
416
417
418struct font_driver_list
419{
420 struct font_driver *driver;
421 struct font_driver_list *next;
422};
423
424extern int enable_font_backend;
425
426EXFUN (Ffont_spec, MANY);
8d3251f2 427EXFUN (Flist_fonts, 4);
c2f5bfd6
KH
428
429extern Lisp_Object font_symbolic_weight P_ ((Lisp_Object font));
430extern Lisp_Object font_symbolic_slant P_ ((Lisp_Object font));
431extern Lisp_Object font_symbolic_width P_ ((Lisp_Object font));
432
217caa37
KH
433extern int font_match_p P_ ((Lisp_Object spec, Lisp_Object entity));
434
c2f5bfd6 435extern Lisp_Object font_find_object P_ ((struct font *font));
217caa37
KH
436extern Lisp_Object font_get_name P_ ((Lisp_Object font_object));
437extern Lisp_Object font_get_spec P_ ((Lisp_Object font_object));
438extern Lisp_Object font_get_frame P_ ((Lisp_Object font_object));
c2f5bfd6
KH
439extern int font_has_char P_ ((FRAME_PTR, Lisp_Object, int));
440extern unsigned font_encode_char P_ ((Lisp_Object, int));
441
442extern int font_set_lface_from_name P_ ((FRAME_PTR f,
443 Lisp_Object lface,
444 Lisp_Object fontname,
445 int force_p, int may_fail_p));
446extern Lisp_Object font_find_for_lface P_ ((FRAME_PTR f, Lisp_Object *lface,
447 Lisp_Object spec));
448extern Lisp_Object font_open_for_lface P_ ((FRAME_PTR f, Lisp_Object *lface,
449 Lisp_Object entity));
450extern void font_load_for_face P_ ((FRAME_PTR f, struct face *face));
451extern void font_prepare_for_face P_ ((FRAME_PTR f, struct face *face));
452extern Lisp_Object font_open_by_name P_ ((FRAME_PTR f, char *name));
453
454extern Lisp_Object intern_downcase P_ ((char *str, int len));
455extern void font_update_sort_order P_ ((int *order));
456
457extern void font_parse_old_font_spec P_ ((Lisp_Object, Lisp_Object,
458 Lisp_Object, Lisp_Object));
459
460
a46bb06e 461extern int font_parse_xlfd P_ ((char *name, Lisp_Object font));
c2f5bfd6
KH
462extern int font_unparse_xlfd P_ ((Lisp_Object font, int pixel_size,
463 char *name, int bytes));
a46bb06e 464extern int font_parse_fcname P_ ((char *name, Lisp_Object font));
217caa37
KH
465extern int font_unparse_fcname P_ ((Lisp_Object font, int pixel_size,
466 char *name, int bytes));
c2f5bfd6
KH
467extern void register_font_driver P_ ((struct font_driver *driver, FRAME_PTR f));
468extern void free_font_driver_list P_ ((FRAME_PTR f));
469
470extern struct font *font_prepare_composition P_ ((struct composition *cmp));
471
472
473#ifdef HAVE_LIBOTF
474/* This can be used as `otf_capability' method of a font-driver. */
475extern Lisp_Object font_otf_capability P_ ((struct font *font));
476/* This can be used as `otf_gsub' method of a font-driver. */
477extern int font_otf_gsub P_ ((struct font *font, Lisp_Object gsub_spec,
478 Lisp_Object gstring_in, int from, int to,
479 Lisp_Object gstring_out, int idx));
480/* This can be used as `otf_gpos' method of a font-driver. */
481extern int font_otf_gpos P_ ((struct font *font, Lisp_Object gpos_spec,
482 Lisp_Object gstring, int from, int to));
483#endif /* HAVE_LIBOTF */
484
485#ifdef HAVE_FREETYPE
486extern struct font_driver ftfont_driver;
487#endif /* HAVE_FREETYPE */
488#ifdef HAVE_X_WINDOWS
489extern struct font_driver xfont_driver;
490extern struct font_driver ftxfont_driver;
491#ifdef HAVE_XFT
492extern struct font_driver xftfont_driver;
493#endif /* HAVE_XFT */
494#endif /* HAVE_X_WINDOWS */
495#ifdef WINDOWSNT
496extern struct font_driver w32font_driver;
497#endif /* WINDOWSNT */
498#ifdef MAC_OS
499extern struct font_driver atmfont_driver;
500#endif /* MAC_OS */
501
502#endif /* not EMACS_FONT_H */
885b7d09
MB
503
504/* arch-tag: 3b7260c3-5bec-4d6b-a0db-95c1b431b1a2
505 (do not change this comment) */