From 57e2b5ef594dc81a78f5b68535b1ec0681f807b2 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 21 Nov 2023 21:07:35 -0500 Subject: [PATCH] LibPDF+Tests: Correctly decode text strings without explicit encoding --- Tests/LibPDF/TestPDF.cpp | 7 ++----- Userland/Libraries/LibPDF/Document.cpp | 4 +--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Tests/LibPDF/TestPDF.cpp b/Tests/LibPDF/TestPDF.cpp index 8d379c79b7e..da721d032ac 100644 --- a/Tests/LibPDF/TestPDF.cpp +++ b/Tests/LibPDF/TestPDF.cpp @@ -54,15 +54,12 @@ TEST_CASE(encodig) auto info_dict = MUST(document->info_dict()).value(); EXPECT_EQ(MUST(info_dict.author()).value(), "Nico Weber"); EXPECT_EQ(MUST(info_dict.producer()).value(), (char const*)u8"Manüally Created"); - - // FIXME: Make this pass. - // EXPECT_EQ(MUST(info_dict.title()).value(), (char const*)u8"Êñ©•ding test"); + EXPECT_EQ(MUST(info_dict.title()).value(), (char const*)u8"Êñ©•ding test"); auto outline_dict = document->outline(); EXPECT_EQ(outline_dict->count, 3u); EXPECT_EQ(outline_dict->children[0]->title, (char const*)u8"Titlè 1"); - // FIXME: Make this pass: - // EXPECT_EQ(outline_dict->children[1]->title, (char const*)u8"Titlè 2"); + EXPECT_EQ(outline_dict->children[1]->title, (char const*)u8"Titlè 2"); EXPECT_EQ(outline_dict->children[2]->title, (char const*)u8"Titlè 3"); } diff --git a/Userland/Libraries/LibPDF/Document.cpp b/Userland/Libraries/LibPDF/Document.cpp index fb63d20b488..995e8529bc4 100644 --- a/Userland/Libraries/LibPDF/Document.cpp +++ b/Userland/Libraries/LibPDF/Document.cpp @@ -92,9 +92,7 @@ DeprecatedString Document::text_string_to_utf8(DeprecatedString const& text_stri return text_string.substring(3); } - // FIXME: Convert from PDFDocEncoding to UTF-8. - - return text_string; + return TextCodec::decoder_for("PDFDocEncoding"sv)->to_utf8(text_string).release_value_but_fixme_should_propagate_errors().to_deprecated_string(); } PDFErrorOr> Document::create(ReadonlyBytes bytes)