CFFFont.java
21.9 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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.agl.util.ULocale
*/
package com.adobe.fontengine.font.cff;
import com.adobe.agl.util.ULocale;
import com.adobe.fontengine.font.CScan;
import com.adobe.fontengine.font.CatalogDescription;
import com.adobe.fontengine.font.CodePage;
import com.adobe.fontengine.font.CoolTypeScript;
import com.adobe.fontengine.font.EmbeddingPermission;
import com.adobe.fontengine.font.FontData;
import com.adobe.fontengine.font.InvalidFontException;
import com.adobe.fontengine.font.LineMetrics;
import com.adobe.fontengine.font.Matrix;
import com.adobe.fontengine.font.OrigFontType;
import com.adobe.fontengine.font.OutlineConsumer;
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.UnderlineMetrics;
import com.adobe.fontengine.font.UnsupportedFontException;
import com.adobe.fontengine.font.XDCFontDescription;
import com.adobe.fontengine.font.cff.CFFScaler;
import com.adobe.fontengine.font.cff.CharStrings;
import com.adobe.fontengine.font.cff.Dict;
import com.adobe.fontengine.font.cff.NameKeyedFont;
import com.adobe.fontengine.font.cff.StringIndex;
import com.adobe.fontengine.font.cff.Type2CStringGenerator;
import com.adobe.fontengine.font.cff.Type2GlyphBBoxCalculator;
import com.adobe.fontengine.font.cff.Type2OutlineParser;
import com.adobe.fontengine.font.postscript.NameHeuristics;
import com.adobe.fontengine.fontmanagement.CacheSupportInfo;
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.Iterator;
import java.util.Set;
public abstract class CFFFont
extends FontData {
protected final StringIndex stringIndex;
protected final CharStrings globalSubrs;
protected final String name;
protected final Dict topDict;
CFFFont(StringIndex stringIndex, CharStrings globalSubrs, Dict topDict, String name, byte[] digest) throws UnsupportedFontException, InvalidFontException {
super(digest);
this.stringIndex = stringIndex;
this.globalSubrs = globalSubrs;
this.topDict = topDict;
this.name = name;
}
public String getName() {
return this.name;
}
public abstract Matrix getFontMatrix();
public double getUnitsPerEmX() throws UnsupportedFontException, InvalidFontException {
return 1.0 / this.getFontMatrix().a;
}
public double getUnitsPerEmY() throws UnsupportedFontException, InvalidFontException {
return 1.0 / this.getFontMatrix().d;
}
public boolean getCoolTypeProportionalRomanFromFontProperties() throws InvalidFontException {
return !this.isFixedPitch();
}
public CoolTypeScript getCoolTypeScript() throws UnsupportedFontException {
ROS ros = this.getROS();
CoolTypeScript ctScript = CoolTypeScript.fromWellKnownROS(ros);
if (ctScript != null) {
return ctScript;
}
ctScript = CoolTypeScript.fromAnyROS(ros);
if (ctScript != null) {
return ctScript;
}
return CoolTypeScript.ROMAN;
}
private Rect getCoolTypeIdeoEmBoxFromCapHeight() throws InvalidFontException, UnsupportedFontException {
double capHeight = this.getCoolTypeCapHeight();
if (Double.isNaN(capHeight)) {
return null;
}
double unitsPerEmX = this.getUnitsPerEmX();
double unitsPerEmY = this.getUnitsPerEmY();
double ymin = (- unitsPerEmY - capHeight) / 2.0;
return new Rect(0.0, ymin, unitsPerEmX, ymin + unitsPerEmY);
}
public Rect getCoolTypeIdeoEmBox() throws InvalidFontException, UnsupportedFontException {
if (this.useCoolTypeCJKHeuristics()) {
Rect r = this.getCoolTypeIdeoEmBoxFromFullBoxCharacter();
if (r != null) {
return r;
}
r = this.getCoolTypeIdeoEmBoxFromTypicalCharacter();
if (r != null) {
return r;
}
} else {
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 {
Rect ideoEmBox = this.getCoolTypeIdeoEmBox();
Rect r = this.getCoolTypeIcfBoxFromTypicalCharacter(ideoEmBox);
if (r != null) {
return r;
}
return this.getCoolTypeIcfBoxFromIdeoEmBox(ideoEmBox);
}
public UnderlineMetrics getCoolTypeUnderlineMetrics() throws UnsupportedFontException, InvalidFontException {
return this.getCoolTypeUnderlineMetrics(this.getCoolTypeUnitsPerEm(), this.getUnitsPerEmY());
}
public UnderlineMetrics getCoolTypeUnderlineMetrics(double coolTypeUnitsPerEm, double unitsPerEmY) throws UnsupportedFontException, InvalidFontException {
double position = this.topDict.get(Dict.NumbersKey.UnderlinePosition, true).getFirstValueAsDouble();
double thickness = this.topDict.get(Dict.NumbersKey.UnderlineThickness, true).getFirstValueAsDouble();
return new UnderlineMetrics(position * unitsPerEmY / coolTypeUnitsPerEm, thickness * unitsPerEmY / coolTypeUnitsPerEm);
}
public abstract int getGlyphForChar(int var1) throws InvalidFontException, UnsupportedFontException;
public abstract double getHorizontalAdvance(int var1) throws InvalidFontException, UnsupportedFontException;
public abstract String getGlyphName(int var1) throws InvalidFontException, UnsupportedFontException;
public abstract void getGlyphOutline(int var1, OutlineConsumer var2) throws InvalidFontException, UnsupportedFontException;
public abstract void getOutline(int var1, Type2OutlineParser var2, OutlineConsumer var3) throws InvalidFontException, UnsupportedFontException;
public Rect getGlyphBBox(int gid) throws UnsupportedFontException, InvalidFontException {
Matrix m = new Matrix(this.getUnitsPerEmX(), 0.0, 0.0, this.getUnitsPerEmY(), 0.0, 0.0);
return new Type2GlyphBBoxCalculator(m).calculateBBox(this, gid);
}
public abstract int getGlyphCid(int var1) throws InvalidFontException, UnsupportedFontException;
public Scaler getScaler(ScanConverter c) throws InvalidFontException, UnsupportedFontException {
if (c == null) {
c = new CScan(false, 1.0, true);
}
return new CFFScaler(this, c);
}
public abstract double getStemVForGlyph(int var1) throws InvalidFontException;
abstract double getItalicAngle();
abstract Rect getRawFontBBox();
abstract int[] getXUID();
abstract String getNotice();
abstract String getCopyright();
abstract String getFullName();
abstract Integer getFSType();
abstract int getFirstChar() throws InvalidFontException, UnsupportedFontException;
abstract int getLastChar() throws InvalidFontException, UnsupportedFontException;
abstract OrigFontType getOrigFontType();
Permission getEmbeddingPermissionGivenFT(boolean wasEmbedded, OrigFontType thisFontType) {
Integer fsType = this.getFSType();
if (fsType != null) {
return EmbeddingPermission.interpretFSType(fsType);
}
OrigFontType oft = this.getOrigFontType();
if (oft == OrigFontType.kTYPE1 || oft == null && thisFontType == OrigFontType.kTYPE1) {
return EmbeddingPermission.getType1DefaultPermission(this.getNotice(), this.getName());
}
if (wasEmbedded) {
return EmbeddingPermission.getDefaultWasEmbeddedPermission();
}
if (oft == OrigFontType.kCID || oft == null && thisFontType == OrigFontType.kCID) {
return EmbeddingPermission.getCIDDefaultPermission(this.getXUID());
}
if (oft == OrigFontType.kTRUETYPE) {
return EmbeddingPermission.getTrueTypeDefaultPermission();
}
return EmbeddingPermission.getOCFDefaultPermission();
}
public Set getCSSFamilyNames() {
HashSet<String> s = new HashSet<String>();
String n = this.getPreferredCSSFamilyName();
if (n != null) {
s.add(n);
}
return s;
}
public String getPreferredCSSFamilyName() {
Dict.StringValue v = this.topDict.get(Dict.StringKey.FamilyName, false);
return v != null ? v.value : this.name;
}
public boolean isCSSStyleNormal() {
return !this.isCSSStyleItalic();
}
public boolean isFixedPitch() {
Dict.NumbersValue v = this.topDict.get(Dict.NumbersKey.isFixedPitch, true);
return v != null && v.getFirstValueAsDouble() != 0.0;
}
public boolean isCSSStyleItalic() {
Dict.NumbersValue v = this.topDict.get(Dict.NumbersKey.ItalicAngle, true);
return v != null && v.getFirstValueAsDouble() != 0.0;
}
public boolean isCSSStyleOblique() {
return this.isCSSStyleItalic();
}
public boolean isCSSVariantNormal() {
return !this.isCSSVariantSmallCaps();
}
public boolean isCSSVariantSmallCaps() {
String n;
Dict.StringValue v = this.topDict.get(Dict.StringKey.FullName, true);
String string = n = v != null ? v.value : this.name;
if (n == null) {
return false;
}
return NameHeuristics.fullNameIndicatesSmallCaps(n);
}
public int getCSSWeight() {
String n;
Dict.StringValue v = this.topDict.get(Dict.StringKey.Weight, true);
if (v != null) {
return NameHeuristics.weightNameToWeight(v.value);
}
v = this.topDict.get(Dict.StringKey.FullName, true);
String string = n = v != null ? v.value : this.name;
if (n != null) {
return NameHeuristics.fullNameToWeight(n);
}
return 400;
}
public CSS20Attribute.CSSStretchValue getCSSStretchValue() {
Dict.StringValue fullName = this.topDict.get(Dict.StringKey.FullName, true);
String n = fullName != null ? fullName.value : this.name;
Dict.StringValue familyName = this.topDict.get(Dict.StringKey.FamilyName, true);
if (n != null) {
return NameHeuristics.fullNameToWidth(n, familyName != null ? familyName.value : null);
}
return CSS20Attribute.CSSStretchValue.NORMAL;
}
public CacheSupportInfo getCacheSupportInfo() throws InvalidFontException, UnsupportedFontException {
return new CacheSupportInfo(this.getClass().getSimpleName(), this.getNumGlyphs(), true);
}
public PostscriptFontDescription[] getPostscriptFontDescription() {
String fontName = this.getName();
if (this.name != null) {
return new PostscriptFontDescription[]{new PostscriptFontDescription(fontName)};
}
return new PostscriptFontDescription[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 abstract ROS getROS();
public SWFFontDescription getSWFFontDescription(boolean wasEmbedded) throws UnsupportedFontException, InvalidFontException {
return new CFFSWFFont3Description(wasEmbedded);
}
public void subsetAndStream(Subset subset, OutputStream os, boolean preserveROS) throws InvalidFontException, UnsupportedFontException, IOException {
this.subsetAndStream(subset, os, preserveROS, null);
}
public abstract void stream(OutputStream var1, Integer var2) throws InvalidFontException, UnsupportedFontException, IOException;
public abstract void subsetAndStream(Subset var1, OutputStream var2, boolean var3, Integer var4) throws InvalidFontException, UnsupportedFontException, IOException;
abstract CharStrings getCharStrings();
abstract CharStrings getLocalSubrsForFD(int var1);
abstract int getNumFDs();
abstract double getDefaultWidthForFD(int var1);
abstract double getNominalWidthForFD(int var1);
abstract int getFDForGlyph(int var1) throws InvalidFontException;
CharStrings createSubsetCharstringIndex(Subset subset, boolean willSubrize) throws InvalidFontException, UnsupportedFontException {
Type2CStringGenerator generator = new Type2CStringGenerator(subset.getNumGlyphs(), this.getNumFDs(), willSubrize);
Type2OutlineParser parser = new Type2OutlineParser(true);
for (int i = 0; i < subset.getNumGlyphs(); ++i) {
int fullGid = subset.getFullGid(i);
int fd = this.getFDForGlyph(fullGid);
generator.newGlyph(i, fd, this.getDefaultWidthForFD(fd), this.getNominalWidthForFD(fd));
parser.parse(this.getCharStrings(), fullGid, this.getLocalSubrsForFD(fd), this.globalSubrs, generator, Matrix.IDENTITY_MATRIX, this instanceof NameKeyedFont ? (NameKeyedFont)this : null);
}
return generator.getCharstringIndex();
}
public CatalogDescription getSelectionDescription() throws InvalidFontException, UnsupportedFontException {
return null;
}
public SWFFont4Description getSWFFont4Description(boolean wasEmbedded) throws UnsupportedFontException, InvalidFontException {
return null;
}
protected abstract class CFFFontXDCFontDescription
extends XDCFontDescription {
protected CFFFontXDCFontDescription() {
}
public ROS getROS() throws UnsupportedFontException, InvalidFontException {
return CFFFont.this.getROS();
}
public boolean pdfFontIsTrueType() {
return false;
}
public String getPostscriptName() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getName();
}
public String getFontFamily() throws InvalidFontException, UnsupportedFontException {
Set s = CFFFont.this.getCSSFamilyNames();
if (!s.isEmpty()) {
return (String)s.iterator().next();
}
return null;
}
public int getNumGlyphs() throws UnsupportedFontException, InvalidFontException {
return CFFFont.this.getNumGlyphs();
}
public int getGlyphCid(int glyphID) throws UnsupportedFontException, InvalidFontException {
return CFFFont.this.getGlyphCid(glyphID);
}
public String getGlyphName(int gid) throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getGlyphName(gid);
}
public double getStemV() throws UnsupportedFontException, InvalidFontException {
int glyphID = CFFFont.this.getGlyphForChar(108);
if (glyphID == 0) {
glyphID = CFFFont.this.getGlyphForChar(73);
}
if (glyphID == 0) {
return 0.0;
}
return CFFFont.this.getStemVForGlyph(glyphID) * 1000.0 / CFFFont.this.getUnitsPerEmX();
}
public Rect getFontBBox() throws InvalidFontException, UnsupportedFontException {
Rect bbox = CFFFont.this.getRawFontBBox();
if (bbox == null) {
return null;
}
return bbox.applyMatrix(CFFFont.this.getFontMatrix().multiply(1000.0));
}
public double getCapHeight() throws UnsupportedFontException, InvalidFontException {
double capHeight = CFFFont.this.getCoolTypeCapHeight();
if (Double.isNaN(capHeight)) {
return 0.0;
}
return capHeight * (1000.0 / CFFFont.this.getUnitsPerEmY());
}
public double getXHeight() throws UnsupportedFontException, InvalidFontException {
double xHeight = CFFFont.this.getCoolTypeXHeight();
if (Double.isNaN(xHeight)) {
return 0.0;
}
return xHeight * (1000.0 / CFFFont.this.getUnitsPerEmY());
}
public double getItalicAngle() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getItalicAngle();
}
public double getAdvance(int glyphID) throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getHorizontalAdvance(glyphID) * 1000.0 / CFFFont.this.getUnitsPerEmX();
}
public String getBase14Name() {
return null;
}
public boolean isSerifFont() throws InvalidFontException, UnsupportedFontException {
int gid1 = CFFFont.this.getGlyphForChar(108);
int gid2 = CFFFont.this.getGlyphForChar(73);
return CFFFont.this.isSerifFont(gid1, gid2, this.getItalicAngle());
}
public boolean isSmallCapFont() throws InvalidFontException, UnsupportedFontException {
if (!this.isAllCapFont()) {
int gid1 = CFFFont.this.getGlyphForChar(104);
int gid2 = CFFFont.this.getGlyphForChar(120);
if (gid2 != 0) {
Rect bbox = CFFFont.this.getGlyphBBox(gid2);
return CFFFont.this.isSmallCapFont(gid1, bbox.ymax);
}
}
return false;
}
public boolean isAllCapFont() throws InvalidFontException, UnsupportedFontException {
int gid1 = CFFFont.this.getGlyphForChar(75);
int gid2 = CFFFont.this.getGlyphForChar(107);
return CFFFont.this.isAllCapFont(gid1, gid2);
}
public abstract CodePage[] getXDCCodePages() throws InvalidFontException, UnsupportedFontException;
}
private class CFFSWFFont3Description
implements SWFFontDescription {
private final boolean wasEmbedded;
private final LineMetrics metrics;
CFFSWFFont3Description(boolean wasEmbedded) throws UnsupportedFontException, InvalidFontException {
this.wasEmbedded = wasEmbedded;
this.metrics = CFFFont.this.getCoolTypeLineMetrics();
}
public boolean canDisplay(char c) throws UnsupportedFontException, InvalidFontException {
return CFFFont.this.getGlyphForChar(c) != 0;
}
public double getHorizontalAdvance(char ccode) throws UnsupportedFontException, InvalidFontException {
int gid = CFFFont.this.getGlyphForChar(ccode);
return CFFFont.this.getHorizontalAdvance(gid);
}
public void getOutline(char ccode, OutlineConsumer consumer) throws UnsupportedFontException, InvalidFontException {
int gid = CFFFont.this.getGlyphForChar(ccode);
CFFFont.this.getGlyphOutline(gid, consumer);
}
public double getEmScale() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getUnitsPerEmX();
}
public double getAscent() throws InvalidFontException, UnsupportedFontException {
return this.metrics.ascender * CFFFont.this.getUnitsPerEmX() / CFFFont.this.getUnitsPerEmY();
}
public double getDescent() throws InvalidFontException, UnsupportedFontException {
return (- this.metrics.descender) * CFFFont.this.getUnitsPerEmX() / CFFFont.this.getUnitsPerEmY();
}
public double getLineGap() throws InvalidFontException, UnsupportedFontException {
return this.metrics.linegap * CFFFont.this.getUnitsPerEmX() / CFFFont.this.getUnitsPerEmY();
}
public String getCopyright() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getCopyright();
}
public String getPostscriptName() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getName();
}
public String getTrademark() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getNotice();
}
public String getFamily() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getPreferredCSSFamilyName();
}
public String getFullName() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getFullName();
}
public int getNumGlyphs() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getNumGlyphs();
}
public Permission getPermissions() throws InvalidFontException, UnsupportedFontException {
Permission perm = CFFFont.this.getEmbeddingPermission(this.wasEmbedded);
if (perm.equals(Permission.ILLEGAL_VALUE)) {
return Permission.EDITABLE;
}
return perm;
}
public boolean isBold() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getCSSWeight() >= 700;
}
public boolean isItalic() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.isCSSStyleItalic();
}
public int getFirstChar() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getFirstChar();
}
public int getLastChar() throws InvalidFontException, UnsupportedFontException {
return CFFFont.this.getLastChar();
}
public String getSubFamily() throws InvalidFontException, UnsupportedFontException {
return null;
}
}
}