mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:58:11 +00:00
LibPDF: Support cascading stream filters
You can specify multiple filters as an array, where each one is fed the output of the one before it.
This commit is contained in:
parent
becd648a78
commit
16ed407c01
1 changed files with 13 additions and 6 deletions
|
@ -476,13 +476,20 @@ PDFErrorOr<NonnullRefPtr<StreamObject>> Parser::parse_stream(NonnullRefPtr<DictO
|
|||
m_document->security_handler()->decrypt(stream_object, m_current_reference_stack.last());
|
||||
|
||||
if (dict->contains(CommonNames::Filter)) {
|
||||
auto filter_type = MUST(dict->get_name(m_document, CommonNames::Filter))->name();
|
||||
auto maybe_bytes = Filter::decode(stream_object->bytes(), filter_type);
|
||||
if (maybe_bytes.is_error()) {
|
||||
warnln("Failed to decode filter: {}", maybe_bytes.error().string_literal());
|
||||
return error(String::formatted("Failed to decode filter {}", maybe_bytes.error().string_literal()));
|
||||
Vector<FlyString> filters;
|
||||
|
||||
// We may either get a single filter or an array of cascading filters
|
||||
auto filter_object = TRY(dict->get_object(m_document, CommonNames::Filter));
|
||||
if (filter_object->is<ArrayObject>()) {
|
||||
auto filter_array = filter_object->cast<ArrayObject>();
|
||||
for (size_t i = 0; i < filter_array->size(); ++i)
|
||||
filters.append(TRY(filter_array->get_name_at(m_document, i))->name());
|
||||
} else {
|
||||
filters.append(filter_object->cast<NameObject>()->name());
|
||||
}
|
||||
stream_object->buffer() = maybe_bytes.release_value();
|
||||
|
||||
for (auto const& filter_type : filters)
|
||||
stream_object->buffer() = TRY(Filter::decode(stream_object->bytes(), filter_type));
|
||||
}
|
||||
|
||||
return stream_object;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue