3 * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
8 #include "LEGlyphStorage.h"
9 #include "CanonShaping.h"
10 #include "GlyphDefinitionTables.h"
11 #include "ClassDefinitionTables.h"
15 void CanonShaping::sortMarks(le_int32
*indices
, const le_int32
*combiningClasses
, le_int32 index
, le_int32 limit
)
17 for (le_int32 j
= index
+ 1; j
< limit
; j
+= 1) {
19 le_int32 v
= indices
[j
];
20 le_int32 c
= combiningClasses
[v
];
22 for (i
= j
- 1; i
>= index
; i
-= 1) {
23 if (c
>= combiningClasses
[indices
[i
]]) {
27 indices
[i
+ 1] = indices
[i
];
34 void CanonShaping::reorderMarks(const LEUnicode
*inChars
, le_int32 charCount
, le_bool rightToLeft
,
35 LEUnicode
*outChars
, LEGlyphStorage
&glyphStorage
)
37 LEErrorCode success
= LE_NO_ERROR
;
38 LEReferenceTo
<GlyphDefinitionTableHeader
> gdefTable(CanonShaping::glyphDefinitionTable
, CanonShaping::glyphDefinitionTableLen
);
39 LEReferenceTo
<ClassDefinitionTable
> classTable
= gdefTable
->getMarkAttachClassDefinitionTable(gdefTable
, success
);
40 le_int32
*combiningClasses
= LE_NEW_ARRAY(le_int32
, charCount
);
41 le_int32
*indices
= LE_NEW_ARRAY(le_int32
, charCount
);
44 for (i
= 0; i
< charCount
; i
+= 1) {
45 combiningClasses
[i
] = classTable
->getGlyphClass(classTable
, (LEGlyphID
) inChars
[i
], success
);
49 for (i
= 0; i
< charCount
; i
+= 1) {
50 if (combiningClasses
[i
] != 0) {
53 for (mark
= i
; mark
< charCount
; mark
+= 1) {
54 if (combiningClasses
[mark
] == 0) {
59 sortMarks(indices
, combiningClasses
, i
, mark
);
63 le_int32 out
= 0, dir
= 1;
70 for (i
= 0; i
< charCount
; i
+= 1, out
+= dir
) {
71 le_int32 index
= indices
[i
];
73 outChars
[i
] = inChars
[index
];
74 glyphStorage
.setCharIndex(out
, index
, success
);
77 LE_DELETE_ARRAY(indices
);
78 LE_DELETE_ARRAY(combiningClasses
);