BaseFormatter.java
11.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.agl.util.LocaleData
* com.adobe.agl.util.ULocale
*/
package com.adobe.fontengine.inlineformatting.infontformatting;
import com.adobe.agl.util.LocaleData;
import com.adobe.agl.util.ULocale;
import com.adobe.fontengine.CharUtil;
import com.adobe.fontengine.font.Font;
import com.adobe.fontengine.font.FontData;
import com.adobe.fontengine.font.FontImpl;
import com.adobe.fontengine.font.FontLoadingException;
import com.adobe.fontengine.font.InvalidFontException;
import com.adobe.fontengine.font.InvalidGlyphException;
import com.adobe.fontengine.font.UnsupportedFontException;
import com.adobe.fontengine.font.opentype.Gpos;
import com.adobe.fontengine.font.opentype.Gsub;
import com.adobe.fontengine.font.opentype.Kern;
import com.adobe.fontengine.font.opentype.OpenTypeFont;
import com.adobe.fontengine.font.opentype.Tag;
import com.adobe.fontengine.font.type1.Type1Font;
import com.adobe.fontengine.inlineformatting.AttributedRun;
import com.adobe.fontengine.inlineformatting.ElementAttribute;
import com.adobe.fontengine.inlineformatting.infontformatting.InFontFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class BaseFormatter {
private static final Map otScriptMap = new HashMap();
public int firstPass(AttributedRun run, int start, int limit) {
return limit;
}
public int canRenderWithNotdef(AttributedRun run, int start, int limit) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
int graphemeLimit;
int usv = run.elementAt(start);
if (CharUtil.isControl(usv)) {
return 1;
}
if (!CharUtil.isBase(usv) || start + 1 == limit || run.getElementStyle(start + 1, ElementAttribute.isGlyph) == Boolean.TRUE || !CharUtil.isCombining(run.elementAt(start + 1))) {
return 1;
}
for (graphemeLimit = start + 1; graphemeLimit < limit && run.getElementStyle(graphemeLimit, ElementAttribute.isGlyph) != Boolean.TRUE && CharUtil.isCombining(run.elementAt(graphemeLimit)); ++graphemeLimit) {
}
return graphemeLimit - start;
}
public int canRenderWithFont(FontData fontData, AttributedRun run, int start, int limit) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
int gid;
int graphemeLimit;
if (this.shouldFormatOT(fontData) ? !this.canFormatOT() : (this.shouldFormatTT(fontData) ? !this.canFormatTT() : (this.shouldFormatT1(fontData) ? !this.canFormatT1() : !this.canFormatGeneric()))) {
return 0;
}
int usv = run.elementAt(start);
if (CharUtil.isControl(usv) && !fontData.isSymbolic()) {
return 1;
}
if (!CharUtil.isBase(usv) || start + 1 == limit || run.getElementStyle(start + 1, ElementAttribute.isGlyph) == Boolean.TRUE || !CharUtil.isCombining(run.elementAt(start + 1))) {
int gid2 = fontData.getGlyphForChar(usv);
return gid2 == 0 ? 0 : 1;
}
for (graphemeLimit = start + 1; graphemeLimit < limit && run.getElementStyle(graphemeLimit, ElementAttribute.isGlyph) != Boolean.TRUE && CharUtil.isCombining(run.elementAt(graphemeLimit)); ++graphemeLimit) {
}
boolean directMappingHasNotdef = false;
int[] usvs = new int[graphemeLimit - start];
int[] gids = new int[graphemeLimit - start];
for (int i = start; i < graphemeLimit; ++i) {
usvs[i - start] = run.elementAt(i);
gid = fontData.getGlyphForChar(usvs[i - start]);
if (gid == 0) {
directMappingHasNotdef = true;
}
gids[i - start] = gid;
}
if (directMappingHasNotdef) {
int usvc = CharUtil.compose(usvs, 0, graphemeLimit - start);
if (usvc != -1 && (gid = fontData.getGlyphForChar(usvc)) != 0) {
return graphemeLimit - start;
}
return 0;
}
return graphemeLimit - start;
}
protected boolean shouldFormatOT(FontData fontData) {
if (fontData instanceof OpenTypeFont) {
OpenTypeFont otFont = (OpenTypeFont)fontData;
return otFont.gpos != null || otFont.gsub != null;
}
return false;
}
protected boolean canFormatOT() {
return false;
}
protected int formatOT(OpenTypeFont otFont, AttributedRun run, int start, int limit, boolean shouldKern) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
throw new UnsupportedFontException();
}
protected boolean shouldFormatTT(FontData fontData) {
if (fontData instanceof OpenTypeFont) {
OpenTypeFont otFont = (OpenTypeFont)fontData;
return otFont.gpos == null && otFont.gsub == null;
}
return false;
}
protected boolean canFormatTT() {
return false;
}
protected int formatTT(OpenTypeFont otFont, AttributedRun run, int start, int limit, boolean shouldKern) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
throw new UnsupportedFontException();
}
protected boolean shouldFormatT1(FontData fontData) {
return fontData instanceof Type1Font;
}
protected boolean canFormatT1() {
return false;
}
protected int formatT1(Type1Font t1Font, AttributedRun run, int start, int limit, boolean shouldKern) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
throw new UnsupportedFontException();
}
protected boolean shouldFormatGeneric(FontData fontData) {
return !(fontData instanceof Type1Font) && !(fontData instanceof OpenTypeFont);
}
protected boolean canFormatGeneric() {
return false;
}
protected int formatGeneric(FontData fontData, AttributedRun run, int start, int limit, boolean shouldKern) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
throw new UnsupportedFontException();
}
public int format(AttributedRun run, int start, int limit, boolean shouldKern) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
while (start < limit) {
int newFontLimit;
int fontLimit = run.getSubrunLimit(start, limit, InFontFormatter.fontAtts);
Font font = (Font)run.getElementStyle(start, ElementAttribute.font);
FontData fontData = ((FontImpl)font).getFontData();
if (this.shouldFormatOT(fontData)) {
newFontLimit = this.formatOT((OpenTypeFont)fontData, run, start, fontLimit, shouldKern);
} else if (this.shouldFormatTT(fontData)) {
newFontLimit = this.formatTT((OpenTypeFont)fontData, run, start, fontLimit, shouldKern);
} else if (this.shouldFormatT1(fontData)) {
Type1Font t1Font = (Type1Font)fontData;
newFontLimit = this.formatT1(t1Font, run, start, fontLimit, shouldKern);
} else {
newFontLimit = this.formatGeneric(fontData, run, start, fontLimit, shouldKern);
}
start = newFontLimit;
limit += newFontLimit - fontLimit;
}
return limit;
}
public void posFromAdvanceWidth(AttributedRun run, FontData fontData, int first, int limit) throws InvalidFontException, UnsupportedFontException, InvalidGlyphException {
run.startWorkingWithPositions(first, limit);
for (int i = first; i < limit; ++i) {
int gid = run.elementAt(i);
if (gid > fontData.getNumGlyphs()) {
throw new InvalidFontException("gid " + gid + " is not a valid gid (numGlyphs = " + fontData.getNumGlyphs() + ")");
}
run.setElementPlacementAndAdvance(i, 0.0, 0.0, fontData.getHorizontalAdvance(gid), 0.0);
}
}
protected void applyKernTable(OpenTypeFont otFont, AttributedRun run, int start, int limit) throws InvalidFontException, UnsupportedFontException {
if (otFont.kern == null) {
return;
}
for (int i = start; i < limit - 1; ++i) {
int[] kernVector = otFont.kern.getKernVector(run.elementAt(i), run.elementAt(i + 1));
run.adjustPlacementAndAdvance(i, 0.0, 0.0, kernVector[0], kernVector[1]);
}
}
static int getOTScriptTag(Integer uscript) {
Integer i = (Integer)otScriptMap.get(uscript);
if (i != null) {
return i;
}
return Tag.script_DFLT;
}
static int getOTLanguageTag(ULocale locale) {
int langTag = LocaleData.getOpenTypeData((ULocale)locale).getLanguageTag();
if (langTag == 0) {
langTag = Tag.language_ENG;
}
return langTag;
}
static {
otScriptMap.put(new Integer(2), new Integer(Tag.script_arab));
otScriptMap.put(new Integer(3), new Integer(Tag.script_armn));
otScriptMap.put(new Integer(4), new Integer(Tag.script_beng));
otScriptMap.put(new Integer(5), new Integer(Tag.script_bopo));
otScriptMap.put(new Integer(46), new Integer(Tag.script_brai));
otScriptMap.put(new Integer(40), new Integer(Tag.script_cans));
otScriptMap.put(new Integer(6), new Integer(Tag.script_cher));
otScriptMap.put(new Integer(8), new Integer(Tag.script_cyrl));
otScriptMap.put(new Integer(10), new Integer(Tag.script_deva));
otScriptMap.put(new Integer(11), new Integer(Tag.script_ethi));
otScriptMap.put(new Integer(12), new Integer(Tag.script_geor));
otScriptMap.put(new Integer(14), new Integer(Tag.script_grek));
otScriptMap.put(new Integer(15), new Integer(Tag.script_gujr));
otScriptMap.put(new Integer(16), new Integer(Tag.script_guru));
otScriptMap.put(new Integer(17), new Integer(Tag.script_hani));
otScriptMap.put(new Integer(18), new Integer(Tag.script_hang));
otScriptMap.put(new Integer(19), new Integer(Tag.script_hebr));
otScriptMap.put(new Integer(20), new Integer(Tag.script_kana));
otScriptMap.put(new Integer(21), new Integer(Tag.script_knda));
otScriptMap.put(new Integer(22), new Integer(Tag.script_kana));
otScriptMap.put(new Integer(23), new Integer(Tag.script_khmr));
otScriptMap.put(new Integer(24), new Integer(Tag.script_lao));
otScriptMap.put(new Integer(25), new Integer(Tag.script_latn));
otScriptMap.put(new Integer(26), new Integer(Tag.script_mlym));
otScriptMap.put(new Integer(27), new Integer(Tag.script_mong));
otScriptMap.put(new Integer(28), new Integer(Tag.script_mymr));
otScriptMap.put(new Integer(29), new Integer(Tag.script_ogam));
otScriptMap.put(new Integer(31), new Integer(Tag.script_orya));
otScriptMap.put(new Integer(32), new Integer(Tag.script_runr));
otScriptMap.put(new Integer(33), new Integer(Tag.script_sinh));
otScriptMap.put(new Integer(34), new Integer(Tag.script_syrc));
otScriptMap.put(new Integer(35), new Integer(Tag.script_taml));
otScriptMap.put(new Integer(36), new Integer(Tag.script_telu));
otScriptMap.put(new Integer(37), new Integer(Tag.script_thaa));
otScriptMap.put(new Integer(38), new Integer(Tag.script_thai));
otScriptMap.put(new Integer(39), new Integer(Tag.script_tibt));
otScriptMap.put(new Integer(41), new Integer(Tag.script_yi));
otScriptMap.put(new Integer(54), new Integer(Tag.script_kana));
}
}