diff options
| author | Tobias Egli <[email protected]> | 2022-02-02 16:00:32 +0100 |
|---|---|---|
| committer | Josef Šimánek <[email protected]> | 2022-02-06 00:37:27 +0100 |
| commit | d3cf7bca5728b166c7643ad839efeba60ed0e256 (patch) | |
| tree | 9175590f74a43cd394d22b03da1788eef7a7d2af /lib/axlsx/workbook/worksheet/cell.rb | |
| parent | 059c9d38c8860775a260711f78222b69535e6163 (diff) | |
| download | caxlsx-d3cf7bca5728b166c7643ad839efeba60ed0e256.tar.gz caxlsx-d3cf7bca5728b166c7643ad839efeba60ed0e256.zip | |
Autowidth cell calculation is now configurable
On the workbook you can now configure the font_scale_divisor and the bold_font_multiplier to get better results for the automatic cell width calculationb
Diffstat (limited to 'lib/axlsx/workbook/worksheet/cell.rb')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 51a14494..3277b8c5 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -409,7 +409,7 @@ module Axlsx # This is still not perfect... # - scaling is not linear as font sizes increase def string_width(string, font_size) - font_scale = font_size / 10.0 + font_scale = font_size / row.worksheet.workbook.font_scale_divisor (string.to_s.size + 3) * font_scale end @@ -418,8 +418,9 @@ module Axlsx # imagemagick and loading metrics for every character. def font_size return sz if sz + font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0] - (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz + font.b || (defined?(@b) && @b) ? (font.sz * row.worksheet.workbook.bold_font_multiplier) : font.sz end # Utility method for setting inline style attributes |
