Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG-GRAVITYPDF.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ New features
* **CSS styling.** Form fields take their CSS colour, background and border. Static fields draw them, and active fields use the border's width and style. [#442] [#469]
* **Static list boxes.** A static list box is drawn as rows of options, with the selected rows highlighted. [#446]

### Paged media

* **Side margins on `:first`, `:left` and `:right` pages.** The `:first`, `:left` and `:right` pages of an `@page` rule, named or not, can set `margin-left` and `margin-right`. Text flowing from page to page is set in the page area of each page, and columns are laid out across it. A side margin on a pseudo page belongs to that side of the physical page, so it is not mirrored. [#476] [#510]

Performance
-----------

Expand Down Expand Up @@ -669,6 +673,7 @@ These changes do not change output.
[#471]: https://github.com/GravityPDF/mpdf/pull/471
[#474]: https://github.com/GravityPDF/mpdf/issues/474
[#475]: https://github.com/GravityPDF/mpdf/issues/475
[#476]: https://github.com/GravityPDF/mpdf/issues/476
[#482]: https://github.com/GravityPDF/mpdf/issues/482
[#485]: https://github.com/GravityPDF/mpdf/pull/485
[#486]: https://github.com/GravityPDF/mpdf/pull/486
Expand All @@ -685,6 +690,7 @@ These changes do not change output.
[#503]: https://github.com/GravityPDF/mpdf/pull/503
[#505]: https://github.com/GravityPDF/mpdf/pull/505
[#507]: https://github.com/GravityPDF/mpdf/pull/507
[#510]: https://github.com/GravityPDF/mpdf/pull/510
[#512]: https://github.com/GravityPDF/mpdf/pull/512
[#514]: https://github.com/GravityPDF/mpdf/pull/514
[#515]: https://github.com/GravityPDF/mpdf/pull/515
Expand Down
65 changes: 65 additions & 0 deletions src/CssManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,69 @@ public function getBorderDominance($side)
{
return $this->cssMerger->getBorderDominance($side);
}

/**
* Whether a :first, :left or :right rule of the plain @page rule, or of the named page, sets a side margin
*
* @param string|null $name The named page, or '' or null for none
* @return bool
*/
public function pseudoPagesSetSideMargins($name)
{
$prefixes = ['@PAGE>>'];
if ($name) {
$prefixes[] = '@PAGE>>NAMED>>' . strtoupper($name) . '>>';
}

foreach ($prefixes as $prefix) {
foreach (['FIRST', 'LEFT', 'RIGHT'] as $pseudo) {
$rule = $prefix . 'PSEUDO>>' . $pseudo;
if (isset($this->CSS[$rule]['MARGIN-LEFT']) || isset($this->CSS[$rule]['MARGIN-RIGHT'])) {
return true;
}
}
}

return false;
}

/**
* The properties the :right, :left and :first rules under an @page rule add to the page, less the sheet size
*
* Their side margins are physical, not inner and outer, so on an even page they are handed over swapped for
* Mpdf::pageSideMargins() to swap back.
*
* @param string $prefix The key of the @page rule in the style sheet, up to its pseudo pages
* @param string $side 'R' or 'L'
* @param bool $first Whether this is the first page
* @param string $oddEven 'E' for an even page when margins are mirrored, else 'O'
* @return array
*/
public function pseudoPageProperties($prefix, $side, $first, $oddEven)
{
$properties = [];
foreach (['RIGHT' => $side == 'R', 'LEFT' => $side == 'L', 'FIRST' => $first] as $pseudo => $applies) {
if (!$applies || !isset($this->CSS[$prefix . 'PSEUDO>>' . $pseudo])) {
continue;
}

$rule = $this->CSS[$prefix . 'PSEUDO>>' . $pseudo];
unset($rule['SIZE'], $rule['SHEET-SIZE']);

if ($oddEven === 'E') {
$physical = $rule;
unset($rule['MARGIN-LEFT'], $rule['MARGIN-RIGHT']);
if (isset($physical['MARGIN-LEFT'])) {
$rule['MARGIN-RIGHT'] = $physical['MARGIN-LEFT'];
}
if (isset($physical['MARGIN-RIGHT'])) {
$rule['MARGIN-LEFT'] = $physical['MARGIN-RIGHT'];
}
}

$properties = array_merge($properties, $rule);
}

return $properties;
}
}
Loading
Loading