PDFSimpleFont.java
16.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.agl.util.ULocale
*/
package com.adobe.fontengine.font.pdffont;
import com.adobe.agl.util.ULocale;
import com.adobe.fontengine.font.CatalogDescription;
import com.adobe.fontengine.font.CodePage;
import com.adobe.fontengine.font.CoolTypeScript;
import com.adobe.fontengine.font.Font;
import com.adobe.fontengine.font.FontData;
import com.adobe.fontengine.font.InvalidFontException;
import com.adobe.fontengine.font.InvalidGlyphException;
import com.adobe.fontengine.font.LineMetrics;
import com.adobe.fontengine.font.OutlineConsumer;
import com.adobe.fontengine.font.PDFFontDescription;
import com.adobe.fontengine.font.Permission;
import com.adobe.fontengine.font.ROS;
import com.adobe.fontengine.font.Rect;
import com.adobe.fontengine.font.SWFFont4Description;
import com.adobe.fontengine.font.SWFFontDescription;
import com.adobe.fontengine.font.Scaler;
import com.adobe.fontengine.font.ScanConverter;
import com.adobe.fontengine.font.Subset;
import com.adobe.fontengine.font.SubsetSimpleTrueType;
import com.adobe.fontengine.font.SubsetSimpleType1;
import com.adobe.fontengine.font.UnderlineMetrics;
import com.adobe.fontengine.font.UnsupportedFontException;
import com.adobe.fontengine.font.XDCFontDescription;
import com.adobe.fontengine.font.postscript.GlyphNamesAccessor;
import com.adobe.fontengine.font.postscript.ScriptHeuristics;
import com.adobe.fontengine.font.postscript.UnicodeCmap;
import com.adobe.fontengine.fontmanagement.CacheSupportInfo;
import com.adobe.fontengine.fontmanagement.PDFSimpleFontValuesAccessor;
import com.adobe.fontengine.fontmanagement.Platform;
import com.adobe.fontengine.fontmanagement.fxg.FXGFontDescription;
import com.adobe.fontengine.fontmanagement.platform.PlatformFontDescription;
import com.adobe.fontengine.fontmanagement.postscript.PostscriptFontDescription;
import com.adobe.fontengine.inlineformatting.css20.CSS20Attribute;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
public final class PDFSimpleFont
extends FontData {
private final String fontFamily;
private final String postscriptName;
private final Rect fontBBox;
private final double capHeight;
private final double xHeight;
private final double ascent;
private final double descent;
private final double leading;
private final double stemV;
private final double italicAngle;
private final int flags;
private final int weight;
private final CSS20Attribute.CSSStretchValue stretch;
private final int numGlyphs;
private final UnicodeCmap cmap;
private final double[] gid2width;
private final String[] gid2name;
public PDFSimpleFont(PDFSimpleFontValuesAccessor dataAccessor) throws InvalidFontException, UnsupportedFontException {
super(null);
this.fontFamily = dataAccessor.getFontFamily();
this.postscriptName = dataAccessor.getPostscriptName();
this.fontBBox = dataAccessor.getFontBBox();
this.capHeight = dataAccessor.getCapHeight();
this.ascent = dataAccessor.getAscent();
this.descent = dataAccessor.getDescent();
this.leading = dataAccessor.getLeading();
this.stemV = dataAccessor.getStemV();
this.italicAngle = dataAccessor.getItalicAngle();
this.flags = dataAccessor.getFlags();
this.weight = dataAccessor.getFontWeight();
this.stretch = dataAccessor.getFontStretch();
this.xHeight = dataAccessor.getXHeight();
int[] gid2characterCode = new int[257];
this.gid2name = new String[257];
int lastGid = 0;
gid2characterCode[0] = 0;
this.gid2name[0] = ".notdef";
for (int characterCode = 0; characterCode < 256; ++characterCode) {
String name = dataAccessor.getGlyphName(characterCode);
if (name == null) continue;
gid2characterCode[++lastGid] = characterCode;
this.gid2name[lastGid] = name;
}
this.numGlyphs = lastGid + 1;
this.cmap = UnicodeCmap.computeCmapFromGlyphNames(this.numGlyphs, false, new GlyphNamesAccessor(){
public String getAGlyphName(int gid) throws InvalidFontException, UnsupportedFontException {
return PDFSimpleFont.this.gid2name[gid];
}
});
this.gid2width = new double[this.numGlyphs];
for (int gid = 0; gid < this.numGlyphs; ++gid) {
this.gid2width[gid] = dataAccessor.getGlyphWidth(gid2characterCode[gid]);
}
}
public boolean getCoolTypeProportionalRomanFromFontProperties() {
return (this.flags & 1) != 0;
}
public boolean isSymbolic() throws UnsupportedFontException, InvalidFontException {
return (this.flags & 4) != 0;
}
public int getNumGlyphs() throws InvalidFontException, UnsupportedFontException {
return this.numGlyphs;
}
public double getUnitsPerEmX() throws UnsupportedFontException, InvalidFontException {
return 1000.0;
}
public double getUnitsPerEmY() throws UnsupportedFontException, InvalidFontException {
return 1000.0;
}
protected Rect getCoolTypeRawFontBBox() throws InvalidFontException, UnsupportedFontException {
return this.fontBBox;
}
public Rect getFontBBox() throws InvalidFontException, UnsupportedFontException {
return this.fontBBox;
}
public CoolTypeScript getCoolTypeScript() throws UnsupportedFontException, InvalidFontException {
return ScriptHeuristics.getCoolTypeScript(this.postscriptName, this.getNumGlyphs(), new GlyphNamesAccessor(){
public String getAGlyphName(int gid) throws InvalidFontException, UnsupportedFontException {
return PDFSimpleFont.this.gid2name[gid];
}
});
}
private Rect getCoolTypeIdeoEmBoxFromCapHeight() throws InvalidFontException, UnsupportedFontException {
if (Double.isNaN(this.capHeight)) {
return null;
}
double unitsPerEmX = this.getUnitsPerEmX();
double unitsPerEmY = this.getUnitsPerEmY();
double ymin = (- unitsPerEmY - this.capHeight) / 2.0;
return new Rect(0.0, ymin, unitsPerEmX, ymin + unitsPerEmY);
}
public Rect getCoolTypeIdeoEmBox() throws UnsupportedFontException, InvalidFontException {
Rect r = this.getCoolTypeIdeoEmBoxFromCapHeight();
if (r != null) {
return r;
}
double unitsPerEmX = this.getUnitsPerEmX();
double unitsPerEmY = this.getUnitsPerEmY();
return new Rect(0.0, -0.12 * unitsPerEmY, unitsPerEmX, 0.88 * unitsPerEmY);
}
public Rect getCoolTypeIcfBox() throws InvalidFontException, UnsupportedFontException {
return this.getCoolTypeIcfBoxFromIdeoEmBox(this.getCoolTypeIdeoEmBox());
}
public LineMetrics getCoolTypeLineMetrics() throws UnsupportedFontException, InvalidFontException {
return new LineMetrics(this.ascent, this.descent, this.leading);
}
public UnderlineMetrics getCoolTypeUnderlineMetrics() throws UnsupportedFontException, InvalidFontException {
return new UnderlineMetrics(-150.0, 50.0);
}
public int getGlyphForChar(int unicodeScalarValue) throws InvalidFontException, UnsupportedFontException {
return this.cmap.getGlyphForChar(unicodeScalarValue);
}
public Rect getGlyphBBox(int gid) throws UnsupportedFontException, InvalidFontException {
return this.fontBBox;
}
public void getGlyphOutline(int gid, OutlineConsumer consumer) throws InvalidFontException, UnsupportedFontException {
throw new UnsupportedFontException("cannot get outline for PDFSimpleFont");
}
public double getHorizontalAdvance(int gid) throws InvalidGlyphException, UnsupportedFontException, InvalidFontException {
return this.gid2width[gid];
}
public Scaler getScaler(ScanConverter c) throws InvalidFontException, UnsupportedFontException {
throw new UnsupportedFontException("getOutlineAccessor not supported for PDFSimpleFont");
}
public Permission getEmbeddingPermission(boolean wasEmbedded) throws InvalidFontException, UnsupportedFontException {
return Permission.RESTRICTED;
}
public PDFFontDescription getPDFFontDescription(Font font) {
return new PDFSimpleFontXDCFontDescription();
}
public XDCFontDescription getXDCFontDescription(Font font) {
return new PDFSimpleFontXDCFontDescription();
}
public Subset createSubset() throws InvalidFontException, UnsupportedFontException {
throw new UnsupportedFontException("createSubset not meaningful for PDFSimpleFont");
}
public void subsetAndStream(Subset subset, OutputStream out, boolean preserveROS) throws InvalidFontException, UnsupportedFontException, IOException {
throw new UnsupportedFontException("subsetAndStream not meaningful for PDFSimpleFont");
}
public CacheSupportInfo getCacheSupportInfo() throws InvalidFontException, UnsupportedFontException {
return new CacheSupportInfo(this.getClass().getSimpleName(), this.getNumGlyphs(), false);
}
public PostscriptFontDescription[] getPostscriptFontDescription() throws InvalidFontException, UnsupportedFontException {
return new PostscriptFontDescription[]{new PostscriptFontDescription(this.postscriptName)};
}
protected Set getCSSFamilyNames() throws InvalidFontException, UnsupportedFontException {
HashSet<String> s = new HashSet<String>();
if (this.fontFamily != null) {
s.add(this.fontFamily);
}
return s;
}
protected String getPreferredCSSFamilyName() throws InvalidFontException, UnsupportedFontException {
return this.fontFamily;
}
protected CSS20Attribute.CSSStretchValue getCSSStretchValue() throws InvalidFontException, UnsupportedFontException {
return this.stretch;
}
protected int getCSSWeight() throws InvalidFontException, UnsupportedFontException {
return this.weight;
}
protected boolean isCSSStyleItalic() throws InvalidFontException, UnsupportedFontException {
return this.italicAngle != 0.0 || (this.flags & 64) != 0;
}
protected boolean isCSSStyleNormal() throws InvalidFontException, UnsupportedFontException {
return !this.isCSSStyleItalic();
}
protected boolean isCSSStyleOblique() throws InvalidFontException, UnsupportedFontException {
return false;
}
protected boolean isCSSVariantNormal() throws InvalidFontException, UnsupportedFontException {
return !this.isCSSVariantSmallCaps();
}
protected boolean isCSSVariantSmallCaps() throws InvalidFontException, UnsupportedFontException {
return (this.flags & 131072) != 0;
}
public FXGFontDescription[] getFXGFontDescription(Platform platform, ULocale locale) throws InvalidFontException, UnsupportedFontException {
return new FXGFontDescription[0];
}
public PlatformFontDescription[] getPlatformFontDescription(Platform platform, ULocale locale) throws InvalidFontException, UnsupportedFontException {
return new PlatformFontDescription[0];
}
public CatalogDescription getSelectionDescription() throws InvalidFontException, UnsupportedFontException {
throw new UnsupportedFontException("getSelectionDescription not supported for PDFSimpleFont");
}
public SWFFontDescription getSWFFontDescription(boolean wasEmbedded) throws UnsupportedFontException, InvalidFontException {
return null;
}
public SWFFont4Description getSWFFont4Description(boolean wasEmbedded) throws UnsupportedFontException, InvalidFontException {
return null;
}
class PDFSimpleFontXDCFontDescription
extends XDCFontDescription {
PDFSimpleFontXDCFontDescription() {
}
public double getAdvance(int gid) throws InvalidFontException, UnsupportedFontException {
return PDFSimpleFont.this.gid2width[gid];
}
public String getBase14Name() {
return null;
}
public double getCapHeight() throws UnsupportedFontException, InvalidFontException {
return PDFSimpleFont.this.capHeight;
}
public double getXHeight() throws UnsupportedFontException, InvalidFontException {
return PDFSimpleFont.this.xHeight;
}
public Rect getFontBBox() throws InvalidFontException, UnsupportedFontException {
return PDFSimpleFont.this.fontBBox;
}
public String getFontFamily() throws InvalidFontException, UnsupportedFontException {
return PDFSimpleFont.this.fontFamily;
}
public int getGlyphCid(int gid) throws UnsupportedFontException, InvalidFontException {
return -1;
}
public String getGlyphName(int gid) throws InvalidFontException, UnsupportedFontException {
return PDFSimpleFont.this.gid2name[gid];
}
public double getItalicAngle() throws InvalidFontException, UnsupportedFontException {
return PDFSimpleFont.this.italicAngle;
}
public int getNumGlyphs() throws InvalidFontException, UnsupportedFontException {
return PDFSimpleFont.this.numGlyphs;
}
public String getPostscriptName() throws InvalidFontException, UnsupportedFontException {
return PDFSimpleFont.this.postscriptName;
}
public ROS getROS() throws UnsupportedFontException, InvalidFontException {
return null;
}
public double getStemV() throws UnsupportedFontException, InvalidFontException {
return PDFSimpleFont.this.stemV;
}
public boolean pdfFontIsTrueType() throws InvalidFontException, UnsupportedFontException {
return false;
}
public boolean isSerifFont() {
return (PDFSimpleFont.this.flags & 2) != 0;
}
public boolean isSmallCapFont() {
return (PDFSimpleFont.this.flags & 131072) != 0;
}
public boolean isAllCapFont() throws InvalidFontException, UnsupportedFontException {
return (PDFSimpleFont.this.flags & 65536) != 0;
}
public int getCIDCount() {
return -1;
}
public void subsetAndStream(Subset subset, OutputStream out, boolean preserveROS) throws UnsupportedFontException {
throw new UnsupportedFontException("subsetAndStream not meaningful for PDFSimpleFont");
}
public void subsetAndStream(SubsetSimpleType1 t1Subset, OutputStream out) throws UnsupportedFontException {
throw new UnsupportedFontException("subsetAndStream not meaningful for PDFSimpleFont");
}
public void subsetAndStream(SubsetSimpleTrueType ttSubset, OutputStream out) throws UnsupportedFontException {
throw new UnsupportedFontException("subsetAndStream not meaningful for PDFSimpleFont");
}
public CodePage[] getXDCCodePages() throws InvalidFontException, UnsupportedFontException {
if (PDFSimpleFont.this.isSymbolic()) {
return new CodePage[0];
}
CodePage theCodePage = null;
for (int i = 0; i < PDFSimpleFont.this.numGlyphs; ++i) {
if (PDFSimpleFont.this.gid2name[i].equals("ecircumflex")) {
if (theCodePage == CodePage.ROMAN2) {
return new CodePage[0];
}
theCodePage = CodePage.ROMAN1;
continue;
}
if (!PDFSimpleFont.this.gid2name[i].equals("Ccaron") && !PDFSimpleFont.this.gid2name[i].equals("ncaron")) continue;
if (theCodePage == CodePage.ROMAN1) {
return new CodePage[0];
}
theCodePage = CodePage.ROMAN2;
}
if (theCodePage == null) {
return new CodePage[0];
}
CodePage[] retVal = new CodePage[]{theCodePage};
return retVal;
}
public void stream(OutputStream out, boolean openTypeFontsAllowed) throws UnsupportedFontException {
throw new UnsupportedFontException("stream not meaningful for PDFSimpleFont");
}
}
}