ooxml_parser 0.5.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ooxml_parser.rb +1 -0
  3. data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice.rb +1 -0
  4. data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice/math_text.rb +1 -0
  5. data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice/math_text/math_paragraph.rb +1 -0
  6. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +6 -0
  7. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/series.rb +2 -2
  8. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/series/series_text.rb +0 -2
  9. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb +1 -20
  10. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_distance_from_text.rb +3 -0
  11. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_properties.rb +51 -4
  12. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb +1 -0
  13. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb +4 -1
  14. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb +1 -0
  15. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +4 -0
  16. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_picture.rb +0 -2
  17. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb +3 -0
  18. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/ooxml_text_box.rb +1 -3
  19. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style.rb +42 -0
  20. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/effect_reference.rb +35 -0
  21. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/fill_reference.rb +35 -0
  22. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/font_reference.rb +35 -0
  23. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/line_reference.rb +35 -0
  24. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_color_scheme.rb +1 -0
  25. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/docx_custom_geometry/docx_shape_line_path/docx_shape_line_element.rb +0 -2
  26. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_line.rb +1 -0
  27. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties.rb +12 -4
  28. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_size.rb +10 -3
  29. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb +1 -3
  30. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_properties.rb +1 -3
  31. data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +3 -0
  32. data/lib/ooxml_parser/common_parser/common_data/color.rb +48 -82
  33. data/lib/ooxml_parser/common_parser/common_data/color/color_helper.rb +4 -3
  34. data/lib/ooxml_parser/common_parser/common_data/color/color_indexes.list +66 -0
  35. data/lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb +5 -0
  36. data/lib/ooxml_parser/common_parser/common_data/colors/color_properties.rb +8 -2
  37. data/lib/ooxml_parser/common_parser/common_data/colors/hsl_color.rb +11 -0
  38. data/lib/ooxml_parser/common_parser/common_data/colors/scheme_color.rb +1 -0
  39. data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +4 -0
  40. data/lib/ooxml_parser/common_parser/common_data/content_types.rb +2 -0
  41. data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_default.rb +3 -0
  42. data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_override.rb +3 -0
  43. data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +7 -0
  44. data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +14 -3
  45. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +28 -2
  46. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +3 -0
  47. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +28 -12
  48. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/outline.rb +4 -2
  49. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering_properties.rb +2 -0
  50. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb +1 -0
  51. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +16 -13
  52. data/lib/ooxml_parser/common_parser/common_data/table.rb +2 -0
  53. data/lib/ooxml_parser/common_parser/common_data/table/margins/paragraph_margins.rb +3 -0
  54. data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +7 -0
  55. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb +1 -0
  56. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties.rb +1 -0
  57. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties/table_style_properties_helper.rb +4 -4
  58. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +4 -5
  59. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/borders.rb +6 -0
  60. data/lib/ooxml_parser/common_parser/common_data/table/table_grid.rb +3 -0
  61. data/lib/ooxml_parser/common_parser/common_data/underline.rb +7 -2
  62. data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +41 -9
  63. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments/comment.rb +3 -0
  64. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +3 -0
  65. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +25 -8
  66. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/bookmark_end.rb +1 -1
  67. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/comment_range_start.rb +1 -0
  68. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/pre_sub_superscript.rb +3 -0
  69. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +13 -3
  70. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb +4 -1
  71. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb +0 -2
  72. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb +3 -0
  73. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb +4 -2
  74. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +8 -4
  75. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/numbering.rb +5 -0
  76. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/columns.rb +3 -0
  77. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +6 -2
  78. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_size.rb +1 -0
  79. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/styles.rb +2 -0
  80. data/lib/ooxml_parser/docx_parser/docx_parser.rb +3 -0
  81. data/lib/ooxml_parser/name.rb +1 -0
  82. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +2 -0
  83. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme.rb +3 -0
  84. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +3 -0
  85. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +5 -2
  86. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node.rb +3 -0
  87. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb +15 -1
  88. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition.rb +3 -0
  89. data/lib/ooxml_parser/pptx_parser/pptx_parser.rb +4 -1
  90. data/lib/ooxml_parser/version.rb +2 -1
  91. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +21 -2
  92. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/chartsheet.rb +3 -0
  93. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache.rb +41 -0
  94. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition.rb +37 -0
  95. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source.rb +33 -0
  96. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source/worksheet_source.rb +26 -0
  97. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet.rb +2 -0
  98. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/xf.rb +5 -0
  99. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb +2 -0
  100. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb +3 -0
  101. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +5 -0
  102. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb +4 -0
  103. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb +4 -0
  104. data/lib/ooxml_parser/xlsx_parser/xlsx_parser.rb +3 -0
  105. metadata +70 -4
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for parsing `a:lnRef` tags
5
+ class LineReference < OOXMLDocumentObject
6
+ # @return [Integer] Style Matrix Index
7
+ attr_reader :index
8
+ # @return [Color] scheme color of LineReference
9
+ attr_reader :scheme_color
10
+
11
+ def initialize(parent: nil)
12
+ @parent = parent
13
+ end
14
+
15
+ # Parse LineReference object
16
+ # @param node [Nokogiri::XML:Element] node to parse
17
+ # @return [LineReference] result of parsing
18
+ def parse(node)
19
+ node.attributes.each do |key, value|
20
+ case key
21
+ when 'idx'
22
+ @index = value.value.to_f
23
+ end
24
+ end
25
+
26
+ node.xpath('*').each do |node_child|
27
+ case node_child.name
28
+ when 'schemeClr'
29
+ @scheme_color = Color.new(parent: self).parse_scheme_color(node_child)
30
+ end
31
+ end
32
+ self
33
+ end
34
+ end
35
+ end
@@ -35,6 +35,7 @@ module OoxmlParser
35
35
  self
