|
|
|
@ -18,6 +18,8 @@ module Submissions
|
|
|
|
TEXT_TOP_MARGIN = 1
|
|
|
|
TEXT_TOP_MARGIN = 1
|
|
|
|
MAX_PAGE_ROTATE = 20
|
|
|
|
MAX_PAGE_ROTATE = 20
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
COURIER_FONT = 'Courier'
|
|
|
|
|
|
|
|
|
|
|
|
A4_SIZE = [595, 842].freeze
|
|
|
|
A4_SIZE = [595, 842].freeze
|
|
|
|
|
|
|
|
|
|
|
|
TESTING_FOOTER = 'Testing Document - NOT LEGALLY BINDING'
|
|
|
|
TESTING_FOOTER = 'Testing Document - NOT LEGALLY BINDING'
|
|
|
|
@ -188,7 +190,8 @@ module Submissions
|
|
|
|
|
|
|
|
|
|
|
|
fill_color = field.dig('preferences', 'color').presence
|
|
|
|
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 = submitter.values[field['uuid']]
|
|
|
|
value = field['default_value'] if field['type'] == 'heading'
|
|
|
|
value = field['default_value'] if field['type'] == 'heading'
|
|
|
|
@ -435,18 +438,19 @@ module Submissions
|
|
|
|
|
|
|
|
|
|
|
|
value = TextUtils.maybe_rtl_reverse(Array.wrap(value).join(', '))
|
|
|
|
value = TextUtils.maybe_rtl_reverse(Array.wrap(value).join(', '))
|
|
|
|
|
|
|
|
|
|
|
|
text = HexaPDF::Layout::TextFragment.create(value, font:,
|
|
|
|
text_params = { font:, fill_color:, font_size: }
|
|
|
|
fill_color:,
|
|
|
|
text_params[:line_height] = text_params[:font_size] * 1.6 if font_name == COURIER_FONT
|
|
|
|
font_size:)
|
|
|
|
|
|
|
|
|
|
|
|
text = HexaPDF::Layout::TextFragment.create(value, **text_params)
|
|
|
|
|
|
|
|
|
|
|
|
lines = layouter.fit([text], area['w'] * width, height).lines
|
|
|
|
lines = layouter.fit([text], area['w'] * width, height).lines
|
|
|
|
box_height = lines.sum(&:height)
|
|
|
|
box_height = lines.sum(&:height)
|
|
|
|
|
|
|
|
|
|
|
|
if preferences_font_size.blank? && box_height > (area['h'] * height) + 1
|
|
|
|
if preferences_font_size.blank? && box_height > (area['h'] * height) + 1
|
|
|
|
text = HexaPDF::Layout::TextFragment.create(value,
|
|
|
|
text_params[:font_size] = (font_size / 1.4).to_i
|
|
|
|
font:,
|
|
|
|
text_params[:line_height] = text_params[:font_size] * 1.6 if font_name == COURIER_FONT
|
|
|
|
fill_color:,
|
|
|
|
|
|
|
|
font_size: (font_size / 1.4).to_i)
|
|
|
|
text = HexaPDF::Layout::TextFragment.create(value, **text_params)
|
|
|
|
|
|
|
|
|
|
|
|
lines = layouter.fit([text], field['type'].in?(%w[date number]) ? width : area['w'] * width, height).lines
|
|
|
|
lines = layouter.fit([text], field['type'].in?(%w[date number]) ? width : area['w'] * width, height).lines
|
|
|
|
|
|
|
|
|
|
|
|
@ -454,10 +458,10 @@ module Submissions
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if preferences_font_size.blank? && box_height > (area['h'] * height) + 1
|
|
|
|
if preferences_font_size.blank? && box_height > (area['h'] * height) + 1
|
|
|
|
text = HexaPDF::Layout::TextFragment.create(value,
|
|
|
|
text_params[:font_size] = (font_size / 1.9).to_i
|
|
|
|
font:,
|
|
|
|
text_params[:line_height] = text_params[:font_size] * 1.6 if font_name == COURIER_FONT
|
|
|
|
fill_color:,
|
|
|
|
|
|
|
|
font_size: (font_size / 1.9).to_i)
|
|
|
|
text = HexaPDF::Layout::TextFragment.create(value, **text_params)
|
|
|
|
|
|
|
|
|
|
|
|
lines = layouter.fit([text], field['type'].in?(%w[date number]) ? width : area['w'] * width, height).lines
|
|
|
|
lines = layouter.fit([text], field['type'].in?(%w[date number]) ? width : area['w'] * width, height).lines
|
|
|
|
|
|
|
|
|
|
|
|
|