Skip to content

Commit

Permalink
Set the quadding of a variable text field by default on creation
Browse files Browse the repository at this point in the history
The quadding /Q of a field has a default value, so it seems that it is
not necessary to explicitly set the field to its default value of 0.

There are (at least) two reasons why it still makes sense to set it
explicitly:

* In certain circumstances [1] the default value for an unset /Q might
  be taken from somewhere else.

* When HexaPDF generates an appearance, it retrieves the value of the
  quadding via field.text_alignment which automatically sets /Q to its
  default value if it is not set. In case of adding a field to a PDF
  but *not* filling it (so no explicit /Q value), then signing the PDF,
  then filling in the field and again signing it, the initial signature
  will be invalided by the now explicitly set /Q.

[1]: #89 (comment)
  • Loading branch information
gettalong committed Sep 17, 2024
1 parent 1250a06 commit 9ed078f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
### Changed

* [HexaPDF::Type::AcroForm::Form] text-like field creation methods to always set
a default appearance string
a default appearance string and the quadding
* Convenience methods for accessing resources to not add the deprecated /ProcSet
entry by default
* [HexaPDF::DigitalSignature::CMSHandler] to add informational output regarding
Expand Down
2 changes: 1 addition & 1 deletion lib/hexapdf/type/acro_form/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def apply_variable_text_properties(field, font: nil, font_options: nil, font_siz
font_options: font_options || {},
font_size: font_size || 0,
font_color: font_color || 0)
field.text_alignment(align) if align
field.text_alignment(align || :left)
end

def perform_validation # :nodoc:
Expand Down
1 change: 1 addition & 0 deletions test/hexapdf/type/acro_form/test_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def applies_variable_text_properties(method, **args)
assert_equal(:'Helvetica', @acro_form.default_resources.font(font_name)[:BaseFont])
assert_equal(0, font_size)
assert_equal(HexaPDF::Content::ColorSpace::DeviceGray.new.color(0), font_color)
assert_equal(0, field.value[:Q])

field = @acro_form.send(method, "field", **args, font: 'Times')
font_name, font_size, font_color = field.parse_default_appearance_string
Expand Down

0 comments on commit 9ed078f

Please sign in to comment.