2
|
1 |
/*
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
3 |
*
|
|
4 |
* This code is free software; you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
6 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
8 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
9 |
*
|
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
* accompanied this code).
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License version
|
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 |
*
|
5506
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
21 |
* or visit www.oracle.com if you need additional information or have any
|
|
22 |
* questions.
|
2
|
23 |
*
|
|
24 |
*/
|
|
25 |
|
|
26 |
|
|
27 |
/*
|
|
28 |
*
|
|
29 |
* (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
|
|
30 |
*
|
|
31 |
*/
|
|
32 |
|
|
33 |
#include "LETypes.h"
|
|
34 |
#include "LEScripts.h"
|
|
35 |
#include "LEGlyphFilter.h"
|
|
36 |
#include "LEGlyphStorage.h"
|
|
37 |
#include "LayoutEngine.h"
|
|
38 |
#include "OpenTypeLayoutEngine.h"
|
|
39 |
#include "ArabicLayoutEngine.h"
|
|
40 |
#include "ScriptAndLanguageTags.h"
|
|
41 |
#include "CharSubstitutionFilter.h"
|
|
42 |
|
|
43 |
#include "GlyphSubstitutionTables.h"
|
|
44 |
#include "GlyphDefinitionTables.h"
|
|
45 |
#include "GlyphPositioningTables.h"
|
|
46 |
|
|
47 |
#include "GDEFMarkFilter.h"
|
|
48 |
|
|
49 |
#include "ArabicShaping.h"
|
|
50 |
#include "CanonShaping.h"
|
|
51 |
|
3935
|
52 |
U_NAMESPACE_BEGIN
|
|
53 |
|
2
|
54 |
le_bool CharSubstitutionFilter::accept(LEGlyphID glyph) const
|
|
55 |
{
|
|
56 |
return fFontInstance->canDisplay((LEUnicode) glyph);
|
|
57 |
}
|
|
58 |
|
3935
|
59 |
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ArabicOpenTypeLayoutEngine)
|
|
60 |
|
|
61 |
ArabicOpenTypeLayoutEngine::ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
|
|
62 |
le_int32 typoFlags, const GlyphSubstitutionTableHeader *gsubTable)
|
2
|
63 |
: OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable)
|
|
64 |
{
|
|
65 |
fFeatureMap = ArabicShaping::getFeatureMap(fFeatureMapCount);
|
|
66 |
fFeatureOrder = TRUE;
|
|
67 |
}
|
|
68 |
|
3935
|
69 |
ArabicOpenTypeLayoutEngine::ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
|
|
70 |
le_int32 typoFlags)
|
2
|
71 |
: OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags)
|
|
72 |
{
|
|
73 |
fFeatureMap = ArabicShaping::getFeatureMap(fFeatureMapCount);
|
|
74 |
|
|
75 |
// NOTE: We don't need to set fFeatureOrder to TRUE here
|
|
76 |
// because this constructor is only called by the constructor
|
|
77 |
// for UnicodeArabicOpenTypeLayoutEngine, which uses a pre-built
|
|
78 |
// GSUB table that has the features in the correct order.
|
|
79 |
|
|
80 |
//fFeatureOrder = TRUE;
|
|
81 |
}
|
|
82 |
|
|
83 |
ArabicOpenTypeLayoutEngine::~ArabicOpenTypeLayoutEngine()
|
|
84 |
{
|
|
85 |
// nothing to do
|
|
86 |
}
|
|
87 |
|
|
88 |
// Input: characters
|
|
89 |
// Output: characters, char indices, tags
|
|
90 |
// Returns: output character count
|
3935
|
91 |
le_int32 ArabicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
|
|
92 |
LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2
|
93 |
{
|
|
94 |
if (LE_FAILURE(success)) {
|
|
95 |
return 0;
|
|
96 |
}
|
|
97 |
|
|
98 |
if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
|
|
99 |
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
100 |
return 0;
|
|
101 |
}
|
|
102 |
|
|
103 |
outChars = LE_NEW_ARRAY(LEUnicode, count);
|
|
104 |
|
|
105 |
if (outChars == NULL) {
|
|
106 |
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
107 |
return 0;
|
|
108 |
}
|
|
109 |
|
|
110 |
glyphStorage.allocateGlyphArray(count, rightToLeft, success);
|
|
111 |
glyphStorage.allocateAuxData(success);
|
|
112 |
|
|
113 |
if (LE_FAILURE(success)) {
|
|
114 |
LE_DELETE_ARRAY(outChars);
|
|
115 |
return 0;
|
|
116 |
}
|
|
117 |
|
|
118 |
CanonShaping::reorderMarks(&chars[offset], count, rightToLeft, outChars, glyphStorage);
|
|
119 |
|
|
120 |
// Note: This processes the *original* character array so we can get context
|
|
121 |
// for the first and last characters. This is OK because only the marks
|
|
122 |
// will have been reordered, and they don't contribute to shaping.
|
|
123 |
ArabicShaping::shape(chars, offset, count, max, rightToLeft, glyphStorage);
|
|
124 |
|
|
125 |
return count;
|
|
126 |
}
|
|
127 |
|
3935
|
128 |
void ArabicOpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse,
|
|
129 |
LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2
|
130 |
{
|
|
131 |
if (LE_FAILURE(success)) {
|
|
132 |
return;
|
|
133 |
}
|
|
134 |
|
|
135 |
if (chars == NULL || offset < 0 || count < 0) {
|
|
136 |
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
137 |
return;
|
|
138 |
}
|
|
139 |
|
|
140 |
if (fGPOSTable != NULL) {
|
3935
|
141 |
OpenTypeLayoutEngine::adjustGlyphPositions(chars, offset, count, reverse, glyphStorage, success);
|
2
|
142 |
} else if (fGDEFTable != NULL) {
|
|
143 |
GDEFMarkFilter filter(fGDEFTable);
|
|
144 |
|
|
145 |
adjustMarkGlyphs(glyphStorage, &filter, success);
|
|
146 |
} else {
|
3935
|
147 |
GlyphDefinitionTableHeader *gdefTable = (GlyphDefinitionTableHeader *) CanonShaping::glyphDefinitionTable;
|
2
|
148 |
GDEFMarkFilter filter(gdefTable);
|
|
149 |
|
|
150 |
adjustMarkGlyphs(&chars[offset], count, reverse, glyphStorage, &filter, success);
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
3935
|
154 |
UnicodeArabicOpenTypeLayoutEngine::UnicodeArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags)
|
2
|
155 |
: ArabicOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags)
|
|
156 |
{
|
|
157 |
fGSUBTable = (const GlyphSubstitutionTableHeader *) CanonShaping::glyphSubstitutionTable;
|
|
158 |
fGDEFTable = (const GlyphDefinitionTableHeader *) CanonShaping::glyphDefinitionTable;
|
|
159 |
|
|
160 |
fSubstitutionFilter = new CharSubstitutionFilter(fontInstance);
|
|
161 |
}
|
|
162 |
|
|
163 |
UnicodeArabicOpenTypeLayoutEngine::~UnicodeArabicOpenTypeLayoutEngine()
|
|
164 |
{
|
|
165 |
delete fSubstitutionFilter;
|
|
166 |
}
|
|
167 |
|
|
168 |
// "glyphs", "indices" -> glyphs, indices
|
3935
|
169 |
le_int32 UnicodeArabicOpenTypeLayoutEngine::glyphPostProcessing(LEGlyphStorage &tempGlyphStorage, LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2
|
170 |
{
|
|
171 |
if (LE_FAILURE(success)) {
|
|
172 |
return 0;
|
|
173 |
}
|
|
174 |
|
|
175 |
// FIXME: we could avoid the memory allocation and copy if we
|
|
176 |
// made a clone of mapCharsToGlyphs which took the fake glyphs
|
|
177 |
// directly.
|
|
178 |
le_int32 tempGlyphCount = tempGlyphStorage.getGlyphCount();
|
|
179 |
LEUnicode *tempChars = LE_NEW_ARRAY(LEUnicode, tempGlyphCount);
|
|
180 |
|
|
181 |
if (tempChars == NULL) {
|
|
182 |
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
183 |
return 0;
|
|
184 |
}
|
|
185 |
|
|
186 |
for (le_int32 i = 0; i < tempGlyphCount; i += 1) {
|
|
187 |
tempChars[i] = (LEUnicode) LE_GET_GLYPH(tempGlyphStorage[i]);
|
|
188 |
}
|
|
189 |
|
|
190 |
glyphStorage.adoptCharIndicesArray(tempGlyphStorage);
|
|
191 |
|
3935
|
192 |
ArabicOpenTypeLayoutEngine::mapCharsToGlyphs(tempChars, 0, tempGlyphCount, FALSE, TRUE, glyphStorage, success);
|
2
|
193 |
|
|
194 |
LE_DELETE_ARRAY(tempChars);
|
|
195 |
|
|
196 |
return tempGlyphCount;
|
|
197 |
}
|
|
198 |
|
3935
|
199 |
void UnicodeArabicOpenTypeLayoutEngine::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, le_bool /*mirror*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2
|
200 |
{
|
|
201 |
if (LE_FAILURE(success)) {
|
|
202 |
return;
|
|
203 |
}
|
|
204 |
|
|
205 |
if (chars == NULL || offset < 0 || count < 0) {
|
|
206 |
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
207 |
return;
|
|
208 |
}
|
|
209 |
|
|
210 |
le_int32 i, dir = 1, out = 0;
|
|
211 |
|
|
212 |
if (reverse) {
|
|
213 |
out = count - 1;
|
|
214 |
dir = -1;
|
|
215 |
}
|
|
216 |
|
|
217 |
glyphStorage.allocateGlyphArray(count, reverse, success);
|
|
218 |
|
|
219 |
for (i = 0; i < count; i += 1, out += dir) {
|
|
220 |
glyphStorage[out] = (LEGlyphID) chars[offset + i];
|
|
221 |
}
|
|
222 |
}
|
|
223 |
|
3935
|
224 |
void UnicodeArabicOpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse,
|
|
225 |
LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2
|
226 |
{
|
|
227 |
if (LE_FAILURE(success)) {
|
|
228 |
return;
|
|
229 |
}
|
|
230 |
|
|
231 |
if (chars == NULL || offset < 0 || count < 0) {
|
|
232 |
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
233 |
return;
|
|
234 |
}
|
|
235 |
|
|
236 |
GDEFMarkFilter filter(fGDEFTable);
|
|
237 |
|
|
238 |
adjustMarkGlyphs(&chars[offset], count, reverse, glyphStorage, &filter, success);
|
|
239 |
}
|
3935
|
240 |
|
|
241 |
U_NAMESPACE_END
|
|
242 |
|