Skip to content

Commit

Permalink
fix cell field font size
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Jul 7, 2024
1 parent edb2997 commit b90c67b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/submissions/generate_result_attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,30 @@ def generate_pdfs(submitter)
cell_width = area['cell_w'] * width

TextUtils.maybe_rtl_reverse(value).chars.each_with_index do |char, index|
next if char.blank?

text = HexaPDF::Layout::TextFragment.create(char, font: pdf.fonts.add(FONT_NAME),
font_size:)

cell_layouter.fit([text], cell_width, area['h'] * height)
line_height = layouter.fit([text], cell_width, height).lines.first.height

if preferences_font_size.blank? && line_height > (area['h'] * height)
text = HexaPDF::Layout::TextFragment.create(char,
font: pdf.fonts.add(FONT_NAME),
font_size: (font_size / 1.4).to_i)

line_height = layouter.fit([text], cell_width, height).lines.first.height
end

if preferences_font_size.blank? && line_height > (area['h'] * height)
text = HexaPDF::Layout::TextFragment.create(char,
font: pdf.fonts.add(FONT_NAME),
font_size: (font_size / 1.9).to_i)

line_height = layouter.fit([text], cell_width, height).lines.first.height
end

cell_layouter.fit([text], cell_width, [line_height, area['h'] * height].max)
.draw(canvas, ((area['x'] * width) + (cell_width * index)),
height - (area['y'] * height))
end
Expand Down

0 comments on commit b90c67b

Please sign in to comment.