summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-09-14 16:01:01 +0900
committerRandy Morgan <[email protected]>2012-09-14 16:01:01 +0900
commitbcf38488906554162d1ec6dc04837f802873b567 (patch)
treef089c6d608bfa5e64401060bdccb2bdcf3a62059
parent397af756fc7ff412dd7472e845143a5223a81a83 (diff)
downloadcaxlsx-bcf38488906554162d1ec6dc04837f802873b567.tar.gz
caxlsx-bcf38488906554162d1ec6dc04837f802873b567.zip
incorporate deeper check for cell size and adjust for bold
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb13
-rw-r--r--test/workbook/worksheet/tc_cell.rb6
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 2846225f..621a51f6 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -330,7 +330,7 @@ module Axlsx
font_scale = (font_size/10.0).to_f
((value.to_s.count(Worksheet.thin_chars) * mdw + 5) / mdw * 256) / 256.0 * font_scale
end
-
+
# returns the absolute or relative string style reference for
# this cell.
# @param [Boolean] absolute -when false a relative reference will be
@@ -338,12 +338,17 @@ module Axlsx
# @return [String]
def reference(absolute=true)
absolute ? r_abs : r
- end
-
+ end
+
private
+ # we scale the font size if bold style is applied to either the style font or
+ # the cell itself. Yes, it is a bit of a hack, but it is much better than using
+ # imagemagick and loading metrics for every character.
def font_size
- sz || @styles.fonts[@styles.cellXfs[style].fontId].sz || @styles.fonts[0].sz
+ font = @styles.fonts[@styles.cellXfs[style].fontId] || @styles.fonts[0]
+ size_from_styles = (font.b || b) ? font.sz * 1.5 : font.sz
+ sz || size_from_styles
end
# Utility method for setting inline style attributes
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index 555fcff7..7188bc1d 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -275,6 +275,12 @@ class TestCell < Test::Unit::TestCase
assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz)
end
+ def test_font_size_with_bolding
+ @c.style = @c.row.worksheet.workbook.styles.add_style :b => true
+ sz = @c.send(:font_size)
+ assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @c.send(:font_size))
+ end
+
def test_font_size_with_custom_sz
@c.style = @c.row.worksheet.workbook.styles.add_style :sz => 52
sz = @c.send(:font_size)