mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 19:57:45 +03:00
LibPDF: Add name -> char code conversion in Encoding
This is an operation that was already being done (sub-optimally) in PS1FontProgram, so we are replacing that. We will use this during CFF parsing too.
This commit is contained in:
parent
c592b889bf
commit
1ec4ad5eb6
Notes:
sideshowbarker
2024-07-17 18:46:30 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/1ec4ad5eb6 Pull-request: https://github.com/SerenityOS/serenity/pull/17082
@ -171,6 +171,14 @@ CharDescriptor const& Encoding::get_char_code_descriptor(u16 char_code) const
|
||||
return const_cast<Encoding*>(this)->m_descriptors.ensure(char_code);
|
||||
}
|
||||
|
||||
u16 Encoding::get_char_code(DeprecatedString const& name) const
|
||||
{
|
||||
auto code_iterator = m_name_mapping.find(name);
|
||||
if (code_iterator != m_name_mapping.end())
|
||||
return code_iterator->value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Encoding::should_map_to_bullet(u16 char_code) const
|
||||
{
|
||||
// PDF Annex D table D.2, note 3:
|
||||
|
@ -645,6 +645,7 @@ public:
|
||||
HashMap<u16, CharDescriptor> const& descriptors() const { return m_descriptors; }
|
||||
HashMap<DeprecatedString, u16> const& name_mapping() const { return m_name_mapping; }
|
||||
|
||||
u16 get_char_code(DeprecatedString const&) const;
|
||||
CharDescriptor const& get_char_code_descriptor(u16 char_code) const;
|
||||
|
||||
bool should_map_to_bullet(u16 char_code) const;
|
||||
|
@ -92,8 +92,8 @@ PDFErrorOr<void> PS1FontProgram::parse_encrypted_portion(ByteBuffer const& buffe
|
||||
if (rd == "-|" || rd == "RD") {
|
||||
auto line = TRY(decrypt(reader.bytes().slice(reader.offset(), encrypted_size), m_encryption_key, m_lenIV));
|
||||
reader.move_by(encrypted_size);
|
||||
auto name_mapping = encoding()->name_mapping();
|
||||
auto char_code = name_mapping.ensure(word.substring_view(1));
|
||||
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))));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user