- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / harfbuzz-ng / src / hb-ot-shape-complex-default.cc
1 /*
2  * Copyright © 2010,2012  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 #include "hb-ot-shape-complex-private.hh"
28
29
30 /* TODO Add kana, and other small shapers here */
31
32
33 /* The default shaper *only* adds additional per-script features.*/
34
35 static const hb_tag_t hangul_features[] =
36 {
37   HB_TAG('l','j','m','o'),
38   HB_TAG('v','j','m','o'),
39   HB_TAG('t','j','m','o'),
40   HB_TAG_NONE
41 };
42
43 static const hb_tag_t tibetan_features[] =
44 {
45   HB_TAG('a','b','v','s'),
46   HB_TAG('b','l','w','s'),
47   HB_TAG('a','b','v','m'),
48   HB_TAG('b','l','w','m'),
49   HB_TAG_NONE
50 };
51
52 static void
53 collect_features_default (hb_ot_shape_planner_t *plan)
54 {
55   const hb_tag_t *script_features = NULL;
56
57   switch ((hb_tag_t) plan->props.script)
58   {
59     /* Unicode-1.1 additions */
60     case HB_SCRIPT_HANGUL:
61       script_features = hangul_features;
62       break;
63
64     /* Unicode-2.0 additions */
65     case HB_SCRIPT_TIBETAN:
66       script_features = tibetan_features;
67       break;
68   }
69
70   for (; script_features && *script_features; script_features++)
71     plan->map.add_global_bool_feature (*script_features);
72 }
73
74 static hb_ot_shape_normalization_mode_t
75 normalization_preference_default (const hb_segment_properties_t *props)
76 {
77   return HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS;
78 }
79
80 static bool
81 compose_default (const hb_ot_shape_normalize_context_t *c,
82                  hb_codepoint_t  a,
83                  hb_codepoint_t  b,
84                  hb_codepoint_t *ab)
85 {
86   /* Hebrew presentation-form shaping.
87    * https://bugzilla.mozilla.org/show_bug.cgi?id=728866
88    * Hebrew presentation forms with dagesh, for characters 0x05D0..0x05EA;
89    * Note that some letters do not have a dagesh presForm encoded.
90    */
91   static const hb_codepoint_t sDageshForms[0x05EA - 0x05D0 + 1] = {
92     0xFB30, /* ALEF */
93     0xFB31, /* BET */
94     0xFB32, /* GIMEL */
95     0xFB33, /* DALET */
96     0xFB34, /* HE */
97     0xFB35, /* VAV */
98     0xFB36, /* ZAYIN */
99     0x0000, /* HET */
100     0xFB38, /* TET */
101     0xFB39, /* YOD */
102     0xFB3A, /* FINAL KAF */
103     0xFB3B, /* KAF */
104     0xFB3C, /* LAMED */
105     0x0000, /* FINAL MEM */
106     0xFB3E, /* MEM */
107     0x0000, /* FINAL NUN */
108     0xFB40, /* NUN */
109     0xFB41, /* SAMEKH */
110     0x0000, /* AYIN */
111     0xFB43, /* FINAL PE */
112     0xFB44, /* PE */
113     0x0000, /* FINAL TSADI */
114     0xFB46, /* TSADI */
115     0xFB47, /* QOF */
116     0xFB48, /* RESH */
117     0xFB49, /* SHIN */
118     0xFB4A /* TAV */
119   };
120
121   bool found = c->unicode->compose (a, b, ab);
122
123   if (!found && (b & ~0x7F) == 0x0580) {
124       /* Special-case Hebrew presentation forms that are excluded from
125        * standard normalization, but wanted for old fonts. */
126       switch (b) {
127       case 0x05B4: /* HIRIQ */
128           if (a == 0x05D9) { /* YOD */
129               *ab = 0xFB1D;
130               found = true;
131           }
132           break;
133       case 0x05B7: /* patah */
134           if (a == 0x05F2) { /* YIDDISH YOD YOD */
135               *ab = 0xFB1F;
136               found = true;
137           } else if (a == 0x05D0) { /* ALEF */
138               *ab = 0xFB2E;
139               found = true;
140           }
141           break;
142       case 0x05B8: /* QAMATS */
143           if (a == 0x05D0) { /* ALEF */
144               *ab = 0xFB2F;
145               found = true;
146           }
147           break;
148       case 0x05B9: /* HOLAM */
149           if (a == 0x05D5) { /* VAV */
150               *ab = 0xFB4B;
151               found = true;
152           }
153           break;
154       case 0x05BC: /* DAGESH */
155           if (a >= 0x05D0 && a <= 0x05EA) {
156               *ab = sDageshForms[a - 0x05D0];
157               found = (*ab != 0);
158           } else if (a == 0xFB2A) { /* SHIN WITH SHIN DOT */
159               *ab = 0xFB2C;
160               found = true;
161           } else if (a == 0xFB2B) { /* SHIN WITH SIN DOT */
162               *ab = 0xFB2D;
163               found = true;
164           }
165           break;
166       case 0x05BF: /* RAFE */
167           switch (a) {
168           case 0x05D1: /* BET */
169               *ab = 0xFB4C;
170               found = true;
171               break;
172           case 0x05DB: /* KAF */
173               *ab = 0xFB4D;
174               found = true;
175               break;
176           case 0x05E4: /* PE */
177               *ab = 0xFB4E;
178               found = true;
179               break;
180           }
181           break;
182       case 0x05C1: /* SHIN DOT */
183           if (a == 0x05E9) { /* SHIN */
184               *ab = 0xFB2A;
185               found = true;
186           } else if (a == 0xFB49) { /* SHIN WITH DAGESH */
187               *ab = 0xFB2C;
188               found = true;
189           }
190           break;
191       case 0x05C2: /* SIN DOT */
192           if (a == 0x05E9) { /* SHIN */
193               *ab = 0xFB2B;
194               found = true;
195           } else if (a == 0xFB49) { /* SHIN WITH DAGESH */
196               *ab = 0xFB2D;
197               found = true;
198           }
199           break;
200       }
201   }
202
203   return found;
204 }
205
206 const hb_ot_complex_shaper_t _hb_ot_complex_shaper_default =
207 {
208   "default",
209   collect_features_default,
210   NULL, /* override_features */
211   NULL, /* data_create */
212   NULL, /* data_destroy */
213   NULL, /* preprocess_text */
214   normalization_preference_default,
215   NULL, /* decompose */
216   compose_default,
217   NULL, /* setup_masks */
218   HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE,
219   true, /* fallback_position */
220 };