LibPDF: Record base font name read from document

This will be useful for debugging, or if we later on want to show all
the fonts found in the document in an organised manner.
This commit is contained in:
Rodrigo Tobar 2023-01-07 12:26:59 +08:00 committed by Andreas Kling
parent 2552399bcd
commit bfeca4ebb3
Notes: sideshowbarker 2024-07-17 01:16:24 +09:00
5 changed files with 8 additions and 3 deletions

View File

@ -33,9 +33,9 @@ static bool is_standard_latin_font(DeprecatedFlyString const& font)
PDFErrorOr<void> PDFFont::CommonData::load_from_dict(Document* document, NonnullRefPtr<DictObject> dict, float font_size)
{
auto base_font = TRY(dict->get_name(document, CommonNames::BaseFont))->name();
if ((is_standard_font = is_standard_latin_font(base_font))) {
auto replacement = replacement_for_standard_latin_font(base_font.to_lowercase());
base_font_name = TRY(dict->get_name(document, CommonNames::BaseFont))->name();
if ((is_standard_font = is_standard_latin_font(base_font_name))) {
auto replacement = replacement_for_standard_latin_font(base_font_name.to_lowercase());
font = Gfx::FontDatabase::the().get(replacement.get<0>(), replacement.get<1>(), font_size);
VERIFY(font);
}

View File

@ -24,6 +24,7 @@ public:
// This is used both by Type 1 and TrueType fonts.
struct CommonData {
DeprecatedFlyString base_font_name;
RefPtr<Gfx::Font> font;
RefPtr<StreamObject> to_unicode;
RefPtr<Encoding> encoding;
@ -45,6 +46,7 @@ public:
virtual bool is_standard_font() const { return m_is_standard_font; }
virtual Type type() const = 0;
virtual DeprecatedFlyString base_font_name() const = 0;
protected:
static Tuple<DeprecatedString, DeprecatedString> replacement_for_standard_latin_font(StringView);

View File

@ -27,6 +27,7 @@ public:
void draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u32, Color) override;
Type type() const override { return PDFFont::Type::TrueType; }
DeprecatedFlyString base_font_name() const override { return m_data.base_font_name; }
private:
PDFFont::CommonData m_data;

View File

@ -30,6 +30,7 @@ public:
void draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u32, Color) override {};
Type type() const override { return PDFFont::Type::Type0; }
DeprecatedFlyString base_font_name() const override { return ""; }
private:
CIDSystemInfo m_system_info;

View File

@ -31,6 +31,7 @@ public:
void draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u32 char_code, Color color) override;
Type type() const override { return PDFFont::Type::Type1; }
DeprecatedFlyString base_font_name() const override { return m_data.base_font_name; };
private:
Data m_data;