36
36
  end
37
37
 
38
+ # @return [String] result of convert of object to string
38
39
  def to_s
39
40
  "Color: #{@color}, type: #{type}"
40
41
  end
@@ -23,8 +23,6 @@ module OoxmlParser
23
23
  @type = :arc
24
24
  when 'cubicBezTo'
25
25
  @type = :cubic_bezier
26
- when 'quadBezTo'
27
- @type = :quadratic_bezier
28
26
  when 'close'
29
27
  @type = :close
30
28
  end
@@ -16,6 +16,7 @@ module OoxmlParser
16
16
  @parent = parent
17
17
  end
18
18
 
19
+ # @return [Integer] stroke size of object
19
20
  def stroke_size
20
21
  if @color_scheme.nil? || @color_scheme.color == :none
21
22
  0
@@ -10,8 +10,18 @@ require_relative 'custom_geometry/ooxml_custom_geometry'
10
10
  module OoxmlParser
11
11
  # DOCX Shape Properties
12
12
  class DocxShapeProperties < OOXMLDocumentObject
13
- attr_accessor :shape_size, :preset_geometry, :fill_color, :text_box, :line, :custom_geometry
14
- attr_accessor :blip_fill
13
+ # @return [DocxShapeSize] size of shape
14
+ attr_reader :shape_size
15
+ # @return [PresetGeometry] preset geometry of object
16
+ attr_reader :preset_geometry
17
+ # @return [DocxColor] color of object
18
+ attr_reader :fill_color
19
+ # @return [DocxShapeLine] line info
20
+ attr_reader :line
21
+ # @return [PresetGeometry] is some geometry custom
22
+ attr_reader :custom_geometry
23
+ # @return [BlipFill] BlipFill data
24
+ attr_reader :blip_fill
15
25
 
16
26
  alias transform shape_size
17
27
  alias fill fill_color
@@ -33,8 +43,6 @@ module OoxmlParser
33
43
  @shape_size = DocxShapeSize.new(parent: self).parse(node_child)
34
44
  when 'prstGeom'
35
45
  @preset_geometry = PresetGeometry.new(parent: self).parse(node_child)
36
- when 'txbx'
37
- @text_box = TextBox.parse_list(node_child)
38
46
  when 'ln'
39
47
  @line = DocxShapeLine.new(parent: self).parse(node_child)
40
48
  when 'blipFill'
@@ -3,9 +3,16 @@
3
3
  module OoxmlParser
4
4
  # Docx Shape Size
5
5
  class DocxShapeSize < OOXMLDocumentObject
6
- attr_accessor :rotation, :offset, :extent
7
- attr_accessor :child_offset
8
- attr_accessor :child_extent
6
+ # @return [OoxmlSize] rotation info
7
+ attr_reader :rotation
8
+ # @return [OOXMLCoordinates] offset info
9
+ attr_reader :offset
10
+ # @return [OOXMLCoordinates] extent info
11
+ attr_reader :extent
12
+ # @return [OOXMLCoordinates] child offset
13
+ attr_reader :child_offset
14
+ # @return [OOXMLCoordinates] child extent
15
+ attr_reader :child_extent
9
16
  # @return [True, False] is image flipped horizontally
