LibPDF: Extract a Document::read_filters() method

No behavior change.
This commit is contained in:
Nico Weber 2023-07-23 22:45:39 -04:00 committed by Tim Flynn
parent 9f4feb7315
commit 532230c0e4
Notes: sideshowbarker 2024-07-17 20:58:35 +09:00
3 changed files with 20 additions and 11 deletions

View File

@ -297,6 +297,23 @@ PDFErrorOr<Optional<InfoDict>> Document::info_dict()
return InfoDict(this, TRY(trailer()->get_dict(this, CommonNames::Info)));
}
PDFErrorOr<Vector<DeprecatedFlyString>> Document::read_filters(NonnullRefPtr<DictObject> dict)
{
Vector<DeprecatedFlyString> filters;
// We may either get a single filter or an array of cascading filters
auto filter_object = TRY(dict->get_object(this, 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(this, i))->name());
} else {
filters.append(filter_object->cast<NameObject>()->name());
}
return filters;
}
PDFErrorOr<void> Document::build_page_tree()
{
auto page_tree = TRY(m_catalog->get_dict(this, CommonNames::Pages));

View File

@ -146,6 +146,8 @@ public:
PDFErrorOr<Optional<InfoDict>> info_dict();
PDFErrorOr<Vector<DeprecatedFlyString>> read_filters(NonnullRefPtr<DictObject>);
private:
explicit Document(NonnullRefPtr<DocumentParser> const& parser);

View File

@ -475,17 +475,7 @@ 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) && m_enable_filters) {
Vector<DeprecatedFlyString> 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());
}
Vector<DeprecatedFlyString> filters = TRY(m_document->read_filters(dict));
// Every filter may get its own parameter dictionary
Vector<RefPtr<DictObject>> decode_parms_vector;