diff options
| author | Weston Ganger <[email protected]> | 2020-02-12 16:07:52 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-02-13 01:07:52 +0100 |
| commit | 5a5c09132060f1270849c2535d00c456a31fa02a (patch) | |
| tree | 3a05366e3e9795266f08ce17fa6d0e387eb8747d /lib/axlsx/workbook/worksheet/cell.rb | |
| parent | a58375fa72fac090d6310e2094808e8a477eab82 (diff) | |
| download | caxlsx-5a5c09132060f1270849c2535d00c456a31fa02a.tar.gz caxlsx-5a5c09132060f1270849c2535d00c456a31fa02a.zip | |
Improve cell string_autowidth calculations (#44)
Previously, cells with autowidth sometimes were too narrow for the content to fit.
The original width calculation tried to take the difference between narrow and wide chars into account, but it didn’t work out very well. The new calculation is simpler. Compared to the previous implementation it results in cells being slightly wider in most cases.
Diffstat (limited to 'lib/axlsx/workbook/worksheet/cell.rb')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 53bea28b..5a00a97d 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -373,6 +373,7 @@ module Axlsx # @return [Float] def autowidth return if is_formula? || value.nil? + if contains_rich_text? string_width('', font_size) + value.autowidth elsif styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text @@ -409,7 +410,7 @@ module Axlsx # - scaling is not linear as font sizes increase def string_width(string, font_size) font_scale = font_size / 10.0 - (string.to_s.count(Worksheet::THIN_CHARS) + 3.0) * font_scale + (string.to_s.size + 3) * font_scale end # we scale the font size if bold style is applied to either the style font or |
