Commit edefc8964f0d5f9b9f265d32b084793a256b46a0
1 parent
8d4de787
Refactor `QPDFWriter`: replace `QPDFObjectHandle` with `Dictionary` in stream di…
…ctionary handling, streamline filtering logic, and simplify length checks.
Showing
1 changed file
with
6 additions
and
7 deletions
libqpdf/QPDFWriter.cc
| ... | ... | @@ -1522,7 +1522,7 @@ QPDFWriter::Members::will_filter_stream(QPDFObjectHandle stream, std::string* st |
| 1522 | 1522 | bool compress_stream = false; |
| 1523 | 1523 | const bool is_root_metadata = stream.isRootMetadata(); |
| 1524 | 1524 | |
| 1525 | - QPDFObjectHandle stream_dict = stream.getDict(); | |
| 1525 | + Dictionary stream_dict = stream.getDict(); | |
| 1526 | 1526 | |
| 1527 | 1527 | bool filter = false; |
| 1528 | 1528 | bool normalize = false; |
| ... | ... | @@ -1535,9 +1535,9 @@ QPDFWriter::Members::will_filter_stream(QPDFObjectHandle stream, std::string* st |
| 1535 | 1535 | // make it worse if the original file used a better Flate algorithm, and we don't spend |
| 1536 | 1536 | // time and CPU cycles uncompressing and recompressing stuff. This can be overridden |
| 1537 | 1537 | // with setRecompressFlate(true). |
| 1538 | - QPDFObjectHandle filter_obj = stream_dict.getKey("/Filter"); | |
| 1539 | - if (!recompress_flate && !stream.isDataModified() && filter_obj.isName() && | |
| 1540 | - (filter_obj.getName() == "/FlateDecode" || filter_obj.getName() == "/Fl")) { | |
| 1538 | + Name Filter = stream_dict["/Filter"]; | |
| 1539 | + if (Filter && !recompress_flate && !stream.isDataModified() && | |
| 1540 | + (Filter == "/FlateDecode" || Filter == "/Fl")) { | |
| 1541 | 1541 | filter = false; |
| 1542 | 1542 | } |
| 1543 | 1543 | } |
| ... | ... | @@ -1554,8 +1554,7 @@ QPDFWriter::Members::will_filter_stream(QPDFObjectHandle stream, std::string* st |
| 1554 | 1554 | } |
| 1555 | 1555 | |
| 1556 | 1556 | // Disable compression for empty streams to improve compatibility |
| 1557 | - if (stream_dict.getKey("/Length").isInteger() && | |
| 1558 | - stream_dict.getKey("/Length").getIntValue() == 0) { | |
| 1557 | + if (Integer(stream_dict["/Length"]) == 0) { | |
| 1559 | 1558 | filter = true; |
| 1560 | 1559 | compress_stream = false; |
| 1561 | 1560 | } |
| ... | ... | @@ -1597,7 +1596,7 @@ QPDFWriter::Members::will_filter_stream(QPDFObjectHandle stream, std::string* st |
| 1597 | 1596 | } |
| 1598 | 1597 | } |
| 1599 | 1598 | if (!filtered) { |
| 1600 | - compress_stream = false; | |
| 1599 | + return {false, false, is_root_metadata}; | |
| 1601 | 1600 | } |
| 1602 | 1601 | return {filtered, compress_stream, is_root_metadata}; |
| 1603 | 1602 | } | ... | ... |