]> git.saurik.com Git - apple/icu.git/blame - icuSources/layout/IndicLayoutEngine.cpp
ICU-8.11.tar.gz
[apple/icu.git] / icuSources / layout / IndicLayoutEngine.cpp
CommitLineData
b75a7d8f
A
1
2/*
b75a7d8f 3 *
73c04bcf 4 * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
b75a7d8f
A
5 *
6 */
7
8#include "LETypes.h"
9#include "LayoutEngine.h"
10#include "OpenTypeLayoutEngine.h"
11#include "IndicLayoutEngine.h"
12#include "ScriptAndLanguageTags.h"
13
14#include "GlyphSubstitutionTables.h"
15#include "GlyphDefinitionTables.h"
16#include "GlyphPositioningTables.h"
17
18#include "GDEFMarkFilter.h"
374ca955 19#include "LEGlyphStorage.h"
b75a7d8f
A
20
21#include "IndicReordering.h"
22
23U_NAMESPACE_BEGIN
24
374ca955 25UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndicOpenTypeLayoutEngine)
b75a7d8f
A
26
27IndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
73c04bcf
A
28 le_int32 typoFlags, const GlyphSubstitutionTableHeader *gsubTable)
29 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable), fMPreFixups(NULL)
b75a7d8f 30{
73c04bcf
A
31 fFeatureMap = IndicReordering::getFeatureMap(fFeatureMapCount);
32 fFeatureOrder = TRUE;
33
34 fFilterZeroWidth = IndicReordering::getFilterZeroWidth(fScriptCode);
b75a7d8f
A
35}
36
73c04bcf
A
37IndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags)
38 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags), fMPreFixups(NULL)
b75a7d8f 39{
73c04bcf
A
40 fFeatureMap = IndicReordering::getFeatureMap(fFeatureMapCount);
41 fFeatureOrder = TRUE;
b75a7d8f
A
42}
43
44IndicOpenTypeLayoutEngine::~IndicOpenTypeLayoutEngine()
45{
46 // nothing to do
47}
48
49// Input: characters, tags
50// Output: glyphs, char indices
374ca955
A
51le_int32 IndicOpenTypeLayoutEngine::glyphProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
52 LEGlyphStorage &glyphStorage, LEErrorCode &success)
b75a7d8f
A
53{
54 if (LE_FAILURE(success)) {
55 return 0;
56 }
57
58 if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
59 success = LE_ILLEGAL_ARGUMENT_ERROR;
60 return 0;
61 }
62
374ca955 63 le_int32 retCount = OpenTypeLayoutEngine::glyphProcessing(chars, offset, count, max, rightToLeft, glyphStorage, success);
b75a7d8f
A
64
65 if (LE_FAILURE(success)) {
66 return 0;
67 }
68
374ca955 69 IndicReordering::adjustMPres(fMPreFixups, glyphStorage);
b75a7d8f
A
70
71 return retCount;
72}
73
74// Input: characters
75// Output: characters, char indices, tags
76// Returns: output character count
374ca955
A
77le_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)
b75a7d8f
A
79{
80 if (LE_FAILURE(success)) {
81 return 0;
82 }
83
84 if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
85 success = LE_ILLEGAL_ARGUMENT_ERROR;
86 return 0;
87 }
88
89 le_int32 worstCase = count * IndicReordering::getWorstCaseExpansion(fScriptCode);
90
91 outChars = LE_NEW_ARRAY(LEUnicode, worstCase);
92
93 if (outChars == NULL) {
94 success = LE_MEMORY_ALLOCATION_ERROR;
95 return 0;
96 }
97
374ca955
A
98 glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success);
99 glyphStorage.allocateAuxData(success);
b75a7d8f 100
374ca955 101 if (LE_FAILURE(success)) {
b75a7d8f 102 LE_DELETE_ARRAY(outChars);
b75a7d8f
A
103 return 0;
104 }
105
106 // NOTE: assumes this allocates featureTags...
107 // (probably better than doing the worst case stuff here...)
374ca955
A
108 le_int32 outCharCount = IndicReordering::reorder(&chars[offset], count, fScriptCode, outChars, glyphStorage, &fMPreFixups);
109
110 glyphStorage.adoptGlyphCount(outCharCount);
111 return outCharCount;
b75a7d8f
A
112}
113
114U_NAMESPACE_END