]> git.saurik.com Git - apple/icu.git/blame - icuSources/layout/ArabicLayoutEngine.cpp
ICU-6.2.16.tar.gz
[apple/icu.git] / icuSources / layout / ArabicLayoutEngine.cpp
CommitLineData
b75a7d8f
A
1
2/*
b75a7d8f 3 *
374ca955 4 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
b75a7d8f
A
5 *
6 */
7
8#include "LETypes.h"
9#include "LEScripts.h"
10#include "LEGlyphFilter.h"
374ca955 11#include "LEGlyphStorage.h"
b75a7d8f
A
12#include "LayoutEngine.h"
13#include "OpenTypeLayoutEngine.h"
14#include "ArabicLayoutEngine.h"
15#include "ScriptAndLanguageTags.h"
374ca955 16#include "CharSubstitutionFilter.h"
b75a7d8f
A
17
18#include "GlyphSubstitutionTables.h"
19#include "GlyphDefinitionTables.h"
20#include "GlyphPositioningTables.h"
21
22#include "GDEFMarkFilter.h"
23
24#include "ArabicShaping.h"
374ca955 25#include "CanonShaping.h"
b75a7d8f
A
26
27U_NAMESPACE_BEGIN
28
b75a7d8f
A
29le_bool CharSubstitutionFilter::accept(LEGlyphID glyph) const
30{
31 return fFontInstance->canDisplay((LEUnicode) glyph);
32}
33
374ca955 34UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ArabicOpenTypeLayoutEngine)
b75a7d8f
A
35
36ArabicOpenTypeLayoutEngine::ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
37 const GlyphSubstitutionTableHeader *gsubTable)
38 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, gsubTable)
39{
374ca955 40 /**/ fFeatureOrder = ArabicShaping::getFeatureOrder();
b75a7d8f
A
41}
42
43ArabicOpenTypeLayoutEngine::ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode)
44 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode)
45{
46 // fFeatureOrder = ArabicShaping::getFeatureOrder();
47}
48
49ArabicOpenTypeLayoutEngine::~ArabicOpenTypeLayoutEngine()
50{
51 // nothing to do
52}
53
54// Input: characters
55// Output: characters, char indices, tags
56// Returns: output character count
57le_int32 ArabicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
374ca955 58 LEUnicode *&/*outChars*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
b75a7d8f
A
59{
60 if (LE_FAILURE(success)) {
61 return 0;
62 }
63
64 if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
65 success = LE_ILLEGAL_ARGUMENT_ERROR;
66 return 0;
67 }
68
374ca955
A
69 glyphStorage.adoptGlyphCount(count);
70 glyphStorage.allocateAuxData(success);
b75a7d8f 71
374ca955 72 if (LE_FAILURE(success)) {
b75a7d8f
A
73 success = LE_MEMORY_ALLOCATION_ERROR;
74 return 0;
75 }
76
374ca955 77 ArabicShaping::shape(chars, offset, count, max, rightToLeft, glyphStorage);
b75a7d8f
A
78
79 return count;
80}
81
82void ArabicOpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse,
374ca955 83 LEGlyphStorage &glyphStorage, LEErrorCode &success)
b75a7d8f
A
84{
85 if (LE_FAILURE(success)) {
86 return;
87 }
88
374ca955 89 if (chars == NULL || offset < 0 || count < 0) {
b75a7d8f
A
90 success = LE_ILLEGAL_ARGUMENT_ERROR;
91 return;
92 }
93
94 if (fGPOSTable != NULL) {
374ca955 95 OpenTypeLayoutEngine::adjustGlyphPositions(chars, offset, count, reverse, glyphStorage, success);
b75a7d8f
A
96 } else if (fGDEFTable != NULL) {
97 GDEFMarkFilter filter(fGDEFTable);
98
374ca955 99 adjustMarkGlyphs(glyphStorage, &filter, success);
b75a7d8f 100 } else {
374ca955 101 GlyphDefinitionTableHeader *gdefTable = (GlyphDefinitionTableHeader *) CanonShaping::glyphDefinitionTable;
b75a7d8f 102 GDEFMarkFilter filter(gdefTable);
b75a7d8f 103
374ca955 104 adjustMarkGlyphs(&chars[offset], count, reverse, glyphStorage, &filter, success);
b75a7d8f
A
105 }
106}
107
108UnicodeArabicOpenTypeLayoutEngine::UnicodeArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode)
109 : ArabicOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode)
110{
374ca955
A
111 fGSUBTable = (const GlyphSubstitutionTableHeader *) CanonShaping::glyphSubstitutionTable;
112 fGDEFTable = (const GlyphDefinitionTableHeader *) CanonShaping::glyphDefinitionTable;
b75a7d8f
A
113
114 fSubstitutionFilter = new CharSubstitutionFilter(fontInstance);
115}
116
117UnicodeArabicOpenTypeLayoutEngine::~UnicodeArabicOpenTypeLayoutEngine()
118{
119 delete fSubstitutionFilter;
120}
121
122// "glyphs", "indices" -> glyphs, indices
374ca955 123le_int32 UnicodeArabicOpenTypeLayoutEngine::glyphPostProcessing(LEGlyphStorage &tempGlyphStorage, LEGlyphStorage &glyphStorage, LEErrorCode &success)
b75a7d8f
A
124{
125 if (LE_FAILURE(success)) {
126 return 0;
127 }
128
b75a7d8f
A
129 // FIXME: we could avoid the memory allocation and copy if we
130 // made a clone of mapCharsToGlyphs which took the fake glyphs
131 // directly.
374ca955 132 le_int32 tempGlyphCount = tempGlyphStorage.getGlyphCount();
b75a7d8f
A
133 LEUnicode *tempChars = LE_NEW_ARRAY(LEUnicode, tempGlyphCount);
134
135 if (tempChars == NULL) {
136 success = LE_MEMORY_ALLOCATION_ERROR;
137 return 0;
138 }
139
140 for (le_int32 i = 0; i < tempGlyphCount; i += 1) {
374ca955 141 tempChars[i] = (LEUnicode) LE_GET_GLYPH(tempGlyphStorage[i]);
b75a7d8f
A
142 }
143
374ca955 144 glyphStorage.adoptCharIndicesArray(tempGlyphStorage);
b75a7d8f 145
374ca955 146 ArabicOpenTypeLayoutEngine::mapCharsToGlyphs(tempChars, 0, tempGlyphCount, FALSE, TRUE, glyphStorage, success);
b75a7d8f
A
147
148 LE_DELETE_ARRAY(tempChars);
149
150 return tempGlyphCount;
151}
152
374ca955 153void UnicodeArabicOpenTypeLayoutEngine::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, le_bool /*mirror*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
b75a7d8f
A
154{
155 if (LE_FAILURE(success)) {
156 return;
157 }
158
159 if (chars == NULL || offset < 0 || count < 0) {
160 success = LE_ILLEGAL_ARGUMENT_ERROR;
161 return;
162 }
163
374ca955 164 le_int32 i, dir = 1, out = 0;
b75a7d8f
A
165
166 if (reverse) {
167 out = count - 1;
168 dir = -1;
169 }
170
374ca955 171 glyphStorage.allocateGlyphArray(count, reverse, success);
b75a7d8f
A
172
173 for (i = 0; i < count; i += 1, out += dir) {
374ca955 174 glyphStorage[out] = (LEGlyphID) chars[offset + i];
b75a7d8f
A
175 }
176}
177
178void UnicodeArabicOpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse,
374ca955 179 LEGlyphStorage &glyphStorage, LEErrorCode &success)
b75a7d8f
A
180{
181 if (LE_FAILURE(success)) {
182 return;
183 }
184
374ca955 185 if (chars == NULL || offset < 0 || count < 0) {
b75a7d8f
A
186 success = LE_ILLEGAL_ARGUMENT_ERROR;
187 return;
188 }
189
190 GDEFMarkFilter filter(fGDEFTable);
191
374ca955 192 adjustMarkGlyphs(&chars[offset], count, reverse, glyphStorage, &filter, success);
b75a7d8f
A
193}
194
195U_NAMESPACE_END
196