2 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * This is part of HarfBuzz, an OpenType Layout engine library.
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.
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
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.
25 #include "harfbuzz-shaper.h"
26 #include "harfbuzz-shaper-private.h"
30 // Uniscribe also defines dlig for Hebrew, but we leave this out for now, as it's mostly
31 // ligatures one does not want in modern Hebrew (as lam-alef ligatures).
34 static const HB_OpenTypeFeature hebrew_features[] = {
35 { HB_MAKE_TAG('c', 'c', 'm', 'p'), CcmpProperty },
40 /* Hebrew shaping. In the non opentype case we try to use the
41 presentation forms specified for Hebrew. Especially for the
42 ligatures with Dagesh this gives much better results than we could
45 HB_Bool HB_HebrewShape(HB_ShaperItem *shaper_item)
57 assert(shaper_item->item.script == HB_Script_Hebrew);
60 if (HB_SelectScript(shaper_item, hebrew_features)) {
62 const int availableGlyphs = shaper_item->num_glyphs;
63 if (!HB_ConvertStringToGlyphIndices(shaper_item))
66 HB_HeuristicSetGlyphAttributes(shaper_item);
67 HB_OpenTypeShape(shaper_item, /*properties*/0);
68 return HB_OpenTypePosition(shaper_item, availableGlyphs, /*doLogClusters*/TRUE);
73 const HB_UChar16 *uc = shaper_item->string + shaper_item->item.pos;
74 unsigned short *logClusters = shaper_item->log_clusters;
75 HB_GlyphAttributes *attributes = shaper_item->attributes;
79 int cluster_start = 0;
82 HB_STACKARRAY(HB_UChar16, shapedChars, 2 * shaper_item->item.length);
86 for (i = 1; i < shaper_item->item.length; ++i) {
87 hb_uint16 base = shapedChars[cluster_start];
89 HB_Bool invalid = FALSE;
90 if (uc[i] == Dagesh) {
98 shaped = base - 0x5d0 + 0xfb30;
99 } else if (base == 0xfb2a || base == 0xfb2b /* Shin with Shin or Sin dot */) {
104 } else if (uc[i] == ShinDot) {
107 else if (base == 0xfb49)
111 } else if (uc[i] == SinDot) {
114 else if (base == 0xfb49)
118 } else if (uc[i] == Patah) {
121 } else if (uc[i] == Qamats) {
124 } else if (uc[i] == Holam) {
127 } else if (uc[i] == Rafe) {
130 else if (base == 0x5db)
132 else if (base == 0x5e4)
137 shapedChars[slen] = 0x25cc;
138 attributes[slen].clusterStart = TRUE;
139 attributes[slen].mark = FALSE;
140 attributes[slen].combiningClass = 0;
141 cluster_start = slen;
145 if (shaper_item->font->klass->canRender(shaper_item->font, (HB_UChar16 *)&shaped, 1)) {
146 shapedChars[cluster_start] = shaped;
151 HB_CharCategory category;
153 shapedChars[slen] = uc[i];
154 HB_GetUnicodeCharProperties(uc[i], &category, &cmb);
155 if (category != HB_Mark_NonSpacing) {
156 attributes[slen].clusterStart = TRUE;
157 attributes[slen].mark = FALSE;
158 attributes[slen].combiningClass = 0;
159 attributes[slen].dontPrint = HB_IsControlChar(uc[i]);
160 cluster_start = slen;
162 attributes[slen].clusterStart = FALSE;
163 attributes[slen].mark = TRUE;
164 attributes[slen].combiningClass = cmb;
168 logClusters[i] = cluster_start;
171 haveGlyphs = shaper_item->font->klass
172 ->convertStringToGlyphIndices(shaper_item->font,
174 shaper_item->glyphs, &shaper_item->num_glyphs,
175 shaper_item->item.bidiLevel % 2);
177 HB_FREE_STACKARRAY(shapedChars);
182 HB_HeuristicPosition(shaper_item);