Imported Upstream version 2.6.4
[platform/upstream/harfbuzz.git] / src / hb-ot-layout.h
1 /*
2  * Copyright © 2007,2008,2009  Red Hat, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  * Red Hat Author(s): Behdad Esfahbod
25  */
26
27 #ifndef HB_OT_H_IN
28 #error "Include <hb-ot.h> instead."
29 #endif
30
31 #ifndef HB_OT_LAYOUT_H
32 #define HB_OT_LAYOUT_H
33
34 #include "hb.h"
35
36 #include "hb-ot-name.h"
37
38 HB_BEGIN_DECLS
39
40
41 #define HB_OT_TAG_BASE HB_TAG('B','A','S','E')
42 #define HB_OT_TAG_GDEF HB_TAG('G','D','E','F')
43 #define HB_OT_TAG_GSUB HB_TAG('G','S','U','B')
44 #define HB_OT_TAG_GPOS HB_TAG('G','P','O','S')
45 #define HB_OT_TAG_JSTF HB_TAG('J','S','T','F')
46
47
48 /*
49  * Script & Language tags.
50  */
51
52 #define HB_OT_TAG_DEFAULT_SCRIPT        HB_TAG ('D', 'F', 'L', 'T')
53 #define HB_OT_TAG_DEFAULT_LANGUAGE      HB_TAG ('d', 'f', 'l', 't')
54
55 /**
56  * HB_OT_MAX_TAGS_PER_SCRIPT:
57  *
58  * Since: 2.0.0
59  **/
60 #define HB_OT_MAX_TAGS_PER_SCRIPT       3u
61 /**
62  * HB_OT_MAX_TAGS_PER_LANGUAGE:
63  *
64  * Since: 2.0.0
65  **/
66 #define HB_OT_MAX_TAGS_PER_LANGUAGE     3u
67
68 HB_EXTERN void
69 hb_ot_tags_from_script_and_language (hb_script_t   script,
70                                      hb_language_t language,
71                                      unsigned int *script_count /* IN/OUT */,
72                                      hb_tag_t     *script_tags /* OUT */,
73                                      unsigned int *language_count /* IN/OUT */,
74                                      hb_tag_t     *language_tags /* OUT */);
75
76 HB_EXTERN hb_script_t
77 hb_ot_tag_to_script (hb_tag_t tag);
78
79 HB_EXTERN hb_language_t
80 hb_ot_tag_to_language (hb_tag_t tag);
81
82 HB_EXTERN void
83 hb_ot_tags_to_script_and_language (hb_tag_t       script_tag,
84                                    hb_tag_t       language_tag,
85                                    hb_script_t   *script /* OUT */,
86                                    hb_language_t *language /* OUT */);
87
88
89 /*
90  * GDEF
91  */
92
93 HB_EXTERN hb_bool_t
94 hb_ot_layout_has_glyph_classes (hb_face_t *face);
95
96 /**
97  * hb_ot_layout_glyph_class_t:
98  * @HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED: Glyphs not matching the other classifications
99  * @HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH: Spacing, single characters, capable of accepting marks
100  * @HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE: Glyphs that represent ligation of multiple characters
101  * @HB_OT_LAYOUT_GLYPH_CLASS_MARK: Non-spacing, combining glyphs that represent marks
102  * @HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT: Spacing glyphs that represent part of a single character
103  *
104  * The GDEF classes defined for glyphs.
105  *
106  **/
107 typedef enum {
108   HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED = 0,
109   HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH   = 1,
110   HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE     = 2,
111   HB_OT_LAYOUT_GLYPH_CLASS_MARK         = 3,
112   HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT    = 4
113 } hb_ot_layout_glyph_class_t;
114
115 HB_EXTERN hb_ot_layout_glyph_class_t
116 hb_ot_layout_get_glyph_class (hb_face_t      *face,
117                               hb_codepoint_t  glyph);
118
119 HB_EXTERN void
120 hb_ot_layout_get_glyphs_in_class (hb_face_t                  *face,
121                                   hb_ot_layout_glyph_class_t  klass,
122                                   hb_set_t                   *glyphs /* OUT */);
123
124
125 /* Not that useful.  Provides list of attach points for a glyph that a
126  * client may want to cache */
127 HB_EXTERN unsigned int
128 hb_ot_layout_get_attach_points (hb_face_t      *face,
129                                 hb_codepoint_t  glyph,
130                                 unsigned int    start_offset,
131                                 unsigned int   *point_count /* IN/OUT */,
132                                 unsigned int   *point_array /* OUT */);
133
134 /* Ligature caret positions */
135 HB_EXTERN unsigned int
136 hb_ot_layout_get_ligature_carets (hb_font_t      *font,
137                                   hb_direction_t  direction,
138                                   hb_codepoint_t  glyph,
139                                   unsigned int    start_offset,
140                                   unsigned int   *caret_count /* IN/OUT */,
141                                   hb_position_t  *caret_array /* OUT */);
142
143
144 /*
145  * GSUB/GPOS feature query and enumeration interface
146  */
147
148 #define HB_OT_LAYOUT_NO_SCRIPT_INDEX            0xFFFFu
149 #define HB_OT_LAYOUT_NO_FEATURE_INDEX           0xFFFFu
150 #define HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX     0xFFFFu
151 #define HB_OT_LAYOUT_NO_VARIATIONS_INDEX        0xFFFFFFFFu
152
153 HB_EXTERN unsigned int
154 hb_ot_layout_table_get_script_tags (hb_face_t    *face,
155                                     hb_tag_t      table_tag,
156                                     unsigned int  start_offset,
157                                     unsigned int *script_count /* IN/OUT */,
158                                     hb_tag_t     *script_tags /* OUT */);
159
160 HB_EXTERN hb_bool_t
161 hb_ot_layout_table_find_script (hb_face_t    *face,
162                                 hb_tag_t      table_tag,
163                                 hb_tag_t      script_tag,
164                                 unsigned int *script_index);
165
166 HB_EXTERN hb_bool_t
167 hb_ot_layout_table_select_script (hb_face_t      *face,
168                                   hb_tag_t        table_tag,
169                                   unsigned int    script_count,
170                                   const hb_tag_t *script_tags,
171                                   unsigned int   *script_index /* OUT */,
172                                   hb_tag_t       *chosen_script /* OUT */);
173
174 HB_EXTERN unsigned int
175 hb_ot_layout_table_get_feature_tags (hb_face_t    *face,
176                                      hb_tag_t      table_tag,
177                                      unsigned int  start_offset,
178                                      unsigned int *feature_count /* IN/OUT */,
179                                      hb_tag_t     *feature_tags /* OUT */);
180
181 HB_EXTERN unsigned int
182 hb_ot_layout_script_get_language_tags (hb_face_t    *face,
183                                        hb_tag_t      table_tag,
184                                        unsigned int  script_index,
185                                        unsigned int  start_offset,
186                                        unsigned int *language_count /* IN/OUT */,
187                                        hb_tag_t     *language_tags /* OUT */);
188
189 HB_EXTERN hb_bool_t
190 hb_ot_layout_script_select_language (hb_face_t      *face,
191                                      hb_tag_t        table_tag,
192                                      unsigned int    script_index,
193                                      unsigned int    language_count,
194                                      const hb_tag_t *language_tags,
195                                      unsigned int   *language_index /* OUT */);
196
197 HB_EXTERN hb_bool_t
198 hb_ot_layout_language_get_required_feature_index (hb_face_t    *face,
199                                                   hb_tag_t      table_tag,
200                                                   unsigned int  script_index,
201                                                   unsigned int  language_index,
202                                                   unsigned int *feature_index);
203
204 HB_EXTERN hb_bool_t
205 hb_ot_layout_language_get_required_feature (hb_face_t    *face,
206                                             hb_tag_t      table_tag,
207                                             unsigned int  script_index,
208                                             unsigned int  language_index,
209                                             unsigned int *feature_index,
210                                             hb_tag_t     *feature_tag);
211
212 HB_EXTERN unsigned int
213 hb_ot_layout_language_get_feature_indexes (hb_face_t    *face,
214                                            hb_tag_t      table_tag,
215                                            unsigned int  script_index,
216                                            unsigned int  language_index,
217                                            unsigned int  start_offset,
218                                            unsigned int *feature_count /* IN/OUT */,
219                                            unsigned int *feature_indexes /* OUT */);
220
221 HB_EXTERN unsigned int
222 hb_ot_layout_language_get_feature_tags (hb_face_t    *face,
223                                         hb_tag_t      table_tag,
224                                         unsigned int  script_index,
225                                         unsigned int  language_index,
226                                         unsigned int  start_offset,
227                                         unsigned int *feature_count /* IN/OUT */,
228                                         hb_tag_t     *feature_tags /* OUT */);
229
230 HB_EXTERN hb_bool_t
231 hb_ot_layout_language_find_feature (hb_face_t    *face,
232                                     hb_tag_t      table_tag,
233                                     unsigned int  script_index,
234                                     unsigned int  language_index,
235                                     hb_tag_t      feature_tag,
236                                     unsigned int *feature_index);
237
238 HB_EXTERN unsigned int
239 hb_ot_layout_feature_get_lookups (hb_face_t    *face,
240                                   hb_tag_t      table_tag,
241                                   unsigned int  feature_index,
242                                   unsigned int  start_offset,
243                                   unsigned int *lookup_count /* IN/OUT */,
244                                   unsigned int *lookup_indexes /* OUT */);
245
246 HB_EXTERN unsigned int
247 hb_ot_layout_table_get_lookup_count (hb_face_t    *face,
248                                      hb_tag_t      table_tag);
249
250 HB_EXTERN void
251 hb_ot_layout_collect_features (hb_face_t      *face,
252                                hb_tag_t        table_tag,
253                                const hb_tag_t *scripts,
254                                const hb_tag_t *languages,
255                                const hb_tag_t *features,
256                                hb_set_t       *feature_indexes /* OUT */);
257
258 HB_EXTERN void
259 hb_ot_layout_collect_lookups (hb_face_t      *face,
260                               hb_tag_t        table_tag,
261                               const hb_tag_t *scripts,
262                               const hb_tag_t *languages,
263                               const hb_tag_t *features,
264                               hb_set_t       *lookup_indexes /* OUT */);
265
266 HB_EXTERN void
267 hb_ot_layout_lookup_collect_glyphs (hb_face_t    *face,
268                                     hb_tag_t      table_tag,
269                                     unsigned int  lookup_index,
270                                     hb_set_t     *glyphs_before, /* OUT.  May be NULL */
271                                     hb_set_t     *glyphs_input,  /* OUT.  May be NULL */
272                                     hb_set_t     *glyphs_after,  /* OUT.  May be NULL */
273                                     hb_set_t     *glyphs_output  /* OUT.  May be NULL */);
274
275 #ifdef HB_NOT_IMPLEMENTED
276 typedef struct
277 {
278   const hb_codepoint_t *before,
279   unsigned int          before_length,
280   const hb_codepoint_t *input,
281   unsigned int          input_length,
282   const hb_codepoint_t *after,
283   unsigned int          after_length,
284 } hb_ot_layout_glyph_sequence_t;
285
286 typedef hb_bool_t
287 (*hb_ot_layout_glyph_sequence_func_t) (hb_font_t    *font,
288                                        hb_tag_t      table_tag,
289                                        unsigned int  lookup_index,
290                                        const hb_ot_layout_glyph_sequence_t *sequence,
291                                        void         *user_data);
292
293 HB_EXTERN void
294 Xhb_ot_layout_lookup_enumerate_sequences (hb_face_t    *face,
295                                          hb_tag_t      table_tag,
296                                          unsigned int  lookup_index,
297                                          hb_ot_layout_glyph_sequence_func_t callback,
298                                          void         *user_data);
299 #endif
300
301 /* Variations support */
302
303 HB_EXTERN hb_bool_t
304 hb_ot_layout_table_find_feature_variations (hb_face_t    *face,
305                                             hb_tag_t      table_tag,
306                                             const int    *coords,
307                                             unsigned int  num_coords,
308                                             unsigned int *variations_index /* out */);
309
310 HB_EXTERN unsigned int
311 hb_ot_layout_feature_with_variations_get_lookups (hb_face_t    *face,
312                                                   hb_tag_t      table_tag,
313                                                   unsigned int  feature_index,
314                                                   unsigned int  variations_index,
315                                                   unsigned int  start_offset,
316                                                   unsigned int *lookup_count /* IN/OUT */,
317                                                   unsigned int *lookup_indexes /* OUT */);
318
319
320 /*
321  * GSUB
322  */
323
324 HB_EXTERN hb_bool_t
325 hb_ot_layout_has_substitution (hb_face_t *face);
326
327 HB_EXTERN hb_bool_t
328 hb_ot_layout_lookup_would_substitute (hb_face_t            *face,
329                                       unsigned int          lookup_index,
330                                       const hb_codepoint_t *glyphs,
331                                       unsigned int          glyphs_length,
332                                       hb_bool_t             zero_context);
333
334 HB_EXTERN void
335 hb_ot_layout_lookup_substitute_closure (hb_face_t    *face,
336                                         unsigned int  lookup_index,
337                                         hb_set_t     *glyphs
338                                         /*TODO , hb_bool_t  inclusive */);
339
340 HB_EXTERN void
341 hb_ot_layout_lookups_substitute_closure (hb_face_t      *face,
342                                          const hb_set_t *lookups,
343                                          hb_set_t       *glyphs);
344
345
346 #ifdef HB_NOT_IMPLEMENTED
347 /* Note: You better have GDEF when using this API, or marks won't do much. */
348 HB_EXTERN hb_bool_t
349 Xhb_ot_layout_lookup_substitute (hb_font_t            *font,
350                                 unsigned int          lookup_index,
351                                 const hb_ot_layout_glyph_sequence_t *sequence,
352                                 unsigned int          out_size,
353                                 hb_codepoint_t       *glyphs_out,   /* OUT */
354                                 unsigned int         *clusters_out, /* OUT */
355                                 unsigned int         *out_length    /* OUT */);
356 #endif
357
358
359 /*
360  * GPOS
361  */
362
363 HB_EXTERN hb_bool_t
364 hb_ot_layout_has_positioning (hb_face_t *face);
365
366 #ifdef HB_NOT_IMPLEMENTED
367 /* Note: You better have GDEF when using this API, or marks won't do much. */
368 HB_EXTERN hb_bool_t
369 Xhb_ot_layout_lookup_position (hb_font_t            *font,
370                               unsigned int          lookup_index,
371                               const hb_ot_layout_glyph_sequence_t *sequence,
372                               hb_glyph_position_t  *positions /* IN / OUT */);
373 #endif
374
375 /* Optical 'size' feature info.  Returns true if found.
376  * https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#size */
377 HB_EXTERN hb_bool_t
378 hb_ot_layout_get_size_params (hb_face_t       *face,
379                               unsigned int    *design_size,       /* OUT.  May be NULL */
380                               unsigned int    *subfamily_id,      /* OUT.  May be NULL */
381                               hb_ot_name_id_t *subfamily_name_id, /* OUT.  May be NULL */
382                               unsigned int    *range_start,       /* OUT.  May be NULL */
383                               unsigned int    *range_end          /* OUT.  May be NULL */);
384
385
386 HB_EXTERN hb_bool_t
387 hb_ot_layout_feature_get_name_ids (hb_face_t       *face,
388                                    hb_tag_t         table_tag,
389                                    unsigned int     feature_index,
390                                    hb_ot_name_id_t *label_id             /* OUT.  May be NULL */,
391                                    hb_ot_name_id_t *tooltip_id           /* OUT.  May be NULL */,
392                                    hb_ot_name_id_t *sample_id            /* OUT.  May be NULL */,
393                                    unsigned int    *num_named_parameters /* OUT.  May be NULL */,
394                                    hb_ot_name_id_t *first_param_id       /* OUT.  May be NULL */);
395
396
397 HB_EXTERN unsigned int
398 hb_ot_layout_feature_get_characters (hb_face_t      *face,
399                                      hb_tag_t        table_tag,
400                                      unsigned int    feature_index,
401                                      unsigned int    start_offset,
402                                      unsigned int   *char_count    /* IN/OUT.  May be NULL */,
403                                      hb_codepoint_t *characters    /* OUT.     May be NULL */);
404
405 /*
406  * BASE
407  */
408
409 /**
410  * hb_ot_layout_baseline_tag_t:
411  * @HB_OT_LAYOUT_BASELINE_TAG_ROMAN: The baseline used by alphabetic scripts such as Latin, Cyrillic and Greek.
412  * In vertical writing mode, the alphabetic baseline for characters rotated 90 degrees clockwise.
413  * (This would not apply to alphabetic characters that remain upright in vertical writing mode, since these
414  * characters are not rotated.)
415  * @HB_OT_LAYOUT_BASELINE_TAG_HANGING: The hanging baseline. In horizontal direction, this is the horizontal
416  * line from which syllables seem, to hang in Tibetan and other similar scripts. In vertical writing mode,
417  * for Tibetan (or some other similar script) characters rotated 90 degrees clockwise.
418  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT: Ideographic character face bottom or left edge,
419  * if the direction is horizontal or vertical, respectively.
420  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT: Ideographic character face top or right edge,
421  * if the direction is horizontal or vertical, respectively.
422  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT: Ideographic em-box bottom or left edge,
423  * if the direction is horizontal or vertical, respectively.
424  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT: Ideographic em-box top or right edge baseline,
425  * if the direction is horizontal or vertical, respectively.
426  * @HB_OT_LAYOUT_BASELINE_TAG_MATH: The baseline about which mathematical characters are centered.
427  * In vertical writing mode when mathematical characters rotated 90 degrees clockwise, are centered.
428  *
429  * Baseline tags from https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags
430  *
431  * Since: 2.6.0
432  */
433 typedef enum {
434   HB_OT_LAYOUT_BASELINE_TAG_ROMAN                       = HB_TAG ('r','o','m','n'),
435   HB_OT_LAYOUT_BASELINE_TAG_HANGING                     = HB_TAG ('h','a','n','g'),
436   HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT    = HB_TAG ('i','c','f','b'),
437   HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT      = HB_TAG ('i','c','f','t'),
438   HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT   = HB_TAG ('i','d','e','o'),
439   HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT     = HB_TAG ('i','d','t','p'),
440   HB_OT_LAYOUT_BASELINE_TAG_MATH                        = HB_TAG ('m','a','t','h'),
441
442   _HB_OT_LAYOUT_BASELINE_TAG_MAX_VALUE = HB_TAG_MAX_SIGNED /*< skip >*/
443 } hb_ot_layout_baseline_tag_t;
444
445 HB_EXTERN hb_bool_t
446 hb_ot_layout_get_baseline (hb_font_t                   *font,
447                            hb_ot_layout_baseline_tag_t  baseline_tag,
448                            hb_direction_t               direction,
449                            hb_tag_t                     script_tag,
450                            hb_tag_t                     language_tag,
451                            hb_position_t               *coord        /* OUT.  May be NULL. */);
452
453
454 HB_END_DECLS
455
456 #endif /* HB_OT_LAYOUT_H */