25
25
import java .util .List ;
26
26
import java .util .Map ;
27
27
28
- import org .apache .fontbox .cff .CFFDataInput ;
29
28
import org .apache .fontbox .cff .CFFOperator ;
29
+ import org .apache .fontbox .cff .DataInputByteArray ;
30
30
31
31
import org .apache .fop .fonts .truetype .FontFileReader ;
32
32
import org .apache .fop .fonts .truetype .OTFFile ;
35
35
* A class to read the CFF data from an OTF CFF font file.
36
36
*/
37
37
public class CFFDataReader {
38
- private CFFDataInput cffData ;
38
+ private DataInputByteArray cffData ;
39
39
40
40
private byte [] header ;
41
41
private CFFIndexData nameIndex ;
@@ -137,14 +137,10 @@ public LinkedHashMap<String, DICTEntry> parseDictData(byte[] dictData) throws IO
137
137
operator [0 ] = dictData [i ];
138
138
}
139
139
String operatorName = "" ;
140
- CFFOperator tempOp = null ;
141
140
if (operator .length > 1 ) {
142
- tempOp = CFFOperator .getOperator (new CFFOperator . Key ( operator [0 ], operator [1 ]) );
141
+ operatorName = CFFOperator .getOperator (operator [0 ], operator [1 ]);
143
142
} else {
144
- tempOp = CFFOperator .getOperator (new CFFOperator .Key (operator [0 ]));
145
- }
146
- if (tempOp != null ) {
147
- operatorName = tempOp .getName ();
143
+ operatorName = CFFOperator .getOperator (operator [0 ]);
148
144
}
149
145
DICTEntry newEntry = new DICTEntry ();
150
146
newEntry .setOperator (operator );
@@ -330,7 +326,7 @@ private CFFIndexData readIndex() throws IOException {
330
326
* @return Returns an object representing the index
331
327
* @throws IOException Throws an IO Exception if an error occurs
332
328
*/
333
- public CFFIndexData readIndex (CFFDataInput input ) throws IOException {
329
+ public CFFIndexData readIndex (DataInputByteArray input ) throws IOException {
334
330
CFFIndexData nameIndex = new CFFIndexData ();
335
331
if (input != null ) {
336
332
int origPos = input .getPosition ();
@@ -352,11 +348,11 @@ public int getSIDFromGID(int charsetOffset, int gid) throws IOException {
352
348
return 0 ;
353
349
}
354
350
cffData .setPosition (charsetOffset );
355
- int charsetFormat = cffData .readCard8 ();
351
+ int charsetFormat = cffData .readUnsignedByte ();
356
352
switch (charsetFormat ) {
357
353
case 0 : //Adjust for .notdef character
358
354
cffData .setPosition (cffData .getPosition () + (--gid * 2 ));
359
- return cffData .readSID ();
355
+ return cffData .readUnsignedShort ();
360
356
case 1 : return getSIDFromGIDFormat (gid , 1 );
361
357
case 2 : return getSIDFromGIDFormat (gid , 2 );
362
358
default : return 0 ;
@@ -367,8 +363,8 @@ private int getSIDFromGIDFormat(int gid, int format) throws IOException {
367
363
int glyphCount = 0 ;
368
364
while (true ) {
369
365
int oldGlyphCount = glyphCount ;
370
- int start = cffData .readSID ();
371
- glyphCount += ((format == 1 ) ? cffData .readCard8 () : cffData .readCard16 ()) + 1 ;
366
+ int start = cffData .readUnsignedShort ();
367
+ glyphCount += ((format == 1 ) ? cffData .readUnsignedByte () : cffData .readUnsignedShort ()) + 1 ;
372
368
if (gid <= glyphCount ) {
373
369
return start + (gid - oldGlyphCount ) - 1 ;
374
370
}
@@ -407,7 +403,7 @@ public CFFIndexData getCharStringIndex() {
407
403
return charStringIndex ;
408
404
}
409
405
410
- public CFFDataInput getCFFData () {
406
+ public DataInputByteArray getCFFData () {
411
407
return cffData ;
412
408
}
413
409
@@ -423,7 +419,7 @@ public List<FontDict> getFDFonts() {
423
419
return fdFonts ;
424
420
}
425
421
426
- public CFFDataInput getLocalSubrsForGlyph (int glyph ) throws IOException {
422
+ public DataInputByteArray getLocalSubrsForGlyph (int glyph ) throws IOException {
427
423
//Subsets are currently written using a Format0 FDSelect
428
424
FDSelect fontDictionary = getFDSelect ();
429
425
if (fontDictionary instanceof Format0FDSelect ) {
@@ -432,7 +428,7 @@ public CFFDataInput getLocalSubrsForGlyph(int glyph) throws IOException {
432
428
FontDict font = getFDFonts ().get (found );
433
429
byte [] localSubrData = font .getLocalSubrData ().getByteData ();
434
430
if (localSubrData != null ) {
435
- return new CFFDataInput (localSubrData );
431
+ return new DataInputByteArray (localSubrData );
436
432
} else {
437
433
return null ;
438
434
}
@@ -448,7 +444,7 @@ public CFFDataInput getLocalSubrsForGlyph(int glyph) throws IOException {
448
444
FontDict font = getFDFonts ().get (index );
449
445
byte [] localSubrsData = font .getLocalSubrData ().getByteData ();
450
446
if (localSubrsData != null ) {
451
- return new CFFDataInput (localSubrsData );
447
+ return new DataInputByteArray (localSubrsData );
452
448
} else {
453
449
return null ;
454
450
}
@@ -473,8 +469,8 @@ private CustomEncoding readEncoding() throws IOException {
473
469
int offset = topDict .get ("Encoding" ).getOperands ().get (0 ).intValue ();
474
470
if (offset != 0 && offset != 1 ) {
475
471
//No need to set the offset as we are reading the data sequentially.
476
- int format = cffData .readCard8 ();
477
- int numEntries = cffData .readCard8 ();
472
+ int format = cffData .readUnsignedByte ();
473
+ int numEntries = cffData .readUnsignedByte ();
478
474
switch (format ) {
479
475
case 0 :
480
476
foundEncoding = readFormat0Encoding (format , numEntries );
@@ -496,7 +492,7 @@ private Format0Encoding readFormat0Encoding(int format, int numEntries)
496
492
newEncoding .setNumEntries (numEntries );
497
493
int [] codes = new int [numEntries ];
498
494
for (int i = 0 ; i < numEntries ; i ++) {
499
- codes [i ] = cffData .readCard8 ();
495
+ codes [i ] = cffData .readUnsignedByte ();
500
496
}
501
497
newEncoding .setCodes (codes );
502
498
return newEncoding ;
@@ -509,8 +505,8 @@ private Format1Encoding readFormat1Encoding(int format, int numEntries)
509
505
newEncoding .setNumEntries (numEntries );
510
506
Map <Integer , Integer > ranges = new LinkedHashMap <Integer , Integer >();
511
507
for (int i = 0 ; i < numEntries ; i ++) {
512
- int first = cffData .readCard8 ();
513
- int left = cffData .readCard8 ();
508
+ int first = cffData .readUnsignedByte ();
509
+ int left = cffData .readUnsignedByte ();
514
510
ranges .put (first , left );
515
511
}
516
512
newEncoding .setRanges (ranges );
@@ -523,7 +519,7 @@ private FDSelect readFDSelect() throws IOException {
523
519
if (fdSelectEntry != null ) {
524
520
int fdOffset = fdSelectEntry .getOperands ().get (0 ).intValue ();
525
521
cffData .setPosition (fdOffset );
526
- int format = cffData .readCard8 ();
522
+ int format = cffData .readUnsignedByte ();
527
523
switch (format ) {
528
524
case 0 :
529
525
fdSelect = readFormat0FDSelect ();
@@ -543,7 +539,7 @@ private Format0FDSelect readFormat0FDSelect() throws IOException {
543
539
int glyphCount = charStringIndex .getNumObjects ();
544
540
int [] fds = new int [glyphCount ];
545
541
for (int i = 0 ; i < glyphCount ; i ++) {
546
- fds [i ] = cffData .readCard8 ();
542
+ fds [i ] = cffData .readUnsignedByte ();
547
543
}
548
544
newFDs .setFDIndexes (fds );
549
545
return newFDs ;
@@ -552,16 +548,16 @@ private Format0FDSelect readFormat0FDSelect() throws IOException {
552
548
private Format3FDSelect readFormat3FDSelect () throws IOException {
553
549
Format3FDSelect newFDs = new Format3FDSelect ();
554
550
newFDs .setFormat (3 );
555
- int rangeCount = cffData .readCard16 ();
551
+ int rangeCount = cffData .readUnsignedShort ();
556
552
newFDs .setRangeCount (rangeCount );
557
553
Map <Integer , Integer > ranges = new LinkedHashMap <Integer , Integer >();
558
554
for (int i = 0 ; i < rangeCount ; i ++) {
559
- int first = cffData .readCard16 ();
560
- int fd = cffData .readCard8 ();
555
+ int first = cffData .readUnsignedShort ();
556
+ int fd = cffData .readUnsignedByte ();
561
557
ranges .put (first , fd );
562
558
}
563
559
newFDs .setRanges (ranges );
564
- newFDs .setSentinelGID (cffData .readCard16 ());
560
+ newFDs .setSentinelGID (cffData .readUnsignedShort ());
565
561
return newFDs ;
566
562
}
567
563
@@ -709,19 +705,19 @@ public byte[] getData() throws IOException {
709
705
* @param cffData A byte array containing the CFF data
710
706
* @throws IOException Throws an IO Exception if an error occurs
711
707
*/
712
- public void parseIndexHeader (CFFDataInput cffData ) throws IOException {
713
- setNumObjects (cffData .readCard16 ());
714
- setOffSize (cffData .readOffSize ());
708
+ public void parseIndexHeader (DataInputByteArray cffData ) throws IOException {
709
+ setNumObjects (cffData .readUnsignedShort ());
710
+ setOffSize (cffData .readUnsignedByte ());
715
711
int [] offsets = new int [getNumObjects () + 1 ];
716
712
byte [] bytes ;
717
713
//Fills the offsets array
718
714
for (int i = 0 ; i <= getNumObjects (); i ++) {
719
715
switch (getOffSize ()) {
720
716
case 1 :
721
- offsets [i ] = cffData .readCard8 ();
717
+ offsets [i ] = cffData .readUnsignedByte ();
722
718
break ;
723
719
case 2 :
724
- offsets [i ] = cffData .readCard16 ();
720
+ offsets [i ] = cffData .readUnsignedShort ();
725
721
break ;
726
722
case 3 :
727
723
bytes = cffData .readBytes (3 );
0 commit comments