Skip to content

Commit e592d84

Browse files
committed
Readded pageBreakTrigger property, fixed page orientation
1 parent 87d42d6 commit e592d84

File tree

6 files changed

+56
-10
lines changed

6 files changed

+56
-10
lines changed

Diff for: src/Modules/Document.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,7 @@ public function addPage($orientation, $size, $rotation)
367367

368368
$widthPt = $this->manager->getConverter()->toPt($size[0]);
369369
$heightPt = $this->manager->getConverter()->toPt($size[1]);
370-
$sizePt = [
371-
0 => $widthPt,
372-
1 => $heightPt,
373-
'width' => $widthPt,
374-
'height' => $heightPt
375-
];
370+
$sizePt = [$widthPt, $heightPt];
376371

377372
$this->document->getCatalog()->getPages()->create($sizePt, $orientation);
378373
$this->rotation = $rotation;

Diff for: src/SetaFpdf.php

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* @property float|int $tMargin
2525
* @property float|int $rMargin
2626
* @property float|int $bMargin
27+
* @property float|int $pageBreakTrigger
2728
*/
2829
class SetaFpdf
2930
{
@@ -979,6 +980,10 @@ public function __get($name)
979980
return $this->manager->getMargin()->getRight();
980981
case 'bMargin':
981982
return $this->manager->getMargin()->getBottom();
983+
case 'pageBreakTrigger':
984+
case 'PageBreakTrigger': // allow both upper- and lower case
985+
$manager = $this->manager;
986+
return ($manager->getConverter()->fromPt($manager->getHeight()) - $manager->getMargin()->getBottom());
982987

983988
default:
984989
throw new \InvalidArgumentException(sprintf('Property "%s" cannot be accessed.', $name));

Diff for: tests/functional/SetaFpdf/FpdfProperties.php

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public function __get($name)
2727
return $this->rMargin;
2828
case 'bMargin':
2929
return $this->bMargin;
30+
case 'pageBreakTrigger':
31+
case 'PageBreakTrigger':
32+
return $this->PageBreakTrigger;
3033

3134
default:
3235
throw new \InvalidArgumentException(sprintf('Property "%s" cannot be accessed.', $name));

Diff for: tests/functional/SetaFpdf/PageValuesTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,15 @@ public function testPageHeight($orientation = 'P', $unit = 'mm', $size = 'A4')
6565
// asserts are done in the proxy
6666
$this->assertSame($height, $proxy->h);
6767
}
68+
69+
public function testDifferentOrienatations()
70+
{
71+
$proxy = $this->getProxy('P', 'pt', [100, 200]);
72+
$this->assertSame(100, $proxy->GetPageWidth());
73+
$this->assertSame(200, $proxy->GetPageHeight());
74+
75+
$proxy->AddPage('L');
76+
$this->assertSame(200, $proxy->GetPageWidth());
77+
$this->assertSame(100, $proxy->GetPageHeight());
78+
}
6879
}

Diff for: tests/functional/SetaFpdf/PropertiesTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,23 @@ public function testPageMargin()
8989
$proxy->SetAutoPageBreak(true, $bottom);
9090
$this->assertSame($bottom, $proxy->bMargin);
9191
}
92+
93+
public function testPageBreakTrigger()
94+
{
95+
$proxy = $this->getProxy('P', 'mm', [100, 200]);
96+
$proxy->SetAutoPageBreak(true, 10);
97+
98+
$this->assertSame(190., $proxy->pageBreakTrigger);
99+
100+
$proxy = $this->getProxy('P', 'pt', [100, 200]);
101+
$proxy->SetAutoPageBreak(true, 10);
102+
$this->assertSame(190, $proxy->pageBreakTrigger);
103+
104+
$proxy = $this->getProxy('P', 'cm', [100, 200]);
105+
$proxy->SetAutoPageBreak(true, 10);
106+
$this->assertSame(190., $proxy->pageBreakTrigger);
107+
108+
$proxy->AddPage('L');
109+
$this->assertSame(90., $proxy->pageBreakTrigger);
110+
}
92111
}

Diff for: tests/visual/SetaFpdf/Single/PageTest.php

+17-4
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function testAutoPageBreakSimple()
3535
$proxy->AddPage();
3636
$f();
3737

38-
$this->assertProxySame($proxy);
38+
$this->assertProxySame($proxy, VisualTestCase::TOLERANCE, 72);
3939
}
4040

4141
public function testAddPagesWithDefault()
4242
{
4343
$proxy = $this->getProxy('L', 'cm', 'A3');
4444
$proxy->AddPage();
4545
$proxy->AddPage();
46-
$this->assertProxySame($proxy);
46+
$this->assertProxySame($proxy, VisualTestCase::TOLERANCE, 72);
4747
}
4848

4949
public function testAddPagesWithOwnValueAndFallback()
@@ -52,7 +52,7 @@ public function testAddPagesWithOwnValueAndFallback()
5252
$proxy->AddPage();
5353
$proxy->AddPage('P', 'A5', 180);
5454
$proxy->AddPage(null, null, 0);
55-
$this->assertProxySame($proxy);
55+
$this->assertProxySame($proxy, VisualTestCase::TOLERANCE, 72);
5656
}
5757

5858
public function testAddPagesWithOwnSize()
@@ -63,6 +63,19 @@ public function testAddPagesWithOwnSize()
6363
$proxy->AddPage(null, null, 0);
6464
$proxy->AddPage('P', [10, 15], 90);
6565
$proxy->AddPage(null, [100, 25], 0);
66-
$this->assertProxySame($proxy);
66+
$this->assertProxySame($proxy, VisualTestCase::TOLERANCE, 72);
67+
}
68+
69+
public function testDifferentOrienatations()
70+
{
71+
$proxy = $this->getProxy('P', 'pt', [100, 200]);
72+
$proxy->AddPage();
73+
$proxy->SetDrawColor(255, 0, 0);
74+
$proxy->Rect(2, 2, $proxy->GetPageWidth() - 4, $proxy->GetPageHeight() - 4);
75+
76+
$proxy->AddPage('L');
77+
$proxy->SetDrawColor(255, 0, 0);
78+
$proxy->Rect(2, 2, $proxy->GetPageWidth() - 4, $proxy->GetPageHeight() - 4);
79+
$this->assertProxySame($proxy, VisualTestCase::TOLERANCE, 72);
6780
}
6881
}

0 commit comments

Comments
 (0)