mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +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:
parent
fb0c3a9e18
commit
286e3e6872
4 changed files with 43 additions and 64 deletions
|
@ -36,19 +36,18 @@ PDFErrorOr<NonnullRefPtr<Type1FontProgram>> PS1FontProgram::create(ReadonlyBytes
|
|||
if (TRY(parse_word(reader)) == "StandardEncoding") {
|
||||
font_program->set_encoding(Encoding::standard_encoding());
|
||||
} else {
|
||||
HashMap<u16, CharDescriptor> descriptors;
|
||||
|
||||
auto encoding = Encoding::create();
|
||||
while (reader.remaining()) {
|
||||
auto word = TRY(parse_word(reader));
|
||||
if (word == "readonly") {
|
||||
break;
|
||||
} else if (word == "dup") {
|
||||
u32 char_code = TRY(parse_int(reader));
|
||||
u8 char_code = TRY(parse_int(reader));
|
||||
auto name = TRY(parse_word(reader));
|
||||
descriptors.set(char_code, { name.starts_with('/') ? name.substring_view(1) : name.view(), char_code });
|
||||
encoding->set(char_code, name.starts_with('/') ? name.substring_view(1) : name.view());
|
||||
}
|
||||
}
|
||||
font_program->set_encoding(TRY(Encoding::create(descriptors)));
|
||||
font_program->set_encoding(move(encoding));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue