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 |
|
2
|
41 |
const LangSysTable *ScriptTable::findLanguage(LETag languageTag, le_bool exactMatch) const
|
|
42 |
{
|
|
43 |
le_uint16 count = SWAPW(langSysCount);
|
|
44 |
Offset langSysTableOffset = exactMatch? 0 : SWAPW(defaultLangSysTableOffset);
|
|
45 |
|
|
46 |
if (count > 0) {
|
|
47 |
Offset foundOffset =
|
|
48 |
OpenTypeUtilities::getTagOffset(languageTag, langSysRecordArray, count);
|
|
49 |
|
|
50 |
if (foundOffset != 0) {
|
|
51 |
langSysTableOffset = foundOffset;
|
|
52 |
}
|
|
53 |
}
|
|
54 |
|
|
55 |
if (langSysTableOffset != 0) {
|
|
56 |
return (const LangSysTable *) ((char *)this + langSysTableOffset);
|
|
57 |
}
|
|
58 |
|
7486
|
59 |
return NULL;
|
2
|
60 |
}
|
|
61 |
|
|
62 |
const ScriptTable *ScriptListTable::findScript(LETag scriptTag) const
|
|
63 |
{
|
7486
|
64 |
/*
|
|
65 |
* There are some fonts that have a large, bogus value for scriptCount. To try
|
|
66 |
* and protect against this, we use the offset in the first scriptRecord,
|
|
67 |
* which we know has to be past the end of the scriptRecordArray, to compute
|
|
68 |
* a value which is greater than or equal to the actual script count.
|
|
69 |
*
|
|
70 |
* Note: normally, the first offset will point to just after the scriptRecordArray,
|
|
71 |
* but there's no guarantee of this, only that it's *after* the scriptRecordArray.
|
|
72 |
* Because of this, a binary serach isn't safe, because the new count may include
|
|
73 |
* data that's not actually in the scriptRecordArray and hence the array will appear
|
|
74 |
* to be unsorted.
|
|
75 |
*/
|
2
|
76 |
le_uint16 count = SWAPW(scriptCount);
|
7486
|
77 |
le_uint16 limit = ((SWAPW(scriptRecordArray[0].offset) - sizeof(ScriptListTable)) / sizeof(scriptRecordArray)) + ANY_NUMBER;
|
|
78 |
Offset scriptTableOffset = 0;
|
|
79 |
|
|
80 |
if (count > limit) {
|
|
81 |
// the scriptCount value is bogus; do a linear search
|
|
82 |
// because limit may still be too large.
|
|
83 |
for(le_int32 s = 0; s < limit; s += 1) {
|
|
84 |
if (SWAPT(scriptRecordArray[s].tag) == scriptTag) {
|
|
85 |
scriptTableOffset = SWAPW(scriptRecordArray[s].offset);
|
|
86 |
break;
|
|
87 |
}
|
|
88 |
}
|
|
89 |
} else {
|
|
90 |
scriptTableOffset = OpenTypeUtilities::getTagOffset(scriptTag, scriptRecordArray, count);
|
|
91 |
}
|
2
|
92 |
|
|
93 |
if (scriptTableOffset != 0) {
|
|
94 |
return (const ScriptTable *) ((char *)this + scriptTableOffset);
|
|
95 |
}
|
|
96 |
|
7486
|
97 |
return NULL;
|
2
|
98 |
}
|
|
99 |
|
|
100 |
const LangSysTable *ScriptListTable::findLanguage(LETag scriptTag, LETag languageTag, le_bool exactMatch) const
|
|
101 |
{
|
|
102 |
const ScriptTable *scriptTable = findScript(scriptTag);
|
|
103 |
|
|
104 |
if (scriptTable == 0) {
|
7486
|
105 |
return NULL;
|
2
|
106 |
}
|
|
107 |
|
|
108 |
return scriptTable->findLanguage(languageTag, exactMatch);
|
|
109 |
}
|
3935
|
110 |
|
|
111 |
U_NAMESPACE_END
|