Skip to content

Commit

Permalink
Fixed #17
Browse files Browse the repository at this point in the history
Fixed a bug in the write method.
Added tests for the write method.
  • Loading branch information
scholz-timo committed Mar 6, 2019
1 parent 5fe0e03 commit 70f6087
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Modules/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,21 @@ public function write($height, $text, $link, $encoding = 'UTF-16BE')
$maxWidth = ($width - 2 * $converter->toPt($margin->getCell()));
if ($text !== '') {
foreach (StaticHelper::getLines($text, $maxWidth, $font->getNewFont(), $font->getNewFontSize()) as $line) {
$lines[] = [true, $line[1], $width];
$lines[] = [$line[0], $line[1], $width];
}
}

$lastLine = array_pop($lines);
foreach ($lines as $line) {
$this->cell($line[2], $height, $line[1], 0, $line[0] ? 2 : 1, '', false, $link, 'UTF-16BE');
$this->cell($line[2], $height, $line[1], 0, 1, '', false, $link, 'UTF-16BE');
}

$this->cell(
$this->getStringWidth($lastLine[1], 'UTF-16BE'),
$height,
$lastLine[1],
0,
0,
$lastLine[0] ? 1 : 0,
'',
false,
$link,
Expand Down
39 changes: 38 additions & 1 deletion tests/visual/SetaFpdf/Single/WriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ public function testWrite()
$proxy->Write(2, 'Da kommt ein sehr langer text und ich weiss nicht mehr wie sich dieses ding verhaelt...');
$proxy->Write(2, 'Da kommt ein sehr langer text und ich weiss nicht mehr wie sich dieses ding verhaelt...');

$this->assertProxySame($proxy, 4);
$proxy->AddPage();


$proxy->Write(2, 'Da kommt ein sehr langer text und ich weiss nicht mehr wie sich dieses ding verhaelt...' . "\n");
$proxy->Write(2, 'Da kommt ein sehr langer text und ich weiss nicht mehr wie sich dieses ding verhaelt...' . "\n");
$proxy->Write(2, 'Da kommt ein sehr langer text und ich weiss nicht mehr wie sich dieses ding verhaelt...' . "\n");
$proxy->Write(2, 'Da kommt ein sehr langer text und ich weiss nicht mehr wie sich dieses ding verhaelt...' . "\n");
$proxy->Write(2, 'Da kommt ein sehr langer text und ich weiss nicht mehr wie sich dieses ding verhaelt...' . "\n");

$this->assertProxySame($proxy, 5.3);
}

public function testWriteWithLineBreak()
Expand Down Expand Up @@ -66,4 +75,32 @@ public function testWriteEmpty()

$proxy->Write(6, '');
}

public function testWriteWithNewLinesSimple()
{
$proxy = $this->getProxy('P', 'pt', 'A4');

$proxy->SetFont('arial');

$proxy->AddPage();
$proxy->Write(8, "A\n");
$proxy->Write(8, "B");


$proxy->AddPage();

$proxy->Write(2, 'A simple test');
$proxy->Write(2, ".\n\nBest regards,\n\nTest Team");
//
$proxy->AddPage();

$proxy->Write(0, 'A test.');
$proxy->Write(0, "\n");
$proxy->Write(0, 'Another test.');

$proxy->AddPage();
$proxy->Write(10, "\nBreaking with the cooking grandma, they have very impressive quality. More cookies is not even \n considered as an option, because the cookies are great.");

$this->assertProxySame($proxy, 1.28, 72);
}
}

0 comments on commit 70f6087

Please sign in to comment.