diff --git a/Meta/Lagom/Fuzzers/FuzzTTF.cpp b/Meta/Lagom/Fuzzers/FuzzTTF.cpp index b401883267f..a194c74f2f2 100644 --- a/Meta/Lagom/Fuzzers/FuzzTTF.cpp +++ b/Meta/Lagom/Fuzzers/FuzzTTF.cpp @@ -4,13 +4,13 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include extern "C" int LLVMFuzzerTestOneInput(u8 const* data, size_t size) { AK::set_debug_enabled(false); - (void)OpenType::Font::try_load_from_externally_owned_memory({ data, size }); + (void)OpenType::Typeface::try_load_from_externally_owned_memory({ data, size }); return 0; } diff --git a/Userland/Libraries/LibGfx/CMakeLists.txt b/Userland/Libraries/LibGfx/CMakeLists.txt index ee1d354bab5..f67128ab88c 100644 --- a/Userland/Libraries/LibGfx/CMakeLists.txt +++ b/Userland/Libraries/LibGfx/CMakeLists.txt @@ -15,10 +15,10 @@ set(SOURCES Font/Font.cpp Font/FontDatabase.cpp Font/OpenType/Cmap.cpp - Font/OpenType/Font.cpp Font/OpenType/Glyf.cpp Font/OpenType/Hinting/Opcodes.cpp Font/OpenType/Tables.cpp + Font/OpenType/Typeface.cpp Font/ScaledFont.cpp Font/Typeface.cpp Font/WOFF/Font.cpp diff --git a/Userland/Libraries/LibGfx/Font/FontDatabase.cpp b/Userland/Libraries/LibGfx/Font/FontDatabase.cpp index 1f1e7d7a54a..617f1f52bb7 100644 --- a/Userland/Libraries/LibGfx/Font/FontDatabase.cpp +++ b/Userland/Libraries/LibGfx/Font/FontDatabase.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -44,7 +44,7 @@ void FontDatabase::load_all_fonts_from_uri(StringView uri) auto path = LexicalPath(uri.bytes_as_string_view()); if (path.has_extension(".ttf"sv)) { // FIXME: What about .otf - if (auto font_or_error = OpenType::Font::try_load_from_resource(resource); !font_or_error.is_error()) { + if (auto font_or_error = OpenType::Typeface::try_load_from_resource(resource); !font_or_error.is_error()) { auto font = font_or_error.release_value(); auto& family = m_private->typeface_by_family.ensure(font->family(), [] { return Vector> {}; diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Typeface.cpp similarity index 92% rename from Userland/Libraries/LibGfx/Font/OpenType/Font.cpp rename to Userland/Libraries/LibGfx/Font/OpenType/Typeface.cpp index 592f68da519..f218564e2f5 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Typeface.cpp @@ -15,9 +15,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -150,7 +150,7 @@ float be_fword(u8 const* ptr) return (float)be_i16(ptr) / (float)(1 << 14); } -ErrorOr> Font::try_load_from_resource(Core::Resource const& resource, unsigned index) +ErrorOr> Typeface::try_load_from_resource(Core::Resource const& resource, unsigned index) { auto font = TRY(try_load_from_externally_owned_memory(resource.data(), { .index = index })); font->m_resource = resource; @@ -163,7 +163,7 @@ static ErrorOr read_tag(ReadonlyBytes buffer) return stream.read_value(); } -ErrorOr> Font::try_load_from_externally_owned_memory(ReadonlyBytes buffer, Options options) +ErrorOr> Typeface::try_load_from_externally_owned_memory(ReadonlyBytes buffer, Options options) { auto tag = TRY(read_tag(buffer)); if (tag == HeaderTag_FontCollection) { @@ -211,7 +211,7 @@ static ErrorOr for_each_table_record(ReadonlyBytes buffer, u32 offset, Fun } // FIXME: "loca" and "glyf" are not available for CFF fonts. -ErrorOr> Font::try_load_from_offset(ReadonlyBytes buffer, u32 offset, Options options) +ErrorOr> Typeface::try_load_from_offset(ReadonlyBytes buffer, u32 offset, Options options) { Optional opt_head_slice = {}; Optional opt_name_slice = {}; @@ -331,7 +331,7 @@ ErrorOr> Font::try_load_from_offset(ReadonlyBytes buffer, u3 if (opt_prep_slice.has_value()) prep = Prep(opt_prep_slice.value()); - return adopt_ref(*new Font( + return adopt_ref(*new Typeface( move(head), move(name), move(hhea), @@ -349,7 +349,7 @@ ErrorOr> Font::try_load_from_offset(ReadonlyBytes buffer, u3 move(gpos))); } -Gfx::ScaledFontMetrics Font::metrics([[maybe_unused]] float x_scale, float y_scale) const +Gfx::ScaledFontMetrics Typeface::metrics([[maybe_unused]] float x_scale, float y_scale) const { i16 raw_ascender; i16 raw_descender; @@ -379,7 +379,7 @@ Gfx::ScaledFontMetrics Font::metrics([[maybe_unused]] float x_scale, float y_sca }; } -Font::EmbeddedBitmapData Font::embedded_bitmap_data_for_glyph(u32 glyph_id) const +Typeface::EmbeddedBitmapData Typeface::embedded_bitmap_data_for_glyph(u32 glyph_id) const { if (!has_color_bitmaps()) return Empty {}; @@ -414,7 +414,7 @@ Font::EmbeddedBitmapData Font::embedded_bitmap_data_for_glyph(u32 glyph_id) cons return Empty {}; } -float Font::glyph_advance(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const +float Typeface::glyph_advance(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const { if (has_color_bitmaps()) return glyph_metrics(glyph_id, x_scale, y_scale, point_width, point_height).advance_width; @@ -429,7 +429,7 @@ float Font::glyph_advance(u32 glyph_id, float x_scale, float y_scale, float poin return static_cast(horizontal_metrics.advance_width) * x_scale; } -Gfx::ScaledGlyphMetrics Font::glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const +Gfx::ScaledGlyphMetrics Typeface::glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const { auto embedded_bitmap_metrics = embedded_bitmap_data_for_glyph(glyph_id).visit( [&](EmbeddedBitmapWithFormat17 const& data) -> Optional { @@ -474,7 +474,7 @@ Gfx::ScaledGlyphMetrics Font::glyph_metrics(u32 glyph_id, float x_scale, float y }; } -float Font::glyphs_horizontal_kerning(u32 left_glyph_id, u32 right_glyph_id, float x_scale) const +float Typeface::glyphs_horizontal_kerning(u32 left_glyph_id, u32 right_glyph_id, float x_scale) const { if (!m_gpos.has_value() && !m_kern.has_value()) return 0.0f; @@ -503,7 +503,7 @@ float Font::glyphs_horizontal_kerning(u32 left_glyph_id, u32 right_glyph_id, flo return 0.0f; } -Font::AscenderAndDescender Font::resolve_ascender_and_descender() const +Typeface::AscenderAndDescender Typeface::resolve_ascender_and_descender() const { i16 ascender = 0; i16 descender = 0; @@ -518,7 +518,7 @@ Font::AscenderAndDescender Font::resolve_ascender_and_descender() const return { ascender, descender }; } -Optional Font::extract_and_append_glyph_path_to(Gfx::Path& path, u32 glyph_id, i16 ascender, i16 descender, float x_scale, float y_scale) const +Optional Typeface::extract_and_append_glyph_path_to(Gfx::Path& path, u32 glyph_id, i16 ascender, i16 descender, float x_scale, float y_scale) const { if (!m_loca.has_value() || !m_glyf.has_value()) { return {}; @@ -552,13 +552,13 @@ Optional Font::extract_and_append_glyph_path_to(Gfx::Path& path, u3 return {}; } -bool Font::append_glyph_path_to(Gfx::Path& path, u32 glyph_id, float x_scale, float y_scale) const +bool Typeface::append_glyph_path_to(Gfx::Path& path, u32 glyph_id, float x_scale, float y_scale) const { auto ascender_and_descender = resolve_ascender_and_descender(); return extract_and_append_glyph_path_to(path, glyph_id, ascender_and_descender.ascender, ascender_and_descender.descender, x_scale, y_scale).has_value(); } -RefPtr Font::rasterize_glyph(u32 glyph_id, float x_scale, float y_scale, Gfx::GlyphSubpixelOffset subpixel_offset) const +RefPtr Typeface::rasterize_glyph(u32 glyph_id, float x_scale, float y_scale, Gfx::GlyphSubpixelOffset subpixel_offset) const { if (auto bitmap = color_bitmap(glyph_id)) return bitmap; @@ -579,17 +579,17 @@ RefPtr Font::rasterize_glyph(u32 glyph_id, float x_scale, float y_s return bitmap; } -u32 Font::glyph_count() const +u32 Typeface::glyph_count() const { return m_maxp.num_glyphs(); } -u16 Font::units_per_em() const +u16 Typeface::units_per_em() const { return m_head.units_per_em(); } -String Font::family() const +String Typeface::family() const { if (!m_name.has_value()) return {}; @@ -605,7 +605,7 @@ String Font::family() const return *m_family; } -String Font::variant() const +String Typeface::variant() const { if (!m_name.has_value()) return {}; @@ -616,7 +616,7 @@ String Font::variant() const return m_name->subfamily_name(); } -u16 Font::weight() const +u16 Typeface::weight() const { if (!m_weight.has_value()) { m_weight = [&]() -> u16 { @@ -631,7 +631,7 @@ u16 Font::weight() const return *m_weight; } -u16 Font::width() const +u16 Typeface::width() const { if (!m_width.has_value()) { m_width = [&]() -> u16 { @@ -643,7 +643,7 @@ u16 Font::width() const return *m_width; } -u8 Font::slope() const +u8 Typeface::slope() const { if (!m_slope.has_value()) { m_slope = [&]() -> u8 { @@ -665,28 +665,28 @@ u8 Font::slope() const return *m_slope; } -bool Font::is_fixed_width() const +bool Typeface::is_fixed_width() const { // FIXME: Read this information from the font file itself. // FIXME: Although, it appears some application do similar hacks return glyph_metrics(glyph_id_for_code_point('.'), 1, 1, 1, 1).advance_width == glyph_metrics(glyph_id_for_code_point('X'), 1, 1, 1, 1).advance_width; } -Optional Font::font_program() const +Optional Typeface::font_program() const { if (m_fpgm.has_value()) return m_fpgm->program_data(); return {}; } -Optional Font::control_value_program() const +Optional Typeface::control_value_program() const { if (m_prep.has_value()) return m_prep->program_data(); return {}; } -Optional Font::glyph_program(u32 glyph_id) const +Optional Typeface::glyph_program(u32 glyph_id) const { if (!m_loca.has_value() || !m_glyf.has_value()) { return {}; @@ -699,12 +699,12 @@ Optional Font::glyph_program(u32 glyph_id) const return glyph->program(); } -u32 Font::glyph_id_for_code_point(u32 code_point) const +u32 Typeface::glyph_id_for_code_point(u32 code_point) const { return glyph_page(code_point / GlyphPage::glyphs_per_page).glyph_ids[code_point % GlyphPage::glyphs_per_page]; } -Font::GlyphPage const& Font::glyph_page(size_t page_index) const +Typeface::GlyphPage const& Typeface::glyph_page(size_t page_index) const { if (page_index == 0) { if (!m_glyph_page_zero) { @@ -724,7 +724,7 @@ Font::GlyphPage const& Font::glyph_page(size_t page_index) const return *glyph_page_ptr; } -void Font::populate_glyph_page(GlyphPage& glyph_page, size_t page_index) const +void Typeface::populate_glyph_page(GlyphPage& glyph_page, size_t page_index) const { u32 first_code_point = page_index * GlyphPage::glyphs_per_page; for (size_t i = 0; i < GlyphPage::glyphs_per_page; ++i) { @@ -732,12 +732,12 @@ void Font::populate_glyph_page(GlyphPage& glyph_page, size_t page_index) const glyph_page.glyph_ids[i] = m_cmap->glyph_id_for_code_point(code_point); } } -bool Font::has_color_bitmaps() const +bool Typeface::has_color_bitmaps() const { return m_cblc.has_value() && m_cbdt.has_value(); } -RefPtr Font::color_bitmap(u32 glyph_id) const +RefPtr Typeface::color_bitmap(u32 glyph_id) const { return embedded_bitmap_data_for_glyph(glyph_id).visit( [&](EmbeddedBitmapWithFormat17 const& data) -> RefPtr { diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.h b/Userland/Libraries/LibGfx/Font/OpenType/Typeface.h similarity index 93% rename from Userland/Libraries/LibGfx/Font/OpenType/Font.h rename to Userland/Libraries/LibGfx/Font/OpenType/Typeface.h index b288686b6ac..c3925b9db76 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Typeface.h @@ -45,13 +45,13 @@ struct FontOptions { u32 skip_tables { 0 }; }; -class Font : public Gfx::Typeface { - AK_MAKE_NONCOPYABLE(Font); +class Typeface : public Gfx::Typeface { + AK_MAKE_NONCOPYABLE(Typeface); public: using Options = FontOptions; - static ErrorOr> try_load_from_resource(Core::Resource const&, unsigned index = 0); - static ErrorOr> try_load_from_externally_owned_memory(ReadonlyBytes bytes, Options options = {}); + static ErrorOr> try_load_from_resource(Core::Resource const&, unsigned index = 0); + static ErrorOr> try_load_from_externally_owned_memory(ReadonlyBytes bytes, Options options = {}); virtual Gfx::ScaledFontMetrics metrics(float x_scale, float y_scale) const override; virtual Gfx::ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const override; @@ -108,9 +108,9 @@ private: EmbeddedBitmapData embedded_bitmap_data_for_glyph(u32 glyph_id) const; - static ErrorOr> try_load_from_offset(ReadonlyBytes, u32 offset, Options options); + static ErrorOr> try_load_from_offset(ReadonlyBytes, u32 offset, Options options); - Font( + Typeface( Head&& head, Optional&& name, Hhea&& hhea, diff --git a/Userland/Libraries/LibGfx/Font/WOFF/Font.cpp b/Userland/Libraries/LibGfx/Font/WOFF/Font.cpp index 501884c0ac3..e8d63c62b24 100644 --- a/Userland/Libraries/LibGfx/Font/WOFF/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/WOFF/Font.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include namespace WOFF { @@ -158,7 +158,7 @@ ErrorOr> Font::try_load_from_externally_owned_memory(Readonl if (header.total_sfnt_size != expected_total_sfnt_size) return Error::from_string_literal("Invalid WOFF total sfnt size"); - auto input_font = TRY(OpenType::Font::try_load_from_externally_owned_memory(font_buffer.bytes(), { .index = index })); + auto input_font = TRY(OpenType::Typeface::try_load_from_externally_owned_memory(font_buffer.bytes(), { .index = index })); auto font = adopt_ref(*new Font(input_font, move(font_buffer))); return font; } diff --git a/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp b/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp index c8f7edce0a0..5ed70f0b4da 100644 --- a/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp @@ -5,7 +5,7 @@ */ #define AK_DONT_REPLACE_STD -#include +#include #include #include @@ -62,7 +62,7 @@ ErrorOr> Font::try_load_from_externally_owned_memory(Readonl if (!result) { return Error::from_string_literal("Failed to convert the WOFF2 font to TTF"); } - auto input_font = TRY(OpenType::Font::try_load_from_externally_owned_memory(ttf_buffer.bytes())); + auto input_font = TRY(OpenType::Typeface::try_load_from_externally_owned_memory(ttf_buffer.bytes())); return adopt_ref(*new Font(input_font, move(ttf_buffer))); } diff --git a/Userland/Libraries/LibWeb/CSS/FontFace.cpp b/Userland/Libraries/LibWeb/CSS/FontFace.cpp index 366c8c77c17..e77010a5b5b 100644 --- a/Userland/Libraries/LibWeb/CSS/FontFace.cpp +++ b/Userland/Libraries/LibWeb/CSS/FontFace.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include @@ -35,7 +35,7 @@ static NonnullRefPtr>> load_vector_fo Platform::EventLoopPlugin::the().deferred_invoke([&data, promise] { // FIXME: This should be de-duplicated with StyleComputer::FontLoader::try_load_font // We don't have the luxury of knowing the MIME type, so we have to try all formats. - auto ttf = OpenType::Font::try_load_from_externally_owned_memory(data); + auto ttf = OpenType::Typeface::try_load_from_externally_owned_memory(data); if (!ttf.is_error()) { promise->resolve(ttf.release_value()); return; diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 9eb384bc764..3fe4caed965 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -167,7 +167,7 @@ ErrorOr> FontLoader::try_load_font() // FIXME: This could maybe use the format() provided in @font-face as well, since often the mime type is just application/octet-stream and we have to try every format auto const& mime_type = resource()->mime_type(); if (mime_type == "font/ttf"sv || mime_type == "application/x-font-ttf"sv) { - if (auto result = OpenType::Font::try_load_from_externally_owned_memory(resource()->encoded_data()); !result.is_error()) { + if (auto result = OpenType::Typeface::try_load_from_externally_owned_memory(resource()->encoded_data()); !result.is_error()) { return result; } } @@ -183,7 +183,7 @@ ErrorOr> FontLoader::try_load_font() } // We don't have the luxury of knowing the MIME type, so we have to try all formats. - auto ttf = OpenType::Font::try_load_from_externally_owned_memory(resource()->encoded_data()); + auto ttf = OpenType::Typeface::try_load_from_externally_owned_memory(resource()->encoded_data()); if (!ttf.is_error()) return ttf.release_value(); auto woff = WOFF::Font::try_load_from_externally_owned_memory(resource()->encoded_data()); diff --git a/Userland/Utilities/ttfdisasm.cpp b/Userland/Utilities/ttfdisasm.cpp index b6eb8e226e2..0c638643389 100644 --- a/Userland/Utilities/ttfdisasm.cpp +++ b/Userland/Utilities/ttfdisasm.cpp @@ -7,8 +7,8 @@ #include #include #include -#include #include +#include #include using namespace OpenType::Hinting; @@ -169,7 +169,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.parse(arguments); auto resource = TRY(Core::Resource::load_from_filesystem(font_path)); - auto font = TRY(OpenType::Font::try_load_from_resource(resource)); + auto font = TRY(OpenType::Typeface::try_load_from_resource(resource)); if (dump_font_program) print_disassembly("Font program"sv, font->font_program(), !no_color);