• 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.hh"
28 
29 
30 static bool
compose_hebrew(const hb_ot_shape_normalize_context_t * c,hb_codepoint_t a,hb_codepoint_t b,hb_codepoint_t * ab)31 compose_hebrew (const hb_ot_shape_normalize_context_t *c,
32 		hb_codepoint_t  a,
33 		hb_codepoint_t  b,
34 		hb_codepoint_t *ab)
35 {
36   /* Hebrew presentation-form shaping.
37    * https://bugzilla.mozilla.org/show_bug.cgi?id=728866
38    * Hebrew presentation forms with dagesh, for characters U+05D0..05EA;
39    * Note that some letters do not have a dagesh presForm encoded.
40    */
41   static const hb_codepoint_t sDageshForms[0x05EAu - 0x05D0u + 1] = {
42     0xFB30u, /* ALEF */
43     0xFB31u, /* BET */
44     0xFB32u, /* GIMEL */
45     0xFB33u, /* DALET */
46     0xFB34u, /* HE */
47     0xFB35u, /* VAV */
48     0xFB36u, /* ZAYIN */
49     0x0000u, /* HET */
50     0xFB38u, /* TET */
51     0xFB39u, /* YOD */
52     0xFB3Au, /* FINAL KAF */
53     0xFB3Bu, /* KAF */
54     0xFB3Cu, /* LAMED */
55     0x0000u, /* FINAL MEM */
56     0xFB3Eu, /* MEM */
57     0x0000u, /* FINAL NUN */
58     0xFB40u, /* NUN */
59     0xFB41u, /* SAMEKH */
60     0x0000u, /* AYIN */
61     0xFB43u, /* FINAL PE */
62     0xFB44u, /* PE */
63     0x0000u, /* FINAL TSADI */
64     0xFB46u, /* TSADI */
65     0xFB47u, /* QOF */
66     0xFB48u, /* RESH */
67     0xFB49u, /* SHIN */
68     0xFB4Au /* TAV */
69   };
70 
71   bool found = (bool) c->unicode->compose (a, b, ab);
72 
73 #ifdef HB_NO_OT_SHAPE_COMPLEX_HEBREW_FALLBACK
74   return found;
75 #endif
76 
77   if (!found && !c->plan->has_gpos_mark)
78   {
79       /* Special-case Hebrew presentation forms that are excluded from
80        * standard normalization, but wanted for old fonts. */
81       switch (b) {
82       case 0x05B4u: /* HIRIQ */
83 	  if (a == 0x05D9u) { /* YOD */
84 	      *ab = 0xFB1Du;
85 	      found = true;
86 	  }
87 	  break;
88       case 0x05B7u: /* patah */
89 	  if (a == 0x05F2u) { /* YIDDISH YOD YOD */
90 	      *ab = 0xFB1Fu;
91 	      found = true;
92 	  } else if (a == 0x05D0u) { /* ALEF */
93 	      *ab = 0xFB2Eu;
94 	      found = true;
95 	  }
96 	  break;
97       case 0x05B8u: /* QAMATS */
98 	  if (a == 0x05D0u) { /* ALEF */
99 	      *ab = 0xFB2Fu;
100 	      found = true;
101 	  }
102 	  break;
103       case 0x05B9u: /* HOLAM */
104 	  if (a == 0x05D5u) { /* VAV */
105 	      *ab = 0xFB4Bu;
106 	      found = true;
107 	  }
108 	  break;
109       case 0x05BCu: /* DAGESH */
110 	  if (a >= 0x05D0u && a <= 0x05EAu) {
111 	      *ab = sDageshForms[a - 0x05D0u];
112 	      found = (*ab != 0);
113 	  } else if (a == 0xFB2Au) { /* SHIN WITH SHIN DOT */
114 	      *ab = 0xFB2Cu;
115 	      found = true;
116 	  } else if (a == 0xFB2Bu) { /* SHIN WITH SIN DOT */
117 	      *ab = 0xFB2Du;
118 	      found = true;
119 	  }
120 	  break;
121       case 0x05BFu: /* RAFE */
122 	  switch (a) {
123 	  case 0x05D1u: /* BET */
124 	      *ab = 0xFB4Cu;
125 	      found = true;
126 	      break;
127 	  case 0x05DBu: /* KAF */
128 	      *ab = 0xFB4Du;
129 	      found = true;
130 	      break;
131 	  case 0x05E4u: /* PE */
132 	      *ab = 0xFB4Eu;
133 	      found = true;
134 	      break;
135 	  }
136 	  break;
137       case 0x05C1u: /* SHIN DOT */
138 	  if (a == 0x05E9u) { /* SHIN */
139 	      *ab = 0xFB2Au;
140 	      found = true;
141 	  } else if (a == 0xFB49u) { /* SHIN WITH DAGESH */
142 	      *ab = 0xFB2Cu;
143 	      found = true;
144 	  }
145 	  break;
146       case 0x05C2u: /* SIN DOT */
147 	  if (a == 0x05E9u) { /* SHIN */
148 	      *ab = 0xFB2Bu;
149 	      found = true;
150 	  } else if (a == 0xFB49u) { /* SHIN WITH DAGESH */
151 	      *ab = 0xFB2Du;
152 	      found = true;
153 	  }
154 	  break;
155       }
156   }
157 
158   return found;
159 }
160 
161 
162 const hb_ot_complex_shaper_t _hb_ot_complex_shaper_hebrew =
163 {
164   nullptr, /* collect_features */
165   nullptr, /* override_features */
166   nullptr, /* data_create */
167   nullptr, /* data_destroy */
168   nullptr, /* preprocess_text */
169   nullptr, /* postprocess_glyphs */
170   HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT,
171   nullptr, /* decompose */
172   compose_hebrew,
173   nullptr, /* setup_masks */
174   HB_TAG ('h','e','b','r'), /* gpos_tag. https://github.com/harfbuzz/harfbuzz/issues/347#issuecomment-267838368 */
175   nullptr, /* reorder_marks */
176   HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE,
177   true, /* fallback_position */
178 };
179