10
17
  attr_reader :flip_horizontal
11
18
  # @return [True, False] is image flipped vertically
@@ -6,7 +6,7 @@ require_relative 'group/old_docx_group'
6
6
  module OoxmlParser
7
7
  # Fallback DOCX Picture
8
8
  class OldDocxPicture < OOXMLDocumentObject
9
- attr_accessor :data, :type, :style_number
9
+ attr_accessor :data, :type
10
10
 
11
11
  # Parse OldDocxPicture object
12
12
  # @param node [Nokogiri::XML:Element] node to parse
@@ -20,8 +20,6 @@ module OoxmlParser
20
20
  when 'group'
21
21
  @type = :group
22
22
  @data = OldDocxGroup.new(parent: self).parse(node_child)
23
- when 'style'
24
- @style_number = node_child.attribute('val').value.to_i
25
23
  end
26
24
  end
27
25
  self
@@ -3,7 +3,7 @@
3
3
  module OoxmlParser
4
4
  # Fallback DOCX Shape Properties
5
5
  class OldDocxShapeProperties < OOXMLDocumentObject
6
- attr_accessor :fill_color, :opacity, :stroke_color, :stroke_weight
6
+ attr_accessor :fill_color, :stroke_color, :stroke_weight
7
7
 
8
8
  # Parse OldDocxShapeProperties object
9
9
  # @param node [Nokogiri::XML:Element] node to parse
@@ -13,8 +13,6 @@ module OoxmlParser
13
13
  case key
14
14
  when 'fillcolor'
15
15
  @fill_color = Color.new(parent: self).parse_hex_string(value.value.delete('#'))
16
- when 'opacity'
17
- @opacity = value.value.to_f
18
16
  when 'strokecolor'
19
17
  @stroke_color = Color.new(parent: self).parse_hex_string(value.value.delete('#'))
20
18
  when 'strokeweight'
@@ -27,12 +27,15 @@ module OoxmlParser
27
27
  size.zero? && val == :none
28
28
  end
29
29
 
30
+ # @return [String] result of convert of object to string
30
31
  def to_s
31
32
  return '' if nil?
32
33
 
33
34
  "borders color: #{@color}, size: #{size}, space: #{@space}, value: #{@val}"
34
35
  end
35
36
 
37
+ # Method to copy object
38
+ # @return [BordersProperties] copied object
36
39
  def copy
37
40
  BordersProperties.new(@color, size, @val, @space)
38
41
  end
@@ -12,79 +12,6 @@ module OoxmlParser
12
12
  # Class for Color in RGB
13
13
  class Color < OOXMLDocumentObject
14
14
  include ColorHelper
15
- # @return [Array] Deprecated Indexed colors
16
- # List of color duplicated from `OpenXML Sdk IndexedColors` class
17
- # See https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.indexedcolors.aspx
18
- COLOR_INDEXED =
19
- %w[
20
- 000000
21
- FFFFFF
22
- FF0000
23
- 00FF00
24
- 0000FF
25
- FFFF00
26
- FF00FF
27
- 00FFFF
28
- 000000
29
- FFFFFF
30
- FF0000
31
- 00FF00
32
- 0000FF
33
- FFFF00
34
- FF00FF
35
- 00FFFF
36
- 800000
37
- 008000
38
- 000080
39
- 808000
40
- 800080
41
- 008080
42
- C0C0C0
43
- 808080
44
- 9999FF
45
- 993366
46
- FFFFCC
47
- CCFFFF
48
- 660066
49
- FF8080
50
- 0066CC
51
- CCCCFF
52
- 000080
53
- FF00FF
54
- FFFF00
55
- 00FFFF
56
- 800080
57
- 800000
58
- 008080
59
- 0000FF
60
- 00CCFF
61
- CCFFFF
62
- CCFFCC
63
- FFFF99
64
- 99CCFF
65
- FF99CC
66
- CC99FF
67
- FFCC99
68
- 3366FF
69
- 33CCCC
70
- 99CC00
71
- FFCC00
72
- FF9900
73
- FF6600
74
- 666699
75
- 969696
76
- 003366
77
- 339966
78
- 003300
79
- 333300
80
- 993300
81
- 993366
82
- 333399
83
- 333333
84
- n/a
85
- n/a
86
- ].freeze
87
-
88
15
  # @return [Integer] Value of Red Part
89
16
  attr_accessor :red
90
17
  # @return [Integer] Value of Green Part
@@ -93,15 +20,17 @@ module OoxmlParser
93
20
  attr_accessor :blue
