1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:07:35 +00:00

LibPDF: Index Type1 glyphs by name, not char code

Storing glyphs indexed by char code in a Type1 Font Program binds a Font
Program instance to the particular Encoding that was used at Font
Program construction time. This makes it difficult to reuse Font Program
instances against different Encodings, which would be otherwise
possible.

This commit changes how we store the glyphs on Type1 Font Programs.
Instead of storing them on a map indexed by char code, the map is now
indexed by glyph name. In turn, when rendering a glyph we use the
Encoding object to turn the char code into a glyph name, which in turn
is used to index into the map of glyphs.

This is the first step towards reusability of Type1 Font Programs. It
also unlocks the ability to render glyphs that are described via the
"seac" command (standard encoding accented character), which requires
accessing the base and accent glyphs by name.
This commit is contained in:
Rodrigo Tobar 2023-02-05 14:04:48 +08:00 committed by Andreas Kling
parent f99c9dc11a
commit c084943457
5 changed files with 25 additions and 27 deletions

View file

@ -92,9 +92,8 @@ PDFErrorOr<void> PS1FontProgram::parse_encrypted_portion(ByteBuffer const& buffe
auto line = TRY(decrypt(reader.bytes().slice(reader.offset(), encrypted_size), m_encryption_key, m_lenIV));
reader.move_by(encrypted_size);
auto glyph_name = word.substring_view(1);
auto char_code = encoding()->get_char_code(glyph_name);
GlyphParserState state;
TRY(add_glyph(char_code, TRY(parse_glyph(line, subroutines, state, false))));
TRY(add_glyph(glyph_name, TRY(parse_glyph(line, subroutines, state, false))));
}
}
}