Skip to content
This repository
Browse code

Add support for underlined text.

  • Loading branch information...
commit 6440dced8ff2da027fd4f60f434262ec60191573 1 parent dc1f292
Stefan Daschek authored February 27, 2012
7  lib/axlsx/stylesheet/font.rb
@@ -54,6 +54,10 @@ class Font
54 54
     # @return [Boolean]
55 55
     attr_reader :i
56 56
 
  57
+    # Indicates if the font should be rendered underlined
  58
+    # @return [Boolean]
  59
+    attr_reader :u
  60
+
57 61
     # Indicates if the font should be rendered with a strikthrough
58 62
     # @return [Boolean]
59 63
     attr_reader :strike
@@ -89,6 +93,7 @@ class Font
89 93
     # @option options [Integer] family
90 94
     # @option options [Boolean] b
91 95
     # @option options [Boolean] i
  96
+    # @option options [Boolean] u
92 97
     # @option options [Boolean] strike
93 98
     # @option options [Boolean] outline
94 99
     # @option options [Boolean] shadow
@@ -111,6 +116,8 @@ def family=(v) Axlsx::validate_unsigned_int v; @family = v end
111 116
     def b=(v) Axlsx::validate_boolean v; @b = v end    
112 117
     # @see i
113 118
     def i=(v) Axlsx::validate_boolean v; @i = v end
  119
+    # @see u
  120
+    def u=(v) Axlsx::validate_boolean v; @u = v end
114 121
     # @see strike
115 122
     def strike=(v) Axlsx::validate_boolean v; @strike = v end
116 123
     # @see outline
5  lib/axlsx/stylesheet/styles.rb
@@ -125,6 +125,7 @@ def initialize()
125 125
     # @option options [Integer] sz The text size
126 126
     # @option options [Boolean] b Indicates if the text should be bold
127 127
     # @option options [Boolean] i Indicates if the text should be italicised
  128
+    # @option options [Boolean] u Indicates if the text should be underlined
128 129
     # @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
129 130
     # @option options [Boolean] strike Indicates if the text should be rendered with a shadow
130 131
     # @option options [Integer] charset The character set to use.
@@ -210,9 +211,9 @@ def add_style(options={})
210 211
                0
211 212
              end
212 213
       
213  
-      fontId = if (options.values_at(:fg_color, :sz, :b, :i, :strike, :outline, :shadow, :charset, :family, :font_name).length)
  214
+      fontId = if (options.values_at(:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name).length)
214 215
                  font = Font.new()
215  
-                 [:b, :i, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
  216
+                 [:b, :i, :u, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
216 217
                  font.color = Color.new(:rgb => options[:fg_color]) unless options[:fg_color].nil?
217 218
                  font.name = options[:font_name] unless options[:font_name].nil?
218 219
                  fonts << font
8  test/stylesheet/tc_font.rb
@@ -17,6 +17,7 @@ def test_initialiation
17 17
     assert_equal(@item.family, nil)
18 18
     assert_equal(@item.b, nil)
19 19
     assert_equal(@item.i, nil)
  20
+    assert_equal(@item.u, nil)
20 21
     assert_equal(@item.strike, nil)
21 22
     assert_equal(@item.outline, nil)
22 23
     assert_equal(@item.shadow, nil)
@@ -61,6 +62,13 @@ def test_i
61 62
     assert_nothing_raised { @item.i = true }
62 63
     assert_equal(@item.i, true)
63 64
   end
  65
+  
  66
+    # def u=(v) Axlsx::validate_boolean v; @u = v end
  67
+  def test_u
  68
+    assert_raise(ArgumentError) { @item.u = -7 }
  69
+    assert_nothing_raised { @item.u = true }
  70
+    assert_equal(@item.u, true)
  71
+  end
64 72
 
65 73
     # def strike=(v) Axlsx::validate_boolean v; @strike = v end
66 74
   def test_strike

2 notes on commit 6440dce

Randy Morgan (@morgan_randy)
Owner

Very well done sir!

Stefan Daschek
Collaborator

Thanks! :)

Please sign in to comment.
Something went wrong with that request. Please try again.