Feature: Labelprint für Kistenetiketten hinzugefügt

This commit is contained in:
2025-10-27 12:14:44 +01:00
parent 43bc416554
commit 14bae6c9ef
1068 changed files with 229014 additions and 1807 deletions

View File

@@ -0,0 +1,214 @@
<?php
/**
* BufferTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfFont
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-font
*
* This file is part of tc-lib-pdf-font software library.
*/
namespace Test;
/**
* Buffer Test
*
* @since 2011-05-23
* @category Library
* @package PdfFont
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-font
*
* @SuppressWarnings("PHPMD.LongVariable")
*/
class BufferTest extends TestUtil
{
public function testStackMissingKey(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$stack->getFont('missing');
}
public function testStackMissingFontName(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$objnum = 1;
$stack->add($objnum, '');
}
public function testStackIFileMissing(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$objnum = 1;
$stack->add($objnum, 'something', '', '/missing/nothere.json');
}
public function testStackIFileNotJson(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$objnum = 1;
$stack->add($objnum, 'something', '', __DIR__ . '/StackTest.php');
}
public function testStackIFileWrongFormat(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$objnum = 1;
file_put_contents($this->getFontPath() . 'badformat.json', '{"bad":"format"}');
$stack->add($objnum, 'something', '', $this->getFontPath() . 'badformat.json');
}
public function testLoadDeafultWidthA(): void
{
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$objnum = 1;
file_put_contents($this->getFontPath() . 'test.json', '{"type":"Type1","cw":{"0":100}}');
$stack->add($objnum, 'test', '', $this->getFontPath() . 'test.json');
$font = $stack->getFont('test');
$this->assertEquals(600, $font['dw']);
}
public function testLoadDeafultWidthB(): void
{
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$objnum = 1;
file_put_contents($this->getFontPath() . 'test.json', '{"type":"Type1","cw":{"32":123}}');
$stack->add($objnum, 'test', '', $this->getFontPath() . 'test.json');
$font = $stack->getFont('test');
$this->assertEquals(123, $font['dw']);
}
public function testLoadDeafultWidthC(): void
{
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$objnum = 1;
file_put_contents(
$this->getFontPath() . 'test.json',
'{"type":"Type1","desc":{"MissingWidth":234},"cw":{"0":600}}'
);
$stack->add($objnum, 'test', '', $this->getFontPath() . 'test.json');
$font = $stack->getFont('test');
$this->assertEquals(234, $font['dw']);
}
public function testLoadWrongType(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$objnum = 1;
file_put_contents($this->getFontPath() . 'test.json', '{"type":"WRONG","cw":{"0":600}}');
$stack->add($objnum, 'test', '', $this->getFontPath() . 'test.json');
}
public function testLoadCidOnPdfa(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1, false, true, true);
$objnum = 1;
file_put_contents($this->getFontPath() . 'test.json', '{"type":"cidfont0","cw":{"0":600}}');
$stack->add($objnum, 'test', '', $this->getFontPath() . 'test.json', false);
}
public function testLoadArtificialStyles(): void
{
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$objnum = 1;
file_put_contents(
$this->getFontPath() . 'test.json',
'{"type":"Core","cw":{"0":600},"mode":{"bold":true,"italic":true}}'
);
$key = $stack->add($objnum, 'symbol', '', $this->getFontPath() . 'test.json');
$this->assertNotEmpty($key);
}
public function testBuffer(): void
{
$this->setupTest();
$indir = dirname(__DIR__) . '/util/vendor/tecnickcom/tc-font-mirror/';
$objnum = 1;
$stack = new \Com\Tecnick\Pdf\Font\Stack(1, false, true, false);
new \Com\Tecnick\Pdf\Font\Import($indir . 'pdfa/pfb/PDFASymbol.pfb', '', 'Type1', 'symbol');
$stack->add($objnum, 'pdfasymbol');
new \Com\Tecnick\Pdf\Font\Import($indir . 'core/Helvetica.afm');
$stack->add($objnum, 'helvetica');
new \Com\Tecnick\Pdf\Font\Import($indir . 'core/Helvetica-Bold.afm');
$stack->add($objnum, 'helvetica', 'B');
new \Com\Tecnick\Pdf\Font\Import($indir . 'core/Helvetica-BoldOblique.afm');
$stack->add($objnum, 'helveticaBI');
new \Com\Tecnick\Pdf\Font\Import($indir . 'core/Helvetica-Oblique.afm');
$stack->add($objnum, 'helvetica', 'I');
new \Com\Tecnick\Pdf\Font\Import($indir . 'freefont/FreeSans.ttf');
$stack->add($objnum, 'freesans', '');
new \Com\Tecnick\Pdf\Font\Import($indir . 'freefont/FreeSansBold.ttf');
$stack->add($objnum, 'freesans', 'B');
new \Com\Tecnick\Pdf\Font\Import($indir . 'freefont/FreeSansOblique.ttf');
$stack->add($objnum, 'freesans', 'I');
new \Com\Tecnick\Pdf\Font\Import($indir . 'freefont/FreeSansBoldOblique.ttf');
$stack->add($objnum, 'freesans', 'BIUDO', '', true);
$fontkey = $stack->add($objnum, 'freesans', 'BI', '', true);
$this->assertEquals('freesansBI', $fontkey);
$this->assertEquals(10, $objnum);
$this->assertCount(9, $stack->getFonts());
$this->assertCount(1, $stack->getEncDiffs());
$font = $stack->getFont('freesansB');
$this->assertNotEmpty($font);
$this->assertEquals('FreeSansBold', $font['name']);
$this->assertEquals('TrueTypeUnicode', $font['type']);
new \Com\Tecnick\Pdf\Font\Import($indir . 'core/ZapfDingbats.afm');
$stack->add($objnum, 'zapfdingbats', 'BIUDO');
$font = $stack->getFont('zapfdingbats');
$this->assertNotEmpty($font);
}
public function testBufferPdfa(): void
{
$this->setupTest();
$indir = dirname(__DIR__) . '/util/vendor/tecnickcom/tc-font-mirror/';
$objnum = 1;
$stack = new \Com\Tecnick\Pdf\Font\Stack(1, true, false, true);
new \Com\Tecnick\Pdf\Font\Import($indir . 'pdfa/pfb/PDFAHelveticaBoldOblique.pfb');
$stack->add($objnum, 'arial', 'BIUDO', '', true);
$font = $stack->getFont('pdfahelveticaBI');
$this->assertNotEmpty($font);
}
}

