From 0d8e2c5ff02a4de10df30dc5f60713acfa208eac Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Sat, 20 Dec 2025 17:12:15 +0200 Subject: [PATCH] adjust signature size --- app/javascript/submission_form/area.vue | 2 +- app/views/submissions/_value.html.erb | 2 +- .../generate_result_attachments.rb | 36 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/javascript/submission_form/area.vue b/app/javascript/submission_form/area.vue index d3a4eaf6..c39cb16d 100644 --- a/app/javascript/submission_form/area.vue +++ b/app/javascript/submission_form/area.vue @@ -560,7 +560,7 @@ export default { return style }, isNarrow () { - return this.area.h > 0 && (this.area.w / this.area.h) > 6 + return this.area.h > 0 && ((this.area.w * this.pageWidth) / (this.area.h * this.pageHeight)) > 4.5 } }, watch: { diff --git a/app/views/submissions/_value.html.erb b/app/views/submissions/_value.html.erb index 5a8e3d22..4213d728 100644 --- a/app/views/submissions/_value.html.erb +++ b/app/views/submissions/_value.html.erb @@ -7,7 +7,7 @@ <% 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 } %> <%= "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 %> + <% is_narrow = area['h'].positive? && ((area['w'] * local_assigns[:page_width]).to_f / (area['h'] * local_assigns[:page_height])) > 4.5 %>
diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index 893202b1..b81a9d79 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -333,12 +333,12 @@ module Submissions result = nil - if area['h']&.positive? && (area['w'].to_f / area['h']) > 6 - area_x = area['x'] * width - area_y = area['y'] * height - area_w = area['w'] * width - area_h = area['h'] * height + area_x = area['x'] * width + area_y = area['y'] * height + area_w = area['w'] * width + area_h = area['h'] * height + if area_h.positive? && (area_w.to_f / area_h) > 4.5 half_width = area_w / 2.0 scale = [half_width / image.width, area_h / image.height].min image_width = image.width * scale @@ -396,7 +396,7 @@ module Submissions font:, font_size: base_font_size) - result = layouter.fit([text], area['w'] * width, base_font_size / 0.65) + result = layouter.fit([text], area_w, base_font_size / 0.65) break if result.status == :success @@ -405,30 +405,30 @@ module Submissions break if id_string.length < 8 end - reason_result = layouter.fit([reason_text], area['w'] * width, height) + reason_result = layouter.fit([reason_text], area_w, height) text_height = result.lines.sum(&:height) + reason_result.lines.sum(&:height) - image_height = (area['h'] * height) - text_height - image_height = (area['h'] * height) / 2 if image_height < (area['h'] * height) / 2 + image_height = area_h - text_height + image_height = area_h / 2 if image_height < area_h / 2 - scale = [(area['w'] * width) / image.width, image_height / image.height].min + scale = [area_w / image.width, image_height / image.height].min io = StringIO.new(image.resize([scale * 4, 1].select(&:positive?).min).write_to_buffer('.png')) - layouter.fit([text], area['w'] * width, base_font_size / 0.65) - .draw(canvas, (area['x'] * width) + TEXT_LEFT_MARGIN, - height - (area['y'] * height) - TEXT_TOP_MARGIN - image_height) + layouter.fit([text], area_w, base_font_size / 0.65) + .draw(canvas, area_x + TEXT_LEFT_MARGIN, + height - area_y - TEXT_TOP_MARGIN - image_height) - layouter.fit([reason_text], area['w'] * width, reason_result.lines.sum(&:height)) - .draw(canvas, (area['x'] * width) + TEXT_LEFT_MARGIN, - height - (area['y'] * height) - TEXT_TOP_MARGIN - + layouter.fit([reason_text], area_w, reason_result.lines.sum(&:height)) + .draw(canvas, area_x + TEXT_LEFT_MARGIN, + height - area_y - TEXT_TOP_MARGIN - result.lines.sum(&:height) - image_height) canvas.image( io, at: [ - (area['x'] * width) + (area['w'] * width / 2) - ((image.width * scale) / 2), - height - (area['y'] * height) - (image.height * scale / 2) - (image_height / 2) + area_x + (area_w / 2) - ((image.width * scale) / 2), + height - area_y - (image.height * scale / 2) - (image_height / 2) ], width: image.width * scale, height: image.height * scale