2
|
1 |
/*
|
|
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
|
5506
|
6 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
8 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
21 |
* or visit www.oracle.com if you need additional information or have any
|
|
22 |
* questions.
|
2
|
23 |
*
|
|
24 |
*/
|
|
25 |
|
|
26 |
/*
|
|
27 |
*
|
3935
|
28 |
*
|
7486
|
29 |
* (C) Copyright IBM Corp. 1998-2010 - All Rights Reserved
|
2
|
30 |
*
|
|
31 |
*/
|
|
32 |
|
|
33 |
#include "LETypes.h"
|
|
34 |
#include "OpenTypeTables.h"
|
|
35 |
#include "OpenTypeUtilities.h"
|
|
36 |
#include "ScriptAndLanguage.h"
|
|
37 |
#include "LESwaps.h"
|
|
38 |
|
3935
|
39 |
U_NAMESPACE_BEGIN
|
|
40 |
|
16891
|
41 |
LEReferenceTo<LangSysTable> ScriptTable::findLanguage(const LETableReference& base, LETag languageTag, LEErrorCode &success, le_bool exactMatch) const
|
2
|
42 |
{
|
|
43 |
le_uint16 count = SWAPW(langSysCount);
|
|
44 |
Offset langSysTableOffset = exactMatch? 0 : SWAPW(defaultLangSysTableOffset);
|
|
45 |
|
|
46 |
if (count > 0) {
|
16891
|
47 |
LEReferenceToArrayOf<TagAndOffsetRecord> langSysRecords(base, success, langSysRecordArray, count);
|
|
48 |
Offset foundOffset =
|
|
49 |
OpenTypeUtilities::getTagOffset(languageTag, langSysRecords, success);
|
2
|
50 |
|
16891
|
51 |
if (foundOffset != 0 && LE_SUCCESS(success)) {
|
|
52 |
langSysTableOffset = foundOffset;
|
|
53 |
}
|
2
|
54 |
}
|
|
55 |
|
|
56 |
if (langSysTableOffset != 0) {
|
16891
|
57 |
return LEReferenceTo<LangSysTable>(base, success, langSysTableOffset);
|
2
|
58 |
}
|
|
59 |
|
16891
|
60 |
return LEReferenceTo<LangSysTable>();
|
2
|
61 |
}
|
|
62 |
|
16891
|
63 |
LEReferenceTo<ScriptTable> ScriptListTable::findScript(const LETableReference &base, LETag scriptTag, LEErrorCode &success) const
|
2
|
64 |
{
|
16891
|
65 |
if (LE_FAILURE(success) ) {
|
|
66 |
return LEReferenceTo<ScriptTable>(); // get out
|
|
67 |
}
|
7486
|
68 |
/*
|
|
69 |
* There are some fonts that have a large, bogus value for scriptCount. To try
|
|
70 |
* and protect against this, we use the offset in the first scriptRecord,
|
|
71 |
* which we know has to be past the end of the scriptRecordArray, to compute
|
|
72 |
* a value which is greater than or equal to the actual script count.
|
|
73 |
*
|
|
74 |
* Note: normally, the first offset will point to just after the scriptRecordArray,
|
|
75 |
* but there's no guarantee of this, only that it's *after* the scriptRecordArray.
|
|
76 |
* Because of this, a binary serach isn't safe, because the new count may include
|
|
77 |
* data that's not actually in the scriptRecordArray and hence the array will appear
|
|
78 |
* to be unsorted.
|
|
79 |
*/
|
2
|
80 |
le_uint16 count = SWAPW(scriptCount);
|
16891
|
81 |
|
|
82 |
if (count == 0) {
|
|
83 |
return LEReferenceTo<ScriptTable>(); // no items, no search
|
|
84 |
}
|
|
85 |
|
|
86 |
// attempt to construct a ref with at least one element
|
|
87 |
LEReferenceToArrayOf<ScriptRecord> oneElementTable(base, success, &scriptRecordArray[0], 1);
|
|
88 |
|
|
89 |
if( LE_FAILURE(success) ) {
|
|
90 |
return LEReferenceTo<ScriptTable>(); // couldn't even read the first record - bad font.
|
|
91 |
}
|
|
92 |
|
7486
|
93 |
le_uint16 limit = ((SWAPW(scriptRecordArray[0].offset) - sizeof(ScriptListTable)) / sizeof(scriptRecordArray)) + ANY_NUMBER;
|
|
94 |
Offset scriptTableOffset = 0;
|
|
95 |
|
16891
|
96 |
|
7486
|
97 |
if (count > limit) {
|
|
98 |
// the scriptCount value is bogus; do a linear search
|
|
99 |
// because limit may still be too large.
|
16891
|
100 |
LEReferenceToArrayOf<ScriptRecord> scriptRecordArrayRef(base, success, &scriptRecordArray[0], limit);
|
|
101 |
for(le_int32 s = 0; (s < limit)&&LE_SUCCESS(success); s += 1) {
|
|
102 |
if (SWAPT(scriptRecordArrayRef(s,success).tag) == scriptTag) {
|
|
103 |
scriptTableOffset = SWAPW(scriptRecordArrayRef(s,success).offset);
|
|
104 |
break;
|
|
105 |
}
|
7486
|
106 |
}
|
|
107 |
} else {
|
16891
|
108 |
LEReferenceToArrayOf<ScriptRecord> scriptRecordArrayRef(base, success, &scriptRecordArray[0], count);
|
|
109 |
scriptTableOffset = OpenTypeUtilities::getTagOffset(scriptTag, scriptRecordArrayRef, success); // TODO
|
7486
|
110 |
}
|
2
|
111 |
|
|
112 |
if (scriptTableOffset != 0) {
|
16891
|
113 |
return LEReferenceTo<ScriptTable>(base, success, scriptTableOffset);
|
2
|
114 |
}
|
|
115 |
|
16891
|
116 |
return LEReferenceTo<ScriptTable>();
|
2
|
117 |
}
|
|
118 |
|
16891
|
119 |
LEReferenceTo<LangSysTable> ScriptListTable::findLanguage(const LETableReference &base, LETag scriptTag, LETag languageTag, LEErrorCode &success, le_bool exactMatch) const
|
2
|
120 |
{
|
16891
|
121 |
const LEReferenceTo<ScriptTable> scriptTable = findScript(base, scriptTag, success);
|
2
|
122 |
|
16891
|
123 |
if (scriptTable.isEmpty()) {
|
|
124 |
return LEReferenceTo<LangSysTable>();
|
|
125 |
}
|
2
|
126 |
|
16891
|
127 |
return scriptTable->findLanguage(scriptTable, languageTag, success, exactMatch).reparent(base);
|
2
|
128 |
}
|
3935
|
129 |
|
|
130 |
U_NAMESPACE_END
|