• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
4  *
5  * Developed at DIT - Government of Bhutan
6  *
7  * Contact person: Pema Geyleg - <pema_geyleg@druknet.bt>
8  *
9  * This file is a modification of the ICU file KhmerReordering.cpp
10  * by Jens Herden and Javier Sola who have given all their possible rights to IBM and the Governement of Bhutan
11  * A first module for Dzongkha was developed by Karunakar under Panlocalisation funding.
12  * Assistance for this module has been received from Namgay Thinley, Christopher Fynn and Javier Sola
13  *
14  */
15 
16 
17 #include "OpenTypeLayoutEngine.h"
18 #include "TibetanLayoutEngine.h"
19 #include "LEGlyphStorage.h"
20 #include "TibetanReordering.h"
21 
22 U_NAMESPACE_BEGIN
23 
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TibetanOpenTypeLayoutEngine)24 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TibetanOpenTypeLayoutEngine)
25 
26 TibetanOpenTypeLayoutEngine::TibetanOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
27                                                          le_int32 typoFlags, const LEReferenceTo<GlyphSubstitutionTableHeader> &gsubTable, LEErrorCode &success)
28     : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable, success)
29 {
30     fFeatureMap   = TibetanReordering::getFeatureMap(fFeatureMapCount);
31     fFeatureOrder = TRUE;
32 }
33 
TibetanOpenTypeLayoutEngine(const LEFontInstance * fontInstance,le_int32 scriptCode,le_int32 languageCode,le_int32 typoFlags,LEErrorCode & success)34 TibetanOpenTypeLayoutEngine::TibetanOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
35 						     le_int32 typoFlags, LEErrorCode &success)
36     : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success)
37 {
38     fFeatureMap   = TibetanReordering::getFeatureMap(fFeatureMapCount);
39     fFeatureOrder = TRUE;
40 }
41 
~TibetanOpenTypeLayoutEngine()42 TibetanOpenTypeLayoutEngine::~TibetanOpenTypeLayoutEngine()
43 {
44     // nothing to do
45 }
46 
47 // Input: characters
48 // Output: characters, char indices, tags
49 // Returns: output character count
characterProcessing(const LEUnicode chars[],le_int32 offset,le_int32 count,le_int32 max,le_bool rightToLeft,LEUnicode * & outChars,LEGlyphStorage & glyphStorage,LEErrorCode & success)50 le_int32 TibetanOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
51         LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
52 {
53     if (LE_FAILURE(success)) {
54         return 0;
55     }
56 
57     if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
58         success = LE_ILLEGAL_ARGUMENT_ERROR;
59         return 0;
60     }
61 
62     le_int32 worstCase = count * 3;  // worst case is 3 for Khmer  TODO check if 2 is enough
63 
64     outChars = LE_NEW_ARRAY(LEUnicode, worstCase);
65 
66     if (outChars == NULL) {
67         success = LE_MEMORY_ALLOCATION_ERROR;
68         return 0;
69     }
70 
71     glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success);
72     glyphStorage.allocateAuxData(success);
73 
74     if (LE_FAILURE(success)) {
75         LE_DELETE_ARRAY(outChars);
76         return 0;
77     }
78 
79     // NOTE: assumes this allocates featureTags...
80     // (probably better than doing the worst case stuff here...)
81     le_int32 outCharCount = TibetanReordering::reorder(&chars[offset], count, fScriptCode, outChars, glyphStorage);
82 
83     glyphStorage.adoptGlyphCount(outCharCount);
84     return outCharCount;
85 }
86 
87 U_NAMESPACE_END
88