From 8fd4e2ee4066b0e5d98a3c338ce5bf26992bfdd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Offenh=C3=A4user?= Date: Sun, 13 Nov 2022 12:19:22 +0100 Subject: [PATCH] LibGfx: Don't require the OS/2 table for ttf files This table seems to only exist for OpenType compatibility. There are some font files, including most embedded fonts in PDF documents, that don't include one. For those cases, we now just zero-initialize one to the largest supported size. --- Userland/Libraries/LibGfx/Font/TrueType/Font.cpp | 6 +++--- Userland/Libraries/LibGfx/Font/TrueType/Tables.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/TrueType/Font.cpp b/Userland/Libraries/LibGfx/Font/TrueType/Font.cpp index 20004833ee..2606bd1afb 100644 --- a/Userland/Libraries/LibGfx/Font/TrueType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/TrueType/Font.cpp @@ -489,9 +489,9 @@ ErrorOr> Font::try_load_from_offset(ReadonlyBytes buffer, u3 return Error::from_string_literal("Could not load Glyf"); auto glyf = Glyf(opt_glyf_slice.value()); - if (!opt_os2_slice.has_value()) - return Error::from_string_literal("Could not load OS/2"); - auto os2 = OS2(opt_os2_slice.value()); + OS2 os2(TRY(ByteBuffer::create_zeroed(static_cast(OS2::Offsets::End)))); + if (opt_os2_slice.has_value()) + os2 = OS2(opt_os2_slice.value()); Optional kern {}; if (opt_kern_slice.has_value()) diff --git a/Userland/Libraries/LibGfx/Font/TrueType/Tables.h b/Userland/Libraries/LibGfx/Font/TrueType/Tables.h index 73cbf998f9..a5c1886a72 100644 --- a/Userland/Libraries/LibGfx/Font/TrueType/Tables.h +++ b/Userland/Libraries/LibGfx/Font/TrueType/Tables.h @@ -140,6 +140,7 @@ public: TypographicAscender = 68, TypographicDescender = 70, TypographicLineGap = 72, + End = 78, }; u16 weight_class() const;