94
21
  # @return [String] Value of Color Style
95
22
  attr_accessor :style
23
+
96
24
  alias set_style style=
97
25
  # @return [String] color scheme of color
98
26
  attr_accessor :scheme
99
27
 
100
28
  # @return [Integer] Value of alpha-channel
101
29
  attr_accessor :alpha_channel
30
+
102
31
  alias set_alpha_channel alpha_channel=
103
32
 
104
- attr_accessor :position
33
+ # @return [ColorProperties] properties of color
105
34
  attr_accessor :properties
106
35
 
107
36
  # Value of color if non selected
@@ -117,6 +46,7 @@ module OoxmlParser
117
46
  @parent = parent
118
47
  end
119
48
 
49
+ # @return [String] result of convert of object to string
120
50
  def to_s
121
51
  if @red == VALUE_FOR_NONE_COLOR && @green == VALUE_FOR_NONE_COLOR && @blue == VALUE_FOR_NONE_COLOR
122
52
  'none'
@@ -125,38 +55,46 @@ module OoxmlParser
125
55
  end
126
56
  end
127
57
 
58
+ # @return [String] inspect of object for debug means
128
59
  def inspect
129
60
  to_s
130
61
  end
131
62
 
63
+ # @return [String] color in hex value
132
64
  def to_hex
133
65
  (@red.to_s(16).rjust(2, '0') + @green.to_s(16).rjust(2, '0') + @blue.to_s(16).rjust(2, '0')).upcase
134
66
  end
135
67
 
136
68
  alias to_int16 to_hex
137
69
 
70
+ # @return [True, False] is color default
138
71
  def none?
139
72
  (@red == VALUE_FOR_NONE_COLOR) && (@green == VALUE_FOR_NONE_COLOR) && (@blue == VALUE_FOR_NONE_COLOR) ||
140
73
  (style == :nil)
141
74
  end
142
75
 
76
+ # @return [True, False] is color not default
143
77
  def any?
144
78
  !none?
145
79
  end
146
80
 
81
+ # @return [True, False] is color white
147
82
  def white?
148
83
  (@red == 255) && (@green == 255) && (@blue == 255)
149
84
  end
150
85
 
86
+ # Method to copy object
87
+ # @return [Color] copied object
151
88
  def copy
152
89
  Color.new(@red, @green, @blue)
153
90
  end
154
91
 
92
+ # Compare this object to other
93
+ # @param other [Object] any other object
94
+ # @return [True, False] result of comparision
155
95
  def ==(other)
156
96
  if other.is_a?(Color)
157
- if nil?
158
- false
159
- elsif (@red == other.red) && (@green == other.green) && (@blue == other.blue)
97
+ if (@red == other.red) && (@green == other.green) && (@blue == other.blue)
160
98
  true
161
99
  elsif (none? && other.white?) || (white? && other.none?)
162
100
  true
@@ -190,18 +128,27 @@ module OoxmlParser
190
128
  (self.red - red).abs < delta && (self.green - green).abs < delta && (self.blue - blue).abs < delta ? true : false
191
129
  end
192
130
 
131
+ # Apply tint to color
132
+ # @param tint [Integer] tint to apply
133
+ # @return [void]
193
134
  def calculate_with_tint!(tint)
194
135
  @red += (tint.to_f * (255 - @red)).to_i
195
136
  @green += (tint.to_f * (255 - @green)).to_i
196
137
  @blue += (tint.to_f * (255 - @blue)).to_i
197
138
  end
198
139
 
140
+ # Apply shade to color
141
+ # @param shade [Integer] shade to apply
142
+ # @return [void]
199
143
  def calculate_with_shade!(shade)
200
144
  @red = (@red * shade.to_f).to_i
201
145
  @green = (@green * shade.to_f).to_i
202
146
  @blue = (@blue * shade.to_f).to_i
203
147
  end
204
148
 
149
+ # Parse color scheme data
150
+ # @param scheme_color_node [Nokogiri::XML:Element] node to parse
151
+ # @return [Color] result of parsing
205
152
  def parse_scheme_color(scheme_color_node)
206
153
  color = root_object.theme.color_scheme[scheme_color_node.attribute('val').value.to_sym].color
207
154
  hls = HSLColor.rgb_to_hsl(color)
@@ -229,6 +176,9 @@ module OoxmlParser
229
176
  self
230
177
  end
231
178
 
179
+ # Parse color model data
180
+ # @param color_model_parent_node [Nokogiri::XML:Element] node to parse
181
+ # @return [Color] result of parsing
232
182
  def parse_color_model(color_model_parent_node)
233
183
  color = nil
234
184
  tint = nil
@@ -240,9 +190,6 @@ module OoxmlParser
240
190
  end
241
191
  end
242
192
  case color_model_node.name
243
- when 'scrgbClr'
244
- color = Color.new(color_model_node.attribute('r').value.to_i, color_model_node.attribute('g').value.to_i, color_model_node.attribute('b').value.to_i)
245
- color.alpha_channel = ColorAlphaChannel.parse(color_model_node)
246
193
  when 'srgbClr'
247
194
  color = Color.new.parse_hex_string(color_model_node.attribute('val').value)
248
195
  color.alpha_channel = ColorAlphaChannel.parse(color_model_node)
@@ -261,6 +208,9 @@ module OoxmlParser
261
208
  self
262
209
  end
263
210
 
211
+ # Parse color data
212
+ # @param color_node [Nokogiri::XML:Element] node to parse
213
+ # @return [Color] result of parsing
264
214
  def parse_color(color_node)
265
215
  case color_node.name
266
216
  when 'srgbClr'
@@ -280,6 +230,7 @@ module OoxmlParser
280
230
  end
281
231
 
282
232
  class << self
233
+ # @return [Color] random color
283
234
  def generate_random_color
284
235
  Color.new(rand(256), rand(256), rand(256))
285
236
  end
@@ -293,19 +244,31 @@ module OoxmlParser
293
244
  const_array_name.map { |current_color| Color.parse_string(current_color) }
294
245
  end
295
246
 
247
+ # @param index [Integer] index to get
248
+ # @return [Color] color by it's index
296
249
  def get_rgb_by_color_index(index)
297
- color_by_index = COLOR_INDEXED[index]
250
+ color_by_index = color_indexes[index]
298
251
  return :unknown if color_by_index.nil?
299
252
 
300
253
  color_by_index == 'n/a' ? Color.new : Color.new.parse_hex_string(color_by_index)
301
254
  end
302
255
 
256
+ # @return [Array] Deprecated Indexed colors
257
+ # List of color duplicated from `OpenXML Sdk IndexedColors` class
258
+ # See https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.indexedcolors.aspx
259
+ def color_indexes
260
+ @color_indexes ||= File.readlines("#{__dir__}/color/color_indexes.list", chomp: true)
261
+ end
262
+
263
+ # Parse color from string
264
+ # @param str [String] string to parse
265
+ # @return [Color] result of parsing
303
266
  def parse_string(str)
304
267
  return str if str.is_a?(Color)
305
268
  return Color.new(VALUE_FOR_NONE_COLOR, VALUE_FOR_NONE_COLOR, VALUE_FOR_NONE_COLOR) if str == 'none' || str == '' || str == 'transparent' || str.nil?
306
269
 
307
270
  split = if str.include?('RGB (') || str.include?('rgb(')
308
- str.gsub(/[(RGBrgb\(\) )]/, '').split(',')
271
+ str.gsub(/[(RGBrgb() )]/, '').split(',')
309
272
  elsif str.include?('RGB ') || str.include?('rgb')
310
273
  str.gsub(/RGB |rgb/, '').split(', ')
311
274
  else
@@ -317,6 +280,9 @@ module OoxmlParser
317
280
 
318
281
  alias parse parse_string
319
282
 
283
+ # Convert other object type to Color
284
+ # @param something [Object] object to convert
285
+ # @return [Color] result of conversion
320
286
  def to_color(something)
321
287
  case something
322
288
  when SchemeColor
@@ -9,15 +9,16 @@ module OoxmlParser
9
9
  return self if %w[auto null].include?(hex_string)
10
10
 
11
11
  char_array = hex_string.split(//)
12
- if char_array.length == 3
12
+ case char_array.length
13
+ when 3
13
14
  @red = char_array[0].hex
14
15
  @green = char_array[1].hex
15
16
  @blue = char_array[2].hex
16
- elsif char_array.length == 6
17
+ when 6
17
18
  @red = (char_array[0] + char_array[1]).hex
18
19
  @green = (char_array[2] + char_array[3]).hex
19
20
  @blue = (char_array[4] + char_array[5]).hex
20
- elsif char_array.length == 8
21
+ when 8
21
22
  @alpha_channel = (char_array[0] + char_array[1]).hex
22
23
  @red = (char_array[2] + char_array[3]).hex
23
24
  @green = (char_array[4] + char_array[5]).hex