Skip to content

Commit

Permalink
LibGfx+LibWeb: Rename Gfx::WOFF2::Font to Gfx::WOFF2::Typeface
Browse files Browse the repository at this point in the history
It's a leftover from VectorFont -> Typeface renaming
  • Loading branch information
kalenikaliaksandr committed Jul 12, 2024
1 parent fd2ce70 commit 07eebe5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Meta/Lagom/Fuzzers/FuzzWOFF2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibGfx/Font/WOFF2/Font.h>
#include <LibGfx/Font/WOFF2/Typeface.h>
#include <stddef.h>

extern "C" int LLVMFuzzerTestOneInput(u8 const* data, size_t size)
{
AK::set_debug_enabled(false);
(void)WOFF2::Font::try_load_from_externally_owned_memory({ data, size });
(void)WOFF2::Typeface::try_load_from_externally_owned_memory({ data, size });
return 0;
}
6 changes: 3 additions & 3 deletions Tests/LibGfx/TestWOFF2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibGfx/Font/WOFF2/Font.h>
#include <LibGfx/Font/WOFF2/Typeface.h>
#include <LibTest/TestCase.h>

#define TEST_INPUT(x) ("test-inputs/" x)

TEST_CASE(tolerate_incorrect_sfnt_size)
{
auto file = MUST(Core::MappedFile::map(TEST_INPUT("woff2/incorrect_sfnt_size.woff2"sv)));
auto font = TRY_OR_FAIL(WOFF2::Font::try_load_from_externally_owned_memory(file->bytes()));
auto font = TRY_OR_FAIL(WOFF2::Typeface::try_load_from_externally_owned_memory(file->bytes()));
EXPECT_EQ(font->family(), "Test"_string);
EXPECT_EQ(font->glyph_count(), 4u);
}
Expand All @@ -26,7 +26,7 @@ TEST_CASE(malformed_woff2)

for (auto test_input : test_inputs) {
auto file = MUST(Core::MappedFile::map(test_input));
auto font_or_error = WOFF2::Font::try_load_from_externally_owned_memory(file->bytes());
auto font_or_error = WOFF2::Typeface::try_load_from_externally_owned_memory(file->bytes());
EXPECT(font_or_error.is_error());
}
}
2 changes: 1 addition & 1 deletion Userland/Libraries/LibGfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set(SOURCES
Font/ScaledFont.cpp
Font/Typeface.cpp
Font/WOFF/Typeface.cpp
Font/WOFF2/Font.cpp
Font/WOFF2/Typeface.cpp
GradientPainting.cpp
ICC/BinaryWriter.cpp
ICC/Enums.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define AK_DONT_REPLACE_STD
#include <LibGfx/Font/OpenType/Typeface.h>
#include <LibGfx/Font/WOFF2/Font.h>
#include <LibGfx/Font/WOFF2/Typeface.h>
#include <woff2/decode.h>

namespace WOFF2 {
Expand Down Expand Up @@ -54,7 +54,7 @@ class WOFF2ByteBufferOut final : public woff2::WOFF2Out {
ByteBuffer& m_buffer;
};

ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(ReadonlyBytes bytes)
ErrorOr<NonnullRefPtr<Typeface>> Typeface::try_load_from_externally_owned_memory(ReadonlyBytes bytes)
{
auto ttf_buffer = TRY(ByteBuffer::create_uninitialized(0));
auto output = WOFF2ByteBufferOut { ttf_buffer };
Expand All @@ -63,7 +63,7 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(Readonl
return Error::from_string_literal("Failed to convert the WOFF2 font to TTF");
}
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)));
return adopt_ref(*new Typeface(input_font, move(ttf_buffer)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

namespace WOFF2 {

class Font : public Gfx::Typeface {
AK_MAKE_NONCOPYABLE(Font);
class Typeface : public Gfx::Typeface {
AK_MAKE_NONCOPYABLE(Typeface);

public:
static ErrorOr<NonnullRefPtr<Font>> try_load_from_externally_owned_memory(ReadonlyBytes);
static ErrorOr<NonnullRefPtr<Typeface>> try_load_from_externally_owned_memory(ReadonlyBytes);

virtual Gfx::ScaledFontMetrics metrics(float x_scale, float y_scale) const override { return m_input_font->metrics(x_scale, y_scale); }
virtual Gfx::ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const override { return m_input_font->glyph_metrics(glyph_id, x_scale, y_scale, point_width, point_height); }
Expand All @@ -44,7 +44,7 @@ class Font : public Gfx::Typeface {
virtual bool has_color_bitmaps() const override { return m_input_font->has_color_bitmaps(); }

private:
Font(NonnullRefPtr<Gfx::Typeface> input_font, ByteBuffer input_font_buffer)
Typeface(NonnullRefPtr<Gfx::Typeface> input_font, ByteBuffer input_font_buffer)
: m_input_font_buffer(move(input_font_buffer))
, m_input_font(move(input_font))
{
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/CSS/FontFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <LibGfx/Font/OpenType/Typeface.h>
#include <LibGfx/Font/Typeface.h>
#include <LibGfx/Font/WOFF/Typeface.h>
#include <LibGfx/Font/WOFF2/Font.h>
#include <LibGfx/Font/WOFF2/Typeface.h>
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/Realm.h>
Expand Down Expand Up @@ -45,7 +45,7 @@ static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> load_vector_fo
promise->resolve(woff.release_value());
return;
}
auto woff2 = WOFF2::Font::try_load_from_externally_owned_memory(data);
auto woff2 = WOFF2::Typeface::try_load_from_externally_owned_memory(data);
if (!woff2.is_error()) {
promise->resolve(woff2.release_value());
return;
Expand Down
6 changes: 3 additions & 3 deletions Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <LibGfx/Font/ScaledFont.h>
#include <LibGfx/Font/Typeface.h>
#include <LibGfx/Font/WOFF/Typeface.h>
#include <LibGfx/Font/WOFF2/Font.h>
#include <LibGfx/Font/WOFF2/Typeface.h>
#include <LibWeb/Animations/AnimationEffect.h>
#include <LibWeb/Animations/DocumentTimeline.h>
#include <LibWeb/CSS/AnimationEvent.h>
Expand Down Expand Up @@ -177,7 +177,7 @@ ErrorOr<NonnullRefPtr<Gfx::Typeface>> FontLoader::try_load_font()
}
}
if (mime_type == "font/woff2"sv || mime_type == "application/font-woff2"sv) {
if (auto result = WOFF2::Font::try_load_from_externally_owned_memory(resource()->encoded_data()); !result.is_error()) {
if (auto result = WOFF2::Typeface::try_load_from_externally_owned_memory(resource()->encoded_data()); !result.is_error()) {
return result;
}
}
Expand All @@ -189,7 +189,7 @@ ErrorOr<NonnullRefPtr<Gfx::Typeface>> FontLoader::try_load_font()
auto woff = WOFF::Typeface::try_load_from_externally_owned_memory(resource()->encoded_data());
if (!woff.is_error())
return woff.release_value();
auto woff2 = WOFF2::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
auto woff2 = WOFF2::Typeface::try_load_from_externally_owned_memory(resource()->encoded_data());
if (!woff2.is_error())
return woff2.release_value();
return Error::from_string_literal("Automatic format detection failed");
Expand Down

0 comments on commit 07eebe5

Please sign in to comment.