mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:47:45 +00:00
LibPDF+LibGfx: Do not try to read "name" table for PDFs
It is often missing in fonts embedded in PDFs. 75 of my 1000 test files complained "Font is missing Name" when trying to read fonts before. Increases number of PDFs that render without diagnostics from 682 to 743.
This commit is contained in:
parent
41eca52b50
commit
5efe80af7f
5 changed files with 31 additions and 11 deletions
|
@ -256,9 +256,12 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_offset(ReadonlyBytes buffer, u3
|
|||
return Error::from_string_literal("Font is missing Head");
|
||||
auto head = TRY(Head::from_slice(opt_head_slice.value()));
|
||||
|
||||
if (!opt_name_slice.has_value())
|
||||
return Error::from_string_literal("Font is missing Name");
|
||||
auto name = TRY(Name::from_slice(opt_name_slice.value()));
|
||||
Optional<Name> name;
|
||||
if (!(options.skip_tables & Options::SkipTables::Name)) {
|
||||
if (!opt_name_slice.has_value())
|
||||
return Error::from_string_literal("Font is missing Name");
|
||||
name = TRY(Name::from_slice(opt_name_slice.value()));
|
||||
}
|
||||
|
||||
if (!opt_hhea_slice.has_value())
|
||||
return Error::from_string_literal("Font is missing Hhea");
|
||||
|
@ -544,12 +547,15 @@ u16 Font::units_per_em() const
|
|||
|
||||
String Font::family() const
|
||||
{
|
||||
if (!m_name.has_value())
|
||||
return {};
|
||||
|
||||
if (!m_family.has_value()) {
|
||||
m_family = [&] {
|
||||
auto string = m_name.typographic_family_name();
|
||||
auto string = m_name->typographic_family_name();
|
||||
if (!string.is_empty())
|
||||
return string;
|
||||
return m_name.family_name();
|
||||
return m_name->family_name();
|
||||
}();
|
||||
}
|
||||
return *m_family;
|
||||
|
@ -557,10 +563,13 @@ String Font::family() const
|
|||
|
||||
String Font::variant() const
|
||||
{
|
||||
auto string = m_name.typographic_subfamily_name();
|
||||
if (!m_name.has_value())
|
||||
return {};
|
||||
|
||||
auto string = m_name->typographic_subfamily_name();
|
||||
if (!string.is_empty())
|
||||
return string;
|
||||
return m_name.subfamily_name();
|
||||
return m_name->subfamily_name();
|
||||
}
|
||||
|
||||
u16 Font::weight() const
|
||||
|
|
|
@ -30,6 +30,12 @@ public:
|
|||
struct FontOptions {
|
||||
unsigned index { 0 };
|
||||
OwnPtr<CharCodeToGlyphIndex> external_cmap {};
|
||||
|
||||
enum SkipTables {
|
||||
// If set, do not try to read the 'name' table. family() and variant() will return empty strings.
|
||||
Name = 1 << 0,
|
||||
};
|
||||
u32 skip_tables { 0 };
|
||||
};
|
||||
|
||||
class Font : public Gfx::VectorFont {
|
||||
|
@ -85,7 +91,7 @@ private:
|
|||
|
||||
Font(
|
||||
Head&& head,
|
||||
Name&& name,
|
||||
Optional<Name>&& name,
|
||||
Hhea&& hhea,
|
||||
Maxp&& maxp,
|
||||
Hmtx&& hmtx,
|
||||
|
@ -121,7 +127,7 @@ private:
|
|||
|
||||
// These are stateful wrappers around non-owning slices
|
||||
Head m_head;
|
||||
Name m_name;
|
||||
Optional<Name> m_name;
|
||||
Hhea m_hhea;
|
||||
Maxp m_maxp;
|
||||
Hmtx m_hmtx;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue