From d22584c3347e53961e43cdbe010a6c4f25df50d8 Mon Sep 17 00:00:00 2001 From: Francesco Pretto Date: Sat, 6 Apr 2024 14:54:34 +0200 Subject: [PATCH] Fix FT_Load_Sfnt_Table() return code check in tryExtractDataFromTTC rc == 0 is success. Also finally tested TTC extraction. Should fix #150 --- extern/resources | 2 +- src/podofo/private/FreetypePrivate.cpp | 2 +- test/unit/DeviceTest.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/extern/resources b/extern/resources index 69a67d90..f3c62ca7 160000 --- a/extern/resources +++ b/extern/resources @@ -1 +1 @@ -Subproject commit 69a67d90399a050bed320d18e7da48eb233984dc +Subproject commit f3c62ca7a972f47b43d31cf38d80927b8c37a624 diff --git a/src/podofo/private/FreetypePrivate.cpp b/src/podofo/private/FreetypePrivate.cpp index 4ac08ffa..1425b880 100644 --- a/src/podofo/private/FreetypePrivate.cpp +++ b/src/podofo/private/FreetypePrivate.cpp @@ -182,7 +182,7 @@ bool tryExtractDataFromTTC(FT_Face face, charbuff& buffer) uint32_t tag; size = sizeof(FT_ULong); rc = FT_Load_Sfnt_Table(face, 0, 0, (FT_Byte*)&tag, &size); - if (rc == 0 || FROM_BIG_ENDIAN(tag) != TTAG_ttcf) + if (rc != 0 || FROM_BIG_ENDIAN(tag) != TTAG_ttcf) return false; // First read the TTC font header and then determine the face offset diff --git a/test/unit/DeviceTest.cpp b/test/unit/DeviceTest.cpp index 11d08b30..fd5482e3 100644 --- a/test/unit/DeviceTest.cpp +++ b/test/unit/DeviceTest.cpp @@ -41,11 +41,11 @@ TEST_CASE("TestStreamedDocument") auto testPath = TestUtils::GetTestOutputFilePath("TestStreamedDocument.pdf"); PdfStreamedDocument document(testPath); auto& page = document.GetPages().CreatePage(PdfPage::CreateStandardPageSize(PdfPageSize::A4)); - auto font = document.GetFonts().SearchFont("LiberationSans"); - REQUIRE(font != nullptr); + // NOTE: use a TTC version of the LiberationSans format to test TTC extraction + auto& font = document.GetFonts().GetOrCreateFont(TestUtils::GetTestInputFilePath("Fonts", "LiberationSans.ttc"), 2); PdfPainter painter; painter.SetCanvas(page); - painter.TextState.SetFont(*font, 18); + painter.TextState.SetFont(font, 18); painter.DrawText("Hello World!", 56.69, page.GetRect().Height - 56.69); painter.FinishDrawing(); }