LibGfx: Remove infallible BitmapFont::create() factory function

This was only used in TestFontHandling. So, let's remove it, and use
the "create" name for the fallible one.
This commit is contained in:
Sam Atkins 2023-10-02 11:56:49 +01:00 committed by Tim Schumacher
parent 2f26a7bb12
commit a1c24ef3ad
4 changed files with 11 additions and 17 deletions

View file

@ -52,7 +52,7 @@ TEST_CASE(test_clone)
{
u8 glyph_height = 1;
u8 glyph_width = 1;
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256);
auto font = MUST(Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256));
auto new_font = font->clone();
EXPECT(!new_font->name().is_empty());
@ -65,7 +65,7 @@ TEST_CASE(test_set_name)
{
u8 glyph_height = 1;
u8 glyph_width = 1;
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256);
auto font = MUST(Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256));
auto name = "my newly created font"_string;
font->set_name(name);
@ -78,7 +78,7 @@ TEST_CASE(test_set_family)
{
u8 glyph_height = 1;
u8 glyph_width = 1;
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256);
auto font = MUST(Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256));
auto family = "my newly created font family"_string;
font->set_family(family);
@ -91,7 +91,7 @@ TEST_CASE(test_set_glyph_width)
{
u8 glyph_height = 1;
u8 glyph_width = 1;
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256);
auto font = MUST(Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256));
size_t ch = 123;
font->set_glyph_width(ch, glyph_width);
@ -103,7 +103,7 @@ TEST_CASE(test_set_glyph_spacing)
{
u8 glyph_height = 1;
u8 glyph_width = 1;
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256);
auto font = MUST(Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256));
u8 glyph_spacing = 8;
font->set_glyph_spacing(glyph_spacing);
@ -115,7 +115,7 @@ TEST_CASE(test_width)
{
u8 glyph_height = 1;
u8 glyph_width = 1;
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256);
auto font = MUST(Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256));
EXPECT(font->width("A"sv) == glyph_width);
}
@ -124,7 +124,7 @@ TEST_CASE(test_glyph_or_emoji_width)
{
u8 glyph_height = 1;
u8 glyph_width = 1;
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256);
auto font = MUST(Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256));
Utf8View view { " "sv };
auto it = view.begin();
@ -142,7 +142,7 @@ TEST_CASE(test_write_to_file)
{
u8 glyph_height = 1;
u8 glyph_width = 1;
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256);
auto font = MUST(Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256));
char path[] = "/tmp/new.font.XXXXXX";
EXPECT(mkstemp(path) != -1);

View file

@ -236,7 +236,7 @@ ErrorOr<NonnullRefPtr<Gfx::BitmapFont>> NewFontDialog::create_font()
{
save_metadata();
auto font = TRY(Gfx::BitmapFont::try_create(m_new_font_metadata.glyph_height, m_new_font_metadata.glyph_width, m_new_font_metadata.is_fixed_width, 0x110000));
auto font = TRY(Gfx::BitmapFont::create(m_new_font_metadata.glyph_height, m_new_font_metadata.glyph_width, m_new_font_metadata.is_fixed_width, 0x110000));
font->set_name(m_new_font_metadata.name);
font->set_family(m_new_font_metadata.family);
font->set_presentation_size(m_new_font_metadata.presentation_size);

View file

@ -61,12 +61,7 @@ ErrorOr<NonnullRefPtr<Font>> BitmapFont::try_clone() const
return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) BitmapFont(m_name, m_family, new_rows, new_widths, m_fixed_width, m_glyph_width, m_glyph_height, m_glyph_spacing, m_range_mask_size, new_range_mask, m_baseline, m_mean_line, m_presentation_size, m_weight, m_slope, true)));
}
NonnullRefPtr<BitmapFont> BitmapFont::create(u8 glyph_height, u8 glyph_width, bool fixed, size_t glyph_count)
{
return MUST(try_create(glyph_height, glyph_width, fixed, glyph_count));
}
ErrorOr<NonnullRefPtr<BitmapFont>> BitmapFont::try_create(u8 glyph_height, u8 glyph_width, bool fixed, size_t glyph_count)
ErrorOr<NonnullRefPtr<BitmapFont>> BitmapFont::create(u8 glyph_height, u8 glyph_width, bool fixed, size_t glyph_count)
{
glyph_count += 256 - (glyph_count % 256);
glyph_count = min(glyph_count, s_max_glyph_count);

View file

@ -22,8 +22,7 @@ class BitmapFont final : public Font {
public:
virtual NonnullRefPtr<Font> clone() const override;
ErrorOr<NonnullRefPtr<Font>> try_clone() const override;
static NonnullRefPtr<BitmapFont> create(u8 glyph_height, u8 glyph_width, bool fixed, size_t glyph_count);
static ErrorOr<NonnullRefPtr<BitmapFont>> try_create(u8 glyph_height, u8 glyph_width, bool fixed, size_t glyph_count);
static ErrorOr<NonnullRefPtr<BitmapFont>> create(u8 glyph_height, u8 glyph_width, bool fixed, size_t glyph_count);
virtual FontPixelMetrics pixel_metrics() const override;