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
3 changes: 3 additions & 0 deletions CHANGELOG-GRAVITYPDF.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ Bugfixes
* Arabic in an SVG was not given an Arabic font. [#281]
* An RGB image converted to CMYK truncated its inks, so full ink fell short of 255. [#349] [#354]
* An image's `/SMask` pointed at whichever object came before it, which is only its mask if nothing was added in between. An image and its soft mask are now registered together. [#373]
* A `<textcircle>` with no `font-size` from its tag or the CSS raised three `Undefined array key "fontsize"` warnings. It is now drawn at the size of the text around it, as though that size were set on it. [#645] [#678]

### Forms

Expand Down Expand Up @@ -935,3 +936,5 @@ These changes do not change output.
[#543]: https://github.com/GravityPDF/mpdf/issues/543
[#656]: https://github.com/GravityPDF/mpdf/pull/656
[#654]: https://github.com/GravityPDF/mpdf/pull/654
[#645]: https://github.com/GravityPDF/mpdf/issues/645
[#678]: https://github.com/GravityPDF/mpdf/pull/678
1 change: 1 addition & 0 deletions src/Tag/TextCircle.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function open($attr, &$ahtml, &$ihtml)
$objattr['visibility'] = $v;
}
}
$objattr['fontsize'] = $this->mpdf->FontSizePt;
if (isset($properties['FONT-SIZE'])) {
if (strtolower($properties['FONT-SIZE']) === 'auto') {
if ($objattr['top-text'] && $objattr['bottom-text']) {
Expand Down
66 changes: 66 additions & 0 deletions tests/Mpdf/TextCircleFontSizeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Mpdf;

/**
* A text circle that neither its tag nor the CSS gives a font-size is drawn at the size of the text around it, as
* though that size had been set on it, rather than raising warnings over the size it was never given
*/
class TextCircleFontSizeTest extends \Yoast\PHPUnitPolyfills\TestCases\TestCase
{

use PageStreams;

/**
* @dataProvider providerContexts
*
* @param string $mode A CssMode constant
* @param string $html The document, with {style} where the text circle's style attribute goes
* @param string $size The size around the text circle, as a Tf operator writes it
*/
public function testATextCircleWithoutAFontSizeDrawsAtTheSizeAroundIt($mode, $html, $size)
{
$pages = $this->drawnPages($mode, $html, '');
$this->assertStringContainsString(' ' . $size . ' Tf', $pages[0]);
$this->assertSame($this->drawnPages($mode, $html, ' style="font-size: ' . $size . 'pt"'), $pages);
}

/**
* Draw the document, asserting it raises nothing, and hand back its page content streams
*
* @param string $mode A CssMode constant
* @param string $html The document, with {style} where the text circle's style attribute goes
* @param string $style What goes in place of {style}
*
* @return string[]
*/
private function drawnPages($mode, $html, $style)
{
$pdf = $this->assertDrawsSilently(function (Mpdf $mpdf) use ($html, $style) {
$mpdf->WriteHTML(str_replace('{style}', $style, $html));
}, ['cssMode' => $mode]);

return $this->pages($pdf);
}

/**
* @return array[] Each CSS mode with a text circle at the top of the document, in a paragraph and in a table cell
*/
public function providerContexts()
{
$contexts = [
'document' => ['<textcircle r="30mm" top-text="Top" bottom-text="Bottom"{style} />', '11.000'],
'paragraph' => ['<p style="font-size: 14pt"><textcircle r="30mm" top-text="Top"{style} /></p>', '14.000'],
'table cell' => ['<table><tr><td style="font-size: 9pt"><textcircle r="10mm" top-text="Top"{style} /></td></tr></table>', '9.000'],
];

$cases = [];
foreach ([CssMode::STANDARD, CssMode::LEGACY] as $mode) {
foreach ($contexts as $name => $context) {
$cases[$mode . ', ' . $name] = array_merge([$mode], $context);
}
}

return $cases;
}
}