lib/write_xlsx/utility.rb in write_xlsx-0.86.0 vs lib/write_xlsx/utility.rb in write_xlsx-0.87.0

- old
+ new

@@ -541,9 +541,94 @@ # def fill_properties(fill) # :nodoc: line_fill_properties(fill) end + # + # Convert user defined pattern properties to the structure required internally. + # + def pattern_properties(args) # :nodoc: + pattern = {} + + return nil unless args + + # Check the pattern type is present. + return nil unless args.has_key?(:pattern) + + # Check the foreground color is present. + retuen nil unless args.has_key?(:fg_color) + + types = { + 'percent_5' => 'pct5', + 'percent_10' => 'pct10', + 'percent_20' => 'pct20', + 'percent_25' => 'pct25', + 'percent_30' => 'pct30', + 'percent_40' => 'pct40', + + 'percent_50' => 'pct50', + 'percent_60' => 'pct60', + 'percent_70' => 'pct70', + 'percent_75' => 'pct75', + 'percent_80' => 'pct80', + 'percent_90' => 'pct90', + + 'light_downward_diagonal' => 'ltDnDiag', + 'light_upward_diagonal' => 'ltUpDiag', + 'dark_downward_diagonal' => 'dkDnDiag', + 'dark_upward_diagonal' => 'dkUpDiag', + 'wide_downward_diagonal' => 'wdDnDiag', + 'wide_upward_diagonal' => 'wdUpDiag', + + 'light_vertical' => 'ltVert', + 'light_horizontal' => 'ltHorz', + 'narrow_vertical' => 'narVert', + 'narrow_horizontal' => 'narHorz', + 'dark_vertical' => 'dkVert', + 'dark_horizontal' => 'dkHorz', + + 'dashed_downward_diagonal' => 'dashDnDiag', + 'dashed_upward_diagonal' => 'dashUpDiag', + 'dashed_horizontal' => 'dashHorz', + 'dashed_vertical' => 'dashVert', + 'small_confetti' => 'smConfetti', + 'large_confetti' => 'lgConfetti', + + 'zigzag' => 'zigZag', + 'wave' => 'wave', + 'diagonal_brick' => 'diagBrick', + 'horizontal_brick' => 'horzBrick', + 'weave' => 'weave', + 'plaid' => 'plaid', + + 'divot' => 'divot', + 'dotted_grid' => 'dotGrid', + 'dotted_diamond' => 'dotDmnd', + 'shingle' => 'shingle', + 'trellis' => 'trellis', + 'sphere' => 'sphere', + + 'small_grid' => 'smGrid', + 'large_grid' => 'lgGrid', + 'small_check' => 'smCheck', + 'large_check' => 'lgCheck', + 'outlined_diamond' => 'openDmnd', + 'solid_diamond' => 'solidDmnd' + } + + # Check for valid types. + if types[args[:pattern]] + pattern[:pattern] = types[args[:pattern]] + else + raise "Unknown pattern type '#{args[:pattern]}'" + end + + pattern[:bg_color] = args[:bg_color] || '#FFFFFF' + pattern[:fg_color] = args[:fg_color] + + pattern + end + def line_fill_properties(params) return { :_defined => 0 } unless params ret = params.dup ret[:dash_type] = yield if block_given? && ret[:dash_type] ret[:_defined] = 1