1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 18:27:42 +00:00
serenity/Userland/Libraries/LibPDF/Fonts
Nico Weber 11bee7a075 LibPDF: Don't crash on fixed-width type 1 fonts that use /MissingWidth
Type 1 fonts usually have a m_font_program and no m_font -- they only
have m_font if we're using a replacement font for the fonts that
were built-in to PDFs before Acrobat 4.0 (and must still work to
show existing files).

However, SimpleFont::get_glyph_width() used to always return a
float, which in Type1Font was only implemented if m_font was set.

Per spec, we're supposed to just use /MissingWidth for fonts that
are missing an entry in the descriptor's /Width array. However, for
built-in fonts, no explicit /Width array is needed (PDF 1.7 spec,
Appendix H.3, 5.5.1). So if we just always use /MissingWidth,
then PDFs that use a built-in font draw all their text on top
of each other (e.g. 000333.pdf from stillhq.com-pdfdb).

So change get_glyph_width() to return Optional<float>, return
it only in Type1Font if m_font is set, and use MissingWidth
if it isn't set.

That way, replacement fonts still return a width, and real
fonts that are supposed to have /Width and use /MissingWidth
for missing entries do what they're supposed to too, instead
of crashing.

From 20 (6%) to 16 (5%) crashes on the 300 first PDFs, and from
39 (7.8%) to 31 (6.2%) on the 500-random PDFs test.
2023-10-23 09:33:03 -04:00
..
CFF.cpp LibPDF: Don't over-read in charset formats 1 and 2 2023-10-23 09:31:11 -04:00
CFF.h LibPDF: Support offset size 3 in CFF index reading 2023-10-23 09:31:11 -04:00
PDFFont.cpp LibPDF: Fix lookup of built-in Bold Italic strings 2023-10-19 16:52:49 -04:00
PDFFont.h LibPDF: Don't ignore word_spacing 2023-07-22 12:24:29 -04:00
PS1FontProgram.cpp LibPDF: Implement support for callgsubr in CFF font programs 2023-10-18 10:50:32 -04:00
PS1FontProgram.h LibPDF: Remove declarations for non-existent methods 2023-01-27 20:33:18 +00:00
SimpleFont.cpp LibPDF: Don't crash on fixed-width type 1 fonts that use /MissingWidth 2023-10-23 09:33:03 -04:00
SimpleFont.h LibPDF: Don't crash on fixed-width type 1 fonts that use /MissingWidth 2023-10-23 09:33:03 -04:00
TrueTypeFont.cpp LibPDF: Don't crash on fixed-width type 1 fonts that use /MissingWidth 2023-10-23 09:33:03 -04:00
TrueTypeFont.h LibPDF: Don't crash on fixed-width type 1 fonts that use /MissingWidth 2023-10-23 09:33:03 -04:00
Type0Font.cpp LibPDF: Replace TODO()s in Type0Font code with Errors 2023-10-20 10:33:59 -06:00
Type0Font.h LibPDF: Sketch out Type0 font support some more 2023-07-25 12:10:36 +02:00
Type1Font.cpp LibPDF: Don't crash on fixed-width type 1 fonts that use /MissingWidth 2023-10-23 09:33:03 -04:00
Type1Font.h LibPDF: Don't crash on fixed-width type 1 fonts that use /MissingWidth 2023-10-23 09:33:03 -04:00
Type1FontProgram.cpp LibPDF: Implement support for callgsubr in CFF font programs 2023-10-18 10:50:32 -04:00
Type1FontProgram.h LibPDF: Implement support for callgsubr in CFF font programs 2023-10-18 10:50:32 -04:00