@@ -1497,6 +1497,55 @@ class Font {
1497
1497
} ) ;
1498
1498
}
1499
1499
hasShortCmap = true ;
1500
+ } else if ( format === 2 ) {
1501
+ const subHeaderKeys = [ ] ;
1502
+ let maxSubHeaderKey = 0 ;
1503
+ // Read subHeaderKeys. If subHeaderKeys[i] === 0, then i is a
1504
+ // single-byte character. Otherwise, i is the first byte of a
1505
+ // multi-byte character, and the value is 8*index into
1506
+ // subHeaders.
1507
+ for ( let i = 0 ; i < 256 ; i ++ ) {
1508
+ const subHeaderKey = file . getUint16 ( ) >> 3 ;
1509
+ subHeaderKeys . push ( subHeaderKey ) ;
1510
+ maxSubHeaderKey = Math . max ( subHeaderKey , maxSubHeaderKey ) ;
1511
+ }
1512
+ // Read subHeaders. The number of entries is determined
1513
+ // dynamically based on the subHeaderKeys found above.
1514
+ const subHeaders = [ ] ;
1515
+ for ( let i = 0 ; i <= maxSubHeaderKey ; i ++ ) {
1516
+ subHeaders . push ( {
1517
+ firstCode : file . getUint16 ( ) ,
1518
+ entryCount : file . getUint16 ( ) ,
1519
+ idDelta : signedInt16 ( file . getByte ( ) , file . getByte ( ) ) ,
1520
+ idRangePos : file . pos + file . getUint16 ( ) ,
1521
+ } ) ;
1522
+ }
1523
+ for ( let i = 0 ; i < 256 ; i ++ ) {
1524
+ if ( subHeaderKeys [ i ] === 0 ) {
1525
+ // i is a single-byte code.
1526
+ file . pos = subHeaders [ 0 ] . idRangePos + 2 * i ;
1527
+ glyphId = file . getUint16 ( ) ;
1528
+ mappings . push ( {
1529
+ charCode : i ,
1530
+ glyphId,
1531
+ } ) ;
1532
+ } else {
1533
+ // i is the first byte of a two-byte code.
1534
+ const s = subHeaders [ subHeaderKeys [ i ] ] ;
1535
+ for ( j = 0 ; j < s . entryCount ; j ++ ) {
1536
+ const charCode = ( i << 8 ) + j + s . firstCode ;
1537
+ file . pos = s . idRangePos + 2 * j ;
1538
+ glyphId = file . getUint16 ( ) ;
1539
+ if ( glyphId !== 0 ) {
1540
+ glyphId = ( glyphId + s . idDelta ) % 65536 ;
1541
+ }
1542
+ mappings . push ( {
1543
+ charCode,
1544
+ glyphId,
1545
+ } ) ;
1546
+ }
1547
+ }
1548
+ }
1500
1549
} else if ( format === 4 ) {
1501
1550
// re-creating the table in format 4 since the encoding
1502
1551
// might be changed
0 commit comments