@@ -2385,6 +2385,14 @@ class PartialEvaluator {
2385
2385
} ) ;
2386
2386
}
2387
2387
2388
+ function applyInverseRotation ( x , y , matrix ) {
2389
+ const scale = Math . hypot ( matrix [ 0 ] , matrix [ 1 ] ) ;
2390
+ return [
2391
+ ( matrix [ 0 ] * x + matrix [ 1 ] * y ) / scale ,
2392
+ ( matrix [ 2 ] * x + matrix [ 3 ] * y ) / scale ,
2393
+ ] ;
2394
+ }
2395
+
2388
2396
function compareWithLastPosition ( ) {
2389
2397
if (
2390
2398
! combineTextItems ||
@@ -2404,9 +2412,8 @@ class PartialEvaluator {
2404
2412
return ;
2405
2413
}
2406
2414
2407
- let rotate = 0 ;
2415
+ let rotate = - 1 ;
2408
2416
// Take into account the rotation is the current transform.
2409
- // Only rotations with an angle of 0, 90, 180 or 270 are considered.
2410
2417
if (
2411
2418
currentTransform [ 0 ] &&
2412
2419
currentTransform [ 1 ] === 0 &&
@@ -2418,28 +2425,40 @@ class PartialEvaluator {
2418
2425
currentTransform [ 0 ] === 0 &&
2419
2426
currentTransform [ 3 ] === 0
2420
2427
) {
2421
- rotate + = currentTransform [ 1 ] > 0 ? 90 : 270 ;
2428
+ rotate = currentTransform [ 1 ] > 0 ? 90 : 270 ;
2422
2429
}
2423
2430
2424
- if ( rotate !== 0 ) {
2425
- switch ( rotate ) {
2426
- case 90 :
2427
- [ posX , posY ] = [ posY , posX ] ;
2428
- [ lastPosX , lastPosY ] = [ lastPosY , lastPosX ] ;
2429
- break ;
2430
- case 180 :
2431
- [ posX , posY , lastPosX , lastPosY ] = [
2432
- - posX ,
2433
- - posY ,
2434
- - lastPosX ,
2435
- - lastPosY ,
2436
- ] ;
2437
- break ;
2438
- case 270 :
2439
- [ posX , posY ] = [ - posY , - posX ] ;
2440
- [ lastPosX , lastPosY ] = [ - lastPosY , - lastPosX ] ;
2441
- break ;
2442
- }
2431
+ switch ( rotate ) {
2432
+ case 0 :
2433
+ break ;
2434
+ case 90 :
2435
+ [ posX , posY ] = [ posY , posX ] ;
2436
+ [ lastPosX , lastPosY ] = [ lastPosY , lastPosX ] ;
2437
+ break ;
2438
+ case 180 :
2439
+ [ posX , posY , lastPosX , lastPosY ] = [
2440
+ - posX ,
2441
+ - posY ,
2442
+ - lastPosX ,
2443
+ - lastPosY ,
2444
+ ] ;
2445
+ break ;
2446
+ case 270 :
2447
+ [ posX , posY ] = [ - posY , - posX ] ;
2448
+ [ lastPosX , lastPosY ] = [ - lastPosY , - lastPosX ] ;
2449
+ break ;
2450
+ default :
2451
+ // This is not a 0, 90, 180, 270 rotation so:
2452
+ // - remove the scale factor from the matrix to get a rotation matrix
2453
+ // - apply the inverse (which is the transposed) to the positions
2454
+ // and we can then compare positions of the glyphes to detect
2455
+ // a whitespace.
2456
+ [ posX , posY ] = applyInverseRotation ( posX , posY , currentTransform ) ;
2457
+ [ lastPosX , lastPosY ] = applyInverseRotation (
2458
+ lastPosX ,
2459
+ lastPosY ,
2460
+ textContentItem . prevTransform
2461
+ ) ;
2443
2462
}
2444
2463
2445
2464
if ( textState . font . vertical ) {
0 commit comments