FontInstance.java
4.76 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.fontengine.font.Font
*/
package com.adobe.xfa.font;
import com.adobe.fontengine.font.Font;
import com.adobe.xfa.font.FontInfo;
import com.adobe.xfa.font.FontItem;
import com.adobe.xfa.ut.UnitSpan;
public class FontInstance
implements Comparable<FontInstance> {
private final FontItem mFontItem;
private final double mXScale;
private final double mYScale;
private final UnitSpan mUnitSize;
private final double mHorizontalScale;
private final double mVerticalScale;
FontInstance(FontItem item, UnitSpan unitSize) {
this(item, unitSize, 1.0, 1.0);
}
FontInstance(FontItem item, UnitSpan unitSize, double horizontalScale, double verticalScale) {
this.mFontItem = item;
this.mUnitSize = unitSize;
this.mHorizontalScale = horizontalScale;
this.mVerticalScale = verticalScale;
double scale = (double)unitSize.valueAsUnit(19) / 1000.0;
this.mXScale = scale * this.mHorizontalScale;
this.mYScale = scale * this.mVerticalScale;
}
public FontItem getFontItem() {
return this.mFontItem;
}
public Font getAFEFont() {
return this.mFontItem.getAFEFont();
}
public String getTypeface() {
return this.mFontItem == null ? null : this.mFontItem.getTypeface();
}
public int getWeight() {
return this.mFontItem == null ? 400 : this.mFontItem.getWeight();
}
public boolean getItalic() {
return this.mFontItem == null ? false : this.mFontItem.getItalic();
}
public UnitSpan getSize() {
return this.mUnitSize;
}
public double getHorizontalScale() {
return this.mHorizontalScale;
}
public double getVerticalScale() {
return this.mVerticalScale;
}
public UnitSpan getAscent() {
return this.toUnitSpanVertical(this.mFontItem.getAscent());
}
public UnitSpan getLegacyAscent() {
return this.toUnitSpanVertical(this.mFontItem.getLegacyAscent());
}
public UnitSpan getDescent() {
return this.toUnitSpanVertical(this.mFontItem.getDescent());
}
public UnitSpan getLineGap() {
return this.toUnitSpanVertical(this.mFontItem.getLineGap());
}
public UnitSpan getLegacyLineGap() {
return this.toUnitSpanVertical(this.mFontItem.getLegacyLineGap());
}
public UnitSpan getspacing() {
return this.toUnitSpanVertical(this.mFontItem.getSpacing());
}
public float getCharWidth(int c, boolean useHorizontalGlyphs) {
return (float)this.toDoubleHorizontal(this.mFontItem.getCharWidth(c, useHorizontalGlyphs));
}
public double getDoubleCharWidth(int c, boolean useHorizontalGlyphs) {
assert (false);
return 0.0;
}
public float getGlyphWidth(int glyphID, boolean useHorizontalGlyphs) {
return (float)this.toDoubleHorizontal(this.mFontItem.getGlyphWidth(glyphID, useHorizontalGlyphs));
}
public int getGlyphID(int c) {
return this.mFontItem.getGlyphID(c);
}
public boolean getGlyphID(int c, int g, boolean h) {
assert (false);
return false;
}
public void mapGlyph(int c, int glyphID) {
this.mFontItem.mapGlyph(c, glyphID);
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null) {
return false;
}
if (object.getClass() != this.getClass()) {
return false;
}
FontInstance other = (FontInstance)object;
return UnitSpan.match(this.mUnitSize, other.mUnitSize) && FontItem.match(this.mFontItem, other.mFontItem);
}
public int hashCode() {
int result = this.mUnitSize == null ? 0 : this.mUnitSize.hashCode();
result = result * 31 ^ (this.mFontItem == null ? 0 : this.mFontItem.hashCode());
return result;
}
public static boolean match(FontInstance o1, FontInstance o2) {
if (o1 == o2) {
return true;
}
if (o1 == null || o2 == null) {
return false;
}
return o1.equals(o2);
}
private final double toDoubleHorizontal(double value) {
return value * this.mXScale;
}
private final double toDoubleVertical(double value) {
return value * this.mYScale;
}
private final UnitSpan toUnitSpanVertical(double value) {
return new UnitSpan(this.toDoubleVertical(value), 19);
}
@Override
public int compareTo(FontInstance other) {
if (other == null) {
throw new NullPointerException();
}
int result = this.mFontItem.compareTo(other.mFontItem);
return result != 0 ? result : this.mUnitSize.compareTo(other.getSize());
}
}