From df2e53bc40e0cffb501da9a508a7ef2d5c3c9df2 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Wed, 5 Feb 2025 16:13:31 +0200 Subject: [PATCH 01/11] font mono --- app/javascript/submission_form/area.vue | 2 +- app/views/submissions/_value.html.erb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/javascript/submission_form/area.vue b/app/javascript/submission_form/area.vue index f30b2dd34..0a4533974 100644 --- a/app/javascript/submission_form/area.vue +++ b/app/javascript/submission_form/area.vue @@ -3,7 +3,7 @@ class="field-area flex absolute lg:text-base -outline-offset-1" dir="auto" :style="computedStyle" - :class="{ 'font-serif': field.preferences?.font === 'Times', 'text-[1.6vw] lg:text-base': !textOverflowChars, 'text-[1.0vw] lg:text-xs': textOverflowChars, 'cursor-default': !submittable, 'border border-red-100 bg-red-100 cursor-pointer': submittable, 'border border-red-100': !isActive && submittable, 'bg-opacity-80': !isActive && !isValueSet && submittable, 'field-area-active outline-red-500 outline-dashed outline-2 z-10': isActive && submittable, 'bg-opacity-40': (isActive || isValueSet) && submittable }" + :class="{ 'font-mono': field.preferences?.font === 'Courier', 'font-serif': field.preferences?.font === 'Times', 'text-[1.6vw] lg:text-base': !textOverflowChars, 'text-[1.0vw] lg:text-xs': textOverflowChars, 'cursor-default': !submittable, 'border border-red-100 bg-red-100 cursor-pointer': submittable, 'border border-red-100': !isActive && submittable, 'bg-opacity-80': !isActive && !isValueSet && submittable, 'field-area-active outline-red-500 outline-dashed outline-2 z-10': isActive && submittable, 'bg-opacity-40': (isActive || isValueSet) && submittable }" >
<% color = field.dig('preferences', 'color') %> -width: <%= area['w'] * 100 %>%; height: <%= area['h'] * 100 %>%; left: <%= area['x'] * 100 %>%; top: <%= area['y'] * 100 %>%; <%= "font-size: clamp(4pt, 1.6vw, #{field['preferences']['font_size'].to_i * 1.23}pt); line-height: `clamp(6pt, 2.0vw, #{(field['preferences']['font_size'].to_i * 1.23) + 3}pt)`" if field.dig('preferences', 'font_size') %>"> +<% font = field.dig('preferences', 'font') %> +width: <%= area['w'] * 100 %>%; height: <%= area['h'] * 100 %>%; left: <%= area['x'] * 100 %>%; top: <%= area['y'] * 100 %>%; <%= "font-size: clamp(4pt, 1.6vw, #{field['preferences']['font_size'].to_i * 1.23}pt); line-height: `clamp(6pt, 2.0vw, #{(field['preferences']['font_size'].to_i * 1.23) + 3}pt)`" if field.dig('preferences', 'font_size') %>"> <% if field['type'] == 'signature' %>
From 5dc80601b26d193d1a811da46a79e548043a4470 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Wed, 5 Feb 2025 18:17:55 +0200 Subject: [PATCH 02/11] courier font --- app/views/submissions/show.html.erb | 2 +- .../generate_result_attachments.rb | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/views/submissions/show.html.erb b/app/views/submissions/show.html.erb index 09d57646d..fff9f56f1 100644 --- a/app/views/submissions/show.html.erb +++ b/app/views/submissions/show.html.erb @@ -232,7 +232,7 @@ <% elsif field['type'] == 'date' %> <%= TimeUtils.format_date_string(value, field.dig('preferences', 'format'), @submission.account.locale) %> <% else %> - <%= Array.wrap(value).join(', ') %> +
<%= Array.wrap(value).join(', ') %>
<% end %>
diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index 1686d7eca..a5941863f 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -18,6 +18,8 @@ module GenerateResultAttachments TEXT_TOP_MARGIN = 1 MAX_PAGE_ROTATE = 20 + COURIER_FONT = 'Courier' + A4_SIZE = [595, 842].freeze TESTING_FOOTER = 'Testing Document - NOT LEGALLY BINDING' @@ -188,7 +190,8 @@ def fill_submitter_fields(submitter, account, pdfs_index, with_signature_id:, is fill_color = field.dig('preferences', 'color').presence - font = pdf.fonts.add(field.dig('preferences', 'font').presence || FONT_NAME) + font_name = field.dig('preferences', 'font').presence || FONT_NAME + font = pdf.fonts.add(font_name) value = submitter.values[field['uuid']] value = field['default_value'] if field['type'] == 'heading' @@ -435,18 +438,19 @@ def fill_submitter_fields(submitter, account, pdfs_index, with_signature_id:, is value = TextUtils.maybe_rtl_reverse(Array.wrap(value).join(', ')) - text = HexaPDF::Layout::TextFragment.create(value, font:, - fill_color:, - font_size:) + text_params = { font:, fill_color:, font_size: } + text_params[:line_height] = text_params[:font_size] * 1.6 if font_name == COURIER_FONT + + text = HexaPDF::Layout::TextFragment.create(value, **text_params) lines = layouter.fit([text], area['w'] * width, height).lines box_height = lines.sum(&:height) if preferences_font_size.blank? && box_height > (area['h'] * height) + 1 - text = HexaPDF::Layout::TextFragment.create(value, - font:, - fill_color:, - font_size: (font_size / 1.4).to_i) + text_params[:font_size] = (font_size / 1.4).to_i + text_params[:line_height] = text_params[:font_size] * 1.6 if font_name == COURIER_FONT + + text = HexaPDF::Layout::TextFragment.create(value, **text_params) lines = layouter.fit([text], field['type'].in?(%w[date number]) ? width : area['w'] * width, height).lines @@ -454,10 +458,10 @@ def fill_submitter_fields(submitter, account, pdfs_index, with_signature_id:, is end if preferences_font_size.blank? && box_height > (area['h'] * height) + 1 - text = HexaPDF::Layout::TextFragment.create(value, - font:, - fill_color:, - font_size: (font_size / 1.9).to_i) + text_params[:font_size] = (font_size / 1.9).to_i + text_params[:line_height] = text_params[:font_size] * 1.6 if font_name == COURIER_FONT + + text = HexaPDF::Layout::TextFragment.create(value, **text_params) lines = layouter.fit([text], field['type'].in?(%w[date number]) ? width : area['w'] * width, height).lines From 974bb85fb7406a1552a1e44f05a3b1685133ce27 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Thu, 6 Feb 2025 12:55:27 +0200 Subject: [PATCH 03/11] rescue malformed PDF --- app/controllers/api/tools_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/tools_controller.rb b/app/controllers/api/tools_controller.rb index 7b2d5cb4e..63a50f89e 100644 --- a/app/controllers/api/tools_controller.rb +++ b/app/controllers/api/tools_controller.rb @@ -34,6 +34,8 @@ def verify } end } + rescue HexaPDF::MalformedPDFError + render json: { error: 'Malformed PDF' }, status: :unprocessable_entity end end end From a15624690b86d25100e3b9c73b92b4c8f9efbedd Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Wed, 5 Feb 2025 21:18:35 +0200 Subject: [PATCH 04/11] show unauthorized message in test environment --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a48146ee6..a3cb0242f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -30,7 +30,7 @@ class ApplicationController < ActionController::Base redirect_to request.referer, alert: 'Too many requests', status: :too_many_requests end - if Rails.env.production? + if Rails.env.production? || Rails.env.test? rescue_from CanCan::AccessDenied do |e| Rollbar.warning(e) if defined?(Rollbar) From 6ea07bc13b6270040d54e49add46cca8ecdf8d4a Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Thu, 6 Feb 2025 13:49:09 +0200 Subject: [PATCH 05/11] show minimize on mobile if with description --- app/javascript/submission_form/form.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/javascript/submission_form/form.vue b/app/javascript/submission_form/form.vue index 01e2de78d..b7d17e27e 100644 --- a/app/javascript/submission_form/form.vue +++ b/app/javascript/submission_form/form.vue @@ -100,7 +100,8 @@