diff --git a/Libraries/LibTTF/Font.cpp b/Libraries/LibTTF/Font.cpp index 2b53332bf1..981478e27b 100644 --- a/Libraries/LibTTF/Font.cpp +++ b/Libraries/LibTTF/Font.cpp @@ -208,6 +208,11 @@ RefPtr Font::load_from_file(const StringView& path, unsigned index) return nullptr; } auto buffer = file->read_all(); + return load_from_memory(buffer, index); +} + +RefPtr Font::load_from_memory(ByteBuffer& buffer, unsigned index) +{ if (buffer.size() < 4) { dbg() << "Font file too small"; return nullptr; @@ -227,7 +232,7 @@ RefPtr Font::load_from_file(const StringView& path, unsigned index) return nullptr; } if (tag != 0x00010000) { - dbg() << "Not a valid font"; + dbg() << "Not a valid font"; return nullptr; } return load_from_offset(move(buffer), 0); diff --git a/Libraries/LibTTF/Font.h b/Libraries/LibTTF/Font.h index 3062cb1190..9250dd9a9d 100644 --- a/Libraries/LibTTF/Font.h +++ b/Libraries/LibTTF/Font.h @@ -65,6 +65,7 @@ class Font : public RefCounted { public: static RefPtr load_from_file(const StringView& path, unsigned index = 0); + static RefPtr load_from_memory(ByteBuffer&, unsigned index = 0); ScaledFontMetrics metrics(float x_scale, float y_scale) const; ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale) const;