FXGFontResolverImpl.java
6.66 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.fontengine.fontmanagement.fxg;
import com.adobe.fontengine.font.Font;
import com.adobe.fontengine.font.FontLoadingException;
import com.adobe.fontengine.font.InvalidFontException;
import com.adobe.fontengine.font.UnsupportedFontException;
import com.adobe.fontengine.fontmanagement.FontResolutionPriority;
import com.adobe.fontengine.fontmanagement.IntelligentResolver;
import com.adobe.fontengine.fontmanagement.fxg.FXGFontDescription;
import com.adobe.fontengine.fontmanagement.fxg.FXGFontResolver;
import com.adobe.fontengine.fontmanagement.fxg.FXGFontSearchAttributes;
import java.util.HashMap;
import java.util.Set;
public class FXGFontResolverImpl
implements FXGFontResolver {
private HashMap fxgFonts;
private FontResolutionPriority resolutionPriority = FontResolutionPriority.FIRST;
private static final long serialVersionUID = 1;
public FXGFontResolverImpl() {
this.fxgFonts = new HashMap();
}
public FXGFontResolverImpl(FXGFontResolverImpl original) {
this.fxgFonts = (HashMap)original.fxgFonts.clone();
this.resolutionPriority = original.resolutionPriority;
}
public void addFont(Font font) throws UnsupportedFontException, InvalidFontException, FontLoadingException {
FXGFontDescription[] fxgDesc = font.getFXGFontDescription();
for (int i = 0; i < fxgDesc.length; ++i) {
this.addFont(fxgDesc[i], font);
}
}
public void addFont(FXGFontDescription fxgDesc, Font font) throws UnsupportedFontException, InvalidFontException, FontLoadingException {
FXGKey searchKey = new FXGKey(fxgDesc);
FXGValue oldValue = (FXGValue)this.fxgFonts.get(searchKey);
if (oldValue != null) {
Font preferredFont;
Font oldFont = oldValue.getFont();
if (this.resolutionPriority == FontResolutionPriority.FIRST) {
return;
}
if ((this.resolutionPriority == FontResolutionPriority.INTELLIGENT_LAST || this.resolutionPriority == FontResolutionPriority.INTELLIGENT_FIRST) && (preferredFont = IntelligentResolver.choosePreferredFont(oldFont, font, this.resolutionPriority == FontResolutionPriority.INTELLIGENT_FIRST)) == oldFont) {
return;
}
}
this.fxgFonts.put(searchKey, new FXGValue(fxgDesc, font));
}
public Font findFont(FXGFontSearchAttributes searchAttributes) {
FXGValue value = (FXGValue)this.fxgFonts.get(new FXGKey(searchAttributes));
if (value == null) {
return null;
}
return value.getFont();
}
public boolean isEmpty() {
return this.fxgFonts.isEmpty();
}
public FontResolutionPriority setResolutionPriority(FontResolutionPriority priority) {
FontResolutionPriority oldPriority = this.resolutionPriority;
this.resolutionPriority = priority;
return oldPriority;
}
public int hashCode() {
int prime = 31;
int result = 1;
result = 31 * result + (this.fxgFonts == null ? 0 : this.fxgFonts.hashCode());
result = 31 * result + (this.resolutionPriority == null ? 0 : this.resolutionPriority.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof FXGFontResolverImpl)) {
return false;
}
FXGFontResolverImpl other = (FXGFontResolverImpl)obj;
if (this.fxgFonts == null ? other.fxgFonts != null : !this.fxgFonts.equals(other.fxgFonts)) {
return false;
}
if (this.resolutionPriority == null ? other.resolutionPriority != null : !this.resolutionPriority.equals(other.resolutionPriority)) {
return false;
}
return true;
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("FXG Fonts:\n");
for (FXGKey k : this.fxgFonts.keySet()) {
sb.append(" ");
sb.append(k);
sb.append(" = ");
sb.append(((FXGValue)this.fxgFonts.get(k)).getFont().toString());
sb.append("\n");
}
return sb.toString();
}
private static final class FXGValue {
private final FXGFontDescription fxgDescription;
private final Font font;
FXGValue(FXGFontDescription fxgDescription, Font font) {
this.fxgDescription = fxgDescription;
this.font = font;
}
FXGFontDescription getFXGDescription() {
return this.fxgDescription;
}
Font getFont() {
return this.font;
}
public String toString() {
return new String(this.fxgDescription.toString() + "\n\t" + this.font.toString());
}
}
private static final class FXGKey {
private final String familyName;
private final boolean isBold;
private final boolean isItalic;
protected FXGKey(FXGFontDescription fxgDescription) {
this.familyName = fxgDescription.getFamilyName();
this.isBold = fxgDescription.isBold();
this.isItalic = fxgDescription.isItalic();
}
protected FXGKey(FXGFontSearchAttributes fxgSearchAttributes) {
this.familyName = fxgSearchAttributes.getFamilyName();
this.isBold = fxgSearchAttributes.isBold();
this.isItalic = fxgSearchAttributes.isItalic();
}
public int hashCode() {
int prime = 31;
int result = 1;
result = 31 * result + (this.familyName == null ? 0 : this.familyName.hashCode());
result = 31 * result + (this.isBold ? 1231 : 1237);
result = 31 * result + (this.isItalic ? 1231 : 1237);
return result;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof FXGKey)) {
return false;
}
FXGKey other = (FXGKey)obj;
if (this.familyName == null ? other.familyName != null : !this.familyName.equals(other.familyName)) {
return false;
}
if (this.isBold != other.isBold) {
return false;
}
if (this.isItalic != other.isItalic) {
return false;
}
return true;
}
public String toString() {
return new String(this.familyName + (this.isBold ? ", bold" : "") + (this.isItalic ? ", italic" : ""));
}
}
}