diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index 98d67c79..c221d38a 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -40,6 +40,8 @@ module Submissions RTL_REGEXP = TextUtils::RTL_REGEXP + TEXT_ALIGNS = %w[left center right justify].freeze + TEXT_VALIGNS = %w[top center bottom].freeze TEXT_LEFT_MARGIN = 1 TEXT_TOP_MARGIN = 1 MAX_PAGE_ROTATE = 50 @@ -280,10 +282,10 @@ module Submissions value = field['default_value'] if field['type'] == 'heading' value = field['default_value'] if field['type'] == 'strikethrough' && value.nil? && field['conditions'].blank? - text_align = field.dig('preferences', 'align').to_s.to_sym.presence || + text_align = field.dig('preferences', 'align').to_s.presence_in(TEXT_ALIGNS)&.to_sym || (value.to_s.match?(RTL_REGEXP) ? :right : :left) - text_valign = (field.dig('preferences', 'valign').to_s.presence || 'center').to_sym + text_valign = (field.dig('preferences', 'valign').to_s.presence_in(TEXT_VALIGNS) || 'center').to_sym layouter = HexaPDF::Layout::TextLayouter.new(text_valign:, text_align:, font:, font_size:) @@ -597,7 +599,7 @@ module Submissions ) when ->(type) { type == 'cells' && !area['cell_w'].to_f.zero? } cell_width = area['cell_w'] * width - cell_valign = field.dig('preferences', 'valign').to_s.presence || 'center' + cell_valign = field.dig('preferences', 'valign').to_s.presence_in(TEXT_VALIGNS) || 'center' cell_layouter = cell_layouters[cell_valign] if (mask = field.dig('preferences', 'mask').presence)