@@ -47,7 +47,7 @@ import { console } from "../libs/console.js";
47
47
this . miterLimit = ctx . miterLimit || 10.0 ;
48
48
this . lastPoint = ctx . lastPoint || new Point ( ) ;
49
49
this . margin = ctx . margin || [ 0 , 0 , 0 , 0 ] ;
50
-
50
+ this . prevPageLastElemOffset = ctx . prevPageLastElemOffset || 0 ;
51
51
this . ignoreClearRect =
52
52
typeof ctx . ignoreClearRect === "boolean" ? ctx . ignoreClearRect : true ;
53
53
return this ;
@@ -1474,29 +1474,45 @@ import { console } from "../libs/console.js";
1474
1474
for ( var i = min ; i < max + 1 ; i ++ ) {
1475
1475
this . pdf . setPage ( i ) ;
1476
1476
1477
+ var topMargin = ( i === min ? Math . max ( this . posY , this . margin [ 0 ] ) : this . margin [ 0 ] ) ;
1478
+ var firstPageHeight = this . pdf . internal . pageSize . height - Math . max ( this . posY , this . margin [ 0 ] ) - this . margin [ 2 ] ;
1479
+ var pageHeightMinusMargin = this . pdf . internal . pageSize . height - this . margin [ 2 ] ;
1480
+ var pageWidthMinusMargin = this . pdf . internal . pageSize . width - this . margin [ 1 ] ;
1481
+ var previousPageHeightSum = i === 1 ? 0 : firstPageHeight + ( i - 2 ) * pageHeightMinusMargin ;
1482
+
1477
1483
if ( this . ctx . clip_path . length !== 0 ) {
1478
1484
var tmpPaths = this . path ;
1479
1485
clipPath = JSON . parse ( JSON . stringify ( this . ctx . clip_path ) ) ;
1480
1486
this . path = pathPositionRedo (
1481
1487
clipPath ,
1488
+ < << << << HEAD
1482
1489
this . posX + this . margin [ 3 ] ,
1483
1490
- 1 * this . pdf . internal . pageSize . height * ( i - 1 ) + this . posY + this . margin [ 0 ]
1491
+ === = ===
1492
+ Math . max ( this . posX , this . margin [ 3 ] ) ,
1493
+ - 1 * previousPageHeightSum + topMargin + this . ctx . prevPageLastElemOffset
1494
+ >>> > >>> 16499 ee4c73991f345d6adab1d68d2c52ab79d00
1484
1495
) ;
1485
1496
drawPaths . call ( this , "fill" , true ) ;
1486
1497
this . path = tmpPaths ;
1487
1498
}
1488
1499
var tmpRect = JSON . parse ( JSON . stringify ( xRect ) ) ;
1489
1500
tmpRect = pathPositionRedo (
1490
1501
[ tmpRect ] ,
1502
+ < << << << HEAD
1491
1503
this . posX + this . margin [ 3 ] ,
1492
1504
- 1 * this . pdf . internal . pageSize . height * ( i - 1 ) + this . posY + this . margin [ 0 ]
1505
+ === = ===
1506
+ Math . max ( this . posX , this . margin [ 3 ] ) ,
1507
+ - 1 * previousPageHeightSum + topMargin + this . ctx . prevPageLastElemOffset
1508
+ >>> > >>> 16499 ee4c73991f345d6adab1d68d2c52ab79d00
1493
1509
) [ 0 ] ;
1494
1510
this . pdf . addImage (
1495
1511
img ,
1496
1512
"JPEG" ,
1497
1513
tmpRect . x ,
1498
1514
tmpRect . y ,
1499
- tmpRect . w ,
1515
+ Math . min ( tmpRect . w , this . pdf . internal . pageSize . width - this . margin [ 1 ] - tmpRect . x ) ,
1500
1516
tmpRect . h ,
1501
1517
null ,
1502
1518
null ,
@@ -1521,7 +1537,7 @@ import { console } from "../libs/console.js";
1521
1537
var getPagesByPath = function ( path , pageWrapX , pageWrapY ) {
1522
1538
var result = [ ] ;
1523
1539
pageWrapX = pageWrapX || this . pdf . internal . pageSize . width ;
1524
- pageWrapY = pageWrapY || this . pdf . internal . pageSize . height ;
1540
+ pageWrapY = pageWrapY || this . pdf . internal . pageSize . height - this . margin [ 0 ] - this . margin [ 2 ] ;
1525
1541
1526
1542
switch ( path . type ) {
1527
1543
default :
@@ -1670,22 +1686,37 @@ import { console } from "../libs/console.js";
1670
1686
this . lineWidth = lineWidth ;
1671
1687
this . lineJoin = lineJoin ;
1672
1688
1689
+ var topMargin = ( k === min ? Math . max ( this . posY , this . margin [ 0 ] ) : this . margin [ 0 ] ) ;
1690
+ var firstPageHeight = this . pdf . internal . pageSize . height - Math . max ( this . posY , this . margin [ 0 ] ) - this . margin [ 2 ] ;
1691
+ var pageHeightMinusMargin = this . pdf . internal . pageSize . height - this . margin [ 2 ] ;
1692
+ var previousPageHeightSum = k === 1 ? 0 : firstPageHeight + ( k - 2 ) * pageHeightMinusMargin ;
1693
+
1673
1694
if ( this . ctx . clip_path . length !== 0 ) {
1674
1695
var tmpPaths = this . path ;
1675
1696
clipPath = JSON . parse ( JSON . stringify ( this . ctx . clip_path ) ) ;
1676
1697
this . path = pathPositionRedo (
1677
1698
clipPath ,
1699
+ < << << << HEAD
1678
1700
this . posX + this . margin [ 3 ] ,
1679
1701
- 1 * this . pdf . internal . pageSize . height * ( k - 1 ) + this . posY + this . margin [ 0 ]
1702
+ === = ===
1703
+ Math . max ( this . posX , this . margin [ 3 ] ) ,
1704
+ - 1 * previousPageHeightSum + topMargin + this . ctx . prevPageLastElemOffset
1705
+ >>> > >>> 16499 ee4c73991f345d6adab1d68d2c52ab79d00
1680
1706
) ;
1681
1707
drawPaths . call ( this , rule , true ) ;
1682
1708
this . path = tmpPaths ;
1683
1709
}
1684
1710
tmpPath = JSON . parse ( JSON . stringify ( origPath ) ) ;
1685
1711
this . path = pathPositionRedo (
1686
1712
tmpPath ,
1713
+ < << << << HEAD
1687
1714
this . posX + this . margin [ 3 ] ,
1688
1715
- 1 * this . pdf . internal . pageSize . height * ( k - 1 ) + this . posY + this . margin [ 0 ]
1716
+ === = ===
1717
+ Math . max ( this . posX , this . margin [ 3 ] ) ,
1718
+ - 1 * previousPageHeightSum + topMargin + this . ctx . prevPageLastElemOffset
1719
+ >>> > >>> 16499 ee4c73991f345d6adab1d68d2c52ab79d00
1689
1720
) ;
1690
1721
if ( isClip === false || k === 0 ) {
1691
1722
drawPaths . call ( this , rule , isClip ) ;
@@ -2024,28 +2055,44 @@ import { console } from "../libs/console.js";
2024
2055
sortPages ( pages ) ;
2025
2056
2026
2057
var clipPath , oldSize , oldLineWidth ;
2027
- if ( this . autoPaging === true ) {
2058
+ if ( this . autoPaging ) {
2028
2059
var min = pages [ 0 ] ;
2029
2060
var max = pages [ pages . length - 1 ] ;
2030
2061
for ( var i = min ; i < max + 1 ; i ++ ) {
2031
2062
this . pdf . setPage ( i ) ;
2032
2063
2064
+ var topMargin = ( i === min ? Math . max ( this . posY , this . margin [ 0 ] ) : this . margin [ 0 ] ) ;
2065
+ var firstPageHeight = this . pdf . internal . pageSize . height - Math . max ( this . posY , this . margin [ 0 ] ) - this . margin [ 2 ] ;
2066
+ var pageHeightMinusMargin = this . pdf . internal . pageSize . height - this . margin [ 2 ] ;
2067
+ var pageWidthMinusMargin = this . pdf . internal . pageSize . width - this . margin [ 1 ] ;
2068
+ var previousPageHeightSum = i === 1 ? 0 : firstPageHeight + ( i - 2 ) * pageHeightMinusMargin ;
2069
+
2033
2070
if ( this . ctx . clip_path . length !== 0 ) {
2034
2071
var tmpPaths = this . path ;
2035
2072
clipPath = JSON . parse ( JSON . stringify ( this . ctx . clip_path ) ) ;
2036
2073
this . path = pathPositionRedo (
2037
2074
clipPath ,
2075
+ < << << << HEAD
2038
2076
this . posX + this . margin [ 3 ] ,
2039
2077
- 1 * this . pdf . internal . pageSize . height * ( i - 1 ) + this . posY + this . margin [ 0 ]
2078
+ === = ===
2079
+ Math . max ( this . posX , this . margin [ 3 ] ) ,
2080
+ - 1 * previousPageHeightSum + topMargin + this . ctx . prevPageLastElemOffset
2081
+ >>> > >>> 16499 ee4c73991f345d6adab1d68d2c52ab79d00
2040
2082
) ;
2041
2083
drawPaths . call ( this , "fill" , true ) ;
2042
2084
this . path = tmpPaths ;
2043
2085
}
2044
2086
var tmpRect = JSON . parse ( JSON . stringify ( textRect ) ) ;
2045
2087
tmpRect = pathPositionRedo (
2046
2088
[ tmpRect ] ,
2089
+ < << << << HEAD
2047
2090
this . posX + this . margin [ 3 ] ,
2048
2091
- 1 * this . pdf . internal . pageSize . height * ( i - 1 ) + this . posY + this . margin [ 0 ]
2092
+ === = ===
2093
+ Math . max ( this . posX , this . margin [ 3 ] ) ,
2094
+ - 1 * previousPageHeightSum + topMargin + this . ctx . prevPageLastElemOffset
2095
+ >>> > >>> 16499 ee4c73991f345d6adab1d68d2c52ab79d00
2049
2096
) [ 0 ] ;
2050
2097
2051
2098
if ( options . scale >= 0.01 ) {
@@ -2054,12 +2101,24 @@ import { console } from "../libs/console.js";
2054
2101
oldLineWidth = this . lineWidth ;
2055
2102
this . lineWidth = oldLineWidth * options . scale ;
2056
2103
}
2057
- this . pdf . text ( options . text , tmpRect . x , tmpRect . y , {
2058
- angle : options . angle ,
2059
- align : textAlign ,
2060
- renderingMode : options . renderingMode ,
2061
- maxWidth : options . maxWidth
2062
- } ) ;
2104
+
2105
+ if ( tmpRect . y <= pageHeightMinusMargin ) {
2106
+ if ( tmpRect . y - tmpRect . h >= 0 && tmpRect . x <= pageWidthMinusMargin ) {
2107
+ this . pdf . text ( options . text , tmpRect . x , tmpRect . y , {
2108
+ angle : options . angle ,
2109
+ align : textAlign ,
2110
+ renderingMode : options . renderingMode ,
2111
+ maxWidth : options . maxWidth || pageWidthMinusMargin - tmpRect . x ,
2112
+ renderMaxWidthOverflow : false
2113
+ } ) ;
2114
+ }
2115
+ } else {
2116
+ // This text is the last element of the page, but it got cut off due to the margin
2117
+ // so we render it in the next page
2118
+
2119
+ // As a result, all other elements have their y offset increased
2120
+ this . ctx . prevPageLastElemOffset += pageHeightMinusMargin - tmpRect . y + tmpRect . h ;
2121
+ }
2063
2122
2064
2123
if ( options . scale >= 0.01 ) {
2065
2124
this . pdf . setFontSize ( oldSize ) ;
@@ -2073,7 +2132,11 @@ import { console } from "../libs/console.js";
2073
2132
oldLineWidth = this . lineWidth ;
2074
2133
this . lineWidth = oldLineWidth * options . scale ;
2075
2134
}
2135
+ < << << << HEAD
2076
2136
this . pdf . text ( options . text , pt . x + this . posX + this . margin [ 3 ] , pt . y + this . posY , {
2137
+ === === =
2138
+ this . pdf . text ( options . text , pt . x + Math . max ( this . posX , this . margin [ 3 ] ) , pt . y + this . posY , {
2139
+ >>> >>> > 16499 ee4c73991f345d6adab1d68d2c52ab79d00
2077
2140
angle : options . angle ,
2078
2141
align : textAlign ,
2079
2142
renderingMode : options . renderingMode ,
0 commit comments