@@ -4443,6 +4443,7 @@ var Type1Parser = function type1Parser() {
4443
4443
// Type1 only command with command not (yet) built-in ,throw an error
4444
4444
'7' : -1 , // sbw
4445
4445
4446
+ '10' : 'add' ,
4446
4447
'11' : 'sub' ,
4447
4448
'12' : 'div' ,
4448
4449
@@ -4507,16 +4508,6 @@ var Type1Parser = function type1Parser() {
4507
4508
return args ;
4508
4509
}
4509
4510
4510
- // Remove the same number of args from the stack that are in the args
4511
- // parameter. Args should be built from breakUpArgs().
4512
- function popArgs (stack , args ) {
4513
- for (var i = 0 , ii = args .length ; i < ii ; i ++) {
4514
- for (var j = 0 , jj = args [i ].arg .length ; j < jj ; j ++) {
4515
- stack .pop ();
4516
- }
4517
- }
4518
- }
4519
-
4520
4511
function decodeCharString (array ) {
4521
4512
var charstring = [];
4522
4513
var lsb = 0 ;
@@ -4617,25 +4608,32 @@ var Type1Parser = function type1Parser() {
4617
4608
break ;
4618
4609
case 0 :
4619
4610
var flexArgs = breakUpArgs (charstring , 17 );
4620
- popArgs (charstring , flexArgs );
4621
-
4622
- charstring .push (
4623
- flexArgs [2 ].value + flexArgs [0 ].value , // bcp1x + rpx
4624
- flexArgs [3 ].value + flexArgs [1 ].value , // bcp1y + rpy
4625
- flexArgs [4 ].value , // bcp2x
4626
- flexArgs [5 ].value , // bcp2y
4627
- flexArgs [6 ].value , // p2x
4628
- flexArgs [7 ].value , // p2y
4629
- flexArgs [8 ].value , // bcp3x
4630
- flexArgs [9 ].value , // bcp3y
4631
- flexArgs [10 ].value , // bcp4x
4632
- flexArgs [11 ].value , // bcp4y
4633
- flexArgs [12 ].value , // p3x
4634
- flexArgs [13 ].value , // p3y
4635
- flexArgs [14 ].value , // flexDepth
4611
+
4612
+ // removing all flex arguments from the stack
4613
+ charstring .splice (flexArgs [0 ].offset ,
4614
+ charstring .length - flexArgs [0 ].offset );
4615
+
4616
+ charstring = charstring .concat (
4617
+ flexArgs [0 ].arg , // bcp1x +
4618
+ flexArgs [2 ].arg , // rpx
4619
+ ['add' ],
4620
+ flexArgs [1 ].arg , // bcp1y +
4621
+ flexArgs [3 ].arg , // rpy
4622
+ ['add' ],
4623
+ flexArgs [4 ].arg , // bcp2x
4624
+ flexArgs [5 ].arg , // bcp2y
4625
+ flexArgs [6 ].arg , // p2x
4626
+ flexArgs [7 ].arg , // p2y
4627
+ flexArgs [8 ].arg , // bcp3x
4628
+ flexArgs [9 ].arg , // bcp3y
4629
+ flexArgs [10 ].arg , // bcp4x
4630
+ flexArgs [11 ].arg , // bcp4y
4631
+ flexArgs [12 ].arg , // p3x
4632
+ flexArgs [13 ].arg , // p3y
4633
+ flexArgs [14 ].arg , // flexDepth
4636
4634
// 15 = finalx unused by flex
4637
4635
// 16 = finaly unused by flex
4638
- 'flex'
4636
+ [ 'flex' ]
4639
4637
);
4640
4638
4641
4639
flexing = false ;
@@ -4650,14 +4648,9 @@ var Type1Parser = function type1Parser() {
4650
4648
charstring .push (0 );
4651
4649
continue ; // ignoring hmoveto
4652
4650
} else if (value == 4 && flexing ) { // vmoveto
4653
- // Add the dx for flex and but also swap the values so they are the
4654
- // right order.
4655
- var vArgs = breakUpArgs (charstring , 1 );
4656
- popArgs (charstring , vArgs );
4657
- charstring .push (0 );
4658
- for (var t = 0 , tt = vArgs [0 ].arg .length ; t < tt ; t ++) {
4659
- charstring .push (vArgs [0 ].arg [t ]);
4660
- }
4651
+ // Insert the dx for flex before dy.
4652
+ var flexArgs = breakUpArgs (charstring , 1 );
4653
+ charstring .splice (flexArgs [0 ].offset , 0 , 0 );
4661
4654
continue ; // ignoring vmoveto
4662
4655
} else if (!HINTING_ENABLED && (value == 1 || value == 3 )) {
4663
4656
charstring .push ('drop' , 'drop' );
@@ -5124,6 +5117,7 @@ Type1Font.prototype = {
5124
5117
'rrcurveto' : 8 ,
5125
5118
'callsubr' : 10 ,
5126
5119
'return' : 11 ,
5120
+ 'add' : [12 , 10 ],
5127
5121
'sub' : [12 , 11 ],
5128
5122
'div' : [12 , 12 ],
5129
5123
'exch' : [12 , 28 ],
@@ -6384,37 +6378,26 @@ var CFFCompiler = (function CFFCompilerClosure() {
6384
6378
else
6385
6379
return this .encodeFloat (value );
6386
6380
},
6387
- encodeFloat : function CFFCompiler_encodeFloat (value ) {
6388
- value = value .toString ();
6389
- // Strip off the any leading zeros.
6390
- if (value .substr (0 , 2 ) === '0.' )
6391
- value = value .substr (1 );
6392
- else if (value .substr (0 , 3 ) === '-0.' )
6393
- value = '-' + value .substr (2 );
6394
- var nibbles = [];
6381
+ encodeFloat : function CFFCompiler_encodeFloat (num ) {
6382
+ var value = num .toString ();
6383
+ var nibbles = '';
6395
6384
for (var i = 0 , ii = value .length ; i < ii ; ++i ) {
6396
- var a = value .charAt (i ), b = value .charAt (i + 1 );
6397
- var nibble ;
6398
- if (a === 'e' && b === '-' ) {
6399
- nibble = 0xc ;
6400
- ++i ;
6385
+ var a = value [i ];
6386
+ if (a === 'e' ) {
6387
+ nibbles += value [++i ] === '-' ? 'c' : 'b' ;
6401
6388
} else if (a === '.' ) {
6402
- nibble = 0xa ;
6403
- } else if (a === 'E' ) {
6404
- nibble = 0xb ;
6389
+ nibbles += 'a' ;
6405
6390
} else if (a === '-' ) {
6406
- nibble = 0xe ;
6391
+ nibbles += 'e' ;
6407
6392
} else {
6408
- nibble = a ;
6393
+ nibbles + = a ;
6409
6394
}
6410
- nibbles .push (nibble );
6411
6395
}
6412
- nibbles .push (0xf );
6413
- if (nibbles .length % 2 )
6414
- nibbles .push (0xf );
6396
+ nibbles += (nibbles .length & 1 ) ? 'f' : 'ff' ;
6415
6397
var out = [30 ];
6416
- for (var i = 0 , ii = nibbles .length ; i < ii ; i += 2 )
6417
- out .push (nibbles [i ] << 4 | nibbles [i + 1 ]);
6398
+ for (var i = 0 , ii = nibbles .length ; i < ii ; i += 2 ) {
6399
+ out .push (parseInt (nibbles .substr (i , 2 ), 16 ));
6400
+ }
6418
6401
return out ;
6419
6402
},
6420
6403
encodeInteger : function CFFCompiler_encodeInteger (value ) {
0 commit comments