1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

LibGfx: Add a helper for constructing a TTF font from temporary bytes

Once we switch from ResourceLoader to Fetch, nobody is going to be
holding onto the downloaded data, so we need to make a permanent copy
of it.
This commit is contained in:
Sam Atkins 2025-05-01 16:08:22 +01:00
parent f76f8dcce1
commit 1967d5bc75
Notes: github-actions[bot] 2025-05-03 11:03:27 +00:00
2 changed files with 8 additions and 0 deletions

View file

@ -25,6 +25,13 @@ ErrorOr<NonnullRefPtr<Typeface>> Typeface::try_load_from_font_data(NonnullOwnPtr
return typeface;
}
ErrorOr<NonnullRefPtr<Typeface>> Typeface::try_load_from_temporary_memory(ReadonlyBytes bytes, int ttc_index)
{
auto buffer = TRY(ByteBuffer::copy(bytes));
auto font_data = FontData::create_from_byte_buffer(move(buffer));
return try_load_from_font_data(move(font_data), ttc_index);
}
ErrorOr<NonnullRefPtr<Typeface>> Typeface::try_load_from_externally_owned_memory(ReadonlyBytes bytes, int ttc_index)
{
return TypefaceSkia::load_from_buffer(bytes, ttc_index);

View file

@ -38,6 +38,7 @@ class Typeface : public RefCounted<Typeface> {
public:
static ErrorOr<NonnullRefPtr<Typeface>> try_load_from_resource(Core::Resource const&, int ttc_index = 0);
static ErrorOr<NonnullRefPtr<Typeface>> try_load_from_font_data(NonnullOwnPtr<Gfx::FontData>, int ttc_index = 0);
static ErrorOr<NonnullRefPtr<Typeface>> try_load_from_temporary_memory(ReadonlyBytes bytes, int ttc_index = 0);
static ErrorOr<NonnullRefPtr<Typeface>> try_load_from_externally_owned_memory(ReadonlyBytes bytes, int ttc_index = 0);
virtual ~Typeface();