NameKeyedFont.java
26.3 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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.fontengine.font.cff;
import com.adobe.fontengine.font.CodePage;
import com.adobe.fontengine.font.Font;
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.PDFFontDescription;
import com.adobe.fontengine.font.Permission;
import com.adobe.fontengine.font.ROS;
import com.adobe.fontengine.font.Rect;
import com.adobe.fontengine.font.Subset;
import com.adobe.fontengine.font.SubsetDefaultImpl;
import com.adobe.fontengine.font.SubsetSimpleTrueType;
import com.adobe.fontengine.font.SubsetSimpleType1;
import com.adobe.fontengine.font.UnsupportedFontException;
import com.adobe.fontengine.font.XDCFontDescription;
import com.adobe.fontengine.font.cff.CFFByteArray;
import com.adobe.fontengine.font.cff.CFFFont;
import com.adobe.fontengine.font.cff.CFFSubrize;
import com.adobe.fontengine.font.cff.CIDComponentFont;
import com.adobe.fontengine.font.cff.CIDKeyedFont;
import com.adobe.fontengine.font.cff.CharStrings;
import com.adobe.fontengine.font.cff.Charset;
import com.adobe.fontengine.font.cff.Dict;
import com.adobe.fontengine.font.cff.Encoding;
import com.adobe.fontengine.font.cff.FdSelect;
import com.adobe.fontengine.font.cff.Header;
import com.adobe.fontengine.font.cff.Index;
import com.adobe.fontengine.font.cff.NameIndex;
import com.adobe.fontengine.font.cff.NameKeyedSubset;
import com.adobe.fontengine.font.cff.StringIndex;
import com.adobe.fontengine.font.cff.Type2Consumer;
import com.adobe.fontengine.font.cff.Type2ConsumerDefaultImpl;
import com.adobe.fontengine.font.cff.Type2OutlineParser;
import com.adobe.fontengine.font.cff.Type2Parser;
import com.adobe.fontengine.font.postscript.GlyphNamesAccessor;
import com.adobe.fontengine.font.postscript.NameHeuristics;
import com.adobe.fontengine.font.postscript.PostscriptTokenParser;
import com.adobe.fontengine.font.postscript.UnicodeCmap;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public final class NameKeyedFont
extends CFFFont {
protected final Dict privateDict;
protected final Charset charset;
protected final Encoding encoding;
protected final CharStrings charStrings;
protected final CharStrings localSubrs;
private final XDCFontDescription xdcDescription;
UnicodeCmap cmap = null;
Object cmapMutex = new Object();
static final Dict.Key[] topDictKeysForSubset = new Dict.Key[]{Dict.Key.Notice, Dict.Key.FullName, Dict.Key.FamilyName, Dict.Key.FontName, Dict.Key.BaseFontName, Dict.Key.BaseFontBlend, Dict.Key.Weight, Dict.Key.FontBBox, Dict.Key.Copyright, Dict.Key.isFixedPitch, Dict.Key.ItalicAngle, Dict.Key.UnderlinePosition, Dict.Key.UnderlineThickness, Dict.Key.PaintType, Dict.Key.CharstringType, Dict.Key.StrokeWidth, Dict.Key.UniqueID, Dict.Key.XUID, Dict.Key.UIDBase, Dict.Key.FontMatrix};
static final Dict.Key[] privateDictKeysForSubset = new Dict.Key[]{Dict.Key.BlueValues, Dict.Key.OtherBlues, Dict.Key.FamilyBlues, Dict.Key.FamilyOtherBlues, Dict.Key.StdHW, Dict.Key.StdVW, Dict.Key.defaultWidthX, Dict.Key.nominalWidthX, Dict.Key.BlueScale, Dict.Key.BlueShift, Dict.Key.BlueFuzz, Dict.Key.StemSnapH, Dict.Key.StemSnapV, Dict.Key.ForceBold, Dict.Key.ForceBoldThreshold, Dict.Key.LanguageGroup, Dict.Key.ExpansionFactor, Dict.Key.initialRandomSeed};
private static final int MAX_CFF_SIZE_FOR_SUBRIZE = 614400;
public NameKeyedFont(StringIndex stringIndex, CharStrings globalSubrs, String name, Dict topDict, CFFByteArray data, byte[] digest) throws IOException, InvalidFontException, UnsupportedFontException {
Dict.OffsetValue o2;
super(stringIndex, globalSubrs, topDict, name, digest);
this.xdcDescription = new NameKeyedFontXDCFontDescription();
Dict.OffsetValue o = topDict.get(Dict.Key.CharStrings, false);
if (o == null) {
throw new InvalidFontException("missing TopDICT/CharStrings");
}
this.charStrings = new CharStrings(data, o.offset);
int numGlyphs = this.charStrings.getCount();
Dict.OffsetValue o3 = topDict.get(Dict.Key.charset, true);
this.charset = new Charset(data, o3.offset, numGlyphs);
Dict.OffsetValue o4 = topDict.get(Dict.Key.Encoding, true);
this.encoding = new Encoding(data, o4.offset);
Dict privateDict = null;
CharStrings localSubrs = null;
Dict.OffsetSizeValue o5 = topDict.get(Dict.Key.Private, false);
if (o5 != null && (o2 = (privateDict = new Dict(data, o5.offset, o5.size, stringIndex)).get(Dict.Key.Subrs, false)) != null) {
localSubrs = new CharStrings(data, o5.offset + o2.offset);
}
this.privateDict = privateDict;
this.localSubrs = localSubrs;
}
public NameKeyedFont(String fontName, Dict topDict, CharStrings charStrings, Dict privateDict) throws InvalidFontException, UnsupportedFontException {
super(null, CharStrings.createEmptyCharstrings(), topDict, fontName, null);
this.xdcDescription = new NameKeyedFontXDCFontDescription();
this.charStrings = charStrings;
this.privateDict = privateDict;
this.localSubrs = null;
this.encoding = null;
this.charset = null;
}
public NameKeyedFont(String fontName, Dict topDict, CharStrings charStrings, Dict privateDict, CharStrings lSubrs, CharStrings gSubrs) throws InvalidFontException, UnsupportedFontException {
super(null, gSubrs != null ? gSubrs : CharStrings.createEmptyCharstrings(), topDict, fontName, null);
this.xdcDescription = new NameKeyedFontXDCFontDescription();
this.charStrings = charStrings;
this.privateDict = privateDict;
this.localSubrs = lSubrs;
this.encoding = null;
this.charset = null;
}
public int getNumGlyphs() {
return this.charStrings.getCount();
}
public int glyphName2gid(String glyphName) throws InvalidFontException, UnsupportedFontException {
for (int i = 0; i < this.getNumGlyphs(); ++i) {
if (!glyphName.equals(this.stringIndex.getString(this.charset.gid2sid(i)))) continue;
return i;
}
return 0;
}
public int charCode2gid(int charCode) throws InvalidFontException, UnsupportedFontException {
return this.encoding.charCode2gid(charCode, this.charset);
}
public String getGlyphName(int gid) throws InvalidFontException, UnsupportedFontException {
return this.stringIndex.getString(this.charset.gid2sid(gid));
}
public ROS getROS() {
return null;
}
public int getGlyphCid(int glyphID) {
return -1;
}
public void getGlyphOutline(int gid, OutlineConsumer consumer) throws InvalidFontException, UnsupportedFontException {
this.getOutline(gid, new Type2OutlineParser(false), consumer);
}
public void getOutline(int gid, Type2OutlineParser parser, OutlineConsumer consumer) throws InvalidFontException, UnsupportedFontException {
parser.parse(this.charStrings, gid, this.localSubrs, this.globalSubrs, consumer, this.getFontMatrix(), this);
}
public double getStemVForGlyph(int gid) {
Dict.NumbersValue value = this.privateDict.get(Dict.NumbersKey.StdVW, false);
if (value != null) {
return value.getFirstValueAsDouble();
}
value = this.privateDict.get(Dict.NumbersKey.StemSnapV, false);
if (value != null) {
return value.getFirstValueAsDouble();
}
return 0.0;
}
public double getHorizontalAdvance(int gid) throws InvalidFontException, UnsupportedFontException {
Type2Parser parser = new Type2Parser();
WidthConsumer consumer = new WidthConsumer();
parser.parse(this.charStrings, gid, this.localSubrs, this.globalSubrs, consumer, this);
if (consumer.widthSeen) {
Dict.NumbersValue v = this.privateDict.get(Dict.Key.nominalWidthX, true);
return v.getFirstValueAsDouble() + consumer.width;
}
Dict.NumbersValue v = this.privateDict.get(Dict.Key.defaultWidthX, true);
return v.getFirstValueAsDouble();
}
public Matrix getFontMatrix() {
return new Matrix(this.topDict.get(Dict.Key.FontMatrix, true).getValuesAsDouble());
}
private Matrix getFontToMetricsMatrix() throws InvalidFontException, UnsupportedFontException {
Matrix m = this.getFontMatrix();
double x = this.getUnitsPerEmX();
double y = this.getUnitsPerEmY();
return new Matrix(x * m.a, y * m.b, x * m.c, y * m.d, x * m.tx, y * m.ty);
}
double getItalicAngle() {
Dict.NumbersValue k = this.topDict.get(Dict.NumbersKey.ItalicAngle, false);
if (k != null) {
return k.getFirstValueAsDouble();
}
return 0.0;
}
Rect getRawFontBBox() {
Dict.NumbersValue v = this.topDict.get(Dict.NumbersKey.FontBBox, false);
if (v != null && v.values.length == 4) {
return new Rect(v.getValuesAsDouble());
}
return null;
}
public Rect getFontBBox() throws InvalidFontException, UnsupportedFontException {
Rect rawBBox = this.getRawFontBBox();
if (rawBBox == null) {
return null;
}
return rawBBox.applyMatrix(this.getFontToMetricsMatrix());
}
public Rect getCoolTypeRawFontBBox() throws InvalidFontException, UnsupportedFontException {
return this.getFontBBox();
}
public LineMetrics getCoolTypeLineMetrics() throws UnsupportedFontException, InvalidFontException {
return this.getCoolTypeLineMetricsFromFontBbox();
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public int getFirstChar() throws InvalidFontException, UnsupportedFontException {
Object object = this.cmapMutex;
synchronized (object) {
this.initCmap();
return this.cmap.getFirstSupportedChar();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public int getLastChar() throws InvalidFontException, UnsupportedFontException {
Object object = this.cmapMutex;
synchronized (object) {
this.initCmap();
return this.cmap.getLastSupportedChar();
}
}
boolean isDingbat() {
Dict.StringValue v = this.topDict.get(Dict.StringKey.FullName, true);
return NameHeuristics.fullNameIndicatesDingbats(v != null ? v.value : null);
}
private void initCmap() throws InvalidFontException, UnsupportedFontException {
if (this.cmap == null) {
this.cmap = UnicodeCmap.computeCmapFromGlyphNames(this.getNumGlyphs(), this.isDingbat(), new GlyphNamesAccessor(){
public String getAGlyphName(int gid) throws UnsupportedFontException, InvalidFontException {
return NameKeyedFont.this.getGlyphName(gid);
}
});
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public int getGlyphForChar(int usv) throws InvalidFontException, UnsupportedFontException {
Object object = this.cmapMutex;
synchronized (object) {
this.initCmap();
return this.cmap.getGlyphForChar(usv);
}
}
int[] getXUID() {
Dict.NumbersValue v = this.topDict.get(Dict.Key.XUID, true);
return v == null ? null : v.getValuesAsInt();
}
String getNotice() {
Dict.StringValue value = this.topDict.get(Dict.Key.Notice, true);
return value == null ? null : value.value;
}
String getCopyright() {
Dict.StringValue value = this.topDict.get(Dict.Key.Copyright, true);
return value == null ? null : value.value;
}
String getFullName() {
Dict.StringValue value = this.topDict.get(Dict.Key.FullName, true);
return value == null ? null : value.value;
}
Integer getFSType() {
return this.topDict.getFSType();
}
OrigFontType getOrigFontType() {
return this.topDict.getOrigFontType();
}
double getDefaultWidthForFD(int fd) {
return this.privateDict.get(Dict.Key.defaultWidthX, true).getFirstValueAsDouble();
}
double getNominalWidthForFD(int fd) {
return this.privateDict.get(Dict.Key.nominalWidthX, true).getFirstValueAsDouble();
}
int getFDForGlyph(int fullGid) throws InvalidFontException {
return 0;
}
CharStrings getLocalSubrsForFD(int fd) {
return this.localSubrs;
}
int getNumFDs() {
return 1;
}
CharStrings getCharStrings() {
return this.charStrings;
}
public Permission getEmbeddingPermission(boolean wasEmbedded) {
return this.getEmbeddingPermissionGivenFT(wasEmbedded, OrigFontType.kTYPE1);
}
CIDKeyedFont toCID(Subset subset) throws InvalidFontException, UnsupportedFontException {
Dict.NumbersValue nv;
LinkedHashMap<Dict.Key, Dict.Value> m = new LinkedHashMap<Dict.Key, Dict.Value>(20, 1.0f);
m.put(Dict.Key.ROS, new Dict.ROSValue("Adobe", "Identity", 0));
m.put(Dict.Key.CIDCount, new Dict.IntegerValue(subset.getNumGlyphs()));
Dict.StringValue sv = this.topDict.get(Dict.Key.Notice, false);
if (sv != null) {
m.put(Dict.Key.Notice, sv);
}
if ((sv = this.topDict.get(Dict.Key.FullName, false)) != null) {
m.put(Dict.Key.FullName, sv);
}
m.put(Dict.Key.FontName, new Dict.StringValue(this.getName()));
sv = this.topDict.get(Dict.Key.FamilyName, false);
if (sv != null) {
m.put(Dict.Key.FamilyName, sv);
}
if ((sv = this.topDict.get(Dict.Key.Weight, false)) != null) {
m.put(Dict.Key.Weight, sv);
}
if ((nv = this.topDict.get(Dict.Key.FontBBox, false)) != null) {
m.put(Dict.Key.FontBBox, nv);
}
if ((sv = this.topDict.get(Dict.Key.Copyright, false)) != null) {
m.put(Dict.Key.Copyright, sv);
}
if ((nv = this.topDict.get(Dict.Key.isFixedPitch, false)) != null) {
m.put(Dict.Key.isFixedPitch, nv);
}
if ((nv = this.topDict.get(Dict.Key.ItalicAngle, false)) != null) {
m.put(Dict.Key.ItalicAngle, nv);
}
if ((nv = this.topDict.get(Dict.Key.UnderlinePosition, false)) != null) {
m.put(Dict.Key.UnderlinePosition, nv);
}
if ((nv = this.topDict.get(Dict.Key.UnderlineThickness, false)) != null) {
m.put(Dict.Key.UnderlineThickness, nv);
}
if ((nv = this.topDict.get(Dict.Key.PaintType, false)) != null) {
m.put(Dict.Key.PaintType, nv);
}
if ((nv = this.topDict.get(Dict.Key.CharstringType, false)) != null) {
m.put(Dict.Key.CharstringType, nv);
}
if ((nv = this.topDict.get(Dict.Key.StrokeWidth, false)) != null) {
m.put(Dict.Key.StrokeWidth, nv);
}
if ((sv = this.topDict.get(Dict.Key.PostScript, false)) != null) {
OrigFontType oft = PostscriptTokenParser.getOrigFontType(sv.value);
if (oft != null) {
m.put(Dict.Key.PostScript, sv);
} else {
m.put(Dict.Key.PostScript, new Dict.StringValue("/OrigFontType /Type1 def " + sv.value));
}
} else {
m.put(Dict.Key.PostScript, new Dict.StringValue("/OrigFontType /Type1 def"));
}
nv = this.topDict.get(Dict.Key.CIDFontType, false);
if (nv != null) {
m.put(Dict.Key.CIDFontType, nv);
}
if ((nv = this.topDict.get(Dict.Key.UIDBase, false)) != null) {
m.put(Dict.Key.UIDBase, nv);
}
Dict CIDtopDict = new Dict(m);
m = new LinkedHashMap();
nv = this.topDict.get(Dict.Key.FontMatrix, false);
if (nv != null) {
m.put(Dict.Key.FontMatrix, nv);
}
Dict CIDfontDict = new Dict(m);
CIDComponentFont[] components = new CIDComponentFont[]{new CIDComponentFont(CIDfontDict, this.privateDict, null)};
return new CIDKeyedFont(null, null, this.name, CIDtopDict, this.createSubsetCharstringIndex(subset, false), Charset.identityCharset(subset.getNumGlyphs()), components, FdSelect.singleFont(subset.getNumGlyphs()));
}
public void subsetAndStream(Subset subset, OutputStream out, boolean preserveROS, Integer fsType) throws InvalidFontException, UnsupportedFontException, IOException {
this.toCID(subset).subsetAndStream(new SubsetDefaultImpl(subset.getNumGlyphs(), false), out, false, fsType);
}
public void subsetAndStream(Subset subset, OutputStream out, boolean preserveROS, Integer fsType, boolean enableSubrizer) throws InvalidFontException, UnsupportedFontException, IOException {
this.toCID(subset).subsetAndStream(new SubsetDefaultImpl(subset.getNumGlyphs(), false), out, false, fsType, enableSubrizer);
}
private void setPSString(CFFByteArray.CFFByteArrayBuilder bb, Integer fsType, List strings) {
OrigFontType oft;
String psString = null;
if (fsType == null) {
fsType = this.topDict.getFSType();
}
if (fsType != null) {
psString = "/FSType " + fsType.toString() + " def ";
}
if ((oft = this.topDict.getOrigFontType()) != null) {
psString = psString != null ? psString + " /OrigFontType /" + oft.toString() + " def" : "/OrigFontType /" + oft.toString() + " def";
}
if (psString != null) {
if (strings.indexOf(psString) == -1) {
strings.add(psString);
}
Dict.streamKeyVal(bb, Dict.Key.PostScript, psString, strings);
}
}
public void stream(OutputStream out, Integer fsType) throws InvalidFontException, UnsupportedFontException, IOException {
SubsetDefaultImpl subset = new SubsetDefaultImpl(this.getNumGlyphs(), false);
this.subsetAndStream((Subset)subset, out, fsType, false, null);
}
public void stream(OutputStream out, Integer fsType, GlyphNameFetcher fetcher) throws InvalidFontException, UnsupportedFontException, IOException {
SubsetDefaultImpl subset = new SubsetDefaultImpl(this.getNumGlyphs(), false);
this.subsetAndStream((Subset)subset, out, fsType, false, fetcher);
}
private int[] buildCharsetData(Subset subset, GlyphNameFetcher fetcher, List strings) throws InvalidFontException, UnsupportedFontException {
int[] glyphSids = null;
glyphSids = new int[subset.getNumGlyphs()];
for (int i = 0; i < glyphSids.length; ++i) {
String glyphName;
if (fetcher == null) {
int fullGid = subset.getFullGid(i);
glyphName = this.getGlyphName(fullGid);
} else {
glyphName = fetcher.getGlyphName(subset, i);
}
int sid = strings.indexOf(glyphName);
if (sid < 0) {
strings.add(glyphName);
sid = strings.size() - 1;
}
glyphSids[i] = sid;
}
return glyphSids;
}
private boolean checkSubrizeLimit(Subset subset) throws InvalidFontException, UnsupportedFontException {
int cffSize = this.charStrings.data.getSize();
if (cffSize <= 614400) {
return true;
}
if (subset == null) {
return false;
}
if ((double)cffSize * (double)subset.getNumGlyphs() <= 614400.0 * (double)this.getNumGlyphs()) {
return true;
}
return false;
}
public void subsetAndStream(Subset subset, OutputStream out, Integer fsType, boolean rebuildCharstrings, GlyphNameFetcher fetcher) throws InvalidFontException, UnsupportedFontException, IOException {
this.subsetAndStream(subset, out, fsType, rebuildCharstrings, fetcher, false);
}
public void subsetAndStream(Subset subset, OutputStream out, Integer fsType, boolean rebuildCharstrings, GlyphNameFetcher fetcher, boolean enableSubrizer) throws InvalidFontException, UnsupportedFontException, IOException {
List strings = StringIndex.collectPredefinedStrings();
int[] glyphSids = null;
glyphSids = this.buildCharsetData(subset, fetcher, strings);
this.topDict.collectStrings(strings);
Dict.StringValue val = this.topDict.get(Dict.StringKey.PostScript, false);
if (val != null) {
strings.remove(strings.indexOf(val.value));
}
CFFByteArray.CFFByteArrayBuilder bb = CFFByteArray.getCFFByteArrayBuilderInstance();
Header.toBinary(bb);
NameIndex.toBinary(bb, this.name);
Index.Cursor cursor = Index.startIndex(bb, 1);
this.topDict.stream(bb, strings, topDictKeysForSubset);
this.setPSString(bb, fsType, strings);
int charsetMarker = Dict.Key.charset.streamDummyValue(bb);
int charStringsMarker = Dict.Key.CharStrings.streamDummyValue(bb);
int privateMarker = Dict.Key.Private.streamDummyValue(bb);
cursor = Index.elementEntered(bb, cursor);
StringIndex.toBinary(bb, strings);
CharStrings subsetCharstrings = null;
CharStrings lSubrStrings = null;
CharStrings gSubrStrings = null;
if (rebuildCharstrings) {
if (enableSubrizer) {
enableSubrizer = this.checkSubrizeLimit(subset);
}
subsetCharstrings = this.createSubsetCharstringIndex(subset, enableSubrizer);
if (enableSubrizer) {
CFFSubrize subrizer = new CFFSubrize();
subsetCharstrings = subrizer.subrize(subsetCharstrings);
lSubrStrings = subrizer.getLSubrs();
gSubrStrings = subrizer.getGSubrs();
if (gSubrStrings == null) {
gSubrStrings = CharStrings.createEmptyCharstrings();
}
gSubrStrings.stream(bb);
} else {
bb.addCard16(0);
}
} else {
subsetCharstrings = this.charStrings;
this.globalSubrs.stream(bb);
}
Dict.Key.charset.fixOffset(bb, charsetMarker, bb.getSize());
Charset.streamCharSet(bb, glyphSids);
Dict.Key.CharStrings.fixOffset(bb, charStringsMarker, bb.getSize());
subsetCharstrings.stream(bb);
int start = bb.getSize();
Dict.Key.Private.fixOffset(bb, privateMarker, start);
this.privateDict.stream(bb, strings, privateDictKeysForSubset);
int localSubrsMarker = 0;
if (rebuildCharstrings && lSubrStrings != null || !rebuildCharstrings && this.localSubrs != null) {
localSubrsMarker = Dict.Key.Subrs.streamDummyValue(bb);
}
Dict.Key.Private.fixSize(bb, privateMarker, bb.getSize() - start);
if (rebuildCharstrings && lSubrStrings != null || !rebuildCharstrings && this.localSubrs != null) {
Dict.Key.Subrs.fixOffset(bb, localSubrsMarker, bb.getSize() - start);
if (rebuildCharstrings) {
lSubrStrings.stream(bb);
} else {
this.localSubrs.stream(bb);
}
}
CFFByteArray byteArray = bb.toCFFByteArray();
byteArray.write(out);
}
public PDFFontDescription getPDFFontDescription(Font font) throws UnsupportedFontException, InvalidFontException {
return this.xdcDescription;
}
public XDCFontDescription getXDCFontDescription(Font font) throws UnsupportedFontException, InvalidFontException {
return this.xdcDescription;
}
public Subset createSubset() throws InvalidFontException, UnsupportedFontException {
NameKeyedSubset s = new NameKeyedSubset(this.getNumGlyphs(), true);
s.getSubsetGid(0);
return s;
}
private class NameKeyedFontXDCFontDescription
extends CFFFont.CFFFontXDCFontDescription {
private NameKeyedFontXDCFontDescription() {
}
public void subsetAndStream(Subset subset, OutputStream out, boolean preserveROS) throws InvalidFontException, UnsupportedFontException, IOException {
NameKeyedFont.this.subsetAndStream(subset, out, preserveROS);
}
public void subsetAndStream(SubsetSimpleType1 t1Subset, OutputStream out) throws InvalidFontException, UnsupportedFontException, IOException {
NameKeyedSubset subset = (NameKeyedSubset)NameKeyedFont.this.createSubset();
subset.addGlyphs(NameKeyedFont.this, t1Subset.getGlyphNames());
NameKeyedFont.this.subsetAndStream((Subset)subset, out, NameKeyedFont.this.getFSType(), true, null);
}
public void subsetAndStream(SubsetSimpleTrueType ttSubset, OutputStream out) throws UnsupportedFontException {
throw new UnsupportedFontException("Not a TrueType font");
}
public void stream(OutputStream out, boolean openTypeOK) throws InvalidFontException, UnsupportedFontException, IOException {
NameKeyedFont.this.stream(out, null);
}
public CodePage[] getXDCCodePages() throws InvalidFontException, UnsupportedFontException {
HashSet<CodePage> codePageSet = new HashSet<CodePage>();
if (NameKeyedFont.this.glyphName2gid("ecircumflex") > 0) {
codePageSet.add(CodePage.ROMAN1);
}
if (NameKeyedFont.this.glyphName2gid("Ccaron") > 0 || NameKeyedFont.this.glyphName2gid("ncaron") > 0) {
codePageSet.add(CodePage.ROMAN2);
}
if (NameKeyedFont.this.glyphName2gid("akatakana") > 0) {
codePageSet.add(CodePage.JAPANESE);
}
CodePage[] retVal = new CodePage[codePageSet.size()];
Iterator iter = codePageSet.iterator();
int index = 0;
while (iter.hasNext()) {
retVal[index++] = (CodePage)iter.next();
}
return retVal;
}
public int getCIDCount() {
return -1;
}
}
public static abstract class GlyphNameFetcher {
public abstract String getGlyphName(Subset var1, int var2);
}
static class WidthConsumer
extends Type2ConsumerDefaultImpl {
public double width;
public boolean widthSeen = false;
WidthConsumer() {
}
public boolean width(double w) {
this.widthSeen = true;
this.width = w;
return false;
}
}
}