]> code.delx.au - gnu-emacs/blob - src/font.h
Include-file cleanup for src directory
[gnu-emacs] / src / font.h
1 /* font.h -- Interface definition for font handling.
2 Copyright (C) 2006-2015 Free Software Foundation, Inc.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
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 3 of the License, or
12 (at your option) 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. If not, see <http://www.gnu.org/licenses/>. */
21
22 #ifndef EMACS_FONT_H
23 #define EMACS_FONT_H
24
25 struct composition_it;
26 struct face;
27 struct glyph_string;
28
29 INLINE_HEADER_BEGIN
30
31 /* We have three types of Lisp objects related to font.
32
33 FONT-SPEC
34
35 Pseudo vector (length FONT_SPEC_MAX) of font properties. Some
36 properties can be left unspecified (i.e. nil). Emacs asks
37 font-drivers to find a font by FONT-SPEC. A fontset entry
38 specifies requisite properties whereas a face specifies just
39 preferable properties.
40
41 FONT-ENTITY
42
43 Pseudo vector (length FONT_ENTITY_MAX) of fully instantiated
44 font properties that a font-driver returns upon a request of
45 FONT-SPEC.
46
47 Note: Only the method `list' and `match' of a font-driver can
48 create this object, and it should never be modified by Lisp.
49
50 FONT-OBJECT
51
52 Pseudo vector (length FONT_OBJECT_MAX) of an opened font.
53
54 Lisp object encapsulating "struct font". This corresponds to
55 an opened font.
56
57 Note: Only the method `open' of a font-driver can create this
58 object, and it should never be modified by Lisp. */
59
60
61 /* An enumerator for each font property. This is used as an index to
62 the vector of FONT-SPEC and FONT-ENTITY.
63
64 Note: The order is important and should not be changed. */
65
66 enum font_property_index
67 {
68 /* FONT-TYPE is a symbol indicating a font backend; currently `x',
69 `xft', and `ftx' are available on X, `uniscribe' and `gdi' on
70 Windows, and `ns' under Cocoa / GNUstep. */
71 FONT_TYPE_INDEX,
72
73 /* FONT-FOUNDRY is a foundry name (symbol). */
74 FONT_FOUNDRY_INDEX,
75
76 /* FONT-FAMILY is a family name (symbol). */
77 FONT_FAMILY_INDEX,
78
79 /* FONT-ADSTYLE is an additional style name (symbol). */
80 FONT_ADSTYLE_INDEX,
81
82 /* FONT-REGISTRY is a combination of a charset-registry and
83 charset-encoding name (symbol). */
84 FONT_REGISTRY_INDEX,
85
86 /* FONT-WEIGHT is a numeric value of weight (e.g. medium, bold) of
87 the font. The lowest 8 bits is an index determining the
88 symbolic name, and the higher bits is the actual numeric value
89 defined in `font-weight-table'. */
90 FONT_WEIGHT_INDEX,
91
92 /* FONT-SLANT is a numeric value of slant (e.g. r, i, o) of the
93 font. The lowest 8 bits is an index determining the symbolic
94 name, and the higher bits is the actual numeric value defined
95 in `font-slant-table'. */
96 FONT_SLANT_INDEX,
97
98 /* FONT-WIDTH is a numeric value of setwidth (e.g. normal) of the
99 font. The lowest 8 bits is an index determining the symbolic
100 name, and the higher bits is the actual numeric value defined
101 `font-width-table'. */
102 FONT_WIDTH_INDEX,
103
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 a float specifying
106 the point size. The value zero means that the font is
107 scalable. */
108 FONT_SIZE_INDEX,
109
110 /* FONT-DPI is a resolution (dot per inch) for which the font is
111 designed. */
112 FONT_DPI_INDEX,
113
114 /* FONT-SPACING is a spacing (mono, proportional, charcell) of the
115 font (integer; one of enum font_spacing). */
116 FONT_SPACING_INDEX,
117
118 /* FONT-AVGWIDTH is an average width (1/10 pixel unit) of the
119 font. */
120 FONT_AVGWIDTH_INDEX,
121
122 #if false
123 /* The following two members are to substitute for the above 6
124 members (FONT_WEIGHT_INDEX to FONT_AVGWIDTH_INDEX excluding
125 FONT_SIZE_INDEX) if it is found that font-entities consumes too
126 much memory. */
127
128 /* FONT-STYLE is a 24-bit integer containing indices for
129 style-related properties WEIGHT, SLANT, and WIDTH. The lowest
130 8 bits is an index to the weight table AREF (font_style_table,
131 0), the next 8 bits is an index to the slant table AREF
132 (font_style_table, 1), the highest 8 bits is an index to the
133 slant table AREF (font_style_table, 2). The index 0 indicates
134 that the corresponding style is not specified. This way, we
135 can represent at most 255 different names for each style, which
136 is surely sufficient. */
137 FONT_STYLE_INDEX,
138
139 /* FONT-METRICS is a 27-bit integer containing metrics-related
140 properties DPI, AVGWIDTH, SPACING. The lowest 12 bits is for
141 DPI, the next 12 bits is for AVGWIDTH, the highest 3 bits is for
142 SPACING. In each bit field, the highest bit indicates that the
143 corresponding value is set or not. This way, we can represent
144 DPI by 11-bit (0 to 2047), AVGWIDTH by 11-bit (0 to 2047),
145 SPACING by 3-bit (0 for proportional, 1 for dual, 2 for mono, 3
146 for charcell), which is surely sufficient. */
147 FONT_METRICS_INDEX,
148 #endif
149
150 /* In a font-spec, the value is an alist of extra information of a
151 font such as name, OpenType features, and language coverage.
152 In addition, in a font-entity, the value may contain a pair
153 (font-entity . INFO) where INFO is extra information to identify
154 a font (font-driver dependent). */
155 FONT_EXTRA_INDEX, /* alist alist */
156
157 /* This value is the length of font-spec vector. */
158 FONT_SPEC_MAX,
159
160 /* The followings are used only for a font-entity and a font-object. */
161
162 /* List of font-objects opened from the font-entity. */
163 FONT_OBJLIST_INDEX = FONT_SPEC_MAX,
164
165 /* This value is the length of font-entity vector. */
166 FONT_ENTITY_MAX,
167
168 /* The followings are used only for a font-object. */
169
170 /* XLFD name of the font (string). */
171 FONT_NAME_INDEX = FONT_ENTITY_MAX,
172
173 /* Full name of the font (string). It is the name extracted from
174 the opened font, and may be different from the above. It may be
175 nil if the opened font doesn't give a name. */
176 FONT_FULLNAME_INDEX,
177
178 /* File name of the font or nil if a file associated with the font
179 is not available. */
180 FONT_FILE_INDEX,
181
182 /* This value is the length of font-object vector. */
183 FONT_OBJECT_MAX
184 };
185
186 /* Return the numeric weight value of FONT. */
187 #define FONT_WEIGHT_NUMERIC(font) \
188 (INTEGERP (AREF ((font), FONT_WEIGHT_INDEX)) \
189 ? (XINT (AREF ((font), FONT_WEIGHT_INDEX)) >> 8) : -1)
190 /* Return the numeric slant value of FONT. */
191 #define FONT_SLANT_NUMERIC(font) \
192 (INTEGERP (AREF ((font), FONT_SLANT_INDEX)) \
193 ? (XINT (AREF ((font), FONT_SLANT_INDEX)) >> 8) : -1)
194 /* Return the numeric width value of FONT. */
195 #define FONT_WIDTH_NUMERIC(font) \
196 (INTEGERP (AREF ((font), FONT_WIDTH_INDEX)) \
197 ? (XINT (AREF ((font), FONT_WIDTH_INDEX)) >> 8) : -1)
198 /* Return the symbolic weight value of FONT. */
199 #define FONT_WEIGHT_SYMBOLIC(font) \
200 font_style_symbolic (font, FONT_WEIGHT_INDEX, false)
201 /* Return the symbolic slant value of FONT. */
202 #define FONT_SLANT_SYMBOLIC(font) \
203 font_style_symbolic (font, FONT_SLANT_INDEX, false)
204 /* Return the symbolic width value of FONT. */
205 #define FONT_WIDTH_SYMBOLIC(font) \
206 font_style_symbolic (font, FONT_WIDTH_INDEX, false)
207 /* Return the face-weight corresponding to the weight of FONT. */
208 #define FONT_WEIGHT_FOR_FACE(font) \
209 font_style_symbolic (font, FONT_WEIGHT_INDEX, true)
210 /* Return the face-slant corresponding to the slant of FONT. */
211 #define FONT_SLANT_FOR_FACE(font) \
212 font_style_symbolic (font, FONT_SLANT_INDEX, true)
213 /* Return the face-swidth corresponding to the slant of FONT. */
214 #define FONT_WIDTH_FOR_FACE(font) \
215 font_style_symbolic (font, FONT_WIDTH_INDEX, true)
216
217 /* Return the numeric weight value corresponding ot the symbol NAME. */
218 #define FONT_WEIGHT_NAME_NUMERIC(name) \
219 (font_style_to_value (FONT_WEIGHT_INDEX, (name), false) >> 8)
220 /* Return the numeric slant value corresponding ot the symbol NAME. */
221 #define FONT_SLANT_NAME_NUMERIC(name) \
222 (font_style_to_value (FONT_SLANT_INDEX, (name), false) >> 8)
223 /* Return the numeric width value corresponding ot the symbol NAME. */
224 #define FONT_WIDTH_NAME_NUMERIC(name) \
225 (font_style_to_value (FONT_WIDTH_INDEX, (name), false) >> 8)
226
227 /* Set the font property PROP of FONT to VAL. PROP is one of
228 style-related font property index (FONT_WEIGHT/SLANT/WIDTH_INDEX).
229 VAL (integer or symbol) is the numeric or symbolic style value. */
230 #define FONT_SET_STYLE(font, prop, val) \
231 ASET ((font), prop, make_number (font_style_to_value (prop, val, true)))
232
233 #ifndef MSDOS
234 #define FONT_WIDTH(f) ((f)->max_width)
235 #else
236 #define FONT_WIDTH(f) 1
237 #endif
238 #define FONT_HEIGHT(f) ((f)->height)
239 #define FONT_BASE(f) ((f)->ascent)
240 #define FONT_DESCENT(f) ((f)->descent)
241
242
243 /* Structure for a font-spec. */
244
245 struct font_spec
246 {
247 struct vectorlike_header header;
248 Lisp_Object props[FONT_SPEC_MAX];
249 };
250
251 /* Structure for a font-entity. */
252
253 struct font_entity
254 {
255 struct vectorlike_header header;
256 Lisp_Object props[FONT_ENTITY_MAX];
257 };
258
259 /* A value which may appear in the member `encoding' of struct font
260 indicating that a font itself doesn't tell which encoding to be
261 used. */
262 #define FONT_ENCODING_NOT_DECIDED 255
263
264 /* Structure for a font-object. */
265
266 struct font
267 {
268 struct vectorlike_header header;
269
270 /* All Lisp_Object components must come first.
271 That ensures they are all aligned normally. */
272
273 Lisp_Object props[FONT_OBJECT_MAX];
274
275 /* Beyond here, there should be no more Lisp_Object components. */
276
277 /* Minimum and maximum glyph widths, in pixels. Some font backends,
278 such as xft, lack the information to easily compute minimum and
279 maximum widths over all characters; in that case, these values
280 are approximate. */
281 int min_width;
282 int max_width;
283
284 /* By which pixel size the font is opened. */
285 int pixel_size;
286
287 /* Height of the font. On X window, this is the same as
288 (font->ascent + font->descent). */
289 int height;
290
291 /* Width of the space glyph of the font. If the font doesn't have a
292 SPACE glyph, the value is 0. */
293 int space_width;
294
295 /* Average width of glyphs in the font. If the font itself doesn't
296 have that information but has glyphs of ASCII characters, the
297 value is the average width of those glyphs. Otherwise, the value
298 is 0. */
299 int average_width;
300
301 /* Ascent and descent of the font (in pixels). */
302 int ascent, descent;
303
304 /* The following members makes sense on graphic displays only. */
305
306 #if defined (HAVE_WINDOW_SYSTEM)
307
308 /* Vertical pixel width of the underline. If is zero if that
309 information is not in the font. */
310 int underline_thickness;
311
312 /* Vertical pixel position (relative to the baseline) of the
313 underline. If it is positive, it is below the baseline. It is
314 negative if that information is not in the font. */
315 int underline_position;
316
317 /* True if `vertical-centering-font-regexp' matches this font name.
318 In this case, we render characters at vertical center positions
319 of lines. */
320 bool vertical_centering;
321
322 /* The baseline position of a font is normally `ascent' value of the
323 font. However, there exist many fonts which don't set `ascent' to
324 an appropriate value to be used as baseline position. This is
325 typical in such ASCII fonts which are designed to be used with
326 Chinese, Japanese, Korean characters. When we use mixture of
327 such fonts and normal fonts (having correct `ascent' value), a
328 display line gets very ugly. Since we have no way to fix it
329 automatically, it is user's responsibility to supply well designed
330 fonts or correct `ascent' value of fonts. But, the latter
331 requires heavy work (modifying all bitmap data in BDF files).
332 So, Emacs accepts a private font property
333 `_MULE_BASELINE_OFFSET'. If a font has this property, we
334 calculate the baseline position by subtracting the value from
335 `ascent'. In other words, the value indicates how many pixels
336 higher than normal ASCII text we should draw a character of the
337 font for better appearance.
338
339 We also have to consider the fact that the concept of `baseline'
340 differs among scripts to which each character belongs. For
341 instance, baseline should be at the bottom-most position of all
342 glyphs for Chinese, Japanese, and Korean. But, many of existing
343 fonts for those characters don't have correct `ascent' values
344 because they are designed to be used with ASCII fonts. To
345 display characters of different language on the same line, the
346 best way will be to arrange them in the middle of the line. So,
347 in such a case, again, we utilize the font property
348 `_MULE_BASELINE_OFFSET'. If the value is larger than `ascent' we
349 calculate baseline so that a character is arranged in the middle
350 of a line. */
351 int baseline_offset;
352
353 /* Non-zero means a character should be composed at a position
354 relative to the height (or depth) of previous glyphs in the
355 following cases:
356 (1) The bottom of the character is higher than this value. In
357 this case, the character is drawn above the previous glyphs.
358 (2) The top of the character is lower than 0 (i.e. baseline
359 height). In this case, the character is drawn below the
360 previous glyphs.
361
362 This value is taken from a private font property
363 `_MULE_RELATIVE_COMPOSE' which is introduced by Emacs. */
364 int relative_compose;
365
366 /* Non-zero means an ascent value to be used for a character
367 registered in char-table `use-default-ascent'. */
368 int default_ascent;
369
370 /* Charset to encode a character code into a glyph code of the font.
371 -1 means that the font doesn't require this information to encode
372 a character. */
373 int encoding_charset;
374
375 /* Charset to check if a character code is supported by the font.
376 -1 means that the contents of the font must be looked up to
377 determine it. */
378 int repertory_charset;
379
380 #endif /* HAVE_WINDOW_SYSTEM */
381
382 /* Font-driver for the font. */
383 struct font_driver *driver;
384
385 /* There are more members in this structure, but they are private
386 to the font-driver. */
387 };
388
389 enum font_spacing
390 {
391 FONT_SPACING_PROPORTIONAL = 0,
392 FONT_SPACING_DUAL = 90,
393 FONT_SPACING_MONO = 100,
394 FONT_SPACING_CHARCELL = 110
395 };
396
397 struct font_metrics
398 {
399 short lbearing, rbearing, width, ascent, descent;
400 };
401
402 struct font_bitmap
403 {
404 int bits_per_pixel;
405 int rows;
406 int width;
407 int pitch;
408 unsigned char *buffer;
409 int left;
410 int top;
411 int advance;
412 };
413
414 /* Predicates to check various font-related objects. */
415
416 /* True iff X is one of font-spec, font-entity, and font-object. */
417 INLINE bool
418 FONTP (Lisp_Object x)
419 {
420 return PSEUDOVECTORP (x, PVEC_FONT);
421 }
422
423 /* True iff X is font-spec. */
424 INLINE bool
425 FONT_SPEC_P (Lisp_Object x)
426 {
427 return FONTP (x) && (ASIZE (x) & PSEUDOVECTOR_SIZE_MASK) == FONT_SPEC_MAX;
428 }
429
430 /* True iff X is font-entity. */
431 INLINE bool
432 FONT_ENTITY_P (Lisp_Object x)
433 {
434 return FONTP (x) && (ASIZE (x) & PSEUDOVECTOR_SIZE_MASK) == FONT_ENTITY_MAX;
435 }
436
437 /* True iff X is font-object. */
438 INLINE bool
439 FONT_OBJECT_P (Lisp_Object x)
440 {
441 return FONTP (x) && (ASIZE (x) & PSEUDOVECTOR_SIZE_MASK) == FONT_OBJECT_MAX;
442 }
443
444 /* Type checking functions for various font-related objects. */
445
446 INLINE void
447 CHECK_FONT (Lisp_Object x)
448 {
449 CHECK_TYPE (FONTP (x), Qfont, x);
450 }
451
452 INLINE void
453 CHECK_FONT_SPEC (Lisp_Object x)
454 {
455 CHECK_TYPE (FONT_SPEC_P (x), Qfont_spec, x);
456 }
457
458 INLINE void
459 CHECK_FONT_ENTITY (Lisp_Object x)
460 {
461 CHECK_TYPE (FONT_ENTITY_P (x), Qfont_entity, x);
462 }
463
464 INLINE void
465 CHECK_FONT_OBJECT (Lisp_Object x)
466 {
467 CHECK_TYPE (FONT_OBJECT_P (x), Qfont_object, x);
468 }
469
470 /* C pointer extraction functions for various font-related objects. */
471
472 INLINE struct font_spec *
473 XFONT_SPEC (Lisp_Object p)
474 {
475 eassert (FONT_SPEC_P (p));
476 return XUNTAG (p, Lisp_Vectorlike);
477 }
478
479 INLINE struct font_entity *
480 XFONT_ENTITY (Lisp_Object p)
481 {
482 eassert (FONT_ENTITY_P (p));
483 return XUNTAG (p, Lisp_Vectorlike);
484 }
485
486 INLINE struct font *
487 XFONT_OBJECT (Lisp_Object p)
488 {
489 eassert (FONT_OBJECT_P (p));
490 return XUNTAG (p, Lisp_Vectorlike);
491 }
492
493 #define XSETFONT(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FONT))
494
495 INLINE struct font *
496 CHECK_FONT_GET_OBJECT (Lisp_Object x)
497 {
498 CHECK_FONT_OBJECT (x);
499 return XFONT_OBJECT (x);
500 }
501
502 /* Number of pt per inch (from the TeXbook). */
503 #define PT_PER_INCH 72.27
504
505 /* Return a pixel size (integer) corresponding to POINT size (double)
506 on resolution DPI. */
507 #define POINT_TO_PIXEL(POINT, DPI) ((POINT) * (DPI) / PT_PER_INCH + 0.5)
508
509 /* Return a point size corresponding to POINT size (integer)
510 on resolution DPI. Note that though point size is a double, we expect
511 it to be rounded to an int, so we add 0.5 here. If the desired value
512 is tenths of points (as in xfld specs), then the pixel size should
513 be multiplied BEFORE the conversion to avoid magnifying the error. */
514 #define PIXEL_TO_POINT(PIXEL, DPI) ((PIXEL) * PT_PER_INCH / (DPI) + 0.5)
515
516 /* Ignore the difference of font pixel sizes less than or equal to
517 this value. */
518 #define FONT_PIXEL_SIZE_QUANTUM 1
519
520 #define FONT_INVALID_CODE 0xFFFFFFFF
521
522 /* Font driver. Members specified as "optional" can be NULL. */
523
524 struct font_driver
525 {
526 /* Symbol indicating the type of the font-driver. */
527 Lisp_Object type;
528
529 /* True iff the font's foundry, family, and adstyle names are case
530 sensitive. */
531 bool case_sensitive;
532
533 /* Return a cache of font-entities on frame F. The cache must be a
534 cons whose cdr part is the actual cache area. */
535 Lisp_Object (*get_cache) (struct frame *f);
536
537 /* List fonts exactly matching with FONT_SPEC on FRAME. The value
538 is a list of font-entities. The font properties to be considered
539 are: :foundry, :family, :adstyle, :registry, :script, :lang, and
540 :otf. See the function `font-spec' for their meanings. Note
541 that the last three properties are stored in FONT_EXTRA_INDEX
542 slot of FONT_SPEC.
543
544 The returned value is a list of font-entities. Each font-entity
545 has :type property whose value is the same as the above `type'.
546 It also has these properties if they are available from the
547 corresponding font; :foundry, :family, :adstyle, :registry,
548 :weight, :slant, :width, :size, :dpi, :spacing, :avgwidth. If
549 the font is scalable, :size and :avgwidth must be 0.
550
551 The `open' method of the same font-backend is called with one of
552 the returned font-entities. If the backend needs additional
553 information to be used in `open' method, this method can add any
554 Lispy value by the property :font-entity to the entities.
555
556 This and the following `match' are the only APIs that allocate
557 font-entities. */
558 Lisp_Object (*list) (struct frame *frame, Lisp_Object font_spec);
559
560 /* Return a font-entity most closely matching with FONT_SPEC on
561 FRAME. Which font property to consider, and how to calculate the
562 closeness is determined by the font backend, thus
563 `face-font-selection-order' is ignored here.
564
565 The properties that the font-entity has is the same as `list'
566 method. */
567 Lisp_Object (*match) (struct frame *f, Lisp_Object spec);
568
569 /* Optional.
570 List available families. The value is a list of family names
571 (symbols). */
572 Lisp_Object (*list_family) (struct frame *f);
573
574 /* Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value).
575 Free FONT_EXTRA_INDEX field of FONT_ENTITY. */
576 void (*free_entity) (Lisp_Object font_entity);
577
578 /* Open a font specified by FONT_ENTITY on frame F. If the font is
579 scalable, open it with PIXEL_SIZE. */
580 Lisp_Object (*open) (struct frame *f, Lisp_Object font_entity,
581 int pixel_size);
582
583 /* Close FONT. NOTE: this can be called by GC. */
584 void (*close) (struct font *font);
585
586 /* Prepare FACE for displaying characters by FONT on frame F by
587 storing some data in FACE->extra. */
588 void (*prepare_face) (struct frame *f, struct face *face);
589
590 /* Optional.
591 Done FACE for displaying characters by FACE->font on frame F. */
592 void (*done_face) (struct frame *f, struct face *face);
593
594 /* Optional.
595 If FONT (FONT-ENTITY or FONT-OBJECT) has a glyph for character C
596 (Unicode code point), return 1. If not, return 0. If FONT is
597 FONT-ENTITY and it must be opened to check it, return -1. */
598 int (*has_char) (Lisp_Object font, int c);
599
600 /* Return a glyph code of FONT for character C (Unicode code point).
601 If FONT doesn't have such a glyph, return FONT_INVALID_CODE. */
602 unsigned (*encode_char) (struct font *font, int c);
603
604 /* Compute the total metrics of the NGLYPHS glyphs specified by
605 the font FONT and the sequence of glyph codes CODE, and store the
606 result in METRICS. */
607 void (*text_extents) (struct font *font,
608 unsigned *code, int nglyphs,
609 struct font_metrics *metrics);
610
611 #ifdef HAVE_WINDOW_SYSTEM
612
613 /* Optional.
614 Draw glyphs between FROM and TO of S->char2b at (X Y) pixel
615 position of frame F with S->FACE and S->GC. If WITH_BACKGROUND,
616 fill the background in advance. It is assured that WITH_BACKGROUND
617 is false when (FROM > 0 || TO < S->nchars). */
618 int (*draw) (struct glyph_string *s, int from, int to,
619 int x, int y, bool with_background);
620
621 /* Optional.
622 Store bitmap data for glyph-code CODE of FONT in BITMAP. It is
623 intended that this method is called from the other font-driver
624 for actual drawing. */
625 int (*get_bitmap) (struct font *font, unsigned code,
626 struct font_bitmap *bitmap,
627 int bits_per_pixel);
628
629 /* Optional.
630 Free bitmap data in BITMAP. */
631 void (*free_bitmap) (struct font *font, struct font_bitmap *bitmap);
632
633 #endif /* HAVE_WINDOW_SYSTEM */
634
635 /* Optional.
636 Get coordinates of the INDEXth anchor point of the glyph whose
637 code is CODE. Store the coordinates in *X and *Y. Return 0 if
638 the operations was successful. Otherwise return -1. */
639 int (*anchor_point) (struct font *font, unsigned code, int index,
640 int *x, int *y);
641
642 /* Optional.
643 Return a list describing which scripts/languages FONT
644 supports by which GSUB/GPOS features of OpenType tables. */
645 Lisp_Object (*otf_capability) (struct font *font);
646
647 /* Optional.
648 Apply FONT's OTF-FEATURES to the glyph string.
649
650 FEATURES specifies which OTF features to apply in this format:
651 (SCRIPT LANGSYS GSUB-FEATURE GPOS-FEATURE)
652 See the documentation of `font-drive-otf' for the details.
653
654 This method applies the specified features to the codes in the
655 elements of GSTRING-IN (between FROMth and TOth). The output
656 codes are stored in GSTRING-OUT at the IDXth element and the
657 following elements.
658
659 Return the number of output codes. If none of the features are
660 applicable to the input data, return 0. If GSTRING-OUT is too
661 short, return -1. */
662 int (*otf_drive) (struct font *font, Lisp_Object features,
663 Lisp_Object gstring_in, int from, int to,
664 Lisp_Object gstring_out, int idx, bool alternate_subst);
665
666 /* Optional.
667 Make the font driver ready for frame F. Usually this function
668 makes some data specific to F and stores it in F by calling
669 font_put_frame_data (). */
670 int (*start_for_frame) (struct frame *f);
671
672 /* Optional.
673 End using the driver for frame F. Usually this function free
674 some data stored for F. */
675 int (*end_for_frame) (struct frame *f);
676
677 /* Optional.
678
679 Shape text in GSTRING. See the docstring of
680 `composition-get-gstring' for the format of GSTRING. If the
681 (N+1)th element of GSTRING is nil, input of shaping is from the
682 1st to (N)th elements. In each input glyph, FROM, TO, CHAR, and
683 CODE are already set.
684
685 This function updates all fields of the input glyphs. If the
686 output glyphs (M) are more than the input glyphs (N), (N+1)th
687 through (M)th elements of GSTRING are updated possibly by making
688 a new glyph object and storing it in GSTRING. If (M) is greater
689 than the length of GSTRING, nil should be return. In that case,
690 this function is called again with the larger GSTRING. */
691 Lisp_Object (*shape) (Lisp_Object lgstring);
692
693 /* Optional.
694
695 If FONT is usable on frame F, return 0. Otherwise return -1.
696 This method is used only for debugging. If this method is NULL,
697 Emacs assumes that the font is usable on any frame. */
698 int (*check) (struct frame *f, struct font *font);
699
700 /* Optional.
701
702 Return the number of variation glyphs of character C supported by
703 FONT. VARIATIONS is an array of 256 elements. If the variation
704 selector N (1..256) defines a glyph, that glyph code is stored in
705 the (N-1)th element of VARIATIONS. */
706 int (*get_variation_glyphs) (struct font *font,
707 int c, unsigned variations[256]);
708
709 void (*filter_properties) (Lisp_Object font, Lisp_Object properties);
710
711 /* Optional.
712
713 Return non-zero if FONT_OBJECT can be used as a (cached) font
714 for ENTITY on frame F. */
715 bool (*cached_font_ok) (struct frame *f,
716 Lisp_Object font_object,
717 Lisp_Object entity);
718 };
719
720
721 /* Chain of font drivers. There's one global font driver list
722 (font_driver_list in font.c). In addition, each frame has
723 its own font driver list at F->font_driver_list. */
724
725 struct font_driver_list
726 {
727 /* True iff this driver is currently used. It is ignored in the global
728 font driver list.*/
729 bool on;
730 /* Pointer to the font driver. */
731 struct font_driver *driver;
732 /* Pointer to the next element of the chain. */
733 struct font_driver_list *next;
734 };
735
736 extern Lisp_Object copy_font_spec (Lisp_Object);
737 extern Lisp_Object merge_font_spec (Lisp_Object, Lisp_Object);
738
739 extern Lisp_Object font_make_entity (void);
740 extern Lisp_Object font_make_object (int, Lisp_Object, int);
741 #if defined (HAVE_XFT) || defined (HAVE_FREETYPE) || defined (HAVE_NS)
742 extern Lisp_Object font_build_object (int, Lisp_Object, Lisp_Object, double);
743 #endif
744
745 extern Lisp_Object find_font_encoding (Lisp_Object);
746 extern int font_registry_charsets (Lisp_Object, struct charset **,
747 struct charset **);
748 extern int font_style_to_value (enum font_property_index prop,
749 Lisp_Object name, bool noerror);
750 extern Lisp_Object font_style_symbolic (Lisp_Object font,
751 enum font_property_index prop,
752 bool for_face);
753
754 extern bool font_match_p (Lisp_Object spec, Lisp_Object font);
755 extern Lisp_Object font_list_entities (struct frame *, Lisp_Object);
756
757 extern Lisp_Object font_get_name (Lisp_Object font_object);
758 extern Lisp_Object font_spec_from_name (Lisp_Object font_name);
759 extern Lisp_Object font_get_frame (Lisp_Object font_object);
760 extern int font_has_char (struct frame *, Lisp_Object, int);
761
762 extern void font_clear_prop (Lisp_Object *attrs,
763 enum font_property_index prop);
764 extern Lisp_Object font_find_for_lface (struct frame *f, Lisp_Object *lface,
765 Lisp_Object spec, int c);
766 extern Lisp_Object font_open_for_lface (struct frame *f, Lisp_Object entity,
767 Lisp_Object *lface,
768 Lisp_Object spec);
769 extern Lisp_Object font_load_for_lface (struct frame *f, Lisp_Object *lface,
770 Lisp_Object spec);
771 extern void font_prepare_for_face (struct frame *f, struct face *face);
772 extern void font_done_for_face (struct frame *f, struct face *face);
773 extern void clear_font_cache (struct frame *);
774
775 extern Lisp_Object font_open_by_spec (struct frame *f, Lisp_Object spec);
776 extern Lisp_Object font_open_by_name (struct frame *f, Lisp_Object name);
777
778 extern Lisp_Object font_intern_prop (const char *str, ptrdiff_t len,
779 bool force_symbol);
780 extern void font_update_sort_order (int *order);
781
782 extern void font_parse_family_registry (Lisp_Object family,
783 Lisp_Object registry,
784 Lisp_Object spec);
785
786 extern int font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font);
787 extern ptrdiff_t font_unparse_xlfd (Lisp_Object font, int pixel_size,
788 char *name, int bytes);
789 extern void register_font_driver (struct font_driver *driver, struct frame *f);
790 extern void free_font_driver_list (struct frame *f);
791 #ifdef ENABLE_CHECKING
792 extern bool valid_font_driver (struct font_driver *);
793 #else
794 INLINE bool
795 valid_font_driver (struct font_driver *d)
796 {
797 return true;
798 }
799 #endif
800 extern Lisp_Object font_update_drivers (struct frame *f, Lisp_Object list);
801 extern Lisp_Object font_range (ptrdiff_t, ptrdiff_t, ptrdiff_t *,
802 struct window *, struct face *,
803 Lisp_Object);
804 extern void font_fill_lglyph_metrics (Lisp_Object, Lisp_Object);
805
806 extern Lisp_Object font_put_extra (Lisp_Object font, Lisp_Object prop,
807 Lisp_Object val);
808
809 #if defined (HAVE_XFT) || defined (HAVE_FREETYPE)
810 extern void font_put_frame_data (struct frame *, Lisp_Object, void *);
811 extern void *font_get_frame_data (struct frame *f, Lisp_Object);
812 #endif /* HAVE_XFT || HAVE_FREETYPE */
813
814 extern void font_filter_properties (Lisp_Object font,
815 Lisp_Object alist,
816 const char *const boolean_properties[],
817 const char *const non_boolean_properties[]);
818
819 #ifdef HAVE_FREETYPE
820 extern struct font_driver ftfont_driver;
821 extern void syms_of_ftfont (void);
822 #endif /* HAVE_FREETYPE */
823 #ifdef HAVE_X_WINDOWS
824 extern struct font_driver xfont_driver;
825 extern void syms_of_xfont (void);
826 extern void syms_of_ftxfont (void);
827 #ifdef HAVE_XFT
828 extern struct font_driver xftfont_driver;
829 #endif
830 #if defined HAVE_FREETYPE || defined HAVE_XFT
831 extern struct font_driver ftxfont_driver;
832 extern void syms_of_xftfont (void);
833 #endif
834 #ifdef HAVE_BDFFONT
835 extern void syms_of_bdffont (void);
836 #endif /* HAVE_BDFFONT */
837 #endif /* HAVE_X_WINDOWS */
838 #ifdef HAVE_NTGUI
839 extern struct font_driver w32font_driver;
840 extern struct font_driver uniscribe_font_driver;
841 extern void syms_of_w32font (void);
842 #endif /* HAVE_NTGUI */
843 #ifdef HAVE_NS
844 extern struct font_driver nsfont_driver;
845 extern void syms_of_nsfont (void);
846 extern void syms_of_macfont (void);
847 #endif /* HAVE_NS */
848 #ifdef USE_CAIRO
849 extern struct font_driver ftcrfont_driver;
850 extern void syms_of_ftcrfont (void);
851 #endif
852
853 #ifndef FONT_DEBUG
854 #define FONT_DEBUG
855 #endif
856
857 extern void font_add_log (const char *, Lisp_Object, Lisp_Object);
858 extern void font_deferred_log (const char *, Lisp_Object, Lisp_Object);
859
860 #define FONT_ADD_LOG(ACTION, ARG, RESULT) \
861 do { \
862 if (! EQ (Vfont_log, Qt)) \
863 font_add_log ((ACTION), (ARG), (RESULT)); \
864 } while (false)
865
866 #define FONT_DEFERRED_LOG(ACTION, ARG, RESULT) \
867 do { \
868 if (! EQ (Vfont_log, Qt)) \
869 font_deferred_log ((ACTION), (ARG), (RESULT)); \
870 } while (false)
871
872 INLINE_HEADER_END
873
874 #endif /* not EMACS_FONT_H */