From d92dffcef4b65fdef0d5cead0bc63444d8b34df0 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Fri, 14 Sep 2012 16:12:14 +0900 Subject: New fonts should use the default font values before applying custom style options via add_style --- lib/axlsx/stylesheet/styles.rb | 2 +- test/stylesheet/tc_styles.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index 0532af66..fd956a8c 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -279,7 +279,7 @@ module Axlsx # @return [Font|Integer] def parse_font_options(options={}) return if (options.keys & [:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name]).empty? - font = Font.new(options) + font = Font.new(fonts.first.instance_values.merge(options)) font.color = Color.new(:rgb => options[:fg_color]) if options[:fg_color] font.name = options[:font_name] if options[:font_name] options[:type] == :dxf ? font : fonts << font diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb index e43d9b55..b9d0b28a 100644 --- a/test/stylesheet/tc_styles.rb +++ b/test/stylesheet/tc_styles.rb @@ -105,6 +105,19 @@ class TestStyles < Test::Unit::TestCase assert(@styles.parse_alignment_options(:alignment => {}).is_a?(Axlsx::CellAlignment)) end + def test_parse_font_using_defaults + original = @styles.fonts.first + @styles.add_style :b => 1, :sz => 99 + created = @styles.fonts.last + original_attributes = original.instance_values + assert_equal(1, created.b) + assert_equal(99, created.sz) + copied = original_attributes.reject{ |key, value| %w(b sz).include? key } + copied.each do |key, value| + assert_equal(created.instance_values[key], value) + end + end + def test_parse_font_options options = { :fg_color => "FF050505", -- cgit v1.2.3