os/textandloc/fontservices/textshaperplugin/IcuSource/layout/ArabicLayoutEngine.cpp
Update contrib.
4 * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
10 #include "LEGlyphFilter.h"
11 #include "LEGlyphStorage.h"
12 #include "LayoutEngine.h"
13 #include "OpenTypeLayoutEngine.h"
14 #include "ArabicLayoutEngine.h"
15 #include "ScriptAndLanguageTags.h"
16 #include "CharSubstitutionFilter.h"
18 #include "GlyphSubstitutionTables.h"
19 #include "GlyphDefinitionTables.h"
20 #include "GlyphPositioningTables.h"
22 #include "GDEFMarkFilter.h"
24 #include "ArabicShaping.h"
25 #include "CanonShaping.h"
29 le_bool CharSubstitutionFilter::accept(LEGlyphID glyph) const
31 return fFontInstance->canDisplay((LEUnicode) glyph);
34 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ArabicOpenTypeLayoutEngine)
36 ArabicOpenTypeLayoutEngine::ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
37 le_int32 typoFlags, const GlyphSubstitutionTableHeader *gsubTable)
38 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable)
40 /**/ fFeatureOrder = ArabicShaping::getFeatureOrder();
43 ArabicOpenTypeLayoutEngine::ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
45 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags)
47 // fFeatureOrder = ArabicShaping::getFeatureOrder();
50 ArabicOpenTypeLayoutEngine::~ArabicOpenTypeLayoutEngine()
56 // Output: characters, char indices, tags
57 // Returns: output character count
58 le_int32 ArabicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
59 LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
61 if (LE_FAILURE(success)) {
65 if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
66 success = LE_ILLEGAL_ARGUMENT_ERROR;
70 outChars = LE_NEW_ARRAY(LEUnicode, count);
72 if (outChars == NULL) {
73 success = LE_MEMORY_ALLOCATION_ERROR;
77 glyphStorage.allocateGlyphArray(count, rightToLeft, success);
78 glyphStorage.allocateAuxData(success);
80 if (LE_FAILURE(success)) {
81 LE_DELETE_ARRAY(outChars);
85 CanonShaping::reorderMarks(&chars[offset], count, rightToLeft, outChars, glyphStorage);
87 // Note: This processes the *original* character array so we can get context
88 // for the first and last characters. This is OK because only the marks
89 // will have been reordered, and they don't contribute to shaping.
90 ArabicShaping::shape(chars, offset, count, max, rightToLeft, glyphStorage);
95 void ArabicOpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse,
96 LEGlyphStorage &glyphStorage, LEErrorCode &success)
98 if (LE_FAILURE(success)) {
102 if (chars == NULL || offset < 0 || count < 0) {
103 success = LE_ILLEGAL_ARGUMENT_ERROR;
107 if (fGPOSTable != NULL) {
108 OpenTypeLayoutEngine::adjustGlyphPositions(chars, offset, count, reverse, glyphStorage, success);
109 } else if (fGDEFTable != NULL) {
110 GDEFMarkFilter filter(fGDEFTable);
112 adjustMarkGlyphs(glyphStorage, &filter, success);
114 GlyphDefinitionTableHeader *gdefTable = (GlyphDefinitionTableHeader *) CanonShaping::glyphDefinitionTable;
115 GDEFMarkFilter filter(gdefTable);
117 adjustMarkGlyphs(&chars[offset], count, reverse, glyphStorage, &filter, success);
121 UnicodeArabicOpenTypeLayoutEngine::UnicodeArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags)
122 : ArabicOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags)
124 fGSUBTable = (const GlyphSubstitutionTableHeader *) CanonShaping::glyphSubstitutionTable;
125 fGDEFTable = (const GlyphDefinitionTableHeader *) CanonShaping::glyphDefinitionTable;
127 fSubstitutionFilter = new CharSubstitutionFilter(fontInstance);
130 UnicodeArabicOpenTypeLayoutEngine::~UnicodeArabicOpenTypeLayoutEngine()
132 delete fSubstitutionFilter;
135 // "glyphs", "indices" -> glyphs, indices
136 le_int32 UnicodeArabicOpenTypeLayoutEngine::glyphPostProcessing(LEGlyphStorage &tempGlyphStorage, LEGlyphStorage &glyphStorage, LEErrorCode &success)
138 if (LE_FAILURE(success)) {
142 // FIXME: we could avoid the memory allocation and copy if we
143 // made a clone of mapCharsToGlyphs which took the fake glyphs
145 le_int32 tempGlyphCount = tempGlyphStorage.getGlyphCount();
146 LEUnicode *tempChars = LE_NEW_ARRAY(LEUnicode, tempGlyphCount);
148 if (tempChars == NULL) {
149 success = LE_MEMORY_ALLOCATION_ERROR;
153 for (le_int32 i = 0; i < tempGlyphCount; i += 1) {
154 tempChars[i] = (LEUnicode) LE_GET_GLYPH(tempGlyphStorage[i]);
157 glyphStorage.adoptCharIndicesArray(tempGlyphStorage);
159 ArabicOpenTypeLayoutEngine::mapCharsToGlyphs(tempChars, 0, tempGlyphCount, FALSE, TRUE, glyphStorage, success);
161 LE_DELETE_ARRAY(tempChars);
163 return tempGlyphCount;
166 void UnicodeArabicOpenTypeLayoutEngine::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, le_bool /*mirror*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
168 if (LE_FAILURE(success)) {
172 if (chars == NULL || offset < 0 || count < 0) {
173 success = LE_ILLEGAL_ARGUMENT_ERROR;
177 le_int32 i, dir = 1, out = 0;
184 glyphStorage.allocateGlyphArray(count, reverse, success);
186 for (i = 0; i < count; i += 1, out += dir) {
187 glyphStorage[out] = (LEGlyphID) chars[offset + i];
191 void UnicodeArabicOpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse,
192 LEGlyphStorage &glyphStorage, LEErrorCode &success)
194 if (LE_FAILURE(success)) {
198 if (chars == NULL || offset < 0 || count < 0) {
199 success = LE_ILLEGAL_ARGUMENT_ERROR;
203 GDEFMarkFilter filter(fGDEFTable);
205 adjustMarkGlyphs(&chars[offset], count, reverse, glyphStorage, &filter, success);