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

LibPDF: Checking for built-in CFF encodings

Only prints a warning for them for now.

Also warn on the not-yet-implemented encoding supplement.
This commit is contained in:
Nico Weber 2023-10-12 11:05:02 -04:00 committed by Andreas Kling
parent 414a164850
commit 96a4936567

View file

@ -115,9 +115,21 @@ PDFErrorOr<NonnullRefPtr<CFF>> CFF::create(ReadonlyBytes const& cff_bytes, RefPt
auto encoding_offset = 0;
if (!operands.is_empty())
encoding_offset = operands[0].get<int>();
// CFF spec, "Table 16 Encoding ID"
switch (encoding_offset) {
case 0:
dbgln("CFF: Built-in Standard Encoding not yet implemented");
break;
case 1:
dbgln("CFF: Built-in Expert Encoding not yet implemented");
break;
default:
encoding_codes = TRY(parse_encoding(Reader(cff_bytes.slice(encoding_offset))));
break;
}
break;
}
case TopDictOperator::Charset: {
if (!operands.is_empty())
charset_offset = operands[0].get<int>();
@ -704,7 +716,7 @@ PDFErrorOr<Vector<u8>> CFF::parse_encoding(Reader&& reader)
// CFF spec, "12 Encodings"
Vector<u8> encoding_codes;
auto format_raw = TRY(reader.try_read<Card8>());
// TODO: support encoding supplements when highest bit is set
auto format = format_raw & 0x7f;
if (format == 0) {
auto n_codes = TRY(reader.try_read<Card8>());
@ -722,6 +734,11 @@ PDFErrorOr<Vector<u8>> CFF::parse_encoding(Reader&& reader)
}
} else
return error(DeprecatedString::formatted("Invalid encoding format: {}", format));
// TODO: support encoding supplements when highest bit is set (tables 14 and 15).
if (format_raw & 0x80)
dbgln("CFF: Support for multiply-encoded glyphs not yet implemented");
return encoding_codes;
}