View File

@@ -0,0 +1,215 @@
<?php
/**
* ImportTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfFont
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-font
*
* This file is part of tc-lib-pdf-font software library.
*/
namespace Test;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* Import Test
*
* @since 2011-05-23
* @category Library
* @package PdfFont
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-font
*
* @SuppressWarnings("PHPMD.LongVariable")
*/
class ImportTest extends TestUtil
{
public function testImportForbiddenProtocol(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
new \Com\Tecnick\Pdf\Font\Import('phar://test.txt');
}
public function testImportParentDir(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
new \Com\Tecnick\Pdf\Font\Import('/tmp/something/../test.txt');
}
public function testImportEmptyName(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
new \Com\Tecnick\Pdf\Font\Import('');
}
public function testImportExist(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$fin = dirname(__DIR__) . '/util/vendor/tecnickcom/tc-font-mirror/core/Helvetica.afm';
$outdir = dirname(__DIR__) . '/target/tmptest/';
system('rm -rf ' . $outdir . ' && mkdir -p ' . $outdir);
new \Com\Tecnick\Pdf\Font\Import($fin, $outdir);
new \Com\Tecnick\Pdf\Font\Import($fin, $outdir);
}
public function testImportWrongFile(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
new \Com\Tecnick\Pdf\Font\Import(dirname(__DIR__) . '/util/vendor/tecnickcom/tc-font-mirror/core/Missing.afm');
}
public function testImportDefaultOutput(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
new \Com\Tecnick\Pdf\Font\Import(dirname(__DIR__) . '/util/vendor/tecnickcom/tc-font-mirror/core/Missing.afm');
}
public function testImportUnsupportedType(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$fin = dirname(__DIR__) . '/util/vendor/tecnickcom/tc-font-mirror/core/Helvetica.afm';
$outdir = dirname(__DIR__) . '/target/tmptest/core/';
system('rm -rf ' . $outdir . ' && mkdir -p ' . $outdir);
new \Com\Tecnick\Pdf\Font\Import($fin, $outdir, 'ERROR');
}
public function testImportUnsupportedOpenType(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$outdir = dirname(__DIR__) . '/target/tmptest/core/';
system('rm -rf ' . $outdir . ' && mkdir -p ' . $outdir);
file_put_contents($outdir . 'test.ttf', 'OTTO 1234');
new \Com\Tecnick\Pdf\Font\Import($outdir . 'test.ttf', $outdir);
}
#[DataProvider('importDataProvider')]
public function testImport(
string $fontdir,
string $font,
mixed $outname,
string $type = '',
string $encoding = ''
): void {
$indir = dirname(__DIR__) . '/util/vendor/tecnickcom/tc-font-mirror/' . $fontdir . '/';
$outdir = dirname(__DIR__) . '/target/tmptest/' . $fontdir . '/';
system('rm -rf ' . dirname(__DIR__) . '/target/tmptest/ && mkdir -p ' . $outdir);
$import = new \Com\Tecnick\Pdf\Font\Import($indir . $font, $outdir, $type, $encoding);
$this->assertEquals($outname, $import->getFontName());
$file = file_get_contents($outdir . $outname . '.json');
$this->assertNotFalse($file);
$json = json_decode($file, true, 512, JSON_THROW_ON_ERROR);
$this->assertNotNull($json);
$this->assertIsArray($json);
$this->assertArrayHasKey('type', $json);
$this->assertArrayHasKey('name', $json);
$this->assertArrayHasKey('up', $json);
$this->assertArrayHasKey('ut', $json);
$this->assertArrayHasKey('dw', $json);
$this->assertArrayHasKey('diff', $json);
$this->assertArrayHasKey('desc', $json);
$this->assertArrayHasKey('Flags', $json['desc']);
$metric = $import->getFontMetrics();
$this->assertEquals('[' . $metric['bbox'] . ']', $json['desc']['FontBBox']);
$this->assertEquals($metric['italicAngle'], $json['desc']['ItalicAngle']);
$this->assertEquals($metric['Ascent'], $json['desc']['Ascent']);
$this->assertEquals($metric['Descent'], $json['desc']['Descent']);
$this->assertEquals($metric['Leading'], $json['desc']['Leading']);
$this->assertEquals($metric['CapHeight'], $json['desc']['CapHeight']);
$this->assertEquals($metric['XHeight'], $json['desc']['XHeight']);
$this->assertEquals($metric['StemV'], $json['desc']['StemV']);
$this->assertEquals($metric['StemH'], $json['desc']['StemH']);
$this->assertEquals($metric['AvgWidth'], $json['desc']['AvgWidth']);
$this->assertEquals($metric['MaxWidth'], $json['desc']['MaxWidth']);
$this->assertEquals($metric['MissingWidth'], $json['desc']['MissingWidth']);
}
/**
* @return array<array<string>>
*/
public static function importDataProvider(): array
{
return [
['core', 'Courier.afm', 'courier'],
['core', 'Courier-Bold.afm', 'courierb'],
['core', 'Courier-BoldOblique.afm', 'courierbi'],
['core', 'Courier-Oblique.afm', 'courieri'],
['core', 'Helvetica.afm', 'helvetica'],
['core', 'Helvetica-Bold.afm', 'helveticab'],
['core', 'Helvetica-BoldOblique.afm', 'helveticabi'],
['core', 'Helvetica-Oblique.afm', 'helveticai'],
['core', 'Symbol.afm', 'symbol'],
['core', 'Times.afm', 'times'],
['core', 'Times-Bold.afm', 'timesb'],
['core', 'Times-BoldItalic.afm', 'timesbi'],
['core', 'Times-Italic.afm', 'timesi'],
['core', 'ZapfDingbats.afm', 'zapfdingbats'],
['pdfa/pfb', 'PDFACourierBoldOblique.pfb', 'pdfacourierbi', '', ''],
['pdfa/pfb', 'PDFACourierBold.pfb', 'pdfacourierb', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFACourierOblique.pfb', 'pdfacourieri', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFACourier.pfb', 'pdfacourier', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFAHelveticaBoldOblique.pfb', 'pdfahelveticabi', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFAHelveticaBold.pfb', 'pdfahelveticab', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFAHelveticaOblique.pfb', 'pdfahelveticai', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFAHelvetica.pfb', 'pdfahelvetica', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFASymbol.pfb', 'pdfasymbol', '', 'symbol'],
['pdfa/pfb', 'PDFATimesBoldItalic.pfb', 'pdfatimesbi', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFATimesBold.pfb', 'pdfatimesb', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFATimesItalic.pfb', 'pdfatimesi', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFATimes.pfb', 'pdfatimes', 'Type1', 'cp1252'],
['pdfa/pfb', 'PDFAZapfDingbats.pfb', 'pdfazapfdingbats'],
['freefont', 'FreeMonoBoldOblique.ttf', 'freemonobi'],
['freefont', 'FreeMonoBold.ttf', 'freemonob'],
['freefont', 'FreeMonoOblique.ttf', 'freemonoi'],
['freefont', 'FreeMono.ttf', 'freemono'],
['freefont', 'FreeSansBoldOblique.ttf', 'freesansbi'],
['freefont', 'FreeSansBold.ttf', 'freesansb'],
['freefont', 'FreeSansOblique.ttf', 'freesansi'],
['freefont', 'FreeSans.ttf', 'freesans'],
['freefont', 'FreeSerifBoldItalic.ttf', 'freeserifbi'],
['freefont', 'FreeSerifBold.ttf', 'freeserifb'],
['freefont', 'FreeSerifItalic.ttf', 'freeserifi'],
['freefont', 'FreeSerif.ttf', 'freeserif'],
['unifont', 'unifont.ttf', 'unifont'],
['cid0', 'cid0cs.ttf', 'cid0cs', 'CID0CS'],
['cid0', 'cid0ct.ttf', 'cid0ct', 'CID0CT'],
['cid0', 'cid0jp.ttf', 'cid0jp', 'CID0JP'],
['cid0', 'cid0kr.ttf', 'cid0kr', 'CID0KR'],
['dejavu/ttf', 'DejaVuSans.ttf', 'dejavusans'],
['dejavu/ttf', 'DejaVuSans-BoldOblique.ttf', 'dejavusansbi'],
['dejavu/ttf', 'DejaVuSans-Bold.ttf', 'dejavusansb'],
['dejavu/ttf', 'DejaVuSans-Oblique.ttf', 'dejavusansi'],
['dejavu/ttf', 'DejaVuSansCondensed.ttf', 'dejavusanscondensed'],
['dejavu/ttf', 'DejaVuSansCondensed-BoldOblique.ttf', 'dejavusanscondensedbi'],
['dejavu/ttf', 'DejaVuSansCondensed-Bold.ttf', 'dejavusanscondensedb'],
['dejavu/ttf', 'DejaVuSansCondensed-Oblique.ttf', 'dejavusanscondensedi'],
['dejavu/ttf', 'DejaVuSansMono.ttf', 'dejavusansmono'],
['dejavu/ttf', 'DejaVuSansMono-BoldOblique.ttf', 'dejavusansmonobi'],
['dejavu/ttf', 'DejaVuSansMono-Bold.ttf', 'dejavusansmonob'],
['dejavu/ttf', 'DejaVuSansMono-Oblique.ttf', 'dejavusansmonoi'],
['dejavu/ttf', 'DejaVuSans-ExtraLight.ttf', 'dejavusansextralight'],
['dejavu/ttf', 'DejaVuSerif.ttf', 'dejavuserif'],
['dejavu/ttf', 'DejaVuSerif-BoldItalic.ttf', 'dejavuserifbi'],
['dejavu/ttf', 'DejaVuSerif-Bold.ttf', 'dejavuserifb'],
['dejavu/ttf', 'DejaVuSerif-Italic.ttf', 'dejavuserifi'],
['dejavu/ttf', 'DejaVuSerifCondensed.ttf', 'dejavuserifcondensed'],
['dejavu/ttf', 'DejaVuSerifCondensed-BoldItalic.ttf', 'dejavuserifcondensedbi'],
['dejavu/ttf', 'DejaVuSerifCondensed-Bold.ttf', 'dejavuserifcondensedb'],
['dejavu/ttf', 'DejaVuSerifCondensed-Italic.ttf', 'dejavuserifcondensedi'],
];
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* OutputTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfFont
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-font
*
* This file is part of tc-lib-pdf-font software library.
*/
namespace Test;
/**
* Output Test
*
* @since 2011-05-23
* @category Library
* @package PdfFont
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-font
*
* @SuppressWarnings("PHPMD.LongVariable")
*/
class OutputTest extends TestUtil
{
public function testOutput(): void
{
$this->setupTest();
$indir = dirname(__DIR__) . '/util/vendor/tecnickcom/tc-font-mirror/';
$objnum = 1;
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
new \Com\Tecnick\Pdf\Font\Import($indir . 'pdfa/pfb/PDFASymbol.pfb', '', 'Type1', 'symbol');
$stack->add($objnum, 'pdfasymbol');
new \Com\Tecnick\Pdf\Font\Import($indir . 'core/Helvetica.afm');
$stack->add($objnum, 'helvetica');
new \Com\Tecnick\Pdf\Font\Import($indir . 'core/Helvetica-Bold.afm');
$stack->add($objnum, 'helvetica', 'B');
new \Com\Tecnick\Pdf\Font\Import($indir . 'core/Helvetica-BoldOblique.afm');
$stack->add($objnum, 'helveticaBI');
new \Com\Tecnick\Pdf\Font\Import($indir . 'core/Helvetica-Oblique.afm');
$stack->add($objnum, 'helvetica', 'I');
new \Com\Tecnick\Pdf\Font\Import($indir . 'freefont/FreeSans.ttf');
$stack->add($objnum, 'freesans', '');
new \Com\Tecnick\Pdf\Font\Import($indir . 'freefont/FreeSansBold.ttf');
$stack->add($objnum, 'freesans', 'B');
new \Com\Tecnick\Pdf\Font\Import($indir . 'freefont/FreeSansOblique.ttf');
$stack->add($objnum, 'freesans', 'I');
new \Com\Tecnick\Pdf\Font\Import($indir . 'freefont/FreeSansBoldOblique.ttf');
$stack->add($objnum, 'freesans', 'BIUDO', '', true);
new \Com\Tecnick\Pdf\Font\Import($indir . 'cid0/cid0jp.ttf', '', 'CID0JP');
$stack->add($objnum, 'cid0jp');
$fonts = $stack->getFonts();
$this->assertCount(10, $fonts);
$encrypt = new \Com\Tecnick\Pdf\Encrypt\Encrypt();
$output = new \Com\Tecnick\Pdf\Font\Output($fonts, $objnum, $encrypt);
$this->assertEquals(37, $output->getObjectNumber());
$this->assertNotEmpty($output->getFontsBlock());
$this->assertNotEmpty($output->getOutFontDict());
$keys = [];
foreach ($fonts as $font) {
$keys[] = $font['key'];
}
$this->assertNotEmpty($output->getOutFontDictByKeys($keys));
}
}

View File

@@ -0,0 +1,188 @@
<?php
/**
* StackTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfFont
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-font
*
* This file is part of tc-lib-pdf-font software library.
*/
namespace Test;
/**
* Buffer Test
*
* @since 2011-05-23
* @category Library
* @package PdfFont
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-font
*
* @SuppressWarnings("PHPMD.LongVariable")
*/
class StackTest extends TestUtil
{
public function testStack(): void
{
$this->setupTest();
$indir = dirname(__DIR__) . '/util/vendor/tecnickcom/tc-font-mirror/';
$objnum = 1;
$stack = new \Com\Tecnick\Pdf\Font\Stack(0.75, true, true, true);
new \Com\Tecnick\Pdf\Font\Import($indir . 'freefont/FreeSans.ttf');
$cfont = $stack->insert($objnum, 'freesans', '', 12, -0.1, 0.9, '', null);
$this->assertNotEmpty($cfont);
$this->assertNotEmpty($cfont['cbbox']);
$this->bcAssertEqualsWithDelta([0.162, 0.0, 7.0308, 8.748], $stack->getCharBBox(65), 0.0001);
new \Com\Tecnick\Pdf\Font\Import($indir . 'pdfa/pfb/PDFATimes.pfb');
$afont = $stack->insert($objnum, 'times', '', 14, 0.3, 1.2, '', null);
$this->assertNotEmpty($afont);
new \Com\Tecnick\Pdf\Font\Import($indir . 'pdfa/pfb/PDFAHelveticaBoldOblique.pfb');
$bfont = $stack->insert($objnum, 'helvetica', 'BIUDO', null, null, null, '', null);
$this->assertNotEmpty($bfont);
$this->assertEquals("BT /F3 14.000000 Tf ET\r", $bfont['out']);
$this->assertEquals('pdfahelveticaBI', $bfont['key']);
$this->assertEquals('Type1', $bfont['type']);
$this->bcAssertEqualsWithDelta(14, $bfont['size'], 0.0001);
$this->bcAssertEqualsWithDelta(0.3, $bfont['spacing'], 0.0001);
$this->bcAssertEqualsWithDelta(1.2, $bfont['stretching'], 0.0001);
$this->bcAssertEqualsWithDelta(18.6667, $bfont['usize'], 0.0001);
$this->bcAssertEqualsWithDelta(0.014, $bfont['cratio'], 0.0001);
$this->bcAssertEqualsWithDelta(-1.554, $bfont['up'], 0.0001);
$this->bcAssertEqualsWithDelta(0.966, $bfont['ut'], 0.0001);
$this->bcAssertEqualsWithDelta(4.6704, $bfont['dw'], 0.0001);
$this->bcAssertEqualsWithDelta(13.342, $bfont['ascent'], 0.0001);
$this->bcAssertEqualsWithDelta(-3.08, $bfont['descent'], 0.0001);
$this->bcAssertEqualsWithDelta(16.422, $bfont['height'], 0.0001);
$this->bcAssertEqualsWithDelta(5.131, $bfont['midpoint'], 0.0001);
$this->bcAssertEqualsWithDelta(10.136, $bfont['capheight'], 0.0001);
$this->bcAssertEqualsWithDelta(7.56, $bfont['xheight'], 0.0001);
$this->bcAssertEqualsWithDelta(9.492, $bfont['avgwidth'], 0.0001);
$this->bcAssertEqualsWithDelta(16.8, $bfont['maxwidth'], 0.0001);
$this->bcAssertEqualsWithDelta(4.6704, $bfont['missingwidth'], 0.0001);
$this->bcAssertEqualsWithDelta([-1.092, -3.08, 18.5976, 13.342], $bfont['fbbox'], 0.0001);
$fkey = $stack->getCurrentFontKey();
$this->assertEquals('pdfahelveticaBI', $fkey);
$font = $stack->getCurrentFont();
$this->assertEquals($bfont, $font);
$this->assertTrue($stack->isCharDefined(65));
$this->assertFalse($stack->isCharDefined(300));
$this->assertEquals(75, $stack->replaceChar(65, 75));
$this->assertEquals(65, $stack->replaceChar(65, 300));
$this->assertEquals([0, 0, 0, 0], $stack->getCharBBox(300));
$this->bcAssertEqualsWithDelta(12.1296, $stack->getCharWidth(65), 0.0001);
$this->bcAssertEqualsWithDelta(0, $stack->getCharWidth(173), 0.0001);
$this->bcAssertEqualsWithDelta(4.6704, $stack->getCharWidth(300), 0.0001);
$uniarr = [65, 173, 300];
$this->bcAssertEqualsWithDelta(17.52, $stack->getOrdArrWidth($uniarr), 0.0001);
$subs = [
65 => [400, 75],
173 => [76, 300],
300 => [400, 77],
];
$this->assertEquals([65, 173, 77], $stack->replaceMissingChars($uniarr, $subs));
$font = $stack->popLastFont();
$this->assertEquals($bfont, $font);
$font = $stack->getCurrentFont();
$this->assertEquals($afont, $font);
$fkey = $stack->getCurrentFontKey();
$this->assertEquals('pdfatimes', $fkey);
$type = $stack->getCurrentFontType();
$this->assertEquals('Type1', $type);
$ftype = $stack->isCurrentUnicodeFont();
$this->assertFalse($ftype);
$ftype = $stack->isCurrentByteFont();
$this->assertTrue($ftype);
$uniarr = [65, 173, 300, 32, 65, 173, 300, 32, 65, 173, 300];
$widths = $stack->getOrdArrDims($uniarr);
$this->assertEquals(11, $widths['chars']);
$this->assertEquals(2, $widths['spaces']);
$this->bcAssertEqualsWithDelta(60.9384, $widths['totwidth'], 0.0001);
$this->bcAssertEqualsWithDelta(8.76, $widths['totspacewidth'], 0.0001);
$this->assertEquals(6, $widths['words']);
$this->assertEquals(11, $widths['split'][5]['pos']);
$this->assertEquals(8203, $widths['split'][5]['ord']);
$this->assertEquals('BN', $widths['split'][5]['septype']);
$this->bcAssertEqualsWithDelta(4.92, $widths['split'][5]['wordwidth'], 0.0001);
$this->assertEquals(2, $widths['split'][5]['spaces']);
$this->bcAssertEqualsWithDelta(60.9384, $widths['split'][5]['totwidth'], 0.0001);
$this->bcAssertEqualsWithDelta(8.76, $widths['split'][5]['totspacewidth'], 0.0001);
$outfont = $stack->getOutCurrentFont();
$this->assertEquals("BT /F2 14.000000 Tf ET\r", $outfont);
$font = $stack->cloneFont($objnum, null, null, 13, 0.3, 0.7);
$this->assertEquals(13, $font['size']);
$this->assertEquals(0.3, $font['spacing']);
$this->assertEquals(0.7, $font['stretching']);
$font = $stack->cloneFont($objnum, 0, 'BI', 17, 0.7, 1.3);
$this->assertEquals('BI', $font['style']);
$this->assertEquals(17, $font['size']);
$this->assertEquals(0.7, $font['spacing']);
$this->assertEquals(1.3, $font['stretching']);
$fname = $stack->getFontFamilyName('unknown');
$this->assertEquals('freesansBI', $fname);
new \Com\Tecnick\Pdf\Font\Import($indir . 'pdfa/pfb/PDFACourier.pfb');
$bfont = $stack->insert($objnum, 'courier', '', null, null, null, '', null);
$this->assertNotEmpty($bfont);
$fname = $stack->getFontFamilyName('freesans');
$this->assertEquals('freesans', $fname);
$fname = $stack->getFontFamilyName('cursive');
$this->assertEquals('pdfatimes', $fname);
$fname = $stack->getFontFamilyName('unknown');
$this->assertEquals('pdfacourier', $fname);
}
public function testEmptyStack(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$stack->popLastFont();
}
public function testStackMissingFont(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Font\Exception::class);
$this->setupTest();
$stack = new \Com\Tecnick\Pdf\Font\Stack(1);
$objnum = 1;
$stack->insert($objnum, 'missing');
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* TestUtil.php
*
* @since 2020-12-19
* @category Library
* @package PdfFont
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-font
*
* This file is part of tc-lib-color software library.
*/
namespace Test;
use PHPUnit\Framework\TestCase;
/**
* Web Color class test
*
* @since 2020-12-19
* @category Library
* @package PdfFont
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-font
*
* @preserveGlobalState disabled
* @runTestsInSeparateProcesses
*/
class TestUtil extends TestCase
{
protected function setupTest(): void
{
if (! defined('K_PATH_FONTS')) {
define('K_PATH_FONTS', dirname(__DIR__) . '/target/tmptest/');
}
system('rm -rf ' . K_PATH_FONTS . ' && mkdir -p ' . K_PATH_FONTS);
}
protected function getFontPath(): string
{
if (defined('K_PATH_FONTS')) {
return K_PATH_FONTS;
}
return '';
}
public function bcAssertEqualsWithDelta(
mixed $expected,
mixed $actual,
float $delta = 0.01,
string $message = ''
): void {
parent::assertEqualsWithDelta($expected, $actual, $delta, $message);
}
/**
* @param class-string<\Throwable> $exception
*/
public function bcExpectException($exception): void
{
parent::expectException($exception);
}
}