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

LibPDF: Simplify Encoding to align with simple font requirements

All "Simple Fonts" in PDF (all but Type0 fonts) have the property that
glyphs are selected with single byte character codes. This means that
the Encoding objects should use u8 for representing these character
codes. Moreover, and as mentioned in a previous commit, there is no need
to store the unicode code point associated with a character (which was
in turn wrongly associated to a glyph).

This commit greatly simplifies the Encoding class. Namely it:

 * Removes the unnecessary CharDescriptor class.
 * Changes the internal maps to be u8 -> FlyString and vice-versa,
   effectively providing two-way lookups.
 * Adds a new method to set a two-way u8 -> FlyString mapping and uses
   it in all possible places.
 * Simplified the creation of Encoding objects.
 * Changes how the WinAnsi special treatment for bullet points is
   implemented.
This commit is contained in:
Rodrigo Tobar 2023-01-23 23:56:43 +08:00 committed by Andreas Kling
parent fb0c3a9e18
commit 286e3e6872
4 changed files with 43 additions and 64 deletions

View file

@ -625,14 +625,10 @@
namespace PDF {
struct CharDescriptor {
DeprecatedString name;
u32 code_point;
};
class Encoding : public RefCounted<Encoding> {
public:
static PDFErrorOr<NonnullRefPtr<Encoding>> create(HashMap<u16, CharDescriptor> descriptors);
using CharCodeType = u8;
static NonnullRefPtr<Encoding> create();
static PDFErrorOr<NonnullRefPtr<Encoding>> from_object(Document*, NonnullRefPtr<Object> const&);
static NonnullRefPtr<Encoding> standard_encoding();
@ -642,17 +638,14 @@ public:
static NonnullRefPtr<Encoding> symbol_encoding();
static NonnullRefPtr<Encoding> zapf_encoding();
HashMap<u16, CharDescriptor> const& descriptors() const { return m_descriptors; }
HashMap<DeprecatedString, u16> const& name_mapping() const { return m_name_mapping; }
HashMap<DeprecatedString, CharCodeType> 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;
void set(CharCodeType char_code, DeprecatedFlyString const& glyph_name);
protected:
HashMap<u16, CharDescriptor> m_descriptors;
HashMap<DeprecatedString, u16> m_name_mapping;
HashMap<CharCodeType, DeprecatedFlyString> m_descriptors;
HashMap<DeprecatedString, CharCodeType> m_name_mapping;
bool m_windows { false };
};