FontService.java
5.64 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.fontengine.font.Font
* com.adobe.fontengine.fontmanagement.FontLoader
* com.adobe.fontengine.inlineformatting.css20.CSS20Attribute
* com.adobe.fontengine.inlineformatting.css20.CSS20Attribute$CSSVariantValue
* com.adobe.fontengine.inlineformatting.css20.CSS20FontDescription
*/
package com.adobe.xfa.font;
import com.adobe.fontengine.font.Font;
import com.adobe.fontengine.fontmanagement.FontLoader;
import com.adobe.fontengine.inlineformatting.css20.CSS20Attribute;
import com.adobe.fontengine.inlineformatting.css20.CSS20FontDescription;
import com.adobe.xfa.font.FontInfo;
import com.adobe.xfa.font.FontInstance;
import com.adobe.xfa.font.FontItem;
import com.adobe.xfa.ut.UnitSpan;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
public class FontService {
public static final int ISO_8859_1 = 1;
public static final int ISO_8859_2 = 2;
public static final int ISO_8859_5 = 3;
public static final int ISO_8859_6 = 4;
public static final int ISO_8859_7 = 5;
public static final int ISO_8859_8 = 6;
public static final int ISO_8859_9 = 7;
public static final int IBM_874 = 8;
public static final int IBM_1258 = 9;
public static final int SHIFT_JIS = 10;
public static final int SHIFT_JIS_83 = 11;
public static final int KSC_5601 = 12;
public static final int BIG_5 = 13;
public static final int HKSCS_BIG5 = 14;
public static final int GBK = 15;
public static final int FONT_SPECIFIC = 16;
public static final int UTF_8 = 17;
public static final int UTF_16 = 18;
public static final int UCS_2 = 19;
public static final int IDENTITY = 20;
public static final int MAC_ROMAN = 21;
public static final int ENCODING_NONE = 22;
private final SortedMap<FontInfo, FontItem> mFontList;
public FontService(String fontPath) {
File fontDir = new File(fontPath);
FontLoader fontLoader = new FontLoader();
Font[] fonts = fontLoader.load(fontDir, true, null);
this.mFontList = new TreeMap<FontInfo, FontItem>();
for (int fontIndex = 0; fontIndex < fonts.length; ++fontIndex) {
CSS20FontDescription[] descs;
Font font;
block10 : {
descs = null;
font = fonts[fontIndex];
try {
descs = font.getCSS20FontDescription();
}
catch (Exception e) {
if ($assertionsDisabled) break block10;
throw new AssertionError();
}
}
if (descs == null) continue;
for (int descIndex = 0; descIndex < descs.length; ++descIndex) {
FontItem fontItem;
CSS20FontDescription desc = descs[descIndex];
if (desc.getVariant() != CSS20Attribute.CSSVariantValue.NORMAL) continue;
FontInfo key = FontInfo.createFromAFEDescription(desc);
boolean put = false;
FontItem existingFont = this.mFontList.get(key);
if (existingFont == null) {
put = true;
} else if (key.getStretchDiff() < existingFont.getStretchDiff()) {
put = true;
} else if (key.getStretchDiff() == existingFont.getStretchDiff() && key.getLegacySizeDiff() < existingFont.getLegacySizeDiff()) {
put = true;
}
if (!put) continue;
if (existingFont != null) {
this.mFontList.remove(key);
}
if (!(fontItem = new FontItem(key, font)).loadMetrics()) continue;
this.mFontList.put(fontItem, fontItem);
}
}
}
public synchronized FontInstance reconcile(FontInfo info, UnitSpan size, double horizontalScale, double verticalScale) {
FontItem fontItem = this.reconcile(info);
if (fontItem == null) {
return null;
}
return fontItem.reconcile(size, horizontalScale, verticalScale);
}
public synchronized FontItem reconcile(FontInfo key) {
FontItem fontItem = this.mFontList.get(key);
if (fontItem != null) {
return fontItem;
}
ArrayList<FontItem> fontItems = new ArrayList<FontItem>();
for (FontItem item : this.mFontList.values()) {
if (!item.getTypeface().equals(key.getTypeface())) continue;
fontItems.add(item);
}
if (fontItems.size() == 0) {
return null;
}
int foundIndex = -1;
int bestWeightDelta = Integer.MAX_VALUE;
for (int i = 0; i < fontItems.size(); ++i) {
FontItem testFont = (FontItem)fontItems.get(i);
if (testFont.getItalic() != key.getItalic()) continue;
int weightDelta = Math.abs(testFont.getWeight() - key.getWeight());
if (foundIndex >= 0 && weightDelta >= bestWeightDelta) continue;
foundIndex = i;
bestWeightDelta = weightDelta;
}
return (FontItem)fontItems.get(foundIndex);
}
public static int getEncoding(String sEncoding) {
return 22;
}
public FontInstance getDefaultFontInstance() {
assert (false);
return null;
}
public synchronized String toString() {
StringBuilder result = new StringBuilder("Font Service:\n");
for (FontItem fontItem : this.mFontList.values()) {
result.append(" (" + fontItem.toString() + ")\n");
}
return result.toString();
}
}