InFontFormatter.java
8.4 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.agl.lang.UScript
*/
package com.adobe.fontengine.inlineformatting.infontformatting;
import com.adobe.agl.lang.UScript;
import com.adobe.fontengine.font.FontData;
import com.adobe.fontengine.font.FontLoadingException;
import com.adobe.fontengine.font.InvalidFontException;
import com.adobe.fontengine.font.UnsupportedFontException;
import com.adobe.fontengine.inlineformatting.AttributedRun;
import com.adobe.fontengine.inlineformatting.ElementAttribute;
import com.adobe.fontengine.inlineformatting.infontformatting.ArabicFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.BaseFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.BengaliFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.DevanagariFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.GenericFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.GlyphFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.GujaratiFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.GurmukhiFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.HanKanaFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.HangulFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.KannadaFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.LaoFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.OriyaFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.TamilFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.TeluguFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.ThaiFormatter;
import com.adobe.fontengine.inlineformatting.infontformatting.TibetanFormatter;
import java.util.HashSet;
import java.util.Set;
public final class InFontFormatter {
private static final BaseFormatter[] scriptFormatters = new BaseFormatter[130];
private static final BaseFormatter glyphFormatter = new GlyphFormatter();
public static final ElementAttribute scriptAttribute;
protected static final Set typographicSystem;
protected static final Set fontAtts;
private InFontFormatter() {
}
static void resolveScript(AttributedRun run, int first, int limit) {
int ambientScriptNumber = 0;
Integer ambientScript = null;
int lastToFix = first - 1;
for (int i = first; i < limit; ++i) {
if (run.getElementStyle(i, ElementAttribute.isGlyph) == Boolean.TRUE) continue;
int script = UScript.getScript((int)run.elementAt(i));
if (script == 0 || script == 1) {
if (ambientScript != null) {
run.setElementStyle(i, scriptAttribute, ambientScript);
continue;
}
lastToFix = i;
continue;
}
if (script != ambientScriptNumber) {
ambientScriptNumber = script;
ambientScript = new Integer(script);
if (lastToFix != first - 1) {
for (int k = first; k <= lastToFix; ++k) {
run.setElementStyle(k, scriptAttribute, ambientScript);
}
lastToFix = first - 1;
}
}
run.setElementStyle(i, scriptAttribute, ambientScript);
}
if (lastToFix != first - 1) {
for (int k = first; k <= lastToFix; ++k) {
run.setElementStyle(k, scriptAttribute, new Integer(25));
}
}
}
public static int preFormat(AttributedRun run, int start, int limit) {
while (start < limit) {
int glyphLimit = run.getSubrunLimit(start, limit, ElementAttribute.isGlyph);
boolean isGlyph = (Boolean)run.getElementStyle(start, ElementAttribute.isGlyph);
if (isGlyph) {
start = glyphLimit;
continue;
}
InFontFormatter.resolveScript(run, start, glyphLimit);
start = glyphLimit;
}
return limit;
}
public static int firstPass(AttributedRun run, int start, int limit) {
while (start < limit) {
int glyphLimit = run.getSubrunLimit(start, limit, ElementAttribute.isGlyph);
boolean isGlyph = (Boolean)run.getElementStyle(start, ElementAttribute.isGlyph);
if (isGlyph) {
start = glyphLimit;
continue;
}
while (start < glyphLimit) {
int newScriptLimit;
int scriptLimit = run.getSubrunLimit(start, glyphLimit, scriptAttribute);
int script = (Integer)run.getElementStyle(start, scriptAttribute);
start = newScriptLimit = scriptFormatters[script].firstPass(run, start, scriptLimit);
glyphLimit += newScriptLimit - scriptLimit;
limit += newScriptLimit - scriptLimit;
}
}
return limit;
}
public static int canRenderWithFont(FontData font, AttributedRun run, int start, int limit) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
int script = (Integer)run.getElementStyle(start, scriptAttribute);
return scriptFormatters[script].canRenderWithFont(font, run, start, limit);
}
public static int canRenderWithNotdef(AttributedRun run, int start, int limit) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
int script = (Integer)run.getElementStyle(start, scriptAttribute);
return scriptFormatters[script].canRenderWithNotdef(run, start, limit);
}
public static int format(AttributedRun run, int start, int limit, boolean shouldKern) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
while (start < limit) {
int newTypographicSystemLimit;
int typographicSystemLimit = run.getSubrunLimit(start, limit, typographicSystem);
boolean isGlyph = (Boolean)run.getElementStyle(start, ElementAttribute.isGlyph);
if (isGlyph) {
newTypographicSystemLimit = glyphFormatter.format(run, start, typographicSystemLimit, shouldKern);
} else {
int script = (Integer)run.getElementStyle(start, scriptAttribute);
newTypographicSystemLimit = scriptFormatters[script].format(run, start, typographicSystemLimit, shouldKern);
}
start = newTypographicSystemLimit;
limit += newTypographicSystemLimit - typographicSystemLimit;
}
return limit;
}
static {
GenericFormatter genericFormatter = new GenericFormatter();
for (int i = 0; i < scriptFormatters.length; ++i) {
InFontFormatter.scriptFormatters[i] = genericFormatter;
}
InFontFormatter.scriptFormatters[2] = new ArabicFormatter();
InFontFormatter.scriptFormatters[4] = new BengaliFormatter();
InFontFormatter.scriptFormatters[10] = new DevanagariFormatter();
InFontFormatter.scriptFormatters[15] = new GujaratiFormatter();
InFontFormatter.scriptFormatters[16] = new GurmukhiFormatter();
InFontFormatter.scriptFormatters[18] = new HangulFormatter();
InFontFormatter.scriptFormatters[21] = new KannadaFormatter();
InFontFormatter.scriptFormatters[24] = new LaoFormatter();
InFontFormatter.scriptFormatters[31] = new OriyaFormatter();
InFontFormatter.scriptFormatters[35] = new TamilFormatter();
InFontFormatter.scriptFormatters[36] = new TeluguFormatter();
InFontFormatter.scriptFormatters[38] = new ThaiFormatter();
InFontFormatter.scriptFormatters[39] = new TibetanFormatter();
HanKanaFormatter hanKanaFormatter = new HanKanaFormatter();
InFontFormatter.scriptFormatters[20] = hanKanaFormatter;
InFontFormatter.scriptFormatters[22] = hanKanaFormatter;
InFontFormatter.scriptFormatters[54] = hanKanaFormatter;
InFontFormatter.scriptFormatters[17] = hanKanaFormatter;
scriptAttribute = new ElementAttribute("script");
typographicSystem = new HashSet();
typographicSystem.add(scriptAttribute);
typographicSystem.add(ElementAttribute.locale);
typographicSystem.add(ElementAttribute.isGlyph);
fontAtts = new HashSet();
fontAtts.add(ElementAttribute.font);
}
}