ScriptHeuristics.java
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.fontengine.font.postscript;
import com.adobe.fontengine.font.CoolTypeScript;
import com.adobe.fontengine.font.InvalidFontException;
import com.adobe.fontengine.font.UnsupportedFontException;
import com.adobe.fontengine.font.postscript.GlyphNamesAccessor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class ScriptHeuristics {
static final Pattern cePattern = Pattern.compile(".*[^A-Z]CE[^A-Za-z].*");
static final Pattern cyrPattern = Pattern.compile(".*[^A-Z]Cyr[^A-Za-z].*");
private static CoolTypeScript getCoolTypeScriptFromPostscriptName(String psName) {
if (psName == null) {
return null;
}
if (cePattern.matcher(psName).find()) {
return CoolTypeScript.EAST_EUROPEAN_ROMAN;
}
if (cyrPattern.matcher(psName).find()) {
return CoolTypeScript.CYRILLIC;
}
if (psName.startsWith("ALBAYAN")) {
return CoolTypeScript.ARABIC;
}
return null;
}
private static CoolTypeScript getCoolTypeScriptFromEncodedGlyphComplement(int numGlyphs, GlyphNamesAccessor glyphNames) throws InvalidFontException, UnsupportedFontException {
if (glyphNames == null) {
return null;
}
boolean hasShin = false;
boolean hasPatah = false;
boolean hasSheen = false;
boolean hasFatha = false;
for (int gid = 0; gid < numGlyphs; ++gid) {
String glyphName = glyphNames.getAGlyphName(gid);
if ("Tcaron".equals(glyphName)) {
return CoolTypeScript.EAST_EUROPEAN_ROMAN;
}
if ("afii10049".equals(glyphName)) {
return CoolTypeScript.CYRILLIC;
}
if (glyphName.startsWith("patah")) {
if (hasShin) {
return CoolTypeScript.HEBREW;
}
hasPatah = true;
}
if (glyphName.startsWith("shin")) {
if (hasPatah) {
return CoolTypeScript.HEBREW;
}
hasShin = true;
}
if (glyphName.startsWith("fatha")) {
if (hasSheen) {
return CoolTypeScript.ARABIC;
}
hasFatha = true;
}
if (!glyphName.startsWith("sheen")) continue;
if (hasFatha) {
return CoolTypeScript.ARABIC;
}
hasSheen = true;
}
return null;
}
public static CoolTypeScript getCoolTypeScript(String psName, int numGlyphs, GlyphNamesAccessor glyphNames) throws InvalidFontException, UnsupportedFontException {
CoolTypeScript ctScript = ScriptHeuristics.getCoolTypeScriptFromPostscriptName(psName);
if (ctScript != null) {
return ctScript;
}
ctScript = ScriptHeuristics.getCoolTypeScriptFromEncodedGlyphComplement(numGlyphs, glyphNames);
if (ctScript != null) {
return ctScript;
}
return CoolTypeScript.ROMAN;
}
}