diff options
| author | randym <[email protected]> | 2018-01-11 17:10:03 +0900 |
|---|---|---|
| committer | randym <[email protected]> | 2018-01-11 17:10:03 +0900 |
| commit | f6a2d20d20fc116d00f1958e945ee8b28d16af6e (patch) | |
| tree | 13d3d0adaf4253702874dfe0bc3a06375e829105 /lib | |
| parent | 977c09de1515e86536f0c952c08be319fbbab870 (diff) | |
| download | caxlsx-f6a2d20d20fc116d00f1958e945ee8b28d16af6e.tar.gz caxlsx-f6a2d20d20fc116d00f1958e945ee8b28d16af6e.zip | |
chore(clean): remove white space
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/rich_text.rb | 8 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/rich_text_run.rb | 43 |
2 files changed, 28 insertions, 23 deletions
diff --git a/lib/axlsx/workbook/worksheet/rich_text.rb b/lib/axlsx/workbook/worksheet/rich_text.rb index 9124dfbe..e8c58c67 100644 --- a/lib/axlsx/workbook/worksheet/rich_text.rb +++ b/lib/axlsx/workbook/worksheet/rich_text.rb @@ -1,5 +1,7 @@ module Axlsx + class RichText < SimpleTypedList + def initialize(text = nil, options={}) super(RichTextRun) add_run(text, options) unless text.nil? @@ -7,12 +9,12 @@ module Axlsx end attr_reader :cell - + def cell=(cell) @cell = cell each { |run| run.cell = cell } end - + def autowidth widtharray = [0] # Are arrays the best way of solving this problem? each { |run| run.autowidth(widtharray) } @@ -22,7 +24,7 @@ module Axlsx def add_run(text, options={}) self << RichTextRun.new(text, options) end - + def runs self end diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb index e56dc3ae..5dcc86a4 100644 --- a/lib/axlsx/workbook/worksheet/rich_text_run.rb +++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb @@ -1,26 +1,26 @@ module Axlsx class RichTextRun - + include Axlsx::OptionsParser - + attr_reader :value - + INLINE_STYLES = [:font_name, :charset, :family, :b, :i, :strike, :outline, :shadow, :condense, :extend, :u, :vertAlign, :sz, :color, :scheme].freeze - + def initialize(value, options={}) self.value = value - parse_options(options) + parse_options(options) end - + def value=(value) @value = value end - + attr_accessor :cell - + # The inline font_name property for the cell # @return [String] attr_reader :font_name @@ -157,7 +157,7 @@ module Axlsx # The Shared Strings Table index for this cell # @return [Integer] attr_reader :ssti - + # @return [Integer] The cellXfs item index applied to this cell. # @raise [ArgumentError] Invalid cellXfs id if the value provided is not within cellXfs items range. def style=(v) @@ -167,6 +167,9 @@ module Axlsx @style = v end + # Tries to work out the width of the longest line in the run + # @param [Array] widtharray this array is populated with the widths of each line in the run. + # @returns [Array] def autowidth(widtharray) return if value.nil? if styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text @@ -184,19 +187,19 @@ module Axlsx end widtharray end - + # Utility method for setting inline style attributes def set_run_style(validator, attr, value) return unless INLINE_STYLES.include?(attr.to_sym) Axlsx.send(validator, value) unless validator.nil? self.instance_variable_set :"@#{attr.to_s}", value end - + def to_xml_string(str = '') valid = RichTextRun::INLINE_STYLES - data = Hash[self.instance_values.map{ |k, v| [k.to_sym, v] }] + data = Hash[self.instance_values.map{ |k, v| [k.to_sym, v] }] data = data.select { |key, value| valid.include?(key) && !value.nil? } - + str << '<r><rPr>' data.keys.each do |key| case key @@ -211,9 +214,9 @@ module Axlsx clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s)) str << ('</rPr><t>' << clean_value << '</t></r>') end - + private - + # Returns the width of a string according to the current style # This is still not perfect... # - scaling is not linear as font sizes increase @@ -221,7 +224,7 @@ module Axlsx font_scale = font_size / 10.0 string.count(Worksheet::THIN_CHARS) * font_scale end - + # 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. @@ -230,15 +233,15 @@ module Axlsx font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0] (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz end - + def style cell.style end - + def styles - cell.row.worksheet.styles + cell.row.worksheet.styles end - + # Converts the value to the correct XML representation (fixes issues with # Numbers) def xml_value value |
