fix font size on large pdfs

pull/105/head
Alex Turchyn 2 years ago
parent f6879d7f94
commit 9cc85595e3

@ -37,6 +37,7 @@ module Submissions
width = page.box.width width = page.box.width
height = page.box.height height = page.box.height
font_size = ((page.box.width / A4_SIZE[0].to_f) * FONT_SIZE).to_i
value = submitter.values[field['uuid']] value = submitter.values[field['uuid']]
@ -70,13 +71,13 @@ module Submissions
items = Array.wrap(value).each_with_object([]) do |uuid, acc| items = Array.wrap(value).each_with_object([]) do |uuid, acc|
attachment = submitter.attachments.find { |a| a.uuid == uuid } attachment = submitter.attachments.find { |a| a.uuid == uuid }
acc << HexaPDF::Layout::InlineBox.create(width: FONT_SIZE, height: FONT_SIZE, acc << HexaPDF::Layout::InlineBox.create(width: font_size, height: font_size,
margin: [0, 1, -2, 0]) do |cv, box| margin: [0, 1, -2, 0]) do |cv, box|
cv.image(PdfIcons.paperclip_io, at: [0, 0], width: box.content_width) cv.image(PdfIcons.paperclip_io, at: [0, 0], width: box.content_width)
end end
acc << HexaPDF::Layout::TextFragment.create("#{attachment.filename}\n", font: pdf.fonts.add(FONT_NAME), acc << HexaPDF::Layout::TextFragment.create("#{attachment.filename}\n", font: pdf.fonts.add(FONT_NAME),
font_size: FONT_SIZE) font_size:)
end end
lines = layouter.fit(items, area['w'] * width, height).lines lines = layouter.fit(items, area['w'] * width, height).lines
@ -132,7 +133,7 @@ module Submissions
value.chars.each_with_index do |char, index| value.chars.each_with_index do |char, index|
text = HexaPDF::Layout::TextFragment.create(char, font: pdf.fonts.add(FONT_NAME), text = HexaPDF::Layout::TextFragment.create(char, font: pdf.fonts.add(FONT_NAME),
font_size: FONT_SIZE) font_size:)
cell_layouter.fit([text], cell_width, area['h'] * height) cell_layouter.fit([text], cell_width, area['h'] * height)
.draw(canvas, ((area['x'] * width) + (cell_width * index)), .draw(canvas, ((area['x'] * width) + (cell_width * index)),
@ -142,7 +143,7 @@ module Submissions
value = I18n.l(Date.parse(value), format: :long) if field['type'] == 'date' value = I18n.l(Date.parse(value), format: :long) if field['type'] == 'date'
text = HexaPDF::Layout::TextFragment.create(Array.wrap(value).join(', '), font: pdf.fonts.add(FONT_NAME), text = HexaPDF::Layout::TextFragment.create(Array.wrap(value).join(', '), font: pdf.fonts.add(FONT_NAME),
font_size: FONT_SIZE) font_size:)
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)

Loading…
Cancel
Save