../3rdparty/harfbuzz/src/harfbuzz-tibetan.c

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/* -
2 * Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies) -
3 * -
4 * This is part of HarfBuzz, an OpenType Layout engine 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 -
25#include "harfbuzz-shaper.h" -
26#include "harfbuzz-shaper-private.h" -
27 -
28#include <assert.h> -
29 -
30/* -
31 tibetan syllables are of the form: -
32 head position consonant -
33 first sub-joined consonant -
34 ....intermediate sub-joined consonants (if any) -
35 last sub-joined consonant -
36 sub-joined vowel (a-chung U+0F71) -
37 standard or compound vowel sign (or 'virama' for devanagari transliteration) -
38*/ -
39 -
40typedef enum { -
41 TibetanOther, -
42 TibetanHeadConsonant, -
43 TibetanSubjoinedConsonant, -
44 TibetanSubjoinedVowel, -
45 TibetanVowel -
46} TibetanForm; -
47 -
48/* this table starts at U+0f40 */ -
49static const unsigned char tibetanForm[0x80] = { -
50 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
51 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
52 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
53 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
54 -
55 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
56 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
57 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
58 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
59 -
60 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
61 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
62 TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, -
63 TibetanOther, TibetanOther, TibetanOther, TibetanOther, -
64 -
65 TibetanOther, TibetanVowel, TibetanVowel, TibetanVowel, -
66 TibetanVowel, TibetanVowel, TibetanVowel, TibetanVowel, -
67 TibetanVowel, TibetanVowel, TibetanVowel, TibetanVowel, -
68 TibetanVowel, TibetanVowel, TibetanVowel, TibetanVowel, -
69 -
70 TibetanVowel, TibetanVowel, TibetanVowel, TibetanVowel, -
71 TibetanVowel, TibetanVowel, TibetanVowel, TibetanVowel, -
72 TibetanOther, TibetanOther, TibetanOther, TibetanOther, -
73 TibetanOther, TibetanOther, TibetanOther, TibetanOther, -
74 -
75 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
76 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
77 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
78 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
79 -
80 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
81 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
82 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
83 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
84 -
85 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
86 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
87 TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, -
88 TibetanSubjoinedConsonant, TibetanOther, TibetanOther, TibetanOther -
89}; -
90 -
91 -
92#define tibetan_form(c) \ -
93 (TibetanForm)tibetanForm[c - 0x0f40] -
94 -
95#ifndef NO_OPENTYPE -
96static const HB_OpenTypeFeature tibetan_features[] = { -
97 { HB_MAKE_TAG('c', 'c', 'm', 'p'), CcmpProperty }, -
98 { HB_MAKE_TAG('a', 'b', 'v', 's'), AboveSubstProperty }, -
99 { HB_MAKE_TAG('b', 'l', 'w', 's'), BelowSubstProperty }, -
100 { HB_MAKE_TAG('c', 'a', 'l', 't'), CaltProperty }, -
101 {0, 0} -
102}; -
103#endif -
104 -
105static HB_Bool tibetan_shape_syllable(HB_Bool openType, HB_ShaperItem *item, HB_Bool invalid) -
106{ -
107 hb_uint32 i;
never executed (the execution status of this line is deduced): hb_uint32 i;
-
108 const HB_UChar16 *str = item->string + item->item.pos;
never executed (the execution status of this line is deduced): const HB_UChar16 *str = item->string + item->item.pos;
-
109 int len = item->item.length;
never executed (the execution status of this line is deduced): int len = item->item.length;
-
110#ifndef NO_OPENTYPE -
111 const int availableGlyphs = item->num_glyphs;
never executed (the execution status of this line is deduced): const int availableGlyphs = item->num_glyphs;
-
112#endif -
113 HB_Bool haveGlyphs;
never executed (the execution status of this line is deduced): HB_Bool haveGlyphs;
-
114 HB_STACKARRAY(HB_UChar16, reordered, len + 4);
never executed: reordered = (HB_UChar16 *)malloc((len + 4) * sizeof(HB_UChar16));
never evaluated: (len + 4) >= 512
0
115 -
116 if (item->num_glyphs < item->item.length + 4) {
never evaluated: item->num_glyphs < item->item.length + 4
0
117 item->num_glyphs = item->item.length + 4;
never executed (the execution status of this line is deduced): item->num_glyphs = item->item.length + 4;
-
118 return FALSE;
never executed: return 0;
0
119 } -
120 -
121 if (invalid) {
never evaluated: invalid
0
122 *reordered = 0x25cc;
never executed (the execution status of this line is deduced): *reordered = 0x25cc;
-
123 memcpy(reordered+1, str, len*sizeof(HB_UChar16));
never executed (the execution status of this line is deduced): memcpy(reordered+1, str, len*sizeof(HB_UChar16));
-
124 len++;
never executed (the execution status of this line is deduced): len++;
-
125 str = reordered;
never executed (the execution status of this line is deduced): str = reordered;
-
126 }
never executed: }
0
127 -
128 haveGlyphs = item->font->klass->convertStringToGlyphIndices(item->font,
never executed (the execution status of this line is deduced): haveGlyphs = item->font->klass->convertStringToGlyphIndices(item->font,
-
129 str, len,
never executed (the execution status of this line is deduced): str, len,
-
130 item->glyphs, &item->num_glyphs,
never executed (the execution status of this line is deduced): item->glyphs, &item->num_glyphs,
-
131 item->item.bidiLevel % 2);
never executed (the execution status of this line is deduced): item->item.bidiLevel % 2);
-
132 -
133 HB_FREE_STACKARRAY(reordered);
never executed: free(reordered);
never evaluated: stackreordered != reordered
0
134 -
135 if (!haveGlyphs)
never evaluated: !haveGlyphs
0
136 return FALSE;
never executed: return 0;
0
137 -
138 for (i = 0; i < item->item.length; i++) {
never evaluated: i < item->item.length
0
139 item->attributes[i].mark = FALSE;
never executed (the execution status of this line is deduced): item->attributes[i].mark = 0;
-
140 item->attributes[i].clusterStart = FALSE;
never executed (the execution status of this line is deduced): item->attributes[i].clusterStart = 0;
-
141 item->attributes[i].justification = 0;
never executed (the execution status of this line is deduced): item->attributes[i].justification = 0;
-
142 item->attributes[i].zeroWidth = FALSE;
never executed (the execution status of this line is deduced): item->attributes[i].zeroWidth = 0;
-
143/* IDEBUG(" %d: %4x", i, str[i]); */ -
144 }
never executed: }
0
145 -
146 /* now we have the syllable in the right order, and can start running it through open type. */ -
147 -
148#ifndef NO_OPENTYPE -
149 if (openType) {
never evaluated: openType
0
150 HB_OpenTypeShape(item, /*properties*/0);
never executed (the execution status of this line is deduced): HB_OpenTypeShape(item, 0);
-
151 if (!HB_OpenTypePosition(item, availableGlyphs, /*doLogClusters*/FALSE))
never evaluated: !HB_OpenTypePosition(item, availableGlyphs, 0)
0
152 return FALSE;
never executed: return 0;
0
153 } else {
never executed: }
0
154 HB_HeuristicPosition(item);
never executed (the execution status of this line is deduced): HB_HeuristicPosition(item);
-
155 }
never executed: }
0
156#endif -
157 -
158 item->attributes[0].clusterStart = TRUE;
never executed (the execution status of this line is deduced): item->attributes[0].clusterStart = (!0);
-
159 return TRUE;
never executed: return (!0);
0
160} -
161 -
162 -
163static int tibetan_nextSyllableBoundary(const HB_UChar16 *s, int start, int end, HB_Bool *invalid) -
164{ -
165 const HB_UChar16 *uc = s + start;
never executed (the execution status of this line is deduced): const HB_UChar16 *uc = s + start;
-
166 -
167 int pos = 0;
never executed (the execution status of this line is deduced): int pos = 0;
-
168 TibetanForm state = tibetan_form(*uc);
never executed (the execution status of this line is deduced): TibetanForm state = (TibetanForm)tibetanForm[*uc - 0x0f40];
-
169 -
170/* qDebug("state[%d]=%d (uc=%4x)", pos, state, uc[pos]);*/ -
171 pos++;
never executed (the execution status of this line is deduced): pos++;
-
172 -
173 if (state != TibetanHeadConsonant) {
never evaluated: state != TibetanHeadConsonant
0
174 if (state != TibetanOther)
never evaluated: state != TibetanOther
0
175 *invalid = TRUE;
never executed: *invalid = (!0);
0
176 goto finish;
never executed: goto finish;
0
177 } -
178 -
179 while (pos < end - start) {
never evaluated: pos < end - start
0
180 TibetanForm newState = tibetan_form(uc[pos]);
never executed (the execution status of this line is deduced): TibetanForm newState = (TibetanForm)tibetanForm[uc[pos] - 0x0f40];
-
181 switch(newState) { -
182 case TibetanSubjoinedConsonant: -
183 case TibetanSubjoinedVowel: -
184 if (state != TibetanHeadConsonant &&
never evaluated: state != TibetanHeadConsonant
0
185 state != TibetanSubjoinedConsonant)
never evaluated: state != TibetanSubjoinedConsonant
0
186 goto finish;
never executed: goto finish;
0
187 state = newState;
never executed (the execution status of this line is deduced): state = newState;
-
188 break;
never executed: break;
0
189 case TibetanVowel: -
190 if (state != TibetanHeadConsonant &&
never evaluated: state != TibetanHeadConsonant
0
191 state != TibetanSubjoinedConsonant &&
never evaluated: state != TibetanSubjoinedConsonant
0
192 state != TibetanSubjoinedVowel)
never evaluated: state != TibetanSubjoinedVowel
0
193 goto finish;
never executed: goto finish;
0
194 break;
never executed: break;
0
195 case TibetanOther: -
196 case TibetanHeadConsonant: -
197 goto finish;
never executed: goto finish;
0
198 } -
199 pos++;
never executed (the execution status of this line is deduced): pos++;
-
200 }
never executed: }
0
201 -
202finish:
code before this statement never executed: finish:
0
203 *invalid = FALSE;
never executed (the execution status of this line is deduced): *invalid = 0;
-
204 return start+pos;
never executed: return start+pos;
0
205} -
206 -
207HB_Bool HB_TibetanShape(HB_ShaperItem *item) -
208{ -
209 -
210 HB_Bool openType = FALSE;
never executed (the execution status of this line is deduced): HB_Bool openType = 0;
-
211 unsigned short *logClusters = item->log_clusters;
never executed (the execution status of this line is deduced): unsigned short *logClusters = item->log_clusters;
-
212 -
213 HB_ShaperItem syllable = *item;
never executed (the execution status of this line is deduced): HB_ShaperItem syllable = *item;
-
214 int first_glyph = 0;
never executed (the execution status of this line is deduced): int first_glyph = 0;
-
215 -
216 int sstart = item->item.pos;
never executed (the execution status of this line is deduced): int sstart = item->item.pos;
-
217 int end = sstart + item->item.length;
never executed (the execution status of this line is deduced): int end = sstart + item->item.length;
-
218 -
219 assert(item->item.script == HB_Script_Tibetan);
never executed (the execution status of this line is deduced): ((item->item.script == HB_Script_Tibetan) ? static_cast<void> (0) : __assert_fail ("item->item.script == HB_Script_Tibetan", "../3rdparty/harfbuzz/src/harfbuzz-tibetan.c", 219, __PRETTY_FUNCTION__));
-
220 -
221#ifndef NO_OPENTYPE -
222 openType = HB_SelectScript(item, tibetan_features);
never executed (the execution status of this line is deduced): openType = HB_SelectScript(item, tibetan_features);
-
223#endif -
224 -
225 while (sstart < end) {
never evaluated: sstart < end
0
226 HB_Bool invalid;
never executed (the execution status of this line is deduced): HB_Bool invalid;
-
227 int i;
never executed (the execution status of this line is deduced): int i;
-
228 int send = tibetan_nextSyllableBoundary(item->string, sstart, end, &invalid);
never executed (the execution status of this line is deduced): int send = tibetan_nextSyllableBoundary(item->string, sstart, end, &invalid);
-
229/* IDEBUG("syllable from %d, length %d, invalid=%s", sstart, send-sstart, -
230 invalid ? "TRUE" : "FALSE"); */ -
231 syllable.item.pos = sstart;
never executed (the execution status of this line is deduced): syllable.item.pos = sstart;
-
232 syllable.item.length = send-sstart;
never executed (the execution status of this line is deduced): syllable.item.length = send-sstart;
-
233 syllable.glyphs = item->glyphs + first_glyph;
never executed (the execution status of this line is deduced): syllable.glyphs = item->glyphs + first_glyph;
-
234 syllable.attributes = item->attributes + first_glyph;
never executed (the execution status of this line is deduced): syllable.attributes = item->attributes + first_glyph;
-
235 syllable.offsets = item->offsets + first_glyph;
never executed (the execution status of this line is deduced): syllable.offsets = item->offsets + first_glyph;
-
236 syllable.advances = item->advances + first_glyph;
never executed (the execution status of this line is deduced): syllable.advances = item->advances + first_glyph;
-
237 syllable.num_glyphs = item->num_glyphs - first_glyph;
never executed (the execution status of this line is deduced): syllable.num_glyphs = item->num_glyphs - first_glyph;
-
238 if (!tibetan_shape_syllable(openType, &syllable, invalid)) {
never evaluated: !tibetan_shape_syllable(openType, &syllable, invalid)
0
239 item->num_glyphs += syllable.num_glyphs;
never executed (the execution status of this line is deduced): item->num_glyphs += syllable.num_glyphs;
-
240 return FALSE;
never executed: return 0;
0
241 } -
242 /* fix logcluster array */ -
243 for (i = sstart; i < send; ++i)
never evaluated: i < send
0
244 logClusters[i-item->item.pos] = first_glyph;
never executed: logClusters[i-item->item.pos] = first_glyph;
0
245 sstart = send;
never executed (the execution status of this line is deduced): sstart = send;
-
246 first_glyph += syllable.num_glyphs;
never executed (the execution status of this line is deduced): first_glyph += syllable.num_glyphs;
-
247 }
never executed: }
0
248 item->num_glyphs = first_glyph;
never executed (the execution status of this line is deduced): item->num_glyphs = first_glyph;
-
249 return TRUE;
never executed: return (!0);
0
250} -
251 -
252void HB_TibetanAttributes(HB_Script script, const HB_UChar16 *text, hb_uint32 from, hb_uint32 len, HB_CharAttributes *attributes) -
253{ -
254 int end = from + len;
never executed (the execution status of this line is deduced): int end = from + len;
-
255 const HB_UChar16 *uc = text + from;
never executed (the execution status of this line is deduced): const HB_UChar16 *uc = text + from;
-
256 hb_uint32 i = 0;
never executed (the execution status of this line is deduced): hb_uint32 i = 0;
-
257 HB_UNUSED(script);
never executed (the execution status of this line is deduced): ((script) = (script));
-
258 attributes += from;
never executed (the execution status of this line is deduced): attributes += from;
-
259 while (i < len) {
never evaluated: i < len
0
260 HB_Bool invalid;
never executed (the execution status of this line is deduced): HB_Bool invalid;
-
261 hb_uint32 boundary = tibetan_nextSyllableBoundary(text, from+i, end, &invalid) - from;
never executed (the execution status of this line is deduced): hb_uint32 boundary = tibetan_nextSyllableBoundary(text, from+i, end, &invalid) - from;
-
262 -
263 attributes[i].graphemeBoundary = TRUE;
never executed (the execution status of this line is deduced): attributes[i].graphemeBoundary = (!0);
-
264 -
265 if (boundary > len-1) boundary = len;
never executed: boundary = len;
never evaluated: boundary > len-1
0
266 i++;
never executed (the execution status of this line is deduced): i++;
-
267 while (i < boundary) {
never evaluated: i < boundary
0
268 attributes[i].graphemeBoundary = FALSE;
never executed (the execution status of this line is deduced): attributes[i].graphemeBoundary = 0;
-
269 ++uc;
never executed (the execution status of this line is deduced): ++uc;
-
270 ++i;
never executed (the execution status of this line is deduced): ++i;
-
271 }
never executed: }
0
272 assert(i == boundary);
never executed (the execution status of this line is deduced): ((i == boundary) ? static_cast<void> (0) : __assert_fail ("i == boundary", "../3rdparty/harfbuzz/src/harfbuzz-tibetan.c", 272, __PRETTY_FUNCTION__));
-
273 }
never executed: }
0
274}
never executed: }
0
275 -
276 -
277 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial