FontWidthStore.java
2.1 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.fontengine.font.Font
* com.adobe.fontengine.font.FontLoadingException
* com.adobe.fontengine.font.InvalidFontException
* com.adobe.fontengine.font.PDFFontDescription
* com.adobe.fontengine.font.UnsupportedFontException
*/
package com.adobe.internal.pdftoolkit.pdf.content.processor;
import com.adobe.fontengine.font.Font;
import com.adobe.fontengine.font.FontLoadingException;
import com.adobe.fontengine.font.InvalidFontException;
import com.adobe.fontengine.font.PDFFontDescription;
import com.adobe.fontengine.font.UnsupportedFontException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Set;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
class FontWidthStore
implements Serializable {
private static final long serialVersionUID = 3376437248636466239L;
private transient Font font;
private HashMap<Integer, Double> widthMap;
public FontWidthStore(Font font) throws InvalidFontException, UnsupportedFontException, FontLoadingException {
this.font = font;
this.widthMap = new HashMap();
this.calculateWidthData();
}
public FontWidthStore(Font font, HashMap<Integer, Double> widthMap) {
this.font = font;
this.widthMap = widthMap;
}
private void calculateWidthData() throws InvalidFontException, UnsupportedFontException, FontLoadingException {
for (int charCode = 32; charCode <= 127; ++charCode) {
PDFFontDescription desc = this.font.getPDFFontDescription();
double width = desc.getAdvance(charCode);
double unitesPerEmX = this.font.getUnitsPerEmX();
if (unitesPerEmX != 0.0) {
width = width * 1000.0 / unitesPerEmX;
}
this.widthMap.put(charCode, width);
}
}
public Set<Integer> getUnicodes() {
return this.widthMap.keySet();
}
double getWidth(int unicode) {
Double width = this.widthMap.get(unicode);
return width == null ? -1.0 : width;
}
}