1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 20:07:35 +00:00

Userland+Tests: Remove uses of direct file loading for BitmapFont

Route them through Core::Resource APIs instead.
This commit is contained in:
Andrew Kaster 2023-10-17 12:45:22 -06:00 committed by Andrew Kaster
parent d587bd0a04
commit 1567332e34
6 changed files with 28 additions and 26 deletions

View file

@ -20,10 +20,10 @@ REGISTER_WIDGET(GUI, Calendar);
namespace GUI {
static auto const extra_large_font = Gfx::BitmapFont::load_from_file("/res/fonts/MarietaRegular36.font");
static auto const large_font = Gfx::BitmapFont::load_from_file("/res/fonts/MarietaRegular24.font");
static auto const medium_font = Gfx::BitmapFont::load_from_file("/res/fonts/PebbletonRegular14.font");
static auto const small_font = Gfx::BitmapFont::load_from_file("/res/fonts/KaticaRegular10.font");
static auto const extra_large_font = Gfx::BitmapFont::load_from_uri("resource://fonts/MarietaRegular36.font"sv);
static auto const large_font = Gfx::BitmapFont::load_from_uri("resource://fonts/MarietaRegular24.font"sv);
static auto const medium_font = Gfx::BitmapFont::load_from_uri("resource://fonts/PebbletonRegular14.font"sv);
static auto const small_font = Gfx::BitmapFont::load_from_uri("resource://fonts/KaticaRegular10.font"sv);
Calendar::Calendar(Core::DateTime date_time, Mode mode)
: m_selected_date(date_time)
@ -451,7 +451,7 @@ void Calendar::paint_event(GUI::PaintEvent& event)
m_months[i].is_being_pressed,
m_months[i].is_hovered,
false, true, false);
set_font(small_font);
set_font(*small_font);
painter.draw_text(month_tile_rect, m_months[i].name, font(), Gfx::TextAlignment::Center, palette().base_text());
i++;
}
@ -623,15 +623,15 @@ void Calendar::paint_tile(GUI::Painter& painter, GUI::Calendar::Tile& tile, Gfx:
font().pixel_size_rounded_up() + 4);
if (width > 150 && height > 150) {
set_font(extra_large_font);
set_font(*extra_large_font);
} else if (width > 100 && height > 100) {
set_font(large_font);
set_font(*large_font);
} else if (width > 50 && height > 50) {
set_font(medium_font);
set_font(*medium_font);
} else if (width >= 30 && height >= 30) {
set_font(small_font);
set_font(*small_font);
} else {
set_font(small_font);
set_font(*small_font);
text_alignment = Gfx::TextAlignment::Center;
text_rect = Gfx::IntRect(tile_rect);
}
@ -654,9 +654,9 @@ void Calendar::paint_tile(GUI::Painter& painter, GUI::Calendar::Tile& tile, Gfx:
painter.fill_rect(tile_rect, palette().base());
if (width > 50 && height > 50) {
set_font(medium_font);
set_font(*medium_font);
} else {
set_font(small_font);
set_font(*small_font);
}
auto display_date = DeprecatedString::number(tile.day);

View file

@ -122,7 +122,7 @@ void FontDatabase::load_all_fonts_from_uri(StringView uri)
auto path_string = resource.filesystem_path().release_value();
auto path = LexicalPath(path_string.bytes_as_string_view());
if (path.has_extension(".font"sv)) {
if (auto font_or_error = Gfx::BitmapFont::try_load_from_file(path.string()); !font_or_error.is_error()) {
if (auto font_or_error = Gfx::BitmapFont::try_load_from_resource(resource); !font_or_error.is_error()) {
auto font = font_or_error.release_value();
m_private->full_name_to_font_map.set(font->qualified_name().to_deprecated_string(), *font);
auto typeface = get_or_create_typeface(font->family(), font->variant());