diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-03-24 16:22:18 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-24 16:53:21 +0100 |
commit | c0513999d6f6ebd9f84789c30cfac29f4ae76ece (patch) | |
tree | 587aac97cfc117d173c7befb0420d2231e13956e /Userland | |
parent | b17fb76ace658a9a8ad3a8399748af3ecf27e7dc (diff) | |
download | serenity-c0513999d6f6ebd9f84789c30cfac29f4ae76ece.zip |
LibGfx: TrueTypeFont cleanup
No functional changes.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGfx/TrueTypeFont/Cmap.cpp | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp | 3 |
2 files changed, 8 insertions, 10 deletions
diff --git a/Userland/Libraries/LibGfx/TrueTypeFont/Cmap.cpp b/Userland/Libraries/LibGfx/TrueTypeFont/Cmap.cpp index fb03026d47..29c979f019 100644 --- a/Userland/Libraries/LibGfx/TrueTypeFont/Cmap.cpp +++ b/Userland/Libraries/LibGfx/TrueTypeFont/Cmap.cpp @@ -121,13 +121,13 @@ u32 Cmap::Subtable::glyph_id_for_code_point_table_12(u32 code_point) const VERIFY(m_slice.size() >= (u32)Table12Sizes::Header + (u32)Table12Sizes::Record * num_groups); for (u32 offset = 0; offset < num_groups * (u32)Table12Sizes::Record; offset += (u32)Table12Sizes::Record) { u32 start_code_point = be_u32(m_slice.offset_pointer((u32)Table12Offsets::Record_StartCode + offset)); - if (code_point < start_code_point) { + if (code_point < start_code_point) break; - } + u32 end_code_point = be_u32(m_slice.offset_pointer((u32)Table12Offsets::Record_EndCode + offset)); - if (code_point > end_code_point) { + if (code_point > end_code_point) continue; - } + u32 glyph_offset = be_u32(m_slice.offset_pointer((u32)Table12Offsets::Record_StartGlyph + offset)); return code_point - start_code_point + glyph_offset; } @@ -137,18 +137,17 @@ u32 Cmap::Subtable::glyph_id_for_code_point_table_12(u32 code_point) const u32 Cmap::glyph_id_for_code_point(u32 code_point) const { auto opt_subtable = subtable(m_active_index); - if (!opt_subtable.has_value()) { + if (!opt_subtable.has_value()) return 0; - } + auto subtable = opt_subtable.value(); return subtable.glyph_id_for_code_point(code_point); } Optional<Cmap> Cmap::from_slice(ReadonlyBytes slice) { - if (slice.size() < (size_t)Sizes::TableHeader) { + if (slice.size() < (size_t)Sizes::TableHeader) return {}; - } return Cmap(slice); } diff --git a/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp b/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp index 80123199a5..8f961551e6 100644 --- a/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp +++ b/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp @@ -10,7 +10,6 @@ #include <AK/Try.h> #include <AK/Utf32View.h> #include <AK/Utf8View.h> -#include <LibCore/File.h> #include <LibCore/MappedFile.h> #include <LibGfx/TrueTypeFont/Cmap.h> #include <LibGfx/TrueTypeFont/Font.h> @@ -429,7 +428,7 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_offset(ReadonlyBytes buffer, u3 u32 table_length = be_u32(buffer.offset_pointer(record_offset + (u32)Offsets::TableRecord_Length)); if (Checked<u32>::addition_would_overflow(table_offset, table_length)) - return Error::from_string_literal("Invalid table offset/length in font."sv); + return Error::from_string_literal("Invalid table offset or length in font"sv); if (buffer.size() < table_offset + table_length) return Error::from_string_literal("Font file too small"sv); |