Skip to content

Commit 6d8fe86

Browse files
committed
release first basic version
1 parent b856b81 commit 6d8fe86

File tree

3 files changed

+93
-36
lines changed

3 files changed

+93
-36
lines changed

examples/formating.jrxml

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@
7373
<textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
7474
</textField>
7575
</band>
76-
<band height="124">
77-
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
78-
<textField>
79-
<reportElement mode="Opaque" x="0" y="0" width="141" height="124" backcolor="#E6FF05" uuid="8a90a4de-b55c-46cd-a546-71954ee5b2cf"/>
76+
<band height="106">
77+
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.spreadsheet.SpreadsheetLayout"/>
78+
<textField textAdjust="StretchHeight">
79+
<reportElement mode="Opaque" x="0" y="0" width="141" height="106" backcolor="#E6FF05" uuid="8a90a4de-b55c-46cd-a546-71954ee5b2cf"/>
8080
<box>
8181
<pen lineWidth="2.0" lineColor="#2205FF"/>
8282
<topPen lineWidth="2.0" lineStyle="Solid" lineColor="#2205FF"/>
@@ -90,7 +90,7 @@
9090
<textFieldExpression><![CDATA[$F{description}+$F{description}]]></textFieldExpression>
9191
</textField>
9292
<textField>
93-
<reportElement mode="Opaque" x="141" y="0" width="138" height="124" backcolor="#A6FFB6" uuid="7d3b6a51-7bda-403d-86bf-7b870ee6a9e9"/>
93+
<reportElement mode="Opaque" x="141" y="0" width="138" height="106" backcolor="#A6FFB6" uuid="7d3b6a51-7bda-403d-86bf-7b870ee6a9e9"/>
9494
<box>
9595
<pen lineWidth="3.75" lineStyle="Solid"/>
9696
<topPen lineWidth="2.75" lineStyle="Solid" lineColor="#FA232A"/>
@@ -104,7 +104,7 @@
104104
<textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
105105
</textField>
106106
<textField>
107-
<reportElement mode="Opaque" x="279" y="0" width="138" height="124" backcolor="#FF99FD" uuid="5ea1f238-24ca-49e7-89e0-48884e9e8d30"/>
107+
<reportElement mode="Opaque" x="279" y="0" width="138" height="106" backcolor="#FF99FD" uuid="5ea1f238-24ca-49e7-89e0-48884e9e8d30"/>
108108
<box>
109109
<pen lineWidth="1.75" lineStyle="Dotted"/>
110110
<topPen lineWidth="4.0" lineStyle="Solid" lineColor="#0505FF"/>
@@ -118,7 +118,7 @@
118118
<textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
119119
</textField>
120120
<textField>
121-
<reportElement mode="Opaque" x="417" y="0" width="138" height="124" backcolor="#52FFFF" uuid="78f3963f-fcc6-4a7b-a36d-e8329198770d"/>
121+
<reportElement mode="Opaque" x="417" y="0" width="138" height="106" backcolor="#52FFFF" uuid="78f3963f-fcc6-4a7b-a36d-e8329198770d"/>
122122
<box>
123123
<pen lineWidth="3.75" lineStyle="Solid"/>
124124
<topPen lineWidth="2.75" lineStyle="Dotted" lineColor="#FA232A"/>
@@ -154,7 +154,7 @@
154154
</ellipse>
155155
</frame>
156156
<rectangle radius="0">
157-
<reportElement mode="Opaque" x="210" y="20" width="100" height="50" backcolor="#FCE405" uuid="33106a8d-b90f-49c9-aef6-dc9e51fd871c"/>
157+
<reportElement mode="Opaque" x="210" y="8" width="100" height="50" backcolor="#FCE405" uuid="33106a8d-b90f-49c9-aef6-dc9e51fd871c"/>
158158
<graphicElement>
159159
<pen lineWidth="3.0" lineColor="#F70AFF"/>
160160
</graphicElement>

examples/formating.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function getS3($a)
1111

