LibPDF+Tests: Correctly decode text strings without explicit encoding

This commit is contained in:
Nico Weber 2023-11-21 21:07:35 -05:00 committed by Andrew Kaster
parent 8f47acee6a
commit 57e2b5ef59
2 changed files with 3 additions and 8 deletions

View file

@ -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");
}

View file

@ -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<NonnullRefPtr<Document>> Document::create(ReadonlyBytes bytes)