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
5 changes: 3 additions & 2 deletions src/Otl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5747,10 +5747,11 @@ public function splitOTLdata(&$cOTLdata, $OTLcutoffpos, $OTLrestartpos = '')

public function sliceOTLdata($OTLdata, $pos, $len)
{
// applyOTL() leaves OTLdata empty for a blank string, so every key here is optional
$newOTLdata = ['GPOSinfo' => [], 'char_data' => []];
$newOTLdata['group'] = substr($OTLdata['group'], $pos, $len);
$newOTLdata['group'] = isset($OTLdata['group']) ? substr($OTLdata['group'], $pos, $len) : '';

if ($OTLdata['GPOSinfo']) {
if (!empty($OTLdata['GPOSinfo'])) {
foreach ($OTLdata['GPOSinfo'] as $k => $val) {
if ($k >= $pos && $k < ($pos + $len)) {
$newOTLdata['GPOSinfo'][($k - $pos)] = $val;
Expand Down
32 changes: 32 additions & 0 deletions tests/Issues/Issue2158Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Issues;

class Issue2158Test extends \Yoast\PHPUnitPolyfills\TestCases\TestCase
{

public function testMultiCellWithEmptyString()
{
$mpdf = new \Mpdf\Mpdf(['default_font' => 'dejavusans']);
$mpdf->AddPage();
$mpdf->MultiCell(0, 5, '');

$output = $mpdf->OutputBinaryData();
$this->assertStringStartsWith('%PDF-', $output);

$mpdf->cleanup();
}

public function testMultiCellWithWhitespaceOnlyString()
{
$mpdf = new \Mpdf\Mpdf(['default_font' => 'dejavusans']);
$mpdf->AddPage();
$mpdf->MultiCell(0, 5, " \n ");

$output = $mpdf->OutputBinaryData();
$this->assertStringStartsWith('%PDF-', $output);

$mpdf->cleanup();
}

}
63 changes: 63 additions & 0 deletions tests/Mpdf/OtlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Mpdf;

use Mpdf\Fonts\FontCache;

class OtlTest extends \Yoast\PHPUnitPolyfills\TestCases\TestCase
{

/**
* @var \Mpdf\Otl
*/
private $otl;

/**
* @var \Mpdf\Mpdf
*/
private $mpdf;

protected function set_up()
{
parent::set_up();

$this->mpdf = new Mpdf(['mode' => 'c']);
$this->otl = new Otl($this->mpdf, new FontCache(new Cache(sys_get_temp_dir() . '/mpdf-otl-test')));
}

protected function tear_down()
{
parent::tear_down();

$this->mpdf->cleanup();
}

public function testSliceOfPopulatedData()
{
$OTLdata = [
'group' => 'SCCSC',
'GPOSinfo' => [1 => ['GPOSinfo'], 3 => ['other']],
'char_data' => [['bidi_class' => 0], ['bidi_class' => 1], ['bidi_class' => 2], ['bidi_class' => 3], ['bidi_class' => 4]],
];

$slice = $this->otl->sliceOTLdata($OTLdata, 1, 3);

$this->assertSame('CCS', $slice['group']);
$this->assertSame([0 => ['GPOSinfo'], 2 => ['other']], $slice['GPOSinfo']);
$this->assertCount(3, $slice['char_data']);
}

/**
* applyOTL() resets OTLdata to an empty array for a blank string, and MultiCell() slices
* whatever it is handed. See mpdf/mpdf#2158.
*/
public function testSliceOfEmptyDataReturnsAnEmptyStructure()
{
$slice = $this->otl->sliceOTLdata([], 0, 0);

$this->assertSame('', $slice['group']);
$this->assertSame([], $slice['GPOSinfo']);
$this->assertSame([], $slice['char_data']);
}

}
Loading