mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibTTF: Add option to load font from a byte buffer
This commit is contained in:
parent
84c2be604a
commit
ad243ef3aa
Notes:
sideshowbarker
2024-07-19 00:13:26 +09:00
Author: https://github.com/Lubrsi
Commit: ad243ef3aa
Pull-request: https://github.com/SerenityOS/serenity/pull/4721
Reviewed-by: https://github.com/awesomekling
2 changed files with 7 additions and 1 deletions
|
@ -208,6 +208,11 @@ RefPtr<Font> Font::load_from_file(const StringView& path, unsigned index)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto buffer = file->read_all();
|
auto buffer = file->read_all();
|
||||||
|
return load_from_memory(buffer, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<Font> Font::load_from_memory(ByteBuffer& buffer, unsigned index)
|
||||||
|
{
|
||||||
if (buffer.size() < 4) {
|
if (buffer.size() < 4) {
|
||||||
dbg() << "Font file too small";
|
dbg() << "Font file too small";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -65,6 +65,7 @@ class Font : public RefCounted<Font> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static RefPtr<Font> load_from_file(const StringView& path, unsigned index = 0);
|
static RefPtr<Font> load_from_file(const StringView& path, unsigned index = 0);
|
||||||
|
static RefPtr<Font> load_from_memory(ByteBuffer&, unsigned index = 0);
|
||||||
|
|
||||||
ScaledFontMetrics metrics(float x_scale, float y_scale) const;
|
ScaledFontMetrics metrics(float x_scale, float y_scale) const;
|
||||||
ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale) const;
|
ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue