Skip to content

Commit

Permalink
Merge pull request #213 from ONLYOFFICE/feature/add-parsing-preset-color
Browse files Browse the repository at this point in the history
Add parsing `PresetColor` to `GradientStop`
  • Loading branch information
ShockwaveNN authored Sep 6, 2016
2 parents 54e3e6d + c0b9f44 commit 6eb62b1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* Clean way to parse `ParagraphSpacing`
* `ParagraphTab` now stored in `Tabs` in `ParagraphProperties`
* Add `OoxmlSize` support of `one_240th_cm` and use in `Spacing`
* Add parsing `PresetColor` to `GradientStop`

### Fixes
* Fix parsing document style id - it can be string, not only digit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.parse(gradient_fill_node)
case gradient_fill_node_child.name
when 'gsLst'
gradient_fill_node_child.xpath('*').each do |gradient_stop_node|
gradient_color.gradient_stops << GradientStop.parse(gradient_stop_node)
gradient_color.gradient_stops << GradientStop.new(parent: gradient_color).parse(gradient_stop_node)
end
when 'path'
gradient_color.path = gradient_fill_node_child.attribute('path').value.to_sym
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
require_relative 'gradient_stop/preset_color'
module OoxmlParser
class GradientStop < OOXMLDocumentObject
attr_accessor :position, :color

def initialize(position)
@position = position
end
# Parse GradientStop object
# @param node [Nokogiri::XML:Element] node to parse
# @return [GradientStop] result of parsing
def parse(node)
node.attributes.each do |key, value|
case key
when 'pos'
@position = value.value.to_i / 1_000
end
end

def self.parse(gs_node)
gradient_stop = GradientStop.new(gs_node.attribute('pos').value.to_i / 1_000)
gs_node.xpath('*').each { |color_node| gradient_stop.color = Color.parse_color(color_node) }
gradient_stop
node.xpath('*').each do |node_child|
@color = case node_child.name
when 'prstClr'
PresetColor.new(parent: self).parse(node_child)
else
Color.parse_color(node_child)
end
end
self
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module OoxmlParser
# Class for working with `a:prstClr` tag
class PresetColor < OOXMLDocumentObject
# @return [String] value of preset color
attr_accessor :value

# Parse PresetColor object
# @param node [Nokogiri::XML:Element] node to parse
# @return [PresetColor] result of parsing
def parse(node)
node.attributes.each do |key, value|
case key
when 'val'
@value = value.value.to_s
end
end
self
end
end
end
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'spec_helper'

describe 'My behaviour' do
it 'gradient_fill.xlsx' do
xlsx = OoxmlParser::XlsxParser.parse_xlsx('spec/workbook/worksheet/drawing/shape/properties/fill_color/value/gradient_stops/gradient_stops_color/gradient_stops_color_preset.xlsx')
expect(xlsx.worksheets[0].drawings.first.shape.properties.fill_color.value.gradient_stops.first.color.value).to eq('lightYellow')
end
end

0 comments on commit 6eb62b1

Please sign in to comment.