FontInfo.java
5.19 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.fontengine.inlineformatting.css20.CSS20Attribute
* com.adobe.fontengine.inlineformatting.css20.CSS20Attribute$CSSStretchValue
* com.adobe.fontengine.inlineformatting.css20.CSS20Attribute$CSSStyleValue
* com.adobe.fontengine.inlineformatting.css20.CSS20FontDescription
*/
package com.adobe.xfa.font;
import com.adobe.fontengine.inlineformatting.css20.CSS20Attribute;
import com.adobe.fontengine.inlineformatting.css20.CSS20FontDescription;
public class FontInfo
implements Comparable<FontInfo> {
public static final int WEIGHT_UNKNOWN = 0;
public static final int WEIGHT_NORMAL = 400;
public static final int WEIGHT_BOLD = 700;
public static final int STYLE_UNKNOWN = -1;
public static final int STYLE_UPRIGHT = 0;
public static final int STYLE_ITALIC = 1;
private static final double LEGACY_SAMPLE_FONT_SIZE = 10.0;
private final String mTypeface;
private final int mWeight;
private final boolean mItalic;
private final double mLegacySizeDiff;
private final int mStretchDiff;
public FontInfo() {
this("", 400, false, 0.0, 0);
}
public FontInfo(FontInfo source) {
this(source.mTypeface, source.mWeight, source.mItalic, source.mLegacySizeDiff, source.mStretchDiff);
}
public FontInfo(String typeface, int weight, boolean italic) {
this(typeface, weight, italic, 0.0, 0);
}
public FontInfo(String typeface, int weight, boolean italic, double legacySizeDiff, int stretchDiff) {
this.mTypeface = typeface;
this.mWeight = weight;
this.mItalic = italic;
this.mLegacySizeDiff = legacySizeDiff;
this.mStretchDiff = stretchDiff;
}
public String getTypeface() {
return this.mTypeface;
}
public int getWeight() {
return this.mWeight;
}
public boolean getItalic() {
return this.mItalic;
}
public double getLegacySizeDiff() {
return this.mLegacySizeDiff;
}
public int getStretchDiff() {
return this.mStretchDiff;
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null) {
return false;
}
if (object.getClass() != this.getClass()) {
return false;
}
FontInfo other = (FontInfo)object;
if (this.mWeight != other.mWeight || this.mItalic != other.mItalic) {
return false;
}
return this.mTypeface.equals(other.mTypeface);
}
public static FontInfo createFromAFEDescription(CSS20FontDescription desc) {
boolean italic = desc.getStyle() != CSS20Attribute.CSSStyleValue.NORMAL;
return new FontInfo(desc.getFamilyName(), desc.getWeight(), italic, FontInfo.getLegacySizeDiff(desc), FontInfo.getStretchDiff(desc));
}
public static boolean match(FontInfo o1, FontInfo o2) {
if (o1 == o2) {
return true;
}
if (o1 == null || o2 == null) {
return false;
}
return o1.equals(o2);
}
public int hashCode() {
int result = this.mWeight;
result = result * 31 ^ Boolean.valueOf(this.mItalic).hashCode();
return result * 31 ^ this.mTypeface.hashCode();
}
public String toString() {
String result = "Typeface: " + this.mTypeface;
result = result + ", Weight: " + (this.mWeight >= 700 ? "bold" : "normal");
result = result + ", Italic: " + (this.mItalic ? "on" : "off");
return result;
}
@Override
public int compareTo(FontInfo other) {
if (other == null) {
throw new NullPointerException();
}
int result = this.mTypeface.compareTo(other.mTypeface);
if (result != 0) {
return result;
}
if (this.mItalic != other.mItalic) {
return this.mItalic ? 1 : -1;
}
if (this.mWeight < other.mWeight) {
return -1;
}
if (this.mWeight > other.mWeight) {
return 1;
}
return 0;
}
static double getLegacySizeDiff(CSS20FontDescription desc) {
double minSize = desc.getLowPointSize();
double maxSize = desc.getHighPointSize();
if (10.0 < minSize) {
return minSize - 10.0;
}
if (10.0 > maxSize) {
return 10.0 - maxSize;
}
return 0.0;
}
static int getStretchDiff(CSS20FontDescription desc) {
CSS20Attribute.CSSStretchValue stretch = desc.getStretch();
if (stretch == CSS20Attribute.CSSStretchValue.SEMICONDENSED || stretch == CSS20Attribute.CSSStretchValue.SEMIEXPANDED) {
return 1;
}
if (stretch == CSS20Attribute.CSSStretchValue.CONDENSED || stretch == CSS20Attribute.CSSStretchValue.EXPANDED) {
return 2;
}
if (stretch == CSS20Attribute.CSSStretchValue.EXTRACONDENSED || stretch == CSS20Attribute.CSSStretchValue.EXTRAEXPANDED) {
return 3;
}
if (stretch == CSS20Attribute.CSSStretchValue.ULTRACONDENSED || stretch == CSS20Attribute.CSSStretchValue.ULTRAEXPANDED) {
return 4;
}
return 0;
}
}