1212
$data = [];
1313
$faker = Faker\Factory::create('en_US');
14-
for($i=0;$i<10;$i++)
14+
for($i=0;$i<20;$i++)
1515
{
1616
$tmp=[
1717
'fullname' => $faker->name(),

src/phpjasperxml/Exports/Pdf.php

+84-27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class Pdf extends TCPDF implements ExportInterface
1212
{
1313
use \Simitsdk\phpjasperxml\Tools\Toolbox;
14+
protected array $currentrowpos=['rowno'=>-1];
1415
protected array $pagesettings=[];
1516
protected array $bands=[];
1617
protected string $lastdetailband='';
@@ -36,6 +37,7 @@ class Pdf extends TCPDF implements ExportInterface
3637
protected $longtextrepeatcount = 0 ;
3738
protected $parentobj = null;
3839
protected $drawtarget = null;
40+
protected $offsetby=0;
3941
public function __construct($prop)
4042
{
4143
$this->pagesettings=$prop;
@@ -611,6 +613,9 @@ public function draw_staticText(string $uuid,array $prop,bool $isTextField=false
611613
$h=$prop['height'];
612614
$x=$this->GetX();
613615
$y=$this->GetY();
616+
$beginingX=$x;
617+
$beginingY=$y;
618+
$beginingPage =$this->PageNo();
614619
$target = $this->drawtarget;
615620
$forecolor = $this->convertColorStrToRGB($prop['forecolor']??'');
616621
$target->SetTextColor($forecolor["r"],$forecolor["g"],$forecolor["b"]);
@@ -739,7 +744,7 @@ public function draw_staticText(string $uuid,array $prop,bool $isTextField=false
739744
}
740745
$stretchtype=0;
741746
$limitY = $this->islastrow ? $this->limitY_last: $this->limitY;
742-
$estimateline = $this->estimateHeight($w,$finaltxt);
747+
743748

744749
if($textAdjust=='StretchHeight')
745750
{
@@ -760,24 +765,63 @@ public function draw_staticText(string $uuid,array $prop,bool $isTextField=false
760765
$allowscale=false;
761766
}
762767

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)
773791
// {
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;
775814
// }
815+
816+
if($newY > $target->lastBandEndY)
817+
{
818+
$target->lastBandEndY = (int) $newY;
819+
// $this->SetY($newY);
820+
}
776821

777-
//$totalline
778-
779-
$balancetxtlength = strlen($this->balancetext);
780822

823+
// $target->Line($x,$y,$x+$w,$newY);
824+
$balancetxtlength = strlen($target->balancetext);
781825

782826
// if($textAdjust=='StretchHeight' && $balancetxtlength)
783827
// {
@@ -786,18 +830,14 @@ public function draw_staticText(string $uuid,array $prop,bool $isTextField=false
786830
// $this->console("maxheight = $maxheight, balance txt = '$this->balancetext'");
787831
// }
788832

789-
$target->StopTransform();
790-
$newY=$this->GetY();
791-
if($newY > $this->lastBandEndY)
792-
{
793-
$this->lastBandEndY = (int) $newY;
794-
}
833+
// $newY=$this->GetY();
834+
795835

796836
// $balancetxtlength=0;
797837
// $allowscale=false;
798838
if($balancetxtlength > 0 && $allowscale==true)
799839
{
800-
$this->longtextrepeatcount++;
840+
// $this->longtextrepeatcount++;
801841
$prop['textFieldExpression'] =$this->balancetext;
802842
// // $this->AddPage();
803843
// $this->console("Print balancetext $this->longtextrepeatcount : $this->balancetext");
@@ -813,7 +853,10 @@ public function draw_staticText(string $uuid,array $prop,bool $isTextField=false
813853

814854
$this->SetXY($x,$this->lastBandEndY);
815855
$this->draw_staticText($uuid,$prop,$isTextField,$callback);
856+
$this->setPage($beginingPage);
857+
// $this->SetXY($beginingX,$beginingY);
816858
}
859+
817860
}
818861
public function setParentObj($parentobj)
819862
{
@@ -995,6 +1038,7 @@ public function prepareBand(string $bandname, mixed $callback=null):array
9951038
{
9961039

9971040
$offsets=[];
1041+
9981042
$this->lastBand=$bandname;
9991043

10001044
if(str_contains($bandname,'detail'))
@@ -1083,6 +1127,21 @@ public function prepareBand(string $bandname, mixed $callback=null):array
10831127
$this->lastBandEndY=$offsety+$height;;
10841128
$this->bands[$bandname]['endY']=$this->lastBandEndY;
10851129
$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+
10861145
// echo "\n Print band($pageno) --$this->printbandcount $bandname, column: $this->columnno, $offsetx:$offsety, height:$height = endY = $this->lastBandEndY \n";
10871146
return $offsets;
10881147

@@ -1410,8 +1469,8 @@ protected function convertToLink(string $text='',string $link='')
14101469

14111470
public function estimateHeight(mixed $w,mixed $txt)
14121471
{
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 = '');
14151474
}
14161475

14171476

@@ -1520,9 +1579,7 @@ public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $st
15201579
$last_i++;
15211580

15221581
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
15261583
break;
15271584
}
15281585
//Get the current character

0 commit comments

Comments
 (0)