URLFont.java
5.85 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.fontengine.fontmanagement;
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.UnsupportedFontException;
import com.adobe.fontengine.font.type1.MetricFile;
import com.adobe.fontengine.font.type1.Type1Font;
import com.adobe.fontengine.fontmanagement.FontLoader;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.ref.SoftReference;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
class URLFont
extends FontImpl {
static final long serialVersionUID = 1;
protected final URL outlineFileURL;
protected URL metricFileURL;
protected final int index;
protected String canonicalPath;
protected long length;
protected long lastModified;
protected ConcurrentHashMap<String, Object> descCache = new ConcurrentHashMap(16, 0.75f, 1);
protected transient SoftReference fontRef;
URLFont(URL outlineFileURL, int index) {
this.outlineFileURL = outlineFileURL;
this.index = index;
this.fontRef = new SoftReference<Object>(null);
this.initCacheTags();
}
URLFont(URL outlineFileURL, int index, FontData font) throws UnsupportedFontException {
this.outlineFileURL = outlineFileURL;
this.index = index;
this.fontRef = new SoftReference<FontData>(font);
this.initCacheTags();
}
void setMetricURL(URL metricFileURL, MetricFile f) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
FontData data = this.retrieveFontData();
if (!(data instanceof Type1Font)) {
return;
}
if (((Type1Font)data).setMetricFile(f)) {
this.metricFileURL = metricFileURL;
}
}
@Override
protected synchronized FontData retrieveFontData() throws InvalidFontException, UnsupportedFontException, FontLoadingException {
FontData font = null;
font = (FontData)this.fontRef.get();
if (font == null) {
FontData[] arr;
try {
arr = FontLoader.fromURL(this.outlineFileURL, this.metricFileURL);
}
catch (IOException e) {
throw new FontLoadingException(e);
}
font = arr[this.index];
this.fontRef = new SoftReference<FontData>(font);
}
return font;
}
@Override
public int hashCode() {
int hash = this.index;
hash ^= this.outlineFileURL.hashCode();
if (this.metricFileURL != null) {
hash ^= this.metricFileURL.hashCode();
}
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj != null) {
if (this == obj) {
return true;
}
if (obj instanceof URLFont) {
URLFont otherURLFont = (URLFont)obj;
if (this.index == otherURLFont.index) {
try {
if (!this.outlineFileURL.toURI().equals(otherURLFont.outlineFileURL.toURI())) {
return false;
}
}
catch (URISyntaxException e) {
return false;
}
if (this.metricFileURL == null && otherURLFont.metricFileURL == null) {
return true;
}
try {
if (this.metricFileURL == null || otherURLFont.metricFileURL == null || !this.metricFileURL.toURI().equals(otherURLFont.metricFileURL.toURI())) {
return false;
}
}
catch (URISyntaxException e) {
return false;
}
return true;
}
}
}
return false;
}
@Override
public String toString() {
return this.outlineFileURL.toString();
}
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
s.defaultReadObject();
this.fontRef = new SoftReference<Object>(null);
}
private void initCacheTags() {
try {
try {
this.canonicalPath = this.outlineFileURL.toURI().getPath();
if (this.canonicalPath == null) {
throw new IOException("Cannot resolve path to file");
}
}
catch (URISyntaxException e) {
throw new IOException(e.toString());
}
File file = new File(this.canonicalPath);
this.canonicalPath = file.getCanonicalPath();
this.length = file.length();
this.lastModified = file.lastModified();
}
catch (IOException e) {
this.canonicalPath = null;
this.length = 0;
this.lastModified = 0;
}
}
@Override
public String getCanonicalPath() {
return this.canonicalPath;
}
@Override
public long getLength() {
return this.length;
}
@Override
public long getLastModified() {
return this.lastModified;
}
@Override
public Object getCachedFontDescription(String key) {
return this.descCache.get(key);
}
@Override
public Map<String, Object> getCachedFontDescriptionMap() {
return this.descCache;
}
@Override
public void setCachedFontDescription(String key, Object value) {
this.descCache.put(key, value);
}
}