1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:47:35 +00:00

LibPDF: Make PDFFont::replacement_for() return a ScaledFont

We only want to load non-bitmap fallback fonts as PDF fallback fonts,
so let's make the return type represent that.

No behavior change.
This commit is contained in:
Nico Weber 2024-03-01 08:08:19 -05:00 committed by Andreas Kling
parent 7d9294b9a4
commit 5dad8b693e
2 changed files with 6 additions and 3 deletions

View file

@ -6,6 +6,7 @@
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/TypeCasts.h>
#include <LibGfx/Font/FontDatabase.h>
#include <LibPDF/CommonNames.h>
#include <LibPDF/Fonts/PDFFont.h>
@ -66,7 +67,7 @@ PDFErrorOr<void> PDFFont::initialize(Document* document, NonnullRefPtr<DictObjec
return {};
}
PDFErrorOr<NonnullRefPtr<Gfx::Font>> PDFFont::replacement_for(StringView name, float font_size)
PDFErrorOr<NonnullRefPtr<Gfx::ScaledFont>> PDFFont::replacement_for(StringView name, float font_size)
{
bool is_bold = name.contains("bold"sv, CaseSensitivity::CaseInsensitive);
bool is_italic = name.contains("italic"sv, CaseSensitivity::CaseInsensitive) || name.contains("oblique"sv, CaseSensitivity::CaseInsensitive);
@ -96,7 +97,9 @@ PDFErrorOr<NonnullRefPtr<Gfx::Font>> PDFFont::replacement_for(StringView name, f
auto font = Gfx::FontDatabase::the().get(font_family, font_variant, point_size);
if (!font)
return Error::internal_error("Failed to load {} {} at {}pt", font_family, font_variant, point_size);
return font.release_nonnull();
VERIFY(is<Gfx::ScaledFont>(*font));
return static_ptr_cast<Gfx::ScaledFont>(font.release_nonnull());
}
}

View file

@ -45,7 +45,7 @@ public:
protected:
virtual PDFErrorOr<void> initialize(Document* document, NonnullRefPtr<DictObject> const& dict, float font_size);
static PDFErrorOr<NonnullRefPtr<Gfx::Font>> replacement_for(StringView name, float font_size);
static PDFErrorOr<NonnullRefPtr<Gfx::ScaledFont>> replacement_for(StringView name, float font_size);
unsigned m_flags { 0 };
};