Skip to content

Commit

Permalink
Fix parsing of default appearance strings to handle invalid PDFs with…
Browse files Browse the repository at this point in the history
… symbolic DAs
  • Loading branch information
gettalong committed Sep 2, 2024
1 parent 063626c commit 3164f99
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* [HexaPDF::Type::AcroForm::AppearanceGenerator] to work for files where check
boxes don't define the name of the on state
* [HexaPDF::Importer#import] to handle null values in all cases
* [HexaPDF::Type::AcroForm::VariableTextField] to handle parsing of invalid PDFs
with symbolic appearance strings


## 0.46.0 - 2024-08-11
Expand Down
2 changes: 1 addition & 1 deletion lib/hexapdf/type/acro_form/variable_text_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def self.parse_appearance_string(appearance_string, &block) # :yield: obj, param
font_params[2] = HexaPDF::Content::ColorSpace.prenormalized_device_color(params)
end
end
HexaPDF::Content::Parser.parse(appearance_string.sub(/\/\//, '/'), &block)
HexaPDF::Content::Parser.parse(appearance_string.to_s.sub(/\/\//, '/'), &block)
block_given? ? nil : font_params
end

Expand Down
5 changes: 5 additions & 0 deletions test/hexapdf/type/acro_form/test_variable_text_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
@field.parse_default_appearance_string)
end

it "converts the /DA to a string in case an invalid PDF uses a Symbol" do
@field[:DA] = :"1 g /F1 20 Tf"
assert_equal([:F1, 20, @color], @field.parse_default_appearance_string)
end

it "fails if no /DA value is set and no default appearance string should be set" do
@doc.acro_form.delete(:DA)
@doc.config['acro_form.fallback_default_appearance'] = nil
Expand Down

0 comments on commit 3164f99

Please sign in to comment.