summaryrefslogtreecommitdiff
path: root/Libraries/LibGfx
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-22 21:59:05 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-23 11:10:52 +0100
commit98fd6b876756022a2573dec86e3cbd5ab8b85cd0 (patch)
tree87edf0acf02e8c7904f889714f27724b851df4e3 /Libraries/LibGfx
parent61bf8e01f9eefb08f7b169347e2cf6a58fcbc739 (diff)
downloadserenity-98fd6b876756022a2573dec86e3cbd5ab8b85cd0.zip
LibGfx: Add a way to construct an empty Font with arbitrary metrics
Diffstat (limited to 'Libraries/LibGfx')
-rw-r--r--Libraries/LibGfx/Font.cpp16
-rw-r--r--Libraries/LibGfx/Font.h3
2 files changed, 16 insertions, 3 deletions
diff --git a/Libraries/LibGfx/Font.cpp b/Libraries/LibGfx/Font.cpp
index ddfb4705d1..02668da35f 100644
--- a/Libraries/LibGfx/Font.cpp
+++ b/Libraries/LibGfx/Font.cpp
@@ -37,6 +37,7 @@
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
+#include <stdlib.h>
namespace Gfx {
@@ -96,7 +97,7 @@ Font& Font::default_bold_font()
return *s_default_bold_font;
}
-RefPtr<Font> Font::clone() const
+NonnullRefPtr<Font> Font::clone() const
{
size_t bytes_per_glyph = sizeof(u32) * glyph_height();
// FIXME: This is leaked!
@@ -107,7 +108,18 @@ RefPtr<Font> Font::clone() const
memcpy(new_widths, m_glyph_widths, 256);
else
memset(new_widths, m_glyph_width, 256);
- return adopt(*new Font(m_name, new_rows, new_widths, m_fixed_width, m_glyph_width, m_glyph_height, m_glyph_spacing));
+ return adopt(*new Font(m_name, new_rows, new_widths, m_fixed_width, m_glyph_width, 12, m_glyph_spacing));
+}
+
+NonnullRefPtr<Font> Font::create(u8 glyph_height, u8 glyph_width, bool fixed)
+{
+ size_t bytes_per_glyph = sizeof(u32) * glyph_height;
+ // FIXME: This is leaked!
+ auto* new_rows = static_cast<unsigned*>(malloc(bytes_per_glyph * 256));
+ memset(new_rows, 0, bytes_per_glyph * 256);
+ auto* new_widths = static_cast<u8*>(malloc(256));
+ memset(new_widths, glyph_width, 256);
+ return adopt(*new Font("Untitled", new_rows, new_widths, fixed, glyph_width, glyph_height, 1));
}
Font::Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing)
diff --git a/Libraries/LibGfx/Font.h b/Libraries/LibGfx/Font.h
index b53776eed3..60b2d32340 100644
--- a/Libraries/LibGfx/Font.h
+++ b/Libraries/LibGfx/Font.h
@@ -76,7 +76,8 @@ public:
static Font& default_fixed_width_font();
static Font& default_bold_fixed_width_font();
- RefPtr<Font> clone() const;
+ NonnullRefPtr<Font> clone() const;
+ static NonnullRefPtr<Font> create(u8 glyph_height, u8 glyph_width, bool fixed);
static RefPtr<Font> load_from_file(const StringView& path);
bool write_to_file(const StringView& path);