1 /* font.h -- Interface definition for font handling.
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 /* We have three types of Lisp objects related to font.
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
42 Vector (length FONT_ENTITY_MAX) of fully specified font
43 properties that a font-driver returns upon a request of
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).
53 Lisp object of type Lisp_Misc_Save_Value encapsulating a
54 pointer to "struct font". This corresponds to an opened font.
56 Note: The note for FONT-ENTITY also applies to this.
63 /* An enumerator for each font property. This is used as an index to
64 the vector of FONT-SPEC and FONT-ENTITY.
66 Note: The order is important and should not be changed. */
68 enum font_property_index
70 /* FONT-TYPE is a symbol indicating a font backend; currently `x',
71 `xft', `ftx', `freetype' are available on X and gdi on Windows.
72 For Windows, we `bdf' and `uniscribe' backends are in progress.
73 For Mac OS X, we need `atm'. */
76 /* FONT-FOUNDRY is a foundry name (symbol). */
79 /* FONT-FAMILY is a family name (symbol). */
82 /* FONT-ADSTYLE is an additional style name (symbol). */
85 /* FONT-REGISTRY is a combination of a charset-registry and
86 charset0encoding name (symbol). */
89 /* FONT-WEIGHT is a numeric value of weight (e.g. medium, bold) of
90 the font. The value is what defined by FC_WEIGHT_* in
94 /* FONT-SLANT is a numeric value of slant (e.g. r, i, o) of the
95 font. The value is what defined by FC_SLANT_* in
96 fontconfig plus 100. */
99 /* FONT-WIDTH is a numeric value of setwidth (e.g. normal,
100 condensed) of the font. The value is what defined by
101 FC_WIDTH_* in fontconfig. */
104 /* FONT-SIZE is a size of the font. If integer, it is a pixel
105 size. For a font-spec, the value can be float specifying a
106 point size. For a font-entity, the value can be zero meaning
107 that the font is scalable. */
110 /* In a font-spec, the value is an alist of extra information of a
111 font such as name, OpenType features, and language coverage.
112 In a font-entity, the value is an extra infomation for
113 identifying a font (font-driver dependent). */
114 FONT_EXTRA_INDEX
, /* alist alist */
116 /* This value is the length of font-spec vector. */
119 /* The followings are used only for a font-entity. */
121 /* Frame on which the font is found. The value is nil if the font
122 can be opend on any frame. */
123 FONT_FRAME_INDEX
= FONT_SPEC_MAX
,
125 /* List of font-objects opened from the font-entity. The value is
126 nil if no font can be opened for this font-entity. */
129 /* This value is the length of font-entity vector. */
133 extern Lisp_Object QCspacing
, QCdpi
, QCscalable
, QCotf
, QClanguage
, QCscript
;
135 /* Important character set symbols. */
136 extern Lisp_Object Qiso8859_1
, Qiso10646_1
, Qunicode_bmp
, Qunicode_sip
;
138 extern Lisp_Object null_string
;
139 extern Lisp_Object null_vector
;
141 /* Structure for an opened font. We can safely cast this structure to
142 "struct font_info". */
146 struct font_info font
;
148 /* From which font-entity the font is opened. */
151 /* By which pixel size the font is opened. */
154 /* Font-driver for the font. */
155 struct font_driver
*driver
;
157 /* Symbol of font font; x, ttf, pcf, etc, */
160 /* File name of the font, or NULL if the font is not associated with
164 /* Charset to encode a character code into a glyph code of the font.
165 -1 means that the font doesn't require this information to encode
167 int encoding_charset
;
169 /* Charset to check if a character code is supported by the font.
170 -1 means that the contents of the font must be looked up to
172 int repertory_charset
;
174 /* Minimum glyph width (in pixels). */
177 /* Ascent and descent of the font (in pixels). */
180 /* 1 iff the font is scalable. */
183 /* There will be more to this structure, but they are private to a
189 FONT_SPACING_PROPORTIONAL
= 0,
190 FONT_SPACING_DUAL
= 90,
191 FONT_SPACING_MONO
= 100,
192 FONT_SPACING_CHARCELL
= 110
197 short lbearing
, rbearing
, width
, ascent
, descent
;
206 unsigned char *buffer
;
213 /* Predicates to check various font-related objects. */
215 #define FONT_SPEC_P(x) \
216 (VECTORP (x) && ASIZE (x) == FONT_SPEC_MAX)
217 #define FONT_ENTITY_P(x) \
218 (VECTORP (x) && ASIZE (x) == FONT_ENTITY_MAX)
219 #define FONT_OBJECT_P(x) \
220 (XTYPE (x) == Lisp_Misc && XMISCTYPE (x) == Lisp_Misc_Save_Value)
222 ((VECTORP (x) && (ASIZE (x) == FONT_SPEC_MAX \
223 || ASIZE (x) == FONT_ENTITY_MAX)) \
224 || FONT_OBJECT_P (x))
226 #define FONT_ENTITY_NOT_LOADABLE(entity) \
227 EQ (AREF (entity, FONT_OBJLIST_INDEX), Qt)
229 #define FONT_ENTITY_SET_NOT_LOADABLE(entity) \
230 ASET (entity, FONT_OBJLIST_INDEX, Qt)
233 /* Check macros for various font-related objects. */
235 #define CHECK_FONT(x) \
236 do { if (! FONTP (x)) x = wrong_type_argument (Qfont, x); } while (0)
237 #define CHECK_FONT_SPEC(x) \
238 do { if (! FONT_SPEC_P (x)) x = wrong_type_argument (Qfont, x); } while (0)
239 #define CHECK_FONT_ENTITY(x) \
240 do { if (! FONT_ENTITY_P (x)) x = wrong_type_argument (Qfont, x); } while (0)
241 #define CHECK_FONT_OBJECT(x) \
242 do { if (! FONT_OBJECT_P (x)) x = wrong_type_argument (Qfont, x); } while (0)
244 #define CHECK_FONT_GET_OBJECT(x, font) \
246 if (! FONT_OBJECT_P (x)) x = wrong_type_argument (Qfont, x); \
247 if (! XSAVE_VALUE (x)->pointer) error ("Font already closed"); \
248 font = XSAVE_VALUE (x)->pointer; \
251 /* Ignore the difference of font pixel sizes less than or equal to
253 #define FONT_PIXEL_SIZE_QUANTUM 1
258 /* Macros for lispy glyph-string. */
259 #define LGSTRING_FONT(lgs) AREF (AREF ((lgs), 0), 0)
260 #define LGSTRING_WIDTH(lgs) XINT (AREF (AREF ((lgs), 0), 1))
261 #define LGSTRING_LBEARING(lgs) XINT (AREF (AREF ((lgs), 0), 2))
262 #define LGSTRING_RBEARING(lgs) XINT (AREF (AREF ((lgs), 0), 3))
263 #define LGSTRING_ASCENT(lgs) XINT (AREF (AREF ((lgs), 0), 4))
264 #define LGSTRING_DESCENT(lgs) XINT (AREF (AREF ((lgs), 0), 5))
265 #define LGSTRING_SET_FONT(lgs, val) \
266 ASET (AREF ((lgs), 0), 0, (val))
267 #define LGSTRING_SET_WIDTH(lgs, val) \
268 ASET (AREF ((lgs), 0), 1, make_number (val))
269 #define LGSTRING_SET_LBEARING(lgs, val) \
270 ASET (AREF ((lgs), 0), 2, make_number (val))
271 #define LGSTRING_SET_RBEARING(lgs, val) \
272 ASET (AREF ((lgs), 0), 3, make_number (val))
273 #define LGSTRING_SET_ASCENT(lgs, val) \
274 ASET (AREF ((lgs), 0), 4, make_number (val))
275 #define LGSTRING_SET_DESCENT(lgs, val) \
276 ASET (AREF ((lgs), 0), 5, make_number (val))
278 #define LGSTRING_LENGTH(lgs) (ASIZE ((lgs)) - 1)
279 #define LGSTRING_GLYPH(lgs, idx) AREF ((lgs), (idx) + 1)
280 #define LGSTRING_SET_GLYPH(lgs, idx, val) ASET ((lgs), (idx) + 1, (val))
282 /* Vector size of Lispy glyph. */
283 #define LGLYPH_SIZE 10
284 #define LGLYPH_FROM(g) XINT (AREF ((g), 0))
285 #define LGLYPH_TO(g) XINT (AREF ((g), 1))
286 #define LGLYPH_CHAR(g) XINT (AREF ((g), 2))
287 #define LGLYPH_CODE(g) XINT (AREF ((g), 3))
288 #define LGLYPH_WIDTH(g) XINT (AREF ((g), 4))
289 #define LGLYPH_LBEARING(g) XINT (AREF ((g), 5))
290 #define LGLYPH_RBEARING(g) XINT (AREF ((g), 6))
291 #define LGLYPH_ASCENT(g) XINT (AREF ((g), 7))
292 #define LGLYPH_DESCENT(g) XINT (AREF ((g), 8))
293 #define LGLYPH_ADJUSTMENT(g) AREF ((g), 9)
294 #define LGLYPH_SET_FROM(g, val) ASET ((g), 0, make_number (val))
295 #define LGLYPH_SET_TO(g, val) ASET ((g), 1, make_number (val))
296 #define LGLYPH_SET_CHAR(g, val) ASET ((g), 2, make_number (val))
297 #define LGLYPH_SET_CODE(g, val) ASET ((g), 3, make_number (val))
298 #define LGLYPH_SET_WIDTH(g, val) ASET ((g), 4, make_number (val))
299 #define LGLYPH_SET_LBEARING(g, val) ASET ((g), 5, make_number (val))
300 #define LGLYPH_SET_RBEARING(g, val) ASET ((g), 6, make_number (val))
301 #define LGLYPH_SET_ASCENT(g, val) ASET ((g), 7, make_number (val))
302 #define LGLYPH_SET_DESCENT(g, val) ASET ((g), 8, make_number (val))
303 #define LGLYPH_SET_ADJUSTMENT(g, val) ASET ((g), 9, (val))
305 #define LGLYPH_XOFF(g) (VECTORP (LGLYPH_ADJUSTMENT (g)) \
306 ? XINT (AREF (LGLYPH_ADJUSTMENT (g), 0)) : 0)
307 #define LGLYPH_YOFF(g) (VECTORP (LGLYPH_ADJUSTMENT (g)) \
308 ? XINT (AREF (LGLYPH_ADJUSTMENT (g), 1)) : 0)
309 #define LGLYPH_WADJUST(g) (VECTORP (LGLYPH_ADJUSTMENT (g)) \
310 ? XINT (AREF (LGLYPH_ADJUSTMENT (g), 2)) : 0)
312 #define FONT_INVALID_CODE 0xFFFFFFFF
314 /* Font driver. Members specified as "optional" can be NULL. */
318 /* Symbol indicating the type of the font-driver. */
321 /* Return a cache of font-entities on frame F. The cache must be a
322 cons whose cdr part is the actual cache area. */
323 Lisp_Object (*get_cache
) P_ ((FRAME_PTR F
));
325 /* List fonts exactly matching with FONT_SPEC on FRAME. The value
326 is a vector of font-entities. This is the sole API that
327 allocates font-entities. */
328 Lisp_Object (*list
) P_ ((Lisp_Object frame
, Lisp_Object font_spec
));
330 /* Return a font entity most closely maching with FONT_SPEC on
331 FRAME. The closeness is detemined by the font backend, thus
332 `face-font-selection-order' is ignored here. */
333 Lisp_Object (*match
) P_ ((Lisp_Object frame
, Lisp_Object font_spec
));
336 List available families. The value is a list of family names
338 Lisp_Object (*list_family
) P_ ((Lisp_Object frame
));
340 /* Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value).
341 Free FONT_EXTRA_INDEX field of FONT_ENTITY. */
342 void (*free_entity
) P_ ((Lisp_Object font_entity
));
344 /* Open a font specified by FONT_ENTITY on frame F. If the font is
345 scalable, open it with PIXEL_SIZE. */
346 struct font
*(*open
) P_ ((FRAME_PTR f
, Lisp_Object font_entity
,
349 /* Close FONT on frame F. */
350 void (*close
) P_ ((FRAME_PTR f
, struct font
*font
));
352 /* Optional (if FACE->extra is not used).
353 Prepare FACE for displaying characters by FONT on frame F by
354 storing some data in FACE->extra. If successful, return 0.
355 Otherwise, return -1. */
356 int (*prepare_face
) P_ ((FRAME_PTR f
, struct face
*face
));
359 Done FACE for displaying characters by FACE->font on frame F. */
360 void (*done_face
) P_ ((FRAME_PTR f
, struct face
*face
));
363 If FONT_ENTITY has a glyph for character C (Unicode code point),
364 return 1. If not, return 0. If a font must be opened to check
366 int (*has_char
) P_ ((Lisp_Object entity
, int c
));
368 /* Return a glyph code of FONT for characer C (Unicode code point).
369 If FONT doesn't have such a glyph, return FONT_INVALID_CODE. */
370 unsigned (*encode_char
) P_ ((struct font
*font
, int c
));
372 /* Computate the total metrics of the NGLYPHS glyphs specified by
373 the font FONT and the sequence of glyph codes CODE, and store the
374 result in METRICS. */
375 int (*text_extents
) P_ ((struct font
*font
,
376 unsigned *code
, int nglyphs
,
377 struct font_metrics
*metrics
));
380 Draw glyphs between FROM and TO of S->char2b at (X Y) pixel
381 position of frame F with S->FACE and S->GC. If WITH_BACKGROUND
382 is nonzero, fill the background in advance. It is assured that
383 WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */
384 int (*draw
) P_ ((struct glyph_string
*s
, int from
, int to
,
385 int x
, int y
, int with_background
));
388 Store bitmap data for glyph-code CODE of FONT in BITMAP. It is
389 intended that this method is callled from the other font-driver
390 for actual drawing. */
391 int (*get_bitmap
) P_ ((struct font
*font
, unsigned code
,
392 struct font_bitmap
*bitmap
,
393 int bits_per_pixel
));
396 Free bitmap data in BITMAP. */
397 void (*free_bitmap
) P_ ((struct font
*font
, struct font_bitmap
*bitmap
));
400 Return an outline data for glyph-code CODE of FONT. The format
401 of the outline data depends on the font-driver. */
402 void *(*get_outline
) P_ ((struct font
*font
, unsigned code
));
405 Free OUTLINE (that is obtained by the above method). */
406 void (*free_outline
) P_ ((struct font
*font
, void *outline
));
409 Get coordinates of the INDEXth anchor point of the glyph whose
410 code is CODE. Store the coordinates in *X and *Y. Return 0 if
411 the operations was successfull. Otherwise return -1. */
412 int (*anchor_point
) P_ ((struct font
*font
, unsigned code
, int index
,
416 Return a list describing which scripts/languages FONT
417 supports by which GSUB/GPOS features of OpenType tables. */
418 Lisp_Object (*otf_capability
) P_ ((struct font
*font
));
421 Apply FONT's OTF-FEATURES to the glyph string.
423 FEATURES specifies which OTF features to apply in this format:
424 (SCRIPT LANGSYS GSUB-FEATURE GPOS-FEATURE)
425 See the documentation of `font-drive-otf' for the detail.
427 This method applies the specified features to the codes in the
428 elements of GSTRING-IN (between FROMth and TOth). The output
429 codes are stored in GSTRING-OUT at the IDXth element and the
432 Return the number of output codes. If none of the features are
433 applicable to the input data, return 0. If GSTRING-OUT is too
435 int (*otf_drive
) P_ ((struct font
*font
, Lisp_Object features
,
436 Lisp_Object gstring_in
, int from
, int to
,
437 Lisp_Object gstring_out
, int idx
, int alternate_subst
));
440 Make the font driver ready for frame F. Usually this function
441 makes some data specific to F and store it in F by calling
442 font_put_frame_data (). */
443 int (*start_for_frame
) P_ ((FRAME_PTR f
));
446 End using the driver for frame F. Usually this function free
447 some data stored for F. */
448 int (*end_for_frame
) P_ ((FRAME_PTR f
));
452 Shape text in LGSTRING. See the docstring of `font-make-gstring'
453 for the format of LGSTRING. If the (N+1)th element of LGSTRING
454 is nil, input of shaping is from the 1st to (N)th elements. In
455 each input glyph, FROM, TO, CHAR, and CODE are already set.
457 This function updates all fields of the input glyphs. If the
458 output glyphs (M) are more than the input glyphs (N), (N+1)th
459 through (M)th elements of LGSTRING are updated possibly by making
460 a new glyph object and storing it in LGSTRING. If (M) is greater
461 than the length of LGSTRING, nil should be return. In that case,
462 this function is called again with the larger LGSTRING. */
463 Lisp_Object (*shape
) P_ ((Lisp_Object lgstring
));
467 /* Chain of font drivers. There's one global font driver list
468 (font_driver_list in font.c). In addition, each frame has it's own
469 font driver list at FRAME_PTR->font_driver_list. */
471 struct font_driver_list
473 /* 1 iff this driver is currently used. It is igonred in the global
476 /* Pointer to the font driver. */
477 struct font_driver
*driver
;
478 /* Pointer to the next element of the chain. */
479 struct font_driver_list
*next
;
483 /* Chain of arbitrary data specific to each font driver. Each frame
484 has it's own font data list at FRAME_PTR->font_data_list. */
486 struct font_data_list
488 /* Pointer to the font driver. */
489 struct font_driver
*driver
;
490 /* Data specific to the font driver. */
492 /* Pointer to the next element of the chain. */
493 struct font_data_list
*next
;
496 extern int enable_font_backend
;
498 EXFUN (Ffont_spec
, MANY
);
499 EXFUN (Ffont_get
, 2);
500 EXFUN (Flist_fonts
, 4);
501 EXFUN (Fclear_font_cache
, 0);
502 EXFUN (Ffont_xlfd_name
, 1);
504 extern int font_registry_charsets
P_ ((Lisp_Object
, struct charset
**,
506 extern Lisp_Object font_symbolic_weight
P_ ((Lisp_Object font
));
507 extern Lisp_Object font_symbolic_slant
P_ ((Lisp_Object font
));
508 extern Lisp_Object font_symbolic_width
P_ ((Lisp_Object font
));
510 extern int font_match_p
P_ ((Lisp_Object spec
, Lisp_Object entity
));
512 extern Lisp_Object font_find_object
P_ ((struct font
*font
));
513 extern Lisp_Object font_get_name
P_ ((Lisp_Object font_object
));
514 extern Lisp_Object font_get_spec
P_ ((Lisp_Object font_object
));
515 extern Lisp_Object font_get_frame
P_ ((Lisp_Object font_object
));
516 extern int font_has_char
P_ ((FRAME_PTR
, Lisp_Object
, int));
517 extern unsigned font_encode_char
P_ ((Lisp_Object
, int));
519 extern int font_set_lface_from_name
P_ ((FRAME_PTR f
,
521 Lisp_Object fontname
,
522 int force_p
, int may_fail_p
));
523 extern Lisp_Object font_find_for_lface
P_ ((FRAME_PTR f
, Lisp_Object
*lface
,
524 Lisp_Object spec
, int c
));
525 extern Lisp_Object font_open_for_lface
P_ ((FRAME_PTR f
, Lisp_Object entity
,
528 extern void font_load_for_face
P_ ((FRAME_PTR f
, struct face
*face
));
529 extern void font_prepare_for_face
P_ ((FRAME_PTR f
, struct face
*face
));
530 extern Lisp_Object font_open_by_name
P_ ((FRAME_PTR f
, char *name
));
531 extern void font_close_object (FRAME_PTR f
, Lisp_Object font_object
);
533 extern Lisp_Object intern_downcase
P_ ((char *str
, int len
));
534 extern void font_update_sort_order
P_ ((int *order
));
536 extern void font_merge_old_spec
P_ ((Lisp_Object name
, Lisp_Object family
,
537 Lisp_Object registry
, Lisp_Object spec
));
540 extern int font_parse_xlfd
P_ ((char *name
, Lisp_Object font
));
541 extern int font_unparse_xlfd
P_ ((Lisp_Object font
, int pixel_size
,
542 char *name
, int bytes
));
543 extern int font_parse_fcname
P_ ((char *name
, Lisp_Object font
));
544 extern int font_unparse_fcname
P_ ((Lisp_Object font
, int pixel_size
,
545 char *name
, int bytes
));
546 extern void register_font_driver
P_ ((struct font_driver
*driver
, FRAME_PTR f
));
547 extern void free_font_driver_list
P_ ((FRAME_PTR f
));
548 extern Lisp_Object font_update_drivers
P_ ((FRAME_PTR f
, Lisp_Object list
));
549 extern Lisp_Object font_at
P_ ((int c
, EMACS_INT pos
, struct face
*face
,
550 struct window
*w
, Lisp_Object object
));
552 extern struct font
*font_prepare_composition
P_ ((struct composition
*cmp
,
555 extern Lisp_Object font_put_extra
P_ ((Lisp_Object font
, Lisp_Object prop
,
558 extern int font_put_frame_data
P_ ((FRAME_PTR f
,
559 struct font_driver
*driver
,
561 extern void *font_get_frame_data
P_ ((FRAME_PTR f
,
562 struct font_driver
*driver
));
565 extern struct font_driver ftfont_driver
;
566 #endif /* HAVE_FREETYPE */
567 #ifdef HAVE_X_WINDOWS
568 extern struct font_driver xfont_driver
;
569 extern struct font_driver ftxfont_driver
;
571 extern struct font_driver xftfont_driver
;
572 #endif /* HAVE_XFT */
573 #endif /* HAVE_X_WINDOWS */
575 extern struct font_driver w32font_driver
;
576 #endif /* WINDOWSNT */
578 extern struct font_driver atmfont_driver
;
581 #endif /* not EMACS_FONT_H */
583 /* arch-tag: 3b7260c3-5bec-4d6b-a0db-95c1b431b1a2
584 (do not change this comment) */