• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
collect_features_default(hb_ot_shape_planner_t * plan)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
normalization_preference_default(const hb_segment_properties_t * props)75 normalization_preference_default (const hb_segment_properties_t *props)
76 {
77   switch ((hb_tag_t) props->script)
78   {
79     /* Unicode-1.1 additions */
80     case HB_SCRIPT_HANGUL:
81       return HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL;
82   }
83   return HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS;
84 }
85 
86 static bool
compose_default(const hb_ot_shape_normalize_context_t * c,hb_codepoint_t a,hb_codepoint_t b,hb_codepoint_t * ab)87 compose_default (const hb_ot_shape_normalize_context_t *c,
88 		 hb_codepoint_t  a,
89 		 hb_codepoint_t  b,
90 		 hb_codepoint_t *ab)
91 {
92   /* Hebrew presentation-form shaping.
93    * https://bugzilla.mozilla.org/show_bug.cgi?id=728866
94    * Hebrew presentation forms with dagesh, for characters 0x05D0..0x05EA;
95    * Note that some letters do not have a dagesh presForm encoded.
96    */
97   static const hb_codepoint_t sDageshForms[0x05EA - 0x05D0 + 1] = {
98     0xFB30, /* ALEF */
99     0xFB31, /* BET */
100     0xFB32, /* GIMEL */
101     0xFB33, /* DALET */
102     0xFB34, /* HE */
103     0xFB35, /* VAV */
104     0xFB36, /* ZAYIN */
105     0x0000, /* HET */
106     0xFB38, /* TET */
107     0xFB39, /* YOD */
108     0xFB3A, /* FINAL KAF */
109     0xFB3B, /* KAF */
110     0xFB3C, /* LAMED */
111     0x0000, /* FINAL MEM */
112     0xFB3E, /* MEM */
113     0x0000, /* FINAL NUN */
114     0xFB40, /* NUN */
115     0xFB41, /* SAMEKH */
116     0x0000, /* AYIN */
117     0xFB43, /* FINAL PE */
118     0xFB44, /* PE */
119     0x0000, /* FINAL TSADI */
120     0xFB46, /* TSADI */
121     0xFB47, /* QOF */
122     0xFB48, /* RESH */
123     0xFB49, /* SHIN */
124     0xFB4A /* TAV */
125   };
126 
127   bool found = c->unicode->compose (a, b, ab);
128 
129   if (!found && (b & ~0x7F) == 0x0580) {
130       /* Special-case Hebrew presentation forms that are excluded from
131        * standard normalization, but wanted for old fonts. */
132       switch (b) {
133       case 0x05B4: /* HIRIQ */
134 	  if (a == 0x05D9) { /* YOD */
135 	      *ab = 0xFB1D;
136 	      found = true;
137 	  }
138 	  break;
139       case 0x05B7: /* patah */
140 	  if (a == 0x05F2) { /* YIDDISH YOD YOD */
141 	      *ab = 0xFB1F;
142 	      found = true;
143 	  } else if (a == 0x05D0) { /* ALEF */
144 	      *ab = 0xFB2E;
145 	      found = true;
146 	  }
147 	  break;
148       case 0x05B8: /* QAMATS */
149 	  if (a == 0x05D0) { /* ALEF */
150 	      *ab = 0xFB2F;
151 	      found = true;
152 	  }
153 	  break;
154       case 0x05B9: /* HOLAM */
155 	  if (a == 0x05D5) { /* VAV */
156 	      *ab = 0xFB4B;
157 	      found = true;
158 	  }
159 	  break;
160       case 0x05BC: /* DAGESH */
161 	  if (a >= 0x05D0 && a <= 0x05EA) {
162 	      *ab = sDageshForms[a - 0x05D0];
163 	      found = (*ab != 0);
164 	  } else if (a == 0xFB2A) { /* SHIN WITH SHIN DOT */
165 	      *ab = 0xFB2C;
166 	      found = true;
167 	  } else if (a == 0xFB2B) { /* SHIN WITH SIN DOT */
168 	      *ab = 0xFB2D;
169 	      found = true;
170 	  }
171 	  break;
172       case 0x05BF: /* RAFE */
173 	  switch (a) {
174 	  case 0x05D1: /* BET */
175 	      *ab = 0xFB4C;
176 	      found = true;
177 	      break;
178 	  case 0x05DB: /* KAF */
179 	      *ab = 0xFB4D;
180 	      found = true;
181 	      break;
182 	  case 0x05E4: /* PE */
183 	      *ab = 0xFB4E;
184 	      found = true;
185 	      break;
186 	  }
187 	  break;
188       case 0x05C1: /* SHIN DOT */
189 	  if (a == 0x05E9) { /* SHIN */
190 	      *ab = 0xFB2A;
191 	      found = true;
192 	  } else if (a == 0xFB49) { /* SHIN WITH DAGESH */
193 	      *ab = 0xFB2C;
194 	      found = true;
195 	  }
196 	  break;
197       case 0x05C2: /* SIN DOT */
198 	  if (a == 0x05E9) { /* SHIN */
199 	      *ab = 0xFB2B;
200 	      found = true;
201 	  } else if (a == 0xFB49) { /* SHIN WITH DAGESH */
202 	      *ab = 0xFB2D;
203 	      found = true;
204 	  }
205 	  break;
206       }
207   }
208 
209   return found;
210 }
211 
212 const hb_ot_complex_shaper_t _hb_ot_complex_shaper_default =
213 {
214   "default",
215   collect_features_default,
216   NULL, /* override_features */
217   NULL, /* data_create */
218   NULL, /* data_destroy */
219   NULL, /* preprocess_text */
220   normalization_preference_default,
221   NULL, /* decompose */
222   compose_default,
223   NULL, /* setup_masks */
224   HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE,
225   true, /* fallback_position */
226 };
227