diff --git a/app/Exports/PdfGenerator.php b/app/Exports/PdfGenerator.php index df40bf44f..10f0624cf 100644 --- a/app/Exports/PdfGenerator.php +++ b/app/Exports/PdfGenerator.php @@ -68,7 +68,6 @@ class PdfGenerator $fontMetrics->setFontFamily($fontFamily, $fonts); } -// dd($userFontfamilies, $fontMetrics->getFontFamilies()); $domPdf->loadHTML($this->convertEntities($html)); $domPdf->render(); diff --git a/tests/Exports/PdfExportTest.php b/tests/Exports/PdfExportTest.php index f311f8457..78da3b0c2 100644 --- a/tests/Exports/PdfExportTest.php +++ b/tests/Exports/PdfExportTest.php @@ -79,6 +79,39 @@ class PdfExportTest extends TestCase $this->assertStringContainsString('
entities->page()->forceFill([ + 'html' => '

Boldtext

', + ]); + $page->save(); + $this->setSettings([ + 'app-custom-head' => '' + ]); + $normalFont = $this->files->testFilePath('fonts/Cardiff.ttf'); + $normalFontTarget = storage_path('fonts/dompdf/MeowWords.ttf'); + $boldFont = $this->files->testFilePath('fonts/Cardiff-Bold.ttf'); + $boldFontTarget = storage_path('fonts/dompdf/MeowWords-Bold.ttf'); + copy($normalFont, $normalFontTarget); + copy($boldFont, $boldFontTarget); + + $resp = $this->asEditor()->get($page->getUrl('/export/pdf')); + $resp->assertStatus(200); + + // Existance of UFM files indicates the metrics have been generated + $this->assertFileExists(storage_path('fonts/dompdf/MeowWords.ufm')); + $this->assertFileExists(storage_path('fonts/dompdf/MeowWords-Bold.ufm')); + // Existence of cache json files indicates the fonts have been used + $this->assertFileExists(storage_path('fonts/dompdf/cache/MeowWords.ufm.json')); + $this->assertFileExists(storage_path('fonts/dompdf/cache/MeowWords-Bold.ufm.json')); + + $filesToCleanUp = [...glob(storage_path('fonts/dompdf/Meow*')), ...glob(storage_path('fonts/dompdf/cache/Meow*'))]; + foreach ($filesToCleanUp as $file) { + unlink($file); + } + } + public function test_wkhtmltopdf_only_used_when_allow_untrusted_is_true() { $page = $this->entities->page(); diff --git a/tests/test-data/fonts/Cardiff-Bold.ttf b/tests/test-data/fonts/Cardiff-Bold.ttf new file mode 100644 index 000000000..efaae4d9e Binary files /dev/null and b/tests/test-data/fonts/Cardiff-Bold.ttf differ diff --git a/tests/test-data/fonts/Cardiff.ttf b/tests/test-data/fonts/Cardiff.ttf new file mode 100644 index 000000000..4e8fea609 Binary files /dev/null and b/tests/test-data/fonts/Cardiff.ttf differ diff --git a/tests/test-data/fonts/attribution.txt b/tests/test-data/fonts/attribution.txt new file mode 100644 index 000000000..e78c38925 --- /dev/null +++ b/tests/test-data/fonts/attribution.txt @@ -0,0 +1,2 @@ +Font files by Roger White, in public domain. +https://web.archive.org/web/20110609213636/http://www.rogersfonts.org.uk/