From 32691b0c0dce764df1cf0d8a9129ead1ed4cb736 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Wed, 29 Oct 2025 10:10:04 +0200 Subject: [PATCH] add background --- app/javascript/submission_form/area.vue | 4 ++++ app/views/submissions/_value.html.erb | 3 ++- lib/submissions/generate_result_attachments.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/javascript/submission_form/area.vue b/app/javascript/submission_form/area.vue index 2a2fd20e..d3a4eaf6 100644 --- a/app/javascript/submission_form/area.vue +++ b/app/javascript/submission_form/area.vue @@ -553,6 +553,10 @@ export default { style.color = this.field.preferences.color } + if (this.field.preferences?.background) { + style.background = this.field.preferences.background + } + return style }, isNarrow () { diff --git a/app/views/submissions/_value.html.erb b/app/views/submissions/_value.html.erb index 025053ef..f0487425 100644 --- a/app/views/submissions/_value.html.erb +++ b/app/views/submissions/_value.html.erb @@ -1,10 +1,11 @@ <% align = field.dig('preferences', 'align') %> <% valign = field.dig('preferences', 'valign') %> <% color = field.dig('preferences', 'color') %> +<% bg_color = field.dig('preferences', 'background') %> <% font = field.dig('preferences', 'font') %> <% font_type = field.dig('preferences', 'font_type') %> <% font_size_px = (field.dig('preferences', 'font_size').presence || Submissions::GenerateResultAttachments::FONT_SIZE).to_i * local_assigns.fetch(:font_scale) { 1000.0 / PdfUtils::US_LETTER_W } %> -width: <%= area['w'] * 100 %>%; height: <%= area['h'] * 100 %>%; left: <%= area['x'] * 100 %>%; top: <%= area['y'] * 100 %>%; font-size: <%= fs = "clamp(1pt, #{font_size_px / 10}vw, #{font_size_px}px)" %>; line-height: calc(<%= fs %> * 1.3); font-size: <%= fs = "#{font_size_px / 10}cqmin" %>; line-height: calc(<%= fs %> * 1.3)"> +<%= "background: #{bg_color}; " if bg_color.present? %>width: <%= area['w'] * 100 %>%; height: <%= area['h'] * 100 %>%; left: <%= area['x'] * 100 %>%; top: <%= area['y'] * 100 %>%; font-size: <%= fs = "clamp(1pt, #{font_size_px / 10}vw, #{font_size_px}px)" %>; line-height: calc(<%= fs %> * 1.3); font-size: <%= fs = "#{font_size_px / 10}cqmin" %>; line-height: calc(<%= fs %> * 1.3)"> <% if field['type'] == 'signature' %> <% is_narrow = area['h']&.positive? && (area['w'].to_f / area['h']) > 6 %>
diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index 9f59bb86..934c86fc 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -244,6 +244,7 @@ module Submissions font_size ||= (([page.box.width, page.box.height].min / A4_SIZE[0].to_f) * FONT_SIZE).to_i fill_color = field.dig('preferences', 'color').to_s.delete_prefix('#').presence + bg_color = field.dig('preferences', 'background').to_s.delete_prefix('#').presence font_name = field.dig('preferences', 'font') font_variant = (field.dig('preferences', 'font_type').presence || 'none').to_sym @@ -289,6 +290,13 @@ module Submissions with_signature_id = field['preferences']['with_signature_id'] end + if bg_color.present? + canvas.fill_color(bg_color) + .rectangle(area['x'] * width, height - (area['y'] * height) - (area['h'] * height), + area['w'] * width, area['h'] * height) + .fill + end + case field_type when ->(type) { type == 'signature' && (with_signature_id || field.dig('preferences', 'reason_field_uuid')) } attachment = submitter.attachments.find { |a| a.uuid == value }