blob: df88840dc6a5ad67b2e81d5a7772746f83076dc3 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
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
6 * published by the Free Software Foundation. Sun designates this
7 * particular file as subject to the "Classpath" exception as provided
8 * by Sun in the LICENSE file that accompanied this code.
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 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
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 "LayoutEngine.h"
35#include "OpenTypeLayoutEngine.h"
36#include "IndicLayoutEngine.h"
37#include "ScriptAndLanguageTags.h"
38
39#include "GlyphSubstitutionTables.h"
40#include "GlyphDefinitionTables.h"
41#include "GlyphPositioningTables.h"
42
43#include "GDEFMarkFilter.h"
44#include "LEGlyphStorage.h"
45
46#include "IndicReordering.h"
47
48IndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance *fontInstance,
49 le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags,
50 const GlyphSubstitutionTableHeader *gsubTable)
51 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable),
52 fMPreFixups(NULL)
53{
54 fFeatureMap = IndicReordering::getFeatureMap(fFeatureMapCount);
55 fFeatureOrder = TRUE;
56}
57
58IndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance *fontInstance,
59 le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags)
60 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags),
61 fMPreFixups(NULL)
62{
63 fFeatureMap = IndicReordering::getFeatureMap(fFeatureMapCount);
64 fFeatureOrder = TRUE;
65}
66
67IndicOpenTypeLayoutEngine::~IndicOpenTypeLayoutEngine()
68{
69 // nothing to do
70}
71
72// Input: characters, tags
73// Output: glyphs, char indices
74le_int32 IndicOpenTypeLayoutEngine::glyphProcessing(const LEUnicode chars[],
75 le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
76 LEGlyphStorage &glyphStorage, LEErrorCode &success)
77{
78 if (LE_FAILURE(success)) {
79 return 0;
80 }
81
82 if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
83 success = LE_ILLEGAL_ARGUMENT_ERROR;
84 return 0;
85 }
86
87 le_int32 retCount = OpenTypeLayoutEngine::glyphProcessing(chars, offset, count, max,
88 rightToLeft, glyphStorage, success);
89
90 if (LE_FAILURE(success)) {
91 return 0;
92 }
93
94 IndicReordering::adjustMPres(fMPreFixups, glyphStorage);
95
96 return retCount;
97}
98
99// Input: characters
100// Output: characters, char indices, tags
101// Returns: output character count
102le_int32 IndicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[],
103 le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
104 LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
105{
106 if (LE_FAILURE(success)) {
107 return 0;
108 }
109
110 if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
111 success = LE_ILLEGAL_ARGUMENT_ERROR;
112 return 0;
113 }
114
115 le_int32 worstCase = count * IndicReordering::getWorstCaseExpansion(fScriptCode);
116
117 outChars = LE_NEW_ARRAY(LEUnicode, worstCase);
118
119 if (outChars == NULL) {
120 success = LE_MEMORY_ALLOCATION_ERROR;
121 return 0;
122 }
123
124 glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success);
125 glyphStorage.allocateAuxData(success);
126
127 if (LE_FAILURE(success)) {
128 LE_DELETE_ARRAY(outChars);
129 return 0;
130 }
131
132 // NOTE: assumes this allocates featureTags...
133 // (probably better than doing the worst case stuff here...)
134 le_int32 outCharCount = IndicReordering::reorder(&chars[offset], count, fScriptCode,
135 outChars, glyphStorage, &fMPreFixups);
136 glyphStorage.adoptGlyphCount(outCharCount);
137
138 return outCharCount;
139}