Sha256: 154b9c7aedbfb13e217ee1eb93435e52406c50d4eeb232edfa31d3e36ac3d6ed

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

require_relative 'color/gradient_color/docx_gradient_color'
require_relative 'color/docx_pattern_fill'
# Color inside DOCX
module OoxmlParser
  class DocxColor < OOXMLDocumentObject
    attr_accessor :type, :value, :stretching_type, :alpha

    def initialize(value = nil)
      @value = value
    end

    def self.parse(shape_properties_node)
      fill_color = DocxColor.new
      shape_properties_node.xpath('*').each do |fill_node|
        case fill_node.name
        when 'blipFill'
          fill_color.type = :picture
          fill_color.value = DocxBlip.parse(fill_node)
          fill_node.xpath('*').each do |fill_type_node_child|
            case fill_type_node_child.name
            when 'tile'
              fill_color.stretching_type = :tile
            when 'stretch'
              fill_color.stretching_type = :stretch
            when 'blip'
              fill_type_node_child.xpath('alphaModFix').each { |alpha_node| fill_color.alpha = alpha_node.attribute('amt').value.to_i / 1_000.0 }
            end
          end
        when 'solidFill'
          fill_color.type = :solid
          fill_color.value = Color.parse_color_model(fill_node)
        when 'gradFill'
          fill_color.type = :gradient
          fill_color.value = DocxGradientColor.parse(fill_node)
        when 'pattFill'
          fill_color.type = :pattern
          fill_color.value = DocxPatternFill.parse(fill_node)
        end
      end
      fill_color
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ooxml_parser-0.1.2 lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb
ooxml_parser-0.1.1 lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb