Class: OoxmlParser::DocxColor

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb

Constant Summary

Constants inherited from OOXMLDocumentObject

OOXMLDocumentObject::DEFAULT_DIRECTORY_FOR_MEDIA

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, copy_media_file, current_xml, dir, encrypted_file?, get_link_from_rels, media_folder, option_enabled?, unzip_file

Constructor Details

#initialize(value = nil) ⇒ DocxColor

Returns a new instance of DocxColor.



8
9
10
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb', line 8

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

Instance Attribute Details

#alphaObject

Returns the value of attribute alpha.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb', line 6

def alpha
  @alpha
end

#stretching_typeObject

Returns the value of attribute stretching_type.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb', line 6

def stretching_type
  @stretching_type
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb', line 6

def type
  @type
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb', line 6

def value
  @value
end

Class Method Details

.parse(shape_properties_node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb', line 12

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