Imported Upstream version 2.6.7
[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 /* Not that useful.  Provides list of attach points for a glyph that a
125  * client may want to cache */
126 HB_EXTERN unsigned int
127 hb_ot_layout_get_attach_points (hb_face_t      *face,
128                                 hb_codepoint_t  glyph,
129                                 unsigned int    start_offset,
130                                 unsigned int   *point_count /* IN/OUT */,
131                                 unsigned int   *point_array /* OUT */);
132
133 /* Ligature caret positions */
134 HB_EXTERN unsigned int
135 hb_ot_layout_get_ligature_carets (hb_font_t      *font,
136                                   hb_direction_t  direction,
137                                   hb_codepoint_t  glyph,
138                                   unsigned int    start_offset,
139                                   unsigned int   *caret_count /* IN/OUT */,
140                                   hb_position_t  *caret_array /* OUT */);
141
142
143 /*
144  * GSUB/GPOS feature query and enumeration interface
145  */
146
147 #define HB_OT_LAYOUT_NO_SCRIPT_INDEX            0xFFFFu
148 #define HB_OT_LAYOUT_NO_FEATURE_INDEX           0xFFFFu
149 #define HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX     0xFFFFu
150 #define HB_OT_LAYOUT_NO_VARIATIONS_INDEX        0xFFFFFFFFu
151
152 HB_EXTERN unsigned int
153 hb_ot_layout_table_get_script_tags (hb_face_t    *face,
154                                     hb_tag_t      table_tag,
155                                     unsigned int  start_offset,
156                                     unsigned int *script_count /* IN/OUT */,
157                                     hb_tag_t     *script_tags /* OUT */);
158
159 HB_EXTERN hb_bool_t
160 hb_ot_layout_table_find_script (hb_face_t    *face,
161                                 hb_tag_t      table_tag,
162                                 hb_tag_t      script_tag,
163                                 unsigned int *script_index /* OUT */);
164
165 HB_EXTERN hb_bool_t
166 hb_ot_layout_table_select_script (hb_face_t      *face,
167                                   hb_tag_t        table_tag,
168                                   unsigned int    script_count,
169                                   const hb_tag_t *script_tags,
170                                   unsigned int   *script_index /* OUT */,
171                                   hb_tag_t       *chosen_script /* OUT */);
172
173 HB_EXTERN unsigned int
174 hb_ot_layout_table_get_feature_tags (hb_face_t    *face,
175                                      hb_tag_t      table_tag,
176                                      unsigned int  start_offset,
177                                      unsigned int *feature_count /* IN/OUT */,
178                                      hb_tag_t     *feature_tags /* OUT */);
179
180 HB_EXTERN unsigned int
181 hb_ot_layout_script_get_language_tags (hb_face_t    *face,
182                                        hb_tag_t      table_tag,
183                                        unsigned int  script_index,
184                                        unsigned int  start_offset,
185                                        unsigned int *language_count /* IN/OUT */,
186                                        hb_tag_t     *language_tags /* OUT */);
187
188 HB_EXTERN hb_bool_t
189 hb_ot_layout_script_select_language (hb_face_t      *face,
190                                      hb_tag_t        table_tag,
191                                      unsigned int    script_index,
192                                      unsigned int    language_count,
193                                      const hb_tag_t *language_tags,
194                                      unsigned int   *language_index /* OUT */);
195
196 HB_EXTERN hb_bool_t
197 hb_ot_layout_language_get_required_feature_index (hb_face_t    *face,
198                                                   hb_tag_t      table_tag,
199                                                   unsigned int  script_index,
200                                                   unsigned int  language_index,
201                                                   unsigned int *feature_index /* OUT */);
202
203 HB_EXTERN hb_bool_t
204 hb_ot_layout_language_get_required_feature (hb_face_t    *face,
205                                             hb_tag_t      table_tag,
206                                             unsigned int  script_index,
207                                             unsigned int  language_index,
208                                             unsigned int *feature_index /* OUT */,
209                                             hb_tag_t     *feature_tag /* OUT */);
210
211 HB_EXTERN unsigned int
212 hb_ot_layout_language_get_feature_indexes (hb_face_t    *face,
213                                            hb_tag_t      table_tag,
214                                            unsigned int  script_index,
215                                            unsigned int  language_index,
216                                            unsigned int  start_offset,
217                                            unsigned int *feature_count /* IN/OUT */,
218                                            unsigned int *feature_indexes /* OUT */);
219
220 HB_EXTERN unsigned int
221 hb_ot_layout_language_get_feature_tags (hb_face_t    *face,
222                                         hb_tag_t      table_tag,
223                                         unsigned int  script_index,
224                                         unsigned int  language_index,
225                                         unsigned int  start_offset,
226                                         unsigned int *feature_count /* IN/OUT */,
227                                         hb_tag_t     *feature_tags /* OUT */);
228
229 HB_EXTERN hb_bool_t
230 hb_ot_layout_language_find_feature (hb_face_t    *face,
231                                     hb_tag_t      table_tag,
232                                     unsigned int  script_index,
233                                     unsigned int  language_index,
234                                     hb_tag_t      feature_tag,
235                                     unsigned int *feature_index /* OUT */);
236
237 HB_EXTERN unsigned int
238 hb_ot_layout_feature_get_lookups (hb_face_t    *face,
239                                   hb_tag_t      table_tag,
240                                   unsigned int  feature_index,
241                                   unsigned int  start_offset,
242                                   unsigned int *lookup_count /* IN/OUT */,
243                                   unsigned int *lookup_indexes /* OUT */);
244
245 HB_EXTERN unsigned int
246 hb_ot_layout_table_get_lookup_count (hb_face_t    *face,
247                                      hb_tag_t      table_tag);
248
249 HB_EXTERN void
250 hb_ot_layout_collect_features (hb_face_t      *face,
251                                hb_tag_t        table_tag,
252                                const hb_tag_t *scripts,
253                                const hb_tag_t *languages,
254                                const hb_tag_t *features,
255                                hb_set_t       *feature_indexes /* OUT */);
256
257 HB_EXTERN void
258 hb_ot_layout_collect_lookups (hb_face_t      *face,
259                               hb_tag_t        table_tag,
260                               const hb_tag_t *scripts,
261                               const hb_tag_t *languages,
262                               const hb_tag_t *features,
263                               hb_set_t       *lookup_indexes /* OUT */);
264
265 #ifdef HB_EXPERIMENTAL_API
266 HB_EXTERN void
267 hb_ot_layout_closure_lookups (hb_face_t      *face,
268                               hb_tag_t        table_tag,
269                               const hb_set_t *glyphs,
270                               hb_set_t       *lookup_indexes /* IN/OUT */);
271
272 HB_EXTERN void
273 hb_ot_layout_closure_features (hb_face_t      *face,
274                                hb_tag_t        table_tag,
275                                const hb_map_t *lookup_indexes, /* IN */
276                                hb_set_t       *feature_indexes /* OUT */);
277 #endif
278
279 HB_EXTERN void
280 hb_ot_layout_lookup_collect_glyphs (hb_face_t    *face,
281                                     hb_tag_t      table_tag,
282                                     unsigned int  lookup_index,
283                                     hb_set_t     *glyphs_before, /* OUT.  May be NULL */
284                                     hb_set_t     *glyphs_input,  /* OUT.  May be NULL */
285                                     hb_set_t     *glyphs_after,  /* OUT.  May be NULL */
286                                     hb_set_t     *glyphs_output  /* OUT.  May be NULL */);
287
288 #ifdef HB_NOT_IMPLEMENTED
289 typedef struct
290 {
291   const hb_codepoint_t *before,
292   unsigned int          before_length,
293   const hb_codepoint_t *input,
294   unsigned int          input_length,
295   const hb_codepoint_t *after,
296   unsigned int          after_length,
297 } hb_ot_layout_glyph_sequence_t;
298
299 typedef hb_bool_t
300 (*hb_ot_layout_glyph_sequence_func_t) (hb_font_t    *font,
301                                        hb_tag_t      table_tag,
302                                        unsigned int  lookup_index,
303                                        const hb_ot_layout_glyph_sequence_t *sequence,
304                                        void         *user_data);
305
306 HB_EXTERN void
307 Xhb_ot_layout_lookup_enumerate_sequences (hb_face_t    *face,
308                                          hb_tag_t      table_tag,
309                                          unsigned int  lookup_index,
310                                          hb_ot_layout_glyph_sequence_func_t callback,
311                                          void         *user_data);
312 #endif
313
314 /* Variations support */
315
316 HB_EXTERN hb_bool_t
317 hb_ot_layout_table_find_feature_variations (hb_face_t    *face,
318                                             hb_tag_t      table_tag,
319                                             const int    *coords,
320                                             unsigned int  num_coords,
321                                             unsigned int *variations_index /* out */);
322
323 HB_EXTERN unsigned int
324 hb_ot_layout_feature_with_variations_get_lookups (hb_face_t    *face,
325                                                   hb_tag_t      table_tag,
326                                                   unsigned int  feature_index,
327                                                   unsigned int  variations_index,
328                                                   unsigned int  start_offset,
329                                                   unsigned int *lookup_count /* IN/OUT */,
330                                                   unsigned int *lookup_indexes /* OUT */);
331
332
333 /*
334  * GSUB
335  */
336
337 HB_EXTERN hb_bool_t
338 hb_ot_layout_has_substitution (hb_face_t *face);
339
340 HB_EXTERN hb_bool_t
341 hb_ot_layout_lookup_would_substitute (hb_face_t            *face,
342                                       unsigned int          lookup_index,
343                                       const hb_codepoint_t *glyphs,
344                                       unsigned int          glyphs_length,
345                                       hb_bool_t             zero_context);
346
347 HB_EXTERN void
348 hb_ot_layout_lookup_substitute_closure (hb_face_t    *face,
349                                         unsigned int  lookup_index,
350                                         hb_set_t     *glyphs
351                                         /*TODO , hb_bool_t  inclusive */);
352
353 HB_EXTERN void
354 hb_ot_layout_lookups_substitute_closure (hb_face_t      *face,
355                                          const hb_set_t *lookups,
356                                          hb_set_t       *glyphs);
357
358
359 #ifdef HB_NOT_IMPLEMENTED
360 /* Note: You better have GDEF when using this API, or marks won't do much. */
361 HB_EXTERN hb_bool_t
362 Xhb_ot_layout_lookup_substitute (hb_font_t            *font,
363                                 unsigned int          lookup_index,
364                                 const hb_ot_layout_glyph_sequence_t *sequence,
365                                 unsigned int          out_size,
366                                 hb_codepoint_t       *glyphs_out,   /* OUT */
367                                 unsigned int         *clusters_out, /* OUT */
368                                 unsigned int         *out_length    /* OUT */);
369 #endif
370
371
372 /*
373  * GPOS
374  */
375
376 HB_EXTERN hb_bool_t
377 hb_ot_layout_has_positioning (hb_face_t *face);
378
379 #ifdef HB_NOT_IMPLEMENTED
380 /* Note: You better have GDEF when using this API, or marks won't do much. */
381 HB_EXTERN hb_bool_t
382 Xhb_ot_layout_lookup_position (hb_font_t            *font,
383                               unsigned int          lookup_index,
384                               const hb_ot_layout_glyph_sequence_t *sequence,
385                               hb_glyph_position_t  *positions /* IN / OUT */);
386 #endif
387
388 /* Optical 'size' feature info.  Returns true if found.
389  * https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#size */
390 HB_EXTERN hb_bool_t
391 hb_ot_layout_get_size_params (hb_face_t       *face,
392                               unsigned int    *design_size,       /* OUT.  May be NULL */
393                               unsigned int    *subfamily_id,      /* OUT.  May be NULL */
394                               hb_ot_name_id_t *subfamily_name_id, /* OUT.  May be NULL */
395                               unsigned int    *range_start,       /* OUT.  May be NULL */
396                               unsigned int    *range_end          /* OUT.  May be NULL */);
397
398
399 HB_EXTERN hb_bool_t
400 hb_ot_layout_feature_get_name_ids (hb_face_t       *face,
401                                    hb_tag_t         table_tag,
402                                    unsigned int     feature_index,
403                                    hb_ot_name_id_t *label_id             /* OUT.  May be NULL */,
404                                    hb_ot_name_id_t *tooltip_id           /* OUT.  May be NULL */,
405                                    hb_ot_name_id_t *sample_id            /* OUT.  May be NULL */,
406                                    unsigned int    *num_named_parameters /* OUT.  May be NULL */,
407                                    hb_ot_name_id_t *first_param_id       /* OUT.  May be NULL */);
408
409
410 HB_EXTERN unsigned int
411 hb_ot_layout_feature_get_characters (hb_face_t      *face,
412                                      hb_tag_t        table_tag,
413                                      unsigned int    feature_index,
414                                      unsigned int    start_offset,
415                                      unsigned int   *char_count    /* IN/OUT.  May be NULL */,
416                                      hb_codepoint_t *characters    /* OUT.     May be NULL */);
417
418 /*
419  * BASE
420  */
421
422 /**
423  * hb_ot_layout_baseline_tag_t:
424  * @HB_OT_LAYOUT_BASELINE_TAG_ROMAN: The baseline used by alphabetic scripts such as Latin, Cyrillic and Greek.
425  * In vertical writing mode, the alphabetic baseline for characters rotated 90 degrees clockwise.
426  * (This would not apply to alphabetic characters that remain upright in vertical writing mode, since these
427  * characters are not rotated.)
428  * @HB_OT_LAYOUT_BASELINE_TAG_HANGING: The hanging baseline. In horizontal direction, this is the horizontal
429  * line from which syllables seem, to hang in Tibetan and other similar scripts. In vertical writing mode,
430  * for Tibetan (or some other similar script) characters rotated 90 degrees clockwise.
431  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT: Ideographic character face bottom or left edge,
432  * if the direction is horizontal or vertical, respectively.
433  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT: Ideographic character face top or right edge,
434  * if the direction is horizontal or vertical, respectively.
435  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT: Ideographic em-box bottom or left edge,
436  * if the direction is horizontal or vertical, respectively.
437  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT: Ideographic em-box top or right edge baseline,
438  * if the direction is horizontal or vertical, respectively.
439  * @HB_OT_LAYOUT_BASELINE_TAG_MATH: The baseline about which mathematical characters are centered.
440  * In vertical writing mode when mathematical characters rotated 90 degrees clockwise, are centered.
441  *
442  * Baseline tags from https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags
443  *
444  * Since: 2.6.0
445  */
446 typedef enum {
447   HB_OT_LAYOUT_BASELINE_TAG_ROMAN                       = HB_TAG ('r','o','m','n'),
448   HB_OT_LAYOUT_BASELINE_TAG_HANGING                     = HB_TAG ('h','a','n','g'),
449   HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT    = HB_TAG ('i','c','f','b'),
450   HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT      = HB_TAG ('i','c','f','t'),
451   HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT   = HB_TAG ('i','d','e','o'),
452   HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT     = HB_TAG ('i','d','t','p'),
453   HB_OT_LAYOUT_BASELINE_TAG_MATH                        = HB_TAG ('m','a','t','h'),
454
455   _HB_OT_LAYOUT_BASELINE_TAG_MAX_VALUE = HB_TAG_MAX_SIGNED /*< skip >*/
456 } hb_ot_layout_baseline_tag_t;
457
458 HB_EXTERN hb_bool_t
459 hb_ot_layout_get_baseline (hb_font_t                   *font,
460                            hb_ot_layout_baseline_tag_t  baseline_tag,
461                            hb_direction_t               direction,
462                            hb_tag_t                     script_tag,
463                            hb_tag_t                     language_tag,
464                            hb_position_t               *coord        /* OUT.  May be NULL. */);
465
466
467 HB_END_DECLS
468
469 #endif /* HB_OT_LAYOUT_H */