xref: /aosp_15_r20/external/harfbuzz_ng/src/hb-ot-shape-normalize.hh (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1*2d1272b8SAndroid Build Coastguard Worker /*
2*2d1272b8SAndroid Build Coastguard Worker  * Copyright © 2012  Google, Inc.
3*2d1272b8SAndroid Build Coastguard Worker  *
4*2d1272b8SAndroid Build Coastguard Worker  *  This is part of HarfBuzz, a text shaping library.
5*2d1272b8SAndroid Build Coastguard Worker  *
6*2d1272b8SAndroid Build Coastguard Worker  * Permission is hereby granted, without written agreement and without
7*2d1272b8SAndroid Build Coastguard Worker  * license or royalty fees, to use, copy, modify, and distribute this
8*2d1272b8SAndroid Build Coastguard Worker  * software and its documentation for any purpose, provided that the
9*2d1272b8SAndroid Build Coastguard Worker  * above copyright notice and the following two paragraphs appear in
10*2d1272b8SAndroid Build Coastguard Worker  * all copies of this software.
11*2d1272b8SAndroid Build Coastguard Worker  *
12*2d1272b8SAndroid Build Coastguard Worker  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13*2d1272b8SAndroid Build Coastguard Worker  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14*2d1272b8SAndroid Build Coastguard Worker  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15*2d1272b8SAndroid Build Coastguard Worker  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16*2d1272b8SAndroid Build Coastguard Worker  * DAMAGE.
17*2d1272b8SAndroid Build Coastguard Worker  *
18*2d1272b8SAndroid Build Coastguard Worker  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19*2d1272b8SAndroid Build Coastguard Worker  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20*2d1272b8SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21*2d1272b8SAndroid Build Coastguard Worker  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22*2d1272b8SAndroid Build Coastguard Worker  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23*2d1272b8SAndroid Build Coastguard Worker  *
24*2d1272b8SAndroid Build Coastguard Worker  * Google Author(s): Behdad Esfahbod
25*2d1272b8SAndroid Build Coastguard Worker  */
26*2d1272b8SAndroid Build Coastguard Worker 
27*2d1272b8SAndroid Build Coastguard Worker #ifndef HB_OT_SHAPE_NORMALIZE_HH
28*2d1272b8SAndroid Build Coastguard Worker #define HB_OT_SHAPE_NORMALIZE_HH
29*2d1272b8SAndroid Build Coastguard Worker 
30*2d1272b8SAndroid Build Coastguard Worker #include "hb.hh"
31*2d1272b8SAndroid Build Coastguard Worker #include "hb-unicode.hh"
32*2d1272b8SAndroid Build Coastguard Worker 
33*2d1272b8SAndroid Build Coastguard Worker 
34*2d1272b8SAndroid Build Coastguard Worker /* buffer var allocations, used during the normalization process */
35*2d1272b8SAndroid Build Coastguard Worker #define glyph_index()	var1.u32
36*2d1272b8SAndroid Build Coastguard Worker 
37*2d1272b8SAndroid Build Coastguard Worker struct hb_ot_shape_plan_t;
38*2d1272b8SAndroid Build Coastguard Worker 
39*2d1272b8SAndroid Build Coastguard Worker enum hb_ot_shape_normalization_mode_t {
40*2d1272b8SAndroid Build Coastguard Worker   HB_OT_SHAPE_NORMALIZATION_MODE_NONE,
41*2d1272b8SAndroid Build Coastguard Worker   HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED,
42*2d1272b8SAndroid Build Coastguard Worker   HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS, /* Never composes base-to-base */
43*2d1272b8SAndroid Build Coastguard Worker   HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT, /* Always fully decomposes and then recompose back */
44*2d1272b8SAndroid Build Coastguard Worker 
45*2d1272b8SAndroid Build Coastguard Worker   HB_OT_SHAPE_NORMALIZATION_MODE_AUTO, /* See hb-ot-shape-normalize.cc for logic. */
46*2d1272b8SAndroid Build Coastguard Worker   HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT = HB_OT_SHAPE_NORMALIZATION_MODE_AUTO
47*2d1272b8SAndroid Build Coastguard Worker };
48*2d1272b8SAndroid Build Coastguard Worker 
49*2d1272b8SAndroid Build Coastguard Worker HB_INTERNAL void _hb_ot_shape_normalize (const hb_ot_shape_plan_t *shaper,
50*2d1272b8SAndroid Build Coastguard Worker 					 hb_buffer_t *buffer,
51*2d1272b8SAndroid Build Coastguard Worker 					 hb_font_t *font);
52*2d1272b8SAndroid Build Coastguard Worker 
53*2d1272b8SAndroid Build Coastguard Worker 
54*2d1272b8SAndroid Build Coastguard Worker struct hb_ot_shape_normalize_context_t
55*2d1272b8SAndroid Build Coastguard Worker {
56*2d1272b8SAndroid Build Coastguard Worker   static bool
decompose_unicodehb_ot_shape_normalize_context_t57*2d1272b8SAndroid Build Coastguard Worker   decompose_unicode (const hb_ot_shape_normalize_context_t *c,
58*2d1272b8SAndroid Build Coastguard Worker 		     hb_codepoint_t  ab,
59*2d1272b8SAndroid Build Coastguard Worker 		     hb_codepoint_t *a,
60*2d1272b8SAndroid Build Coastguard Worker 		     hb_codepoint_t *b)
61*2d1272b8SAndroid Build Coastguard Worker   {
62*2d1272b8SAndroid Build Coastguard Worker     return (bool) c->unicode->decompose (ab, a, b);
63*2d1272b8SAndroid Build Coastguard Worker   }
64*2d1272b8SAndroid Build Coastguard Worker 
65*2d1272b8SAndroid Build Coastguard Worker   static bool
compose_unicodehb_ot_shape_normalize_context_t66*2d1272b8SAndroid Build Coastguard Worker   compose_unicode (const hb_ot_shape_normalize_context_t *c,
67*2d1272b8SAndroid Build Coastguard Worker 		   hb_codepoint_t  a,
68*2d1272b8SAndroid Build Coastguard Worker 		   hb_codepoint_t  b,
69*2d1272b8SAndroid Build Coastguard Worker 		   hb_codepoint_t *ab)
70*2d1272b8SAndroid Build Coastguard Worker   {
71*2d1272b8SAndroid Build Coastguard Worker     return (bool) c->unicode->compose (a, b, ab);
72*2d1272b8SAndroid Build Coastguard Worker   }
73*2d1272b8SAndroid Build Coastguard Worker 
74*2d1272b8SAndroid Build Coastguard Worker   void
override_decompose_and_composehb_ot_shape_normalize_context_t75*2d1272b8SAndroid Build Coastguard Worker   override_decompose_and_compose (bool (*decompose) (const hb_ot_shape_normalize_context_t *c,
76*2d1272b8SAndroid Build Coastguard Worker 						      hb_codepoint_t  ab,
77*2d1272b8SAndroid Build Coastguard Worker 						      hb_codepoint_t *a,
78*2d1272b8SAndroid Build Coastguard Worker 						      hb_codepoint_t *b),
79*2d1272b8SAndroid Build Coastguard Worker 				  bool (*compose) (const hb_ot_shape_normalize_context_t *c,
80*2d1272b8SAndroid Build Coastguard Worker 						   hb_codepoint_t  a,
81*2d1272b8SAndroid Build Coastguard Worker 						   hb_codepoint_t  b,
82*2d1272b8SAndroid Build Coastguard Worker 						   hb_codepoint_t *ab))
83*2d1272b8SAndroid Build Coastguard Worker   {
84*2d1272b8SAndroid Build Coastguard Worker     this->decompose = decompose ? decompose : decompose_unicode;
85*2d1272b8SAndroid Build Coastguard Worker     this->compose = compose ? compose : compose_unicode;
86*2d1272b8SAndroid Build Coastguard Worker   }
87*2d1272b8SAndroid Build Coastguard Worker 
88*2d1272b8SAndroid Build Coastguard Worker   const hb_ot_shape_plan_t *plan;
89*2d1272b8SAndroid Build Coastguard Worker   hb_buffer_t *buffer;
90*2d1272b8SAndroid Build Coastguard Worker   hb_font_t *font;
91*2d1272b8SAndroid Build Coastguard Worker   hb_unicode_funcs_t *unicode;
92*2d1272b8SAndroid Build Coastguard Worker   bool (*decompose) (const hb_ot_shape_normalize_context_t *c,
93*2d1272b8SAndroid Build Coastguard Worker 		     hb_codepoint_t  ab,
94*2d1272b8SAndroid Build Coastguard Worker 		     hb_codepoint_t *a,
95*2d1272b8SAndroid Build Coastguard Worker 		     hb_codepoint_t *b);
96*2d1272b8SAndroid Build Coastguard Worker   bool (*compose) (const hb_ot_shape_normalize_context_t *c,
97*2d1272b8SAndroid Build Coastguard Worker 		   hb_codepoint_t  a,
98*2d1272b8SAndroid Build Coastguard Worker 		   hb_codepoint_t  b,
99*2d1272b8SAndroid Build Coastguard Worker 		   hb_codepoint_t *ab);
100*2d1272b8SAndroid Build Coastguard Worker };
101*2d1272b8SAndroid Build Coastguard Worker 
102*2d1272b8SAndroid Build Coastguard Worker 
103*2d1272b8SAndroid Build Coastguard Worker #endif /* HB_OT_SHAPE_NORMALIZE_HH */
104