mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:17:44 +00:00
LibPDF: Implement support for callgsubr in CFF font programs
Font programs are bytecode programs defining glyphs. If several glyphs share a piece of outline, that opcode sequence can be put in a subroutine ("subr") table and the definition of those glyphs can then call that subroutine by number, to reduce file size. CFF fonts can in theory contain multiple fonts, and so there's a global subr table shared by all the fonts in one CFF, and a local per-fornt subr table. We used to only implement the local subr table, now we implement both. (We only support one font per CFF, and at least in PDF files, that's all that's ever used. So a global subr table isn't very useful. But the spec explicitly allows it -- "Global subroutines may be used in a FontSet even if it only contains one font." -- and it happens in practice.)
This commit is contained in:
parent
185573c03f
commit
3907374621
5 changed files with 15 additions and 11 deletions
|
@ -221,11 +221,9 @@ PDFErrorOr<NonnullRefPtr<CFF>> CFF::create(ReadonlyBytes const& cff_bytes, RefPt
|
|||
TRY(parse_index(reader, [&](ReadonlyBytes const& subroutine_bytes) -> PDFErrorOr<void> {
|
||||
return TRY(global_subroutines.try_append(TRY(ByteBuffer::copy(subroutine_bytes))));
|
||||
}));
|
||||
if (!global_subroutines.is_empty())
|
||||
dbgln("CFF data contains Global subrs, which aren't implemented yet"); // FIXME
|
||||
|
||||
// Create glyphs (now that we have the subroutines) and associate missing information to store them and their encoding
|
||||
auto glyphs = TRY(parse_charstrings(Reader(cff_bytes.slice(charstrings_offset)), local_subroutines));
|
||||
auto glyphs = TRY(parse_charstrings(Reader(cff_bytes.slice(charstrings_offset)), local_subroutines, global_subroutines));
|
||||
|
||||
// CFF spec, "Table 16 Encoding ID"
|
||||
// FIXME: Only read this if the built-in encoding is actually needed? (ie. `if (!encoding)`)
|
||||
|
@ -765,13 +763,13 @@ PDFErrorOr<Vector<DeprecatedFlyString>> CFF::parse_charset(Reader&& reader, size
|
|||
return names;
|
||||
}
|
||||
|
||||
PDFErrorOr<Vector<CFF::Glyph>> CFF::parse_charstrings(Reader&& reader, Vector<ByteBuffer> const& subroutines)
|
||||
PDFErrorOr<Vector<CFF::Glyph>> CFF::parse_charstrings(Reader&& reader, Vector<ByteBuffer> const& local_subroutines, Vector<ByteBuffer> const& global_subroutines)
|
||||
{
|
||||
// CFF spec, "14 CharStrings INDEX"
|
||||
Vector<Glyph> glyphs;
|
||||
TRY(parse_index(reader, [&](ReadonlyBytes const& charstring_data) -> PDFErrorOr<void> {
|
||||
GlyphParserState state;
|
||||
auto glyph = TRY(parse_glyph(charstring_data, subroutines, state, true));
|
||||
auto glyph = TRY(parse_glyph(charstring_data, local_subroutines, global_subroutines, state, true));
|
||||
return TRY(glyphs.try_append(glyph));
|
||||
}));
|
||||
return glyphs;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue