diff --git a/CHANGELOG.md b/CHANGELOG.md index ae95692a..54d24e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ a standard default appearance string for a variable text field if none is found +### Changed + +* [HexaPDF::Task::Optimize] to not remove optional /Type entries containing + default values + ### Fixed * [HexaPDF::Layout::TableBox] to correctly calculcate and distribute row diff --git a/lib/hexapdf/task/optimize.rb b/lib/hexapdf/task/optimize.rb index e56e0bf8..79141e5a 100644 --- a/lib/hexapdf/task/optimize.rb +++ b/lib/hexapdf/task/optimize.rb @@ -214,13 +214,13 @@ def self.process_xref_streams(doc, method) end end - # Deletes field entries of the object that are optional and currently set to their default - # value. + # Deletes field entries (except for /Type) of the object that are optional and currently set + # to their default value. def self.delete_fields_with_defaults(obj) return unless obj.kind_of?(HexaPDF::Dictionary) && !obj.null? obj.each do |name, value| - if (field = obj.class.field(name)) && !field.required? && field.default? && - value == field.default + if name != :Type && (field = obj.class.field(name)) && !field.required? && + field.default? && value == field.default obj.delete(name) end end diff --git a/test/hexapdf/task/test_optimize.rb b/test/hexapdf/task/test_optimize.rb index 7f482e68..9267be27 100644 --- a/test/hexapdf/task/test_optimize.rb +++ b/test/hexapdf/task/test_optimize.rb @@ -8,6 +8,7 @@ class TestType < HexaPDF::Dictionary define_type :Test + define_field :Type, type: Symbol, default: type define_field :Optional, type: Symbol, default: :Optional end @@ -46,6 +47,7 @@ def assert_no_xrefstms end def assert_default_deleted + assert(@doc.object(1).key?(:Type)) refute(@doc.object(1).key?(:Optional)) end