LibGfx: Convert Font APIs to return String instead of DeprecatedString

This commit is contained in:
Andreas Kling 2023-09-05 15:32:52 +02:00 committed by Tim Flynn
parent 4e9dc127ae
commit 545d8336b8
29 changed files with 106 additions and 104 deletions

View file

@ -87,7 +87,7 @@ void FontPlugin::update_generic_fonts()
gfx_font = Gfx::FontDatabase::default_font();
}
m_generic_font_names[static_cast<size_t>(generic_font)] = gfx_font->family();
m_generic_font_names[static_cast<size_t>(generic_font)] = gfx_font->family().to_deprecated_string();
};
// Fallback fonts to look for if Gfx::Font can't load expected font

View file

@ -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)

View file

@ -176,7 +176,7 @@ ErrorOr<void> 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());
}

View file

@ -72,16 +72,16 @@ ErrorOr<void> 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());
}
}

View file

@ -321,14 +321,14 @@ static ErrorOr<FontInfo> 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<Gfx::Typeface>(font->family(), font->variant()));
auto typeface = TRY(try_make_ref_counted<Gfx::Typeface>(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<Gfx::Typeface>(font->family(), font->variant()));
auto typeface = TRY(try_make_ref_counted<Gfx::Typeface>(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<FontInfo> 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<Gfx::Typeface>(font->family(), font->variant()));
auto typeface = TRY(try_make_ref_counted<Gfx::Typeface>(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,

View file

@ -532,13 +532,13 @@ ErrorOr<void> MainWidget::create_widgets()
m_name_textbox = find_descendant_of_type_named<GUI::TextBox>("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<GUI::TextBox>("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();
};

View file

@ -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();

View file

@ -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;

View file

@ -114,13 +114,13 @@ ErrorOr<GUI::Widget*> TextTool::get_properties_widget()
auto font_header = TRY(properties_widget->try_add<GUI::Label>("Current Font:"_string));
font_header->set_text_alignment(Gfx::TextAlignment::CenterLeft);
m_font_label = TRY(properties_widget->try_add<GUI::Label>(TRY(String::from_deprecated_string(m_selected_font->human_readable_name()))));
m_font_label = TRY(properties_widget->try_add<GUI::Label>(m_selected_font->human_readable_name()));
auto change_font_button = TRY(properties_widget->try_add<GUI::Button>("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);

View file

@ -403,7 +403,7 @@ ErrorOr<int> 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());

View file

@ -116,13 +116,13 @@ ErrorOr<void> 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<void> 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 {

View file

@ -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;
}
});

View file

@ -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;
}
});

View file

@ -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);

View file

@ -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();
}
}

View file

@ -85,7 +85,7 @@ ErrorOr<NonnullRefPtr<BitmapFont>> BitmapFont::try_create(u8 glyph_height, u8 gl
auto* new_widths = static_cast<u8*>(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<NonnullRefPtr<BitmapFont>> BitmapFont::unmasked_character_set() const
@ -148,7 +148,7 @@ ErrorOr<NonnullRefPtr<BitmapFont>> 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<NonnullRefPtr<BitmapFont>> 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> BitmapFont::load_from_file(DeprecatedString const& path)
@ -267,8 +269,8 @@ ErrorOr<void> BitmapFont::write_to_file(NonnullOwnPtr<Core::File> 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<Font> 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;

View file

@ -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<Font> 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 };

View file

@ -9,9 +9,9 @@
#include <AK/Bitmap.h>
#include <AK/ByteReader.h>
#include <AK/DeprecatedString.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <LibCore/MappedFile.h>
#include <LibGfx/Bitmap.h>
@ -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<Font> with_size(float point_size) const = 0;

View file

@ -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));
}
}

View file

@ -292,7 +292,7 @@ Optional<i16> 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())

View file

@ -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;

View file

@ -326,10 +326,10 @@ public:
};
static Optional<Name> 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;
};

View file

@ -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<Font> with_size(float point_size) const override;

View file

@ -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;

View file

@ -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(); }

View file

@ -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(); }

View file

@ -21,7 +21,7 @@ RefPtr<Gfx::Font const> FontCache::get(FontSelector const& font_selector) const
NonnullRefPtr<Gfx::Font const> 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;
}

View file

@ -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";

View file

@ -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;
}
});