1
2/*
3 * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
4 *
5 * This file is a modification of the ICU file IndicLayoutEngine.cpp
6 * by Jens Herden and Javier Sola for Khmer language
7 *
8 */
9
10
11#include "OpenTypeLayoutEngine.h"
12#include "KhmerLayoutEngine.h"
13#include "LEGlyphStorage.h"
14#include "KhmerReordering.h"
15
16U_NAMESPACE_BEGIN
17
18UOBJECT_DEFINE_RTTI_IMPLEMENTATION(KhmerOpenTypeLayoutEngine)
19
20KhmerOpenTypeLayoutEngine::KhmerOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
21                                                     le_int32 typoFlags, const LEReferenceTo<GlyphSubstitutionTableHeader> &gsubTable, LEErrorCode &success)
22    : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable, success)
23{
24    fFeatureMap   = KhmerReordering::getFeatureMap(fFeatureMapCount);
25    fFeatureOrder = TRUE;
26}
27
28KhmerOpenTypeLayoutEngine::KhmerOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
29						     le_int32 typoFlags, LEErrorCode &success)
30    : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success)
31{
32    fFeatureMap   = KhmerReordering::getFeatureMap(fFeatureMapCount);
33    fFeatureOrder = TRUE;
34}
35
36KhmerOpenTypeLayoutEngine::~KhmerOpenTypeLayoutEngine()
37{
38    // nothing to do
39}
40
41// Input: characters
42// Output: characters, char indices, tags
43// Returns: output character count
44le_int32 KhmerOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
45        LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
46{
47    if (LE_FAILURE(success)) {
48        return 0;
49    }
50
51    if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
52        success = LE_ILLEGAL_ARGUMENT_ERROR;
53        return 0;
54    }
55
56    le_int32 worstCase = count * 3;  // worst case is 3 for Khmer  TODO check if 2 is enough
57
58    outChars = LE_NEW_ARRAY(LEUnicode, worstCase);
59
60    if (outChars == NULL) {
61        success = LE_MEMORY_ALLOCATION_ERROR;
62        return 0;
63    }
64
65    glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success);
66    glyphStorage.allocateAuxData(success);
67
68    if (LE_FAILURE(success)) {
69        LE_DELETE_ARRAY(outChars);
70        return 0;
71    }
72
73    // NOTE: assumes this allocates featureTags...
74    // (probably better than doing the worst case stuff here...)
75    le_int32 outCharCount = KhmerReordering::reorder(&chars[offset], count, fScriptCode, outChars, glyphStorage);
76
77    glyphStorage.adoptGlyphCount(outCharCount);
78    return outCharCount;
79}
80
81U_NAMESPACE_END
82