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);
59 HB_HeuristicSetGlyphAttributes(shaper_item);
62 if (HB_SelectScript(shaper_item, hebrew_features)) {
64 const int availableGlyphs = shaper_item->num_glyphs;
65 if (!HB_ConvertStringToGlyphIndices(shaper_item))
69 HB_OpenTypeShape(shaper_item, /*properties*/0);
70 return HB_OpenTypePosition(shaper_item, availableGlyphs, /*doLogClusters*/TRUE);
75 const HB_UChar16 *uc = shaper_item->string + shaper_item->item.pos;
76 unsigned short *logClusters = shaper_item->log_clusters;
77 HB_GlyphAttributes *attributes = shaper_item->attributes;
81 int cluster_start = 0;
84 HB_STACKARRAY(HB_UChar16, shapedChars, 2 * shaper_item->item.length);
88 for (i = 1; i < shaper_item->item.length; ++i) {
89 hb_uint16 base = shapedChars[slen-1];
91 HB_Bool invalid = FALSE;
92 if (uc[i] == Dagesh) {
100 shaped = base - 0x5d0 + 0xfb30;
101 } else if (base == 0xfb2a || base == 0xfb2b /* Shin with Shin or Sin dot */) {
106 } else if (uc[i] == ShinDot) {
109 else if (base == 0xfb49)
113 } else if (uc[i] == SinDot) {
116 else if (base == 0xfb49)
120 } else if (uc[i] == Patah) {
123 } else if (uc[i] == Qamats) {
126 } else if (uc[i] == Holam) {
129 } else if (uc[i] == Rafe) {
132 else if (base == 0x5db)
134 else if (base == 0x5e4)
139 shapedChars[slen] = 0x25cc;
140 attributes[slen].clusterStart = TRUE;
141 attributes[slen].mark = FALSE;
142 attributes[slen].combiningClass = 0;
143 cluster_start = slen;
147 if (shaper_item->font->klass->canRender(shaper_item->font, (HB_UChar16 *)&shaped, 1)) {
148 shapedChars[slen-1] = shaped;
153 HB_CharCategory category;
155 shapedChars[slen] = uc[i];
156 HB_GetUnicodeCharProperties(uc[i], &category, &cmb);
157 if (category != HB_Mark_NonSpacing) {
158 attributes[slen].clusterStart = TRUE;
159 attributes[slen].mark = FALSE;
160 attributes[slen].combiningClass = 0;
161 attributes[slen].dontPrint = HB_IsControlChar(uc[i]);
162 cluster_start = slen;
164 attributes[slen].clusterStart = FALSE;
165 attributes[slen].mark = TRUE;
166 attributes[slen].combiningClass = cmb;
170 logClusters[i] = cluster_start;
173 haveGlyphs = shaper_item->font->klass
174 ->convertStringToGlyphIndices(shaper_item->font,
176 shaper_item->glyphs, &shaper_item->num_glyphs,
177 shaper_item->item.bidiLevel % 2);
179 HB_FREE_STACKARRAY(shapedChars);
184 HB_HeuristicPosition(shaper_item);