11
11
class Pdf extends TCPDF implements ExportInterface
12
12
{
13
13
use \Simitsdk \phpjasperxml \Tools \Toolbox;
14
+ protected array $ currentrowpos =['rowno ' =>-1 ];
14
15
protected array $ pagesettings =[];
15
16
protected array $ bands =[];
16
17
protected string $ lastdetailband ='' ;
@@ -36,6 +37,7 @@ class Pdf extends TCPDF implements ExportInterface
36
37
protected $ longtextrepeatcount = 0 ;
37
38
protected $ parentobj = null ;
38
39
protected $ drawtarget = null ;
40
+ protected $ offsetby =0 ;
39
41
public function __construct ($ prop )
40
42
{
41
43
$ this ->pagesettings =$ prop ;
@@ -611,6 +613,9 @@ public function draw_staticText(string $uuid,array $prop,bool $isTextField=false
611
613
$ h =$ prop ['height ' ];
612
614
$ x =$ this ->GetX ();
613
615
$ y =$ this ->GetY ();
616
+ $ beginingX =$ x ;
617
+ $ beginingY =$ y ;
618
+ $ beginingPage =$ this ->PageNo ();
614
619
$ target = $ this ->drawtarget ;
615
620
$ forecolor = $ this ->convertColorStrToRGB ($ prop ['forecolor ' ]??'' );
616
621
$ target ->SetTextColor ($ forecolor ["r " ],$ forecolor ["g " ],$ forecolor ["b " ]);
@@ -739,7 +744,7 @@ public function draw_staticText(string $uuid,array $prop,bool $isTextField=false
739
744
}
740
745
$ stretchtype =0 ;
741
746
$ limitY = $ this ->islastrow ? $ this ->limitY_last : $ this ->limitY ;
742
- $ estimateline = $ this -> estimateHeight ( $ w , $ finaltxt );
747
+
743
748
744
749
if ($ textAdjust =='StretchHeight ' )
745
750
{
@@ -760,24 +765,63 @@ public function draw_staticText(string $uuid,array $prop,bool $isTextField=false
760
765
$ allowscale =false ;
761
766
}
762
767
763
- // if($textAdjust=='StretchHeight')
764
- // {
765
- // $this->console("print $this->lastBand, UUID : $uuid, length ".strlen(($text)).", h:$h, max height: $maxheight ");
766
- // $this->console($text);
767
- // }
768
- // if(!empty($this->parentobj))
769
- // {
770
- $ totalline = $ target ->MultiCell ($ w ,$ h ,$ finaltxt ,$ border ,$ halign ,$ fill ,0 ,$ x ,$ y ,true ,$ stretchtype ,$ ishtml ,true ,$ maxheight ,$ valign );
771
- // }
772
- // else
768
+ //dry run, get estimated $newY
769
+ // $target->startTransaction();
770
+ // $target->MultiCell($w,0,$finaltxt,$border,$halign,$fill,0,$x,$y,true,$stretchtype,$ishtml,true,$maxheight,$valign);
771
+ // $newY=$target->GetY();
772
+ // $target = $target->rollbackTransaction();
773
+ if (!$ ishtml )
774
+ {
775
+ $ this ->offsetby += 10 ;
776
+ $ estimateHeight = max ($ target ->estimateHeight ($ w ,$ finaltxt ),$ h );
777
+ $ newY = $ y +$ estimateHeight ;
778
+ // $target->Line(0+$this->offsetby,$y,10+$this->offsetby,$newY);
779
+
780
+ }
781
+ else {
782
+ $ estimateHeight = $ h ;
783
+ }
784
+ // $newY= $y+$estimateHeight;
785
+ $ target ->MultiCell ($ w ,$ h ,$ finaltxt ,$ border ,$ halign ,$ fill ,0 ,$ x ,$ y ,true ,$ stretchtype ,$ ishtml ,true ,$ maxheight ,$ valign );
786
+ $ target ->StopTransform ();
787
+ $ newY = $ beginingY +$ estimateHeight ;
788
+
789
+
790
+ // switch($rotation)
773
791
// {
774
- // $totalline = $this->MultiCell($w,$h,$finaltxt,$border,$halign,$fill,2,$x,$y,true,$stretchtype,$ishtml,true,$maxheight,$valign);
792
+ // case 'Left':
793
+ // $y+=$h;
794
+ // $tmpw=$w;
795
+ // $w=$h;
796
+ // $h=$tmpw;
797
+ // $target->SetXY($x,$y);
798
+ // break;
799
+ // case 'Right':
800
+ // $x+=$w;
801
+ // $tmpw=$w;
802
+ // $w=$h;
803
+ // $h=$tmpw;
804
+ // $this->SetXY($x,$y);
805
+ // break;
806
+ // case 'UpsideDown':
807
+ // $x+=$w;
808
+ // $y+=$h;
809
+ // $target->SetXY($x,$y);
810
+ // $target->Rotate(180);
811
+ // break;
812
+ // default:
813
+ // break;
775
814
// }
815
+
816
+ if ($ newY > $ target ->lastBandEndY )
817
+ {
818
+ $ target ->lastBandEndY = (int ) $ newY ;
819
+ // $this->SetY($newY);
820
+ }
776
821
777
- //$totalline
778
-
779
- $ balancetxtlength = strlen ($ this ->balancetext );
780
822
823
+ // $target->Line($x,$y,$x+$w,$newY);
824
+ $ balancetxtlength = strlen ($ target ->balancetext );
781
825
782
826
// if($textAdjust=='StretchHeight' && $balancetxtlength)
783
827
// {
@@ -786,18 +830,14 @@ public function draw_staticText(string $uuid,array $prop,bool $isTextField=false
786
830
// $this->console("maxheight = $maxheight, balance txt = '$this->balancetext'");
787
831
// }
788
832
789
- $ target ->StopTransform ();
790
- $ newY =$ this ->GetY ();
791
- if ($ newY > $ this ->lastBandEndY )
792
- {
793
- $ this ->lastBandEndY = (int ) $ newY ;
794
- }
833
+ // $newY=$this->GetY();
834
+
795
835
796
836
// $balancetxtlength=0;
797
837
// $allowscale=false;
798
838
if ($ balancetxtlength > 0 && $ allowscale ==true )
799
839
{
800
- $ this ->longtextrepeatcount ++;
840
+ // $this->longtextrepeatcount++;
801
841
$ prop ['textFieldExpression ' ] =$ this ->balancetext ;
802
842
// // $this->AddPage();
803
843
// $this->console("Print balancetext $this->longtextrepeatcount : $this->balancetext");
@@ -813,7 +853,10 @@ public function draw_staticText(string $uuid,array $prop,bool $isTextField=false
813
853
814
854
$ this ->SetXY ($ x ,$ this ->lastBandEndY );
815
855
$ this ->draw_staticText ($ uuid ,$ prop ,$ isTextField ,$ callback );
856
+ $ this ->setPage ($ beginingPage );
857
+ // $this->SetXY($beginingX,$beginingY);
816
858
}
859
+
817
860
}
818
861
public function setParentObj ($ parentobj )
819
862
{
@@ -995,6 +1038,7 @@ public function prepareBand(string $bandname, mixed $callback=null):array
995
1038
{
996
1039
997
1040
$ offsets =[];
1041
+
998
1042
$ this ->lastBand =$ bandname ;
999
1043
1000
1044
if (str_contains ($ bandname ,'detail ' ))
@@ -1083,6 +1127,21 @@ public function prepareBand(string $bandname, mixed $callback=null):array
1083
1127
$ this ->lastBandEndY =$ offsety +$ height ;;
1084
1128
$ this ->bands [$ bandname ]['endY ' ]=$ this ->lastBandEndY ;
1085
1129
$ pageno =$ this ->PageNo ();
1130
+
1131
+
1132
+ if ($ this ->currentrowpos ['rowno ' ]!=$ this ->currentRowNo )
1133
+ {
1134
+ $ this ->currentrowpos =[
1135
+ 'rowno ' =>$ this ->currentRowNo ,
1136
+ 'beginpage ' =>$ this ->PageNo (),
1137
+ 'beginx ' =>$ offsets ['x ' ],
1138
+ 'beginy ' =>$ offsets ['y ' ],
1139
+ 'endx ' =>$ offsets ['x ' ],
1140
+ 'endy ' =>$ offsety +$ height ,
1141
+ 'height ' =>$ height
1142
+ ];
1143
+ }
1144
+
1086
1145
// echo "\n Print band($pageno) --$this->printbandcount $bandname, column: $this->columnno, $offsetx:$offsety, height:$height = endY = $this->lastBandEndY \n";
1087
1146
return $ offsets ;
1088
1147
@@ -1410,8 +1469,8 @@ protected function convertToLink(string $text='',string $link='')
1410
1469
1411
1470
public function estimateHeight (mixed $ w ,mixed $ txt )
1412
1471
{
1413
- return $ this ->getNumLines ($ txt ,$ w );
1414
- // return $this->getStringHeight($w, $txt, $reseth = false, $autopadding = true, $cellMargin = '', $lineWidth = '');
1472
+ // return $this->getNumLines($txt,$w);
1473
+ return $ this ->getStringHeight ($ w , $ txt , $ reseth = false , $ autopadding = true , $ cellMargin = '' , $ lineWidth = '' );
1415
1474
}
1416
1475
1417
1476
@@ -1520,9 +1579,7 @@ public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $st
1520
1579
$ last_i ++;
1521
1580
1522
1581
if (($ maxh > 0 ) AND ($ this ->y > $ maxy ) ) {
1523
- $ this ->balancetext =TCPDF_FONTS ::UniArrSubString ($ uchars ,$ j ); //phpjasperxml code
1524
- // $this->console(" (maxh $maxh > 0) AND (this->y $this->y > $maxy maxy) ");
1525
- // $this->console(" write text, balance text (i=$i,j=$j,last_i=$last_i,nb=$nb,nl=$nl)= $this->balancetext");
1582
+ $ this ->balancetext =TCPDF_FONTS ::UniArrSubString ($ uchars ,$ j ); //phpjasperxml code
1526
1583
break ;
1527
1584
}
1528
1585
//Get the current character
0 commit comments