+
<% if (local_assigns[:with_signature_id] || field.dig('preferences', 'reason_field_uuid').present?) && attachment = attachments_index[value] %>
diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb
index 88d44f1f40..108d6d8d35 100644
--- a/lib/submissions/generate_result_attachments.rb
+++ b/lib/submissions/generate_result_attachments.rb
@@ -305,6 +305,10 @@ def fill_submitter_fields(submitter, account, pdfs_index, with_signature_id:, is
io = StringIO.new(image.resize([scale * 4, 1].select(&:positive?).min).write_to_buffer('.png'))
+ if field['type'] == 'signature' && field.dig('preferences', 'opaque_background')
+ canvas.fill_color('white').rectangle(image_x, image_y, image_width, image_height).fill
+ end
+
canvas.image(io, at: [image_x, image_y], width: image_width, height: image_height)
id_string = "ID: #{attachment.uuid}".upcase
@@ -369,6 +373,14 @@ def fill_submitter_fields(submitter, account, pdfs_index, with_signature_id:, is
height - (area['y'] * height) - TEXT_TOP_MARGIN -
result.lines.sum(&:height) - image_height)
+ if field.dig('preferences', 'opaque_background')
+ image_x = (area['x'] * width) + (area['w'] * width / 2) - ((image.width * scale) / 2)
+ image_y = height - (area['y'] * height) - (image.height * scale / 2) - (image_height / 2)
+
+ canvas.fill_color('white').rectangle(image_x, image_y, image.width * scale,
+ image.height * scale).fill
+ end
+
canvas.image(
io,
at: [
@@ -397,6 +409,14 @@ def fill_submitter_fields(submitter, account, pdfs_index, with_signature_id:, is
io = StringIO.new(image.resize([scale * 4, 1].select(&:positive?).min).write_to_buffer('.png'))
+ if field['type'] == 'signature' && field.dig('preferences', 'opaque_background')
+ image_x = (area['x'] * width) + (area['w'] * width / 2) - ((image.width * scale) / 2)
+ image_y = height - (area['y'] * height) - (image.height * scale / 2) - (area['h'] * height / 2)
+
+ canvas.fill_color('white').rectangle(image_x, image_y, image.width * scale,
+ image.height * scale).fill
+ end
+
canvas.image(
io,
at: [
diff --git a/spec/lib/submissions/generate_result_attachments_spec.rb b/spec/lib/submissions/generate_result_attachments_spec.rb
index 2ca5205d03..46f3dfd614 100644
--- a/spec/lib/submissions/generate_result_attachments_spec.rb
+++ b/spec/lib/submissions/generate_result_attachments_spec.rb
@@ -325,4 +325,51 @@ def assign_checkbox(value)
end
end
end
+
+ describe '.fill_submitter_fields opaque signature background' do
+ let(:field_uuid) { SecureRandom.uuid }
+
+ def page_raw_content
+ page = pdfs_index[attachment_uuid].pages[0]
+ content = page.contents
+ content = content.data if content.respond_to?(:data)
+ content.to_s
+ end
+
+ def page_draws_white_fill_rectangle?
+ content = page_raw_content
+
+ white_fill = content.match?(/1(\.0+)?\s+g\b|1(\.0+)?\s+1(\.0+)?\s+1(\.0+)?\s+rg\b/)
+
+ white_fill && content.match?(/\bre\b/) && content.match?(/\bf\b/)
+ end
+
+ def assign_signature_with_opaque_background
+ blob = ActiveStorage::Blob.create_and_upload!(
+ io: Rails.root.join('spec/fixtures/sample-image.png').open,
+ filename: 'signature.png',
+ content_type: 'image/png'
+ )
+ submitter.attachments.attach(blob)
+
+ assign_fields(
+ [{
+ 'uuid' => field_uuid,
+ 'submitter_uuid' => submitter.uuid,
+ 'type' => 'signature',
+ 'preferences' => { 'opaque_background' => true },
+ 'areas' => [base_area]
+ }],
+ { field_uuid => submitter.attachments.first.uuid }
+ )
+ end
+
+ it 'draws a white fill rectangle under the signature image' do
+ assign_signature_with_opaque_background
+ fill
+
+ expect(image_xobject_count).to eq(1)
+ expect(page_draws_white_fill_rectangle?).to be(true)
+ end
+ end
end