4 * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
9 #include "LayoutEngine.h"
10 #include "OpenTypeLayoutEngine.h"
11 #include "IndicLayoutEngine.h"
12 #include "ScriptAndLanguageTags.h"
14 #include "GlyphSubstitutionTables.h"
15 #include "GlyphDefinitionTables.h"
16 #include "GlyphPositioningTables.h"
18 #include "GDEFMarkFilter.h"
19 #include "LEGlyphStorage.h"
21 #include "IndicReordering.h"
25 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndicOpenTypeLayoutEngine
)
27 IndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance
*fontInstance
, le_int32 scriptCode
, le_int32 languageCode
,
28 le_int32 typoFlags
, const GlyphSubstitutionTableHeader
*gsubTable
)
29 : OpenTypeLayoutEngine(fontInstance
, scriptCode
, languageCode
, typoFlags
, gsubTable
), fMPreFixups(NULL
)
31 fFeatureMap
= IndicReordering::getFeatureMap(fFeatureMapCount
);
34 fFilterZeroWidth
= IndicReordering::getFilterZeroWidth(fScriptCode
);
37 IndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance
*fontInstance
, le_int32 scriptCode
, le_int32 languageCode
, le_int32 typoFlags
)
38 : OpenTypeLayoutEngine(fontInstance
, scriptCode
, languageCode
, typoFlags
), fMPreFixups(NULL
)
40 fFeatureMap
= IndicReordering::getFeatureMap(fFeatureMapCount
);
44 IndicOpenTypeLayoutEngine::~IndicOpenTypeLayoutEngine()
49 // Input: characters, tags
50 // Output: glyphs, char indices
51 le_int32
IndicOpenTypeLayoutEngine::glyphProcessing(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool rightToLeft
,
52 LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
)
54 if (LE_FAILURE(success
)) {
58 if (chars
== NULL
|| offset
< 0 || count
< 0 || max
< 0 || offset
>= max
|| offset
+ count
> max
) {
59 success
= LE_ILLEGAL_ARGUMENT_ERROR
;
63 le_int32 retCount
= OpenTypeLayoutEngine::glyphProcessing(chars
, offset
, count
, max
, rightToLeft
, glyphStorage
, success
);
65 if (LE_FAILURE(success
)) {
69 IndicReordering::adjustMPres(fMPreFixups
, glyphStorage
);
75 // Output: characters, char indices, tags
76 // Returns: output character count
77 le_int32
IndicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool rightToLeft
,
78 LEUnicode
*&outChars
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
)
80 if (LE_FAILURE(success
)) {
84 if (chars
== NULL
|| offset
< 0 || count
< 0 || max
< 0 || offset
>= max
|| offset
+ count
> max
) {
85 success
= LE_ILLEGAL_ARGUMENT_ERROR
;
89 le_int32 worstCase
= count
* IndicReordering::getWorstCaseExpansion(fScriptCode
);
91 outChars
= LE_NEW_ARRAY(LEUnicode
, worstCase
);
93 if (outChars
== NULL
) {
94 success
= LE_MEMORY_ALLOCATION_ERROR
;
98 glyphStorage
.allocateGlyphArray(worstCase
, rightToLeft
, success
);
99 glyphStorage
.allocateAuxData(success
);
101 if (LE_FAILURE(success
)) {
102 LE_DELETE_ARRAY(outChars
);
106 // NOTE: assumes this allocates featureTags...
107 // (probably better than doing the worst case stuff here...)
108 le_int32 outCharCount
= IndicReordering::reorder(&chars
[offset
], count
, fScriptCode
, outChars
, glyphStorage
, &fMPreFixups
);
110 glyphStorage
.adoptGlyphCount(outCharCount
);