mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03: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
Notes:
sideshowbarker
2024-07-17 04:19:47 +09:00
Author: https://github.com/janso3 Commit: https://github.com/SerenityOS/serenity/commit/16ed407c01 Pull-request: https://github.com/SerenityOS/serenity/pull/16015 Reviewed-by: https://github.com/mattco98 ✅
@ -476,13 +476,20 @@ PDFErrorOr<NonnullRefPtr<StreamObject>> Parser::parse_stream(NonnullRefPtr<DictO
|
|||||||
m_document->security_handler()->decrypt(stream_object, m_current_reference_stack.last());
|
m_document->security_handler()->decrypt(stream_object, m_current_reference_stack.last());
|
||||||
|
|
||||||
if (dict->contains(CommonNames::Filter)) {
|
if (dict->contains(CommonNames::Filter)) {
|
||||||
auto filter_type = MUST(dict->get_name(m_document, CommonNames::Filter))->name();
|
Vector<FlyString> filters;
|
||||||
auto maybe_bytes = Filter::decode(stream_object->bytes(), filter_type);
|
|
||||||
if (maybe_bytes.is_error()) {
|
// We may either get a single filter or an array of cascading filters
|
||||||
warnln("Failed to decode filter: {}", maybe_bytes.error().string_literal());
|
auto filter_object = TRY(dict->get_object(m_document, CommonNames::Filter));
|
||||||
return error(String::formatted("Failed to decode filter {}", maybe_bytes.error().string_literal()));
|
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;
|
return stream_object;
|
||||||
|
Loading…
Reference in New Issue
Block a user