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