• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2018  Google, 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  * Google Author(s): Behdad Esfahbod
25  */
26 
27 #ifndef HB_OT_SHAPE_COMPLEX_MYANMAR_HH
28 #define HB_OT_SHAPE_COMPLEX_MYANMAR_HH
29 
30 #include "hb.hh"
31 
32 #include "hb-ot-shape-complex-indic.hh"
33 
34 
35 /* buffer var allocations */
36 #define myanmar_category() indic_category() /* myanmar_category_t */
37 #define myanmar_position() indic_position() /* myanmar_position_t */
38 
39 
40 /* Note: This enum is duplicated in the -machine.rl source file.
41  * Not sure how to avoid duplication. */
42 enum myanmar_category_t {
43   OT_As  = 18,  /* Asat */
44   OT_D0  = 20, /* Digit zero */
45   OT_DB  = OT_N, /* Dot below */
46   OT_GB  = OT_PLACEHOLDER,
47   OT_MH  = 21, /* Various consonant medial types */
48   OT_MR  = 22, /* Various consonant medial types */
49   OT_MW  = 23, /* Various consonant medial types */
50   OT_MY  = 24, /* Various consonant medial types */
51   OT_PT  = 25, /* Pwo and other tones */
52   OT_VAbv = 26,
53   OT_VBlw = 27,
54   OT_VPre = 28,
55   OT_VPst = 29,
56   OT_VS   = 30, /* Variation selectors */
57   OT_P    = 31, /* Punctuation */
58   OT_D    = 32, /* Digits except zero */
59 };
60 
61 
62 static inline void
set_myanmar_properties(hb_glyph_info_t & info)63 set_myanmar_properties (hb_glyph_info_t &info)
64 {
65   hb_codepoint_t u = info.codepoint;
66   unsigned int type = hb_indic_get_categories (u);
67   unsigned int cat = type & 0x7Fu;
68   indic_position_t pos = (indic_position_t) (type >> 8);
69 
70   /* Myanmar
71    * https://docs.microsoft.com/en-us/typography/script-development/myanmar#analyze
72    */
73   if (unlikely (hb_in_range<hb_codepoint_t> (u, 0xFE00u, 0xFE0Fu)))
74     cat = OT_VS;
75 
76   switch (u)
77   {
78     case 0x104Eu:
79       cat = OT_C; /* The spec says C, IndicSyllableCategory doesn't have. */
80       break;
81 
82     case 0x002Du: case 0x00A0u: case 0x00D7u: case 0x2012u:
83     case 0x2013u: case 0x2014u: case 0x2015u: case 0x2022u:
84     case 0x25CCu: case 0x25FBu: case 0x25FCu: case 0x25FDu:
85     case 0x25FEu:
86       cat = OT_GB;
87       break;
88 
89     case 0x1004u: case 0x101Bu: case 0x105Au:
90       cat = OT_Ra;
91       break;
92 
93     case 0x1032u: case 0x1036u:
94       cat = OT_A;
95       break;
96 
97     case 0x1039u:
98       cat = OT_H;
99       break;
100 
101     case 0x103Au:
102       cat = OT_As;
103       break;
104 
105     case 0x1041u: case 0x1042u: case 0x1043u: case 0x1044u:
106     case 0x1045u: case 0x1046u: case 0x1047u: case 0x1048u:
107     case 0x1049u: case 0x1090u: case 0x1091u: case 0x1092u:
108     case 0x1093u: case 0x1094u: case 0x1095u: case 0x1096u:
109     case 0x1097u: case 0x1098u: case 0x1099u:
110       cat = OT_D;
111       break;
112 
113     case 0x1040u:
114       cat = OT_D; /* XXX The spec says D0, but Uniscribe doesn't seem to do. */
115       break;
116 
117     case 0x103Eu: case 0x1060u:
118       cat = OT_MH;
119       break;
120 
121     case 0x103Cu:
122       cat = OT_MR;
123       break;
124 
125     case 0x103Du: case 0x1082u:
126       cat = OT_MW;
127       break;
128 
129     case 0x103Bu: case 0x105Eu: case 0x105Fu:
130       cat = OT_MY;
131       break;
132 
133     case 0x1063u: case 0x1064u: case 0x1069u: case 0x106Au:
134     case 0x106Bu: case 0x106Cu: case 0x106Du: case 0xAA7Bu:
135       cat = OT_PT;
136       break;
137 
138     case 0x1038u: case 0x1087u: case 0x1088u: case 0x1089u:
139     case 0x108Au: case 0x108Bu: case 0x108Cu: case 0x108Du:
140     case 0x108Fu: case 0x109Au: case 0x109Bu: case 0x109Cu:
141       cat = OT_SM;
142       break;
143 
144     case 0x104Au: case 0x104Bu:
145       cat = OT_P;
146       break;
147 
148     case 0xAA74u: case 0xAA75u: case 0xAA76u:
149       /* https://github.com/roozbehp/unicode-data/issues/3 */
150       cat = OT_C;
151       break;
152   }
153 
154   if (cat == OT_M)
155   {
156     switch ((int) pos)
157     {
158       case POS_PRE_C:	cat = OT_VPre;
159 			pos = POS_PRE_M; break;
160       case POS_ABOVE_C:	cat = OT_VAbv;   break;
161       case POS_BELOW_C:	cat = OT_VBlw;   break;
162       case POS_POST_C:	cat = OT_VPst;   break;
163     }
164   }
165 
166   info.myanmar_category() = cat;
167   info.myanmar_position() = pos;
168 }
169 
170 
171 #endif /* HB_OT_SHAPE_COMPLEX_MYANMAR_HH */
172