diff --git a/Ladybird/FontPlugin.cpp b/Ladybird/FontPlugin.cpp index 6488ae544ca..5ebb1c20a76 100644 --- a/Ladybird/FontPlugin.cpp +++ b/Ladybird/FontPlugin.cpp @@ -87,7 +87,7 @@ void FontPlugin::update_generic_fonts() gfx_font = Gfx::FontDatabase::default_font(); } - m_generic_font_names[static_cast(generic_font)] = gfx_font->family(); + m_generic_font_names[static_cast(generic_font)] = gfx_font->family().to_deprecated_string(); }; // Fallback fonts to look for if Gfx::Font can't load expected font diff --git a/Tests/LibGfx/TestFontHandling.cpp b/Tests/LibGfx/TestFontHandling.cpp index 1c229895941..4731d315b9b 100644 --- a/Tests/LibGfx/TestFontHandling.cpp +++ b/Tests/LibGfx/TestFontHandling.cpp @@ -25,14 +25,14 @@ TEST_CASE(test_fontdatabase_get_by_name) auto name = "Family 12 400 0"sv; auto& font_database = Gfx::FontDatabase::the(); - EXPECT(!font_database.get_by_name(name)->name().is_null()); + EXPECT(!font_database.get_by_name(name)->name().is_empty()); } TEST_CASE(test_fontdatabase_get) { Gfx::FontDatabase::set_default_fonts_lookup_path(TEST_INPUT("")); auto& font_database = Gfx::FontDatabase::the(); - EXPECT(!font_database.get("Family", 12, 400, Gfx::FontWidth::Normal, 0)->name().is_null()); + EXPECT(!font_database.get("Family", 12, 400, Gfx::FontWidth::Normal, 0)->name().is_empty()); } TEST_CASE(test_fontdatabase_for_each_font) @@ -41,9 +41,9 @@ TEST_CASE(test_fontdatabase_for_each_font) auto& font_database = Gfx::FontDatabase::the(); font_database.for_each_font([&](Gfx::Font const& font) { - EXPECT(!font.name().is_null()); - EXPECT(!font.qualified_name().is_null()); - EXPECT(!font.family().is_null()); + EXPECT(!font.name().is_empty()); + EXPECT(!font.qualified_name().is_empty()); + EXPECT(!font.family().is_empty()); EXPECT(font.glyph_count() > 0); }); } @@ -55,9 +55,9 @@ TEST_CASE(test_clone) auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256); auto new_font = font->clone(); - EXPECT(!new_font->name().is_null()); - EXPECT(!new_font->qualified_name().is_null()); - EXPECT(!new_font->family().is_null()); + EXPECT(!new_font->name().is_empty()); + EXPECT(!new_font->qualified_name().is_empty()); + EXPECT(!new_font->family().is_empty()); EXPECT(new_font->glyph_count() > 0); } @@ -67,10 +67,10 @@ TEST_CASE(test_set_name) u8 glyph_width = 1; auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256); - auto name = "my newly created font"sv; + auto name = "my newly created font"_string; font->set_name(name); - EXPECT(!font->name().is_null()); + EXPECT(!font->name().is_empty()); EXPECT(font->name().contains(name)); } @@ -80,10 +80,10 @@ TEST_CASE(test_set_family) u8 glyph_width = 1; auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, 256); - auto family = "my newly created font family"sv; + auto family = "my newly created font family"_string; font->set_family(family); - EXPECT(!font->family().is_null()); + EXPECT(!font->family().is_empty()); EXPECT(font->family().contains(family)); } @@ -135,7 +135,7 @@ TEST_CASE(test_glyph_or_emoji_width) TEST_CASE(test_load_from_file) { auto font = Gfx::BitmapFont::load_from_file(TEST_INPUT("TestFont.font"sv)); - EXPECT(!font->name().is_null()); + EXPECT(!font->name().is_empty()); } TEST_CASE(test_write_to_file) diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp index 98b915a0882..0eeecd9c933 100644 --- a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp +++ b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp @@ -176,7 +176,7 @@ ErrorOr CharacterMapWidget::initialize_menubar(GUI::Window& window) void CharacterMapWidget::did_change_font() { m_glyph_map->set_font(font()); - m_font_name_label->set_text(String::from_deprecated_string(font().human_readable_name()).release_value_but_fixme_should_propagate_errors()); + m_font_name_label->set_text(font().human_readable_name()); m_output_box->set_font(font()); } diff --git a/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp b/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp index a76487d7333..2bc6d39cb2e 100644 --- a/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp @@ -72,16 +72,16 @@ ErrorOr FontSettingsWidget::setup_interface() static void update_label_with_font(GUI::Label& label, Gfx::Font const& font) { - label.set_text(String::from_deprecated_string(font.human_readable_name()).release_value_but_fixme_should_propagate_errors()); + label.set_text(font.human_readable_name()); label.set_font(font); } void FontSettingsWidget::apply_settings() { GUI::ConnectionToWindowServer::the().set_system_fonts( - m_default_font_label->font().qualified_name(), - m_fixed_width_font_label->font().qualified_name(), - m_window_title_font_label->font().qualified_name()); + m_default_font_label->font().qualified_name().to_deprecated_string(), + m_fixed_width_font_label->font().qualified_name().to_deprecated_string(), + m_window_title_font_label->font().qualified_name().to_deprecated_string()); } } diff --git a/Userland/Applications/FileManager/PropertiesWindow.cpp b/Userland/Applications/FileManager/PropertiesWindow.cpp index 5d7e23f8366..12d989a2028 100644 --- a/Userland/Applications/FileManager/PropertiesWindow.cpp +++ b/Userland/Applications/FileManager/PropertiesWindow.cpp @@ -321,14 +321,14 @@ static ErrorOr load_font(StringView path, StringView mime_type, Nonnul { if (path.ends_with(".font"sv)) { auto font = TRY(Gfx::BitmapFont::try_load_from_mapped_file(mapped_file)); - auto typeface = TRY(try_make_ref_counted(font->family(), font->variant())); + auto typeface = TRY(try_make_ref_counted(font->family().to_deprecated_string(), font->variant().to_deprecated_string())); typeface->add_bitmap_font(move(font)); return FontInfo { FontInfo::Format::BitmapFont, move(typeface) }; } if (mime_type == "font/otf" || mime_type == "font/ttf") { auto font = TRY(OpenType::Font::try_load_from_externally_owned_memory(mapped_file->bytes())); - auto typeface = TRY(try_make_ref_counted(font->family(), font->variant())); + auto typeface = TRY(try_make_ref_counted(font->family().to_deprecated_string(), font->variant().to_deprecated_string())); typeface->set_vector_font(move(font)); return FontInfo { mime_type == "font/otf" ? FontInfo::Format::OpenType : FontInfo::Format::TrueType, @@ -338,7 +338,7 @@ static ErrorOr load_font(StringView path, StringView mime_type, Nonnul if (mime_type == "font/woff" || mime_type == "font/woff2") { auto font = TRY(WOFF::Font::try_load_from_externally_owned_memory(mapped_file->bytes())); - auto typeface = TRY(try_make_ref_counted(font->family(), font->variant())); + auto typeface = TRY(try_make_ref_counted(font->family().to_deprecated_string(), font->variant().to_deprecated_string())); typeface->set_vector_font(move(font)); return FontInfo { mime_type == "font/woff" ? FontInfo::Format::WOFF : FontInfo::Format::WOFF2, diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index c734ce5a209..e68c3d2db9f 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -532,13 +532,13 @@ ErrorOr MainWidget::create_widgets() m_name_textbox = find_descendant_of_type_named("name_textbox"); m_name_textbox->on_change = [this] { - m_font->set_name(m_name_textbox->text()); + m_font->set_name(MUST(String::from_deprecated_string(m_name_textbox->text()))); did_modify_font(); }; m_family_textbox = find_descendant_of_type_named("family_textbox"); m_family_textbox->on_change = [this] { - m_font->set_family(m_family_textbox->text()); + m_font->set_family(MUST(String::from_deprecated_string(m_family_textbox->text()))); did_modify_font(); }; diff --git a/Userland/Applications/FontEditor/NewFontDialog.cpp b/Userland/Applications/FontEditor/NewFontDialog.cpp index 9de99494bea..3c849ccc2c1 100644 --- a/Userland/Applications/FontEditor/NewFontDialog.cpp +++ b/Userland/Applications/FontEditor/NewFontDialog.cpp @@ -218,8 +218,8 @@ NewFontDialog::NewFontDialog(GUI::Window* parent_window) void NewFontDialog::save_metadata() { - m_new_font_metadata.name = m_name_textbox->text(); - m_new_font_metadata.family = m_family_textbox->text(); + m_new_font_metadata.name = MUST(String::from_deprecated_string(m_name_textbox->text())); + m_new_font_metadata.family = MUST(String::from_deprecated_string(m_family_textbox->text())); m_new_font_metadata.weight = Gfx::name_to_weight(m_weight_combobox->text()); m_new_font_metadata.slope = Gfx::name_to_slope(m_slope_combobox->text()); m_new_font_metadata.presentation_size = m_presentation_spinbox->value(); diff --git a/Userland/Applications/FontEditor/NewFontDialog.h b/Userland/Applications/FontEditor/NewFontDialog.h index 14635d28c42..f3e5f2c91af 100644 --- a/Userland/Applications/FontEditor/NewFontDialog.h +++ b/Userland/Applications/FontEditor/NewFontDialog.h @@ -35,8 +35,8 @@ private: u8 presentation_size; u16 weight; u8 slope; - DeprecatedString name; - DeprecatedString family; + String name; + String family; bool is_fixed_width; } m_new_font_metadata; diff --git a/Userland/Applications/PixelPaint/Tools/TextTool.cpp b/Userland/Applications/PixelPaint/Tools/TextTool.cpp index 0226ebb779e..2759f5c16b0 100644 --- a/Userland/Applications/PixelPaint/Tools/TextTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/TextTool.cpp @@ -114,13 +114,13 @@ ErrorOr TextTool::get_properties_widget() auto font_header = TRY(properties_widget->try_add("Current Font:"_string)); font_header->set_text_alignment(Gfx::TextAlignment::CenterLeft); - m_font_label = TRY(properties_widget->try_add(TRY(String::from_deprecated_string(m_selected_font->human_readable_name())))); + m_font_label = TRY(properties_widget->try_add(m_selected_font->human_readable_name())); auto change_font_button = TRY(properties_widget->try_add("Change Font..."_string)); change_font_button->on_click = [this](auto) { auto picker = GUI::FontPicker::construct(nullptr, m_selected_font, false); if (picker->exec() == GUI::Dialog::ExecResult::OK) { - m_font_label->set_text(String::from_deprecated_string(picker->font()->human_readable_name()).release_value_but_fixme_should_propagate_errors()); + m_font_label->set_text(picker->font()->human_readable_name()); m_selected_font = picker->font(); m_text_editor->set_font(m_selected_font); m_editor->set_focus(true); diff --git a/Userland/Applications/Terminal/main.cpp b/Userland/Applications/Terminal/main.cpp index 8655a615a00..a5272d27245 100644 --- a/Userland/Applications/Terminal/main.cpp +++ b/Userland/Applications/Terminal/main.cpp @@ -403,7 +403,7 @@ ErrorOr serenity_main(Main::Arguments arguments) auto adjust_font_size = [&](float adjustment) { auto& font = terminal->font(); auto new_size = max(5, font.presentation_size() + adjustment); - if (auto new_font = Gfx::FontDatabase::the().get(font.family(), new_size, font.weight(), font.width(), font.slope())) { + if (auto new_font = Gfx::FontDatabase::the().get(font.family().to_deprecated_string(), new_size, font.weight(), font.width(), font.slope())) { terminal->set_font_and_resize_to_fit(*new_font); terminal->apply_size_increments_to_window(*window); window->resize(terminal->size()); diff --git a/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp b/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp index 1c83970bc12..13480df6423 100644 --- a/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp +++ b/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp @@ -116,13 +116,13 @@ ErrorOr TerminalSettingsViewWidget::setup() else m_font = Gfx::FontDatabase::the().get_by_name(font_name); m_original_font = m_font; - font_text.set_text(TRY(String::from_deprecated_string(m_font->human_readable_name()))); + font_text.set_text(m_font->human_readable_name()); font_text.set_font(m_font); font_button.on_click = [&](auto) { auto picker = GUI::FontPicker::construct(window(), m_font.ptr(), true); if (picker->exec() == GUI::Dialog::ExecResult::OK) { m_font = picker->font(); - font_text.set_text(String::from_deprecated_string(m_font->human_readable_name()).release_value_but_fixme_should_propagate_errors()); + font_text.set_text(m_font->human_readable_name()); font_text.set_font(m_font); Config::write_string("Terminal"sv, "Text"sv, "Font"sv, m_font->qualified_name()); set_modified(true); @@ -135,7 +135,7 @@ ErrorOr TerminalSettingsViewWidget::setup() if (use_default_font) { font_selection.set_enabled(false); m_font = Gfx::FontDatabase::the().default_fixed_width_font(); - font_text.set_text(String::from_deprecated_string(m_font->human_readable_name()).release_value_but_fixme_should_propagate_errors()); + font_text.set_text(m_font->human_readable_name()); font_text.set_font(m_font); Config::write_string("Terminal"sv, "Text"sv, "Font"sv, m_font->qualified_name()); } else { diff --git a/Userland/Games/2048/BoardView.cpp b/Userland/Games/2048/BoardView.cpp index 960775a549f..2fc527d587c 100644 --- a/Userland/Games/2048/BoardView.cpp +++ b/Userland/Games/2048/BoardView.cpp @@ -53,7 +53,7 @@ void BoardView::pick_font() return; auto size = font.pixel_size_rounded_up(); if (size * 2 <= m_cell_size && size > best_font_size) { - best_font_name = String::from_deprecated_string(font.qualified_name()).release_value_but_fixme_should_propagate_errors(); + best_font_name = font.qualified_name(); best_font_size = size; } }); diff --git a/Userland/Games/MasterWord/WordGame.cpp b/Userland/Games/MasterWord/WordGame.cpp index 0e30a336ca3..f42eacc6427 100644 --- a/Userland/Games/MasterWord/WordGame.cpp +++ b/Userland/Games/MasterWord/WordGame.cpp @@ -63,7 +63,7 @@ void WordGame::pick_font() return; auto size = font.pixel_size_rounded_up(); if (size * 2 <= m_letter_height && size > best_font_size) { - best_font_name = font.qualified_name(); + best_font_name = font.qualified_name().to_deprecated_string(); best_font_size = size; } }); diff --git a/Userland/Libraries/LibGUI/FontPicker.cpp b/Userland/Libraries/LibGUI/FontPicker.cpp index ad4eddaf589..8e553edb8a3 100644 --- a/Userland/Libraries/LibGUI/FontPicker.cpp +++ b/Userland/Libraries/LibGUI/FontPicker.cpp @@ -190,15 +190,15 @@ void FontPicker::set_font(Gfx::Font const* font) return; } - m_family = font->family(); - m_variant = font->variant(); + m_family = font->family().to_deprecated_string(); + m_variant = font->variant().to_deprecated_string(); m_size = font->presentation_size(); - auto family_index = m_families.find_first_index(m_font->family()); + auto family_index = m_families.find_first_index(m_font->family().to_deprecated_string()); if (family_index.has_value()) m_family_list_view->set_cursor(m_family_list_view->model()->index(family_index.value()), GUI::AbstractView::SelectionUpdate::Set); - auto variant_index = m_variants.find_first_index(m_font->variant()); + auto variant_index = m_variants.find_first_index(m_font->variant().to_deprecated_string()); if (variant_index.has_value()) m_variant_list_view->set_cursor(m_variant_list_view->model()->index(variant_index.value()), GUI::AbstractView::SelectionUpdate::Set); diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index 961eb6f004e..2732451440d 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -826,20 +826,20 @@ void Widget::set_font_family(String const& family) void Widget::set_font_size(unsigned size) { - set_font(Gfx::FontDatabase::the().get(m_font->family(), size, m_font->weight(), m_font->width(), m_font->slope())); + set_font(Gfx::FontDatabase::the().get(m_font->family().to_deprecated_string(), size, m_font->weight(), m_font->width(), m_font->slope())); } void Widget::set_font_weight(unsigned weight) { - set_font(Gfx::FontDatabase::the().get(m_font->family(), m_font->presentation_size(), weight, m_font->width(), m_font->slope())); + set_font(Gfx::FontDatabase::the().get(m_font->family().to_deprecated_string(), m_font->presentation_size(), weight, m_font->width(), m_font->slope())); } void Widget::set_font_fixed_width(bool fixed_width) { if (fixed_width) - set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_fixed_width_font().family(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope())); + set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_fixed_width_font().family().to_deprecated_string(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope())); else - set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_font().family(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope())); + set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_font().family().to_deprecated_string(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope())); } bool Widget::is_font_fixed_width() @@ -1272,7 +1272,7 @@ void Widget::add_spacer() String Widget::font_family() const { - return String::from_deprecated_string(m_font->family()).release_value_but_fixme_should_propagate_errors(); + return m_font->family(); } } diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp index 025b855d88e..fc411286f18 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp @@ -85,7 +85,7 @@ ErrorOr> BitmapFont::try_create(u8 glyph_height, u8 gl auto* new_widths = static_cast(calloc(glyph_count, 1)); if (!new_widths) return Error::from_errno(errno); - return adopt_nonnull_ref_or_enomem(new (nothrow) BitmapFont("Untitled", "Untitled", new_rows, new_widths, fixed, glyph_width, glyph_height, 1, range_mask_size, new_range_mask, 0, 0, 0, 400, 0, true)); + return adopt_nonnull_ref_or_enomem(new (nothrow) BitmapFont("Untitled"_string, "Untitled"_string, new_rows, new_widths, fixed, glyph_width, glyph_height, 1, range_mask_size, new_range_mask, 0, 0, 0, 400, 0, true)); } ErrorOr> BitmapFont::unmasked_character_set() const @@ -148,7 +148,7 @@ ErrorOr> BitmapFont::masked_character_set() const return 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, new_range_mask_size, new_range_mask, m_baseline, m_mean_line, m_presentation_size, m_weight, m_slope, true)); } -BitmapFont::BitmapFont(DeprecatedString name, DeprecatedString family, u8* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing, u16 range_mask_size, u8* range_mask, u8 baseline, u8 mean_line, u8 presentation_size, u16 weight, u8 slope, bool owns_arrays) +BitmapFont::BitmapFont(String name, String family, u8* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing, u16 range_mask_size, u8* range_mask, u8 baseline, u8 mean_line, u8 presentation_size, u16 weight, u8 slope, bool owns_arrays) : m_name(move(name)) , m_family(move(family)) , m_range_mask_size(range_mask_size) @@ -223,7 +223,9 @@ ErrorOr> BitmapFont::load_from_memory(u8 const* data) glyph_count += 256 * popcount(range_mask[i]); u8* rows = range_mask + header.range_mask_size; u8* widths = (u8*)(rows) + glyph_count * bytes_per_glyph; - return adopt_nonnull_ref_or_enomem(new (nothrow) BitmapFont(DeprecatedString(header.name), DeprecatedString(header.family), rows, widths, !header.is_variable_width, header.glyph_width, header.glyph_height, header.glyph_spacing, header.range_mask_size, range_mask, header.baseline, header.mean_line, header.presentation_size, header.weight, header.slope)); + auto name = TRY(String::from_utf8(ReadonlyBytes { header.name, strlen(header.name) })); + auto family = TRY(String::from_utf8(ReadonlyBytes { header.family, strlen(header.family) })); + return adopt_nonnull_ref_or_enomem(new (nothrow) BitmapFont(move(name), move(family), rows, widths, !header.is_variable_width, header.glyph_width, header.glyph_height, header.glyph_spacing, header.range_mask_size, range_mask, header.baseline, header.mean_line, header.presentation_size, header.weight, header.slope)); } RefPtr BitmapFont::load_from_file(DeprecatedString const& path) @@ -267,8 +269,8 @@ ErrorOr BitmapFont::write_to_file(NonnullOwnPtr file) header.presentation_size = m_presentation_size; header.weight = m_weight; header.slope = m_slope; - memcpy(header.name, m_name.characters(), min(m_name.length(), sizeof(header.name) - 1)); - memcpy(header.family, m_family.characters(), min(m_family.length(), sizeof(header.family) - 1)); + memcpy(header.name, m_name.bytes().data(), min(m_name.bytes().size(), sizeof(header.name) - 1)); + memcpy(header.family, m_family.bytes().data(), min(m_family.bytes().size(), sizeof(header.family) - 1)); size_t bytes_per_glyph = sizeof(u32) * m_glyph_height; TRY(file->write_until_depleted({ &header, sizeof(header) })); @@ -386,12 +388,12 @@ ALWAYS_INLINE int BitmapFont::unicode_view_width(T const& view) const return longest_width; } -DeprecatedString BitmapFont::qualified_name() const +String BitmapFont::qualified_name() const { - return DeprecatedString::formatted("{} {} {} {}", family(), presentation_size(), weight(), slope()); + return MUST(String::formatted("{} {} {} {}", family(), presentation_size(), weight(), slope())); } -DeprecatedString BitmapFont::variant() const +String BitmapFont::variant() const { StringBuilder builder; builder.append(weight_to_name(weight())); @@ -402,19 +404,19 @@ DeprecatedString BitmapFont::variant() const builder.append(' '); builder.append(slope_to_name(slope())); } - return builder.to_deprecated_string(); + return MUST(builder.to_string()); } RefPtr BitmapFont::with_size(float point_size) const { - return Gfx::FontDatabase::the().get(family(), point_size, weight(), width(), slope()); + return Gfx::FontDatabase::the().get(family().to_deprecated_string(), point_size, weight(), width(), slope()); } Font const& Font::bold_variant() const { if (m_bold_variant) return *m_bold_variant; - m_bold_variant = Gfx::FontDatabase::the().get(family(), presentation_size(), 700, Gfx::FontWidth::Normal, 0); + m_bold_variant = Gfx::FontDatabase::the().get(family().to_deprecated_string(), presentation_size(), 700, Gfx::FontWidth::Normal, 0); if (!m_bold_variant) m_bold_variant = this; return *m_bold_variant; diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.h b/Userland/Libraries/LibGfx/Font/BitmapFont.h index cd9827ea594..8f7c5e22e1f 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.h +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.h @@ -102,8 +102,8 @@ public: virtual int width_rounded_up(StringView) const override; - DeprecatedString name() const override { return m_name; } - void set_name(DeprecatedString name) { m_name = move(name); } + virtual String name() const override { return m_name; } + void set_name(String name) { m_name = move(name); } bool is_fixed_width() const override { return m_fixed_width; } void set_fixed_width(bool b) { m_fixed_width = b; } @@ -123,17 +123,17 @@ public: u16 range_size() const { return m_range_mask_size; } bool is_range_empty(u32 code_point) const { return !(m_range_mask[code_point / 256 / 8] & 1 << (code_point / 256 % 8)); } - DeprecatedString family() const override { return m_family; } - void set_family(DeprecatedString family) { m_family = move(family); } - DeprecatedString variant() const override; + virtual String family() const override { return m_family; } + void set_family(String family) { m_family = move(family); } + virtual String variant() const override; - DeprecatedString qualified_name() const override; - DeprecatedString human_readable_name() const override { return DeprecatedString::formatted("{} {} {}", family(), variant(), presentation_size()); } + virtual String qualified_name() const override; + virtual String human_readable_name() const override { return MUST(String::formatted("{} {} {}", family(), variant(), presentation_size())); } virtual RefPtr with_size(float point_size) const override; private: - BitmapFont(DeprecatedString name, DeprecatedString family, u8* rows, u8* widths, bool is_fixed_width, + BitmapFont(String name, String family, u8* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing, u16 range_mask_size, u8* range_mask, u8 baseline, u8 mean_line, u8 presentation_size, u16 weight, u8 slope, bool owns_arrays = false); @@ -146,8 +146,8 @@ private: virtual bool has_color_bitmaps() const override { return false; } - DeprecatedString m_name; - DeprecatedString m_family; + String m_name; + String m_family; size_t m_glyph_count { 0 }; u16 m_range_mask_size { 0 }; diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index f0633eb557d..19b940d3e7c 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -9,9 +9,9 @@ #include #include -#include #include #include +#include #include #include #include @@ -198,7 +198,7 @@ public: virtual int width_rounded_up(StringView) const = 0; - virtual DeprecatedString name() const = 0; + virtual String name() const = 0; virtual bool is_fixed_width() const = 0; @@ -206,11 +206,11 @@ public: virtual size_t glyph_count() const = 0; - virtual DeprecatedString family() const = 0; - virtual DeprecatedString variant() const = 0; + virtual String family() const = 0; + virtual String variant() const = 0; - virtual DeprecatedString qualified_name() const = 0; - virtual DeprecatedString human_readable_name() const = 0; + virtual String qualified_name() const = 0; + virtual String human_readable_name() const = 0; virtual RefPtr with_size(float point_size) const = 0; diff --git a/Userland/Libraries/LibGfx/Font/FontDatabase.cpp b/Userland/Libraries/LibGfx/Font/FontDatabase.cpp index 2c33a96830b..316cb7d8d2e 100644 --- a/Userland/Libraries/LibGfx/Font/FontDatabase.cpp +++ b/Userland/Libraries/LibGfx/Font/FontDatabase.cpp @@ -143,21 +143,21 @@ void FontDatabase::load_all_fonts_from_path(DeprecatedString const& root) if (path.ends_with(".font"sv)) { if (auto font_or_error = Gfx::BitmapFont::try_load_from_file(path); !font_or_error.is_error()) { auto font = font_or_error.release_value(); - m_private->full_name_to_font_map.set(font->qualified_name(), *font); - auto typeface = get_or_create_typeface(font->family(), font->variant()); + m_private->full_name_to_font_map.set(font->qualified_name().to_deprecated_string(), *font); + auto typeface = get_or_create_typeface(font->family().to_deprecated_string(), font->variant().to_deprecated_string()); typeface->add_bitmap_font(font); } } else if (path.ends_with(".ttf"sv)) { // FIXME: What about .otf if (auto font_or_error = OpenType::Font::try_load_from_file(path); !font_or_error.is_error()) { auto font = font_or_error.release_value(); - auto typeface = get_or_create_typeface(font->family(), font->variant()); + auto typeface = get_or_create_typeface(font->family().to_deprecated_string(), font->variant().to_deprecated_string()); typeface->set_vector_font(move(font)); } } else if (path.ends_with(".woff"sv)) { if (auto font_or_error = WOFF::Font::try_load_from_file(path); !font_or_error.is_error()) { auto font = font_or_error.release_value(); - auto typeface = get_or_create_typeface(font->family(), font->variant()); + auto typeface = get_or_create_typeface(font->family().to_deprecated_string(), font->variant().to_deprecated_string()); typeface->set_vector_font(move(font)); } } diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp index 869f2b5fd79..5addc9f941a 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp @@ -292,7 +292,7 @@ Optional Kern::read_glyph_kerning_format0(ReadonlyBytes slice, u16 left_gly return pair->value; } -DeprecatedString Name::string_for_id(NameId id) const +String Name::string_for_id(NameId id) const { auto const count = header().count; auto const storage_offset = header().storage_offset; @@ -306,7 +306,7 @@ DeprecatedString Name::string_for_id(NameId id) const } if (valid_ids.is_empty()) - return DeprecatedString::empty(); + return String {}; auto it = valid_ids.find_if([this](auto const& i) { // check if font has naming table for en-US language id @@ -326,10 +326,10 @@ DeprecatedString Name::string_for_id(NameId id) const if (platform_id == to_underlying(Platform::Windows)) { static auto& decoder = *TextCodec::decoder_for("utf-16be"sv); - return decoder.to_utf8(StringView { (char const*)m_slice.offset_pointer(storage_offset + offset), length }).release_value_but_fixme_should_propagate_errors().to_deprecated_string(); + return decoder.to_utf8(StringView { (char const*)m_slice.offset_pointer(storage_offset + offset), length }).release_value_but_fixme_should_propagate_errors(); } - return DeprecatedString((char const*)m_slice.offset_pointer(storage_offset + offset), length); + return String::from_utf8(m_slice.slice(storage_offset + offset, length)).release_value_but_fixme_should_propagate_errors(); } GlyphHorizontalMetrics Hmtx::get_glyph_horizontal_metrics(u32 glyph_id) const @@ -763,7 +763,7 @@ u16 Font::units_per_em() const return m_head.units_per_em(); } -DeprecatedString Font::family() const +String Font::family() const { auto string = m_name.typographic_family_name(); if (!string.is_empty()) @@ -771,7 +771,7 @@ DeprecatedString Font::family() const return m_name.family_name(); } -DeprecatedString Font::variant() const +String Font::variant() const { auto string = m_name.typographic_subfamily_name(); if (!string.is_empty()) diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.h b/Userland/Libraries/LibGfx/Font/OpenType/Font.h index 80a0dd16377..fb0a32ab20b 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.h @@ -34,8 +34,8 @@ public: virtual u32 glyph_count() const override; virtual u16 units_per_em() const override; virtual u32 glyph_id_for_code_point(u32 code_point) const override; - virtual DeprecatedString family() const override; - virtual DeprecatedString variant() const override; + virtual String family() const override; + virtual String variant() const override; virtual u16 weight() const override; virtual u16 width() const override; virtual u8 slope() const override; diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Tables.h b/Userland/Libraries/LibGfx/Font/OpenType/Tables.h index b70b059b3d6..60d9c66a22b 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Tables.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Tables.h @@ -326,10 +326,10 @@ public: }; static Optional from_slice(ReadonlyBytes); - DeprecatedString family_name() const { return string_for_id(NameId::FamilyName); } - DeprecatedString subfamily_name() const { return string_for_id(NameId::SubfamilyName); } - DeprecatedString typographic_family_name() const { return string_for_id(NameId::TypographicFamilyName); } - DeprecatedString typographic_subfamily_name() const { return string_for_id(NameId::TypographicSubfamilyName); } + String family_name() const { return string_for_id(NameId::FamilyName); } + String subfamily_name() const { return string_for_id(NameId::SubfamilyName); } + String typographic_family_name() const { return string_for_id(NameId::TypographicFamilyName); } + String typographic_subfamily_name() const { return string_for_id(NameId::TypographicSubfamilyName); } private: // https://learn.microsoft.com/en-us/typography/opentype/spec/name#name-records @@ -373,7 +373,7 @@ private: { } - DeprecatedString string_for_id(NameId) const; + [[nodiscard]] String string_for_id(NameId) const; ReadonlyBytes m_slice; }; diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.h b/Userland/Libraries/LibGfx/Font/ScaledFont.h index ada2754dbb2..2e13982b139 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.h +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.h @@ -62,14 +62,14 @@ public: virtual float width(Utf8View const&) const override; virtual float width(Utf32View const&) const override; virtual int width_rounded_up(StringView) const override; - virtual DeprecatedString name() const override { return DeprecatedString::formatted("{} {}", family(), variant()); } + virtual String name() const override { return MUST(String::formatted("{} {}", family(), variant())); } virtual bool is_fixed_width() const override { return m_font->is_fixed_width(); } virtual u8 glyph_spacing() const override { return 0; } virtual size_t glyph_count() const override { return m_font->glyph_count(); } - virtual DeprecatedString family() const override { return m_font->family(); } - virtual DeprecatedString variant() const override { return m_font->variant(); } - virtual DeprecatedString qualified_name() const override { return DeprecatedString::formatted("{} {} {} {}", family(), presentation_size(), weight(), slope()); } - virtual DeprecatedString human_readable_name() const override { return DeprecatedString::formatted("{} {} {}", family(), variant(), presentation_size()); } + virtual String family() const override { return m_font->family(); } + virtual String variant() const override { return m_font->variant(); } + virtual String qualified_name() const override { return MUST(String::formatted("{} {} {} {}", family(), presentation_size(), weight(), slope())); } + virtual String human_readable_name() const override { return MUST(String::formatted("{} {} {}", family(), variant(), presentation_size())); } virtual RefPtr with_size(float point_size) const override; diff --git a/Userland/Libraries/LibGfx/Font/VectorFont.h b/Userland/Libraries/LibGfx/Font/VectorFont.h index 945eb1e54e6..ebd8714ff3a 100644 --- a/Userland/Libraries/LibGfx/Font/VectorFont.h +++ b/Userland/Libraries/LibGfx/Font/VectorFont.h @@ -42,8 +42,8 @@ public: virtual u32 glyph_count() const = 0; virtual u16 units_per_em() const = 0; virtual u32 glyph_id_for_code_point(u32 code_point) const = 0; - virtual DeprecatedString family() const = 0; - virtual DeprecatedString variant() const = 0; + virtual String family() const = 0; + virtual String variant() const = 0; virtual u16 weight() const = 0; virtual u16 width() const = 0; virtual u8 slope() const = 0; diff --git a/Userland/Libraries/LibGfx/Font/WOFF/Font.h b/Userland/Libraries/LibGfx/Font/WOFF/Font.h index cec576368c7..8c68981b898 100644 --- a/Userland/Libraries/LibGfx/Font/WOFF/Font.h +++ b/Userland/Libraries/LibGfx/Font/WOFF/Font.h @@ -31,8 +31,8 @@ public: virtual u32 glyph_count() const override { return m_input_font->glyph_count(); } virtual u16 units_per_em() const override { return m_input_font->units_per_em(); } virtual u32 glyph_id_for_code_point(u32 code_point) const override { return m_input_font->glyph_id_for_code_point(code_point); } - virtual DeprecatedString family() const override { return m_input_font->family(); } - virtual DeprecatedString variant() const override { return m_input_font->variant(); } + virtual String family() const override { return m_input_font->family(); } + virtual String variant() const override { return m_input_font->variant(); } virtual u16 weight() const override { return m_input_font->weight(); } virtual u16 width() const override { return m_input_font->width(); } virtual u8 slope() const override { return m_input_font->slope(); } diff --git a/Userland/Libraries/LibGfx/Font/WOFF2/Font.h b/Userland/Libraries/LibGfx/Font/WOFF2/Font.h index 3ec19caee9a..2f609766abf 100644 --- a/Userland/Libraries/LibGfx/Font/WOFF2/Font.h +++ b/Userland/Libraries/LibGfx/Font/WOFF2/Font.h @@ -35,8 +35,8 @@ public: virtual u32 glyph_count() const override { return m_input_font->glyph_count(); } virtual u16 units_per_em() const override { return m_input_font->units_per_em(); } virtual u32 glyph_id_for_code_point(u32 code_point) const override { return m_input_font->glyph_id_for_code_point(code_point); } - virtual DeprecatedString family() const override { return m_input_font->family(); } - virtual DeprecatedString variant() const override { return m_input_font->variant(); } + virtual String family() const override { return m_input_font->family(); } + virtual String variant() const override { return m_input_font->variant(); } virtual u16 weight() const override { return m_input_font->weight(); } virtual u16 width() const override { return m_input_font->width(); } virtual u8 slope() const override { return m_input_font->slope(); } diff --git a/Userland/Libraries/LibWeb/FontCache.cpp b/Userland/Libraries/LibWeb/FontCache.cpp index 76b0c9a3c31..f7d991d4e5c 100644 --- a/Userland/Libraries/LibWeb/FontCache.cpp +++ b/Userland/Libraries/LibWeb/FontCache.cpp @@ -21,7 +21,7 @@ RefPtr FontCache::get(FontSelector const& font_selector) const NonnullRefPtr FontCache::scaled_font(Gfx::Font const& font, float scale_factor) { auto device_font_pt_size = font.point_size() * scale_factor; - FontSelector font_selector = { FlyString::from_deprecated_fly_string(font.family()).release_value_but_fixme_should_propagate_errors(), device_font_pt_size, font.weight(), font.width(), font.slope() }; + FontSelector font_selector = { font.family(), device_font_pt_size, font.weight(), font.width(), font.slope() }; if (auto cached_font = get(font_selector)) { return *cached_font; } diff --git a/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.cpp b/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.cpp index c860977dffd..c8f437e98c5 100644 --- a/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.cpp +++ b/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.cpp @@ -37,10 +37,10 @@ DeprecatedString FontPluginSerenity::generic_font_name(GenericFont generic_font) case GenericFont::UiSansSerif: case GenericFont::Cursive: case GenericFont::UiRounded: - return default_font().family(); + return default_font().family().to_deprecated_string(); case GenericFont::Monospace: case GenericFont::UiMonospace: - return default_fixed_width_font().family(); + return default_fixed_width_font().family().to_deprecated_string(); case GenericFont::Serif: case GenericFont::UiSerif: return "Roman"; diff --git a/Userland/Services/WindowServer/Overlays.cpp b/Userland/Services/WindowServer/Overlays.cpp index d2dee235163..7f09445827f 100644 --- a/Userland/Services/WindowServer/Overlays.cpp +++ b/Userland/Services/WindowServer/Overlays.cpp @@ -183,7 +183,7 @@ void ScreenNumberOverlay::pick_font() return; } } - best_font_name = font.qualified_name(); + best_font_name = font.qualified_name().to_deprecated_string(); best_font_size = size; } });