@@ -247,10 +247,30 @@ def generate_pdfs(submitter)
247247 cell_width = area [ 'cell_w' ] * width
248248
249249 TextUtils . maybe_rtl_reverse ( value ) . chars . each_with_index do |char , index |
250+ next if char . blank?
251+
250252 text = HexaPDF ::Layout ::TextFragment . create ( char , font : pdf . fonts . add ( FONT_NAME ) ,
251253 font_size :)
252254
253- cell_layouter . fit ( [ text ] , cell_width , area [ 'h' ] * height )
255+ line_height = layouter . fit ( [ text ] , cell_width , height ) . lines . first . height
256+
257+ if preferences_font_size . blank? && line_height > ( area [ 'h' ] * height )
258+ text = HexaPDF ::Layout ::TextFragment . create ( char ,
259+ font : pdf . fonts . add ( FONT_NAME ) ,
260+ font_size : ( font_size / 1.4 ) . to_i )
261+
262+ line_height = layouter . fit ( [ text ] , cell_width , height ) . lines . first . height
263+ end
264+
265+ if preferences_font_size . blank? && line_height > ( area [ 'h' ] * height )
266+ text = HexaPDF ::Layout ::TextFragment . create ( char ,
267+ font : pdf . fonts . add ( FONT_NAME ) ,
268+ font_size : ( font_size / 1.9 ) . to_i )
269+
270+ line_height = layouter . fit ( [ text ] , cell_width , height ) . lines . first . height
271+ end
272+
273+ cell_layouter . fit ( [ text ] , cell_width , [ line_height , area [ 'h' ] * height ] . max )
254274 . draw ( canvas , ( ( area [ 'x' ] * width ) + ( cell_width * index ) ) ,
255275 height - ( area [ 'y' ] * height ) )
256276 end
0 commit comments