blob: 77aca5e3e2e2581ebf183a2c8b11135f8d319369 [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 * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
29 *
30 */
31
32#include "LETypes.h"
33#include "LEGlyphStorage.h"
34#include "CanonShaping.h"
35#include "GlyphDefinitionTables.h"
36#include "ClassDefinitionTables.h"
37
38void CanonShaping::sortMarks(le_int32 *indices,
39 const le_int32 *combiningClasses, le_int32 index, le_int32 limit)
40{
41 for (le_int32 j = index + 1; j < limit; j += 1) {
42 le_int32 i;
43 le_int32 v = indices[j];
44 le_int32 c = combiningClasses[v];
45
46 for (i = j - 1; i >= index; i -= 1) {
47 if (c >= combiningClasses[indices[i]]) {
48 break;
49 }
50
51 indices[i + 1] = indices[i];
52 }
53
54 indices[i + 1] = v;
55 }
56}
57
58void CanonShaping::reorderMarks(const LEUnicode *inChars, le_int32 charCount,
59 le_bool rightToLeft, LEUnicode *outChars, LEGlyphStorage &glyphStorage)
60{
61 const GlyphDefinitionTableHeader *gdefTable =
62 (const GlyphDefinitionTableHeader *) glyphDefinitionTable;
63 const ClassDefinitionTable *classTable =
64 gdefTable->getMarkAttachClassDefinitionTable();
65 le_int32 *combiningClasses = LE_NEW_ARRAY(le_int32, charCount);
66 le_int32 *indices = LE_NEW_ARRAY(le_int32, charCount);
67 LEErrorCode status = LE_NO_ERROR;
68 le_int32 i;
69
70 for (i = 0; i < charCount; i += 1) {
71 combiningClasses[i] = classTable->getGlyphClass((LEGlyphID) inChars[i]);
72 indices[i] = i;
73 }
74
75 for (i = 0; i < charCount; i += 1) {
76 if (combiningClasses[i] != 0) {
77 le_int32 mark;
78
79 for (mark = i; mark < charCount; mark += 1) {
80 if (combiningClasses[mark] == 0) {
81 break;
82 }
83 }
84
85 sortMarks(indices, combiningClasses, i, mark);
86 }
87 }
88
89 le_int32 out = 0, dir = 1;
90
91 if (rightToLeft) {
92 out = charCount - 1;
93 dir = -1;
94 }
95
96 for (i = 0; i < charCount; i += 1, out += dir) {
97 le_int32 index = indices[i];
98
99 outChars[i] = inChars[index];
100 glyphStorage.setCharIndex(out, index, status);
101 }
102
103 LE_DELETE_ARRAY(indices);
104 LE_DELETE_ARRAY(combiningClasses);
105}