ooxml_parser 0.5.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ooxml_parser.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice/math_text.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice/math_text/math_paragraph.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +6 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/series.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/series/series_text.rb +0 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_distance_from_text.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb +4 -1
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +4 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_picture.rb +0 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/ooxml_text_box.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style.rb +42 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/effect_reference.rb +35 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/fill_reference.rb +35 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/font_reference.rb +35 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/line_reference.rb +35 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_color_scheme.rb +1 -0
- 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
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_line.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_properties.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/color.rb +39 -7
- data/lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb +5 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/hsl_color.rb +11 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/scheme_color.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +4 -0
- data/lib/ooxml_parser/common_parser/common_data/content_types.rb +2 -0
- data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_default.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_override.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +7 -0
- data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +24 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +0 -6
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering_properties.rb +2 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +16 -13
- data/lib/ooxml_parser/common_parser/common_data/table.rb +2 -0
- data/lib/ooxml_parser/common_parser/common_data/table/margins/paragraph_margins.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +7 -0
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties/table_style_properties_helper.rb +4 -4
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +4 -5
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/borders.rb +6 -0
- data/lib/ooxml_parser/common_parser/common_data/table/table_grid.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/underline.rb +4 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +27 -3
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments/comment.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +22 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/bookmark_end.rb +1 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/comment_range_start.rb +1 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/pre_sub_superscript.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +13 -3
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb +4 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb +0 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb +2 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +0 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/numbering.rb +5 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/columns.rb +1 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_size.rb +1 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/styles.rb +2 -0
- data/lib/ooxml_parser/docx_parser/docx_parser.rb +3 -0
- data/lib/ooxml_parser/name.rb +1 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +2 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb +15 -1
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_parser.rb +3 -0
- data/lib/ooxml_parser/version.rb +2 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +21 -2
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/chartsheet.rb +3 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache.rb +41 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition.rb +37 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source.rb +33 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source/worksheet_source.rb +26 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet.rb +2 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/xf.rb +5 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb +2 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb +3 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +5 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb +4 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb +4 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_parser.rb +3 -0
- metadata +69 -4
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module OoxmlParser
|
|
4
4
|
# Fallback DOCX Shape Properties
|
|
5
5
|
class OldDocxShapeProperties < OOXMLDocumentObject
|
|
6
|
-
attr_accessor :fill_color, :
|
|
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
|
|
@@ -93,12 +93,14 @@ module OoxmlParser
|
|
|
93
93
|
attr_accessor :blue
|
|
94
94
|
# @return [String] Value of Color Style
|
|
95
95
|
attr_accessor :style
|
|
96
|
+
|
|
96
97
|
alias set_style style=
|
|
97
98
|
# @return [String] color scheme of color
|
|
98
99
|
attr_accessor :scheme
|
|
99
100
|
|
|
100
101
|
# @return [Integer] Value of alpha-channel
|
|
101
102
|
attr_accessor :alpha_channel
|
|
103
|
+
|
|
102
104
|
alias set_alpha_channel alpha_channel=
|
|
103
105
|
|
|
104
106
|
attr_accessor :position
|
|
@@ -117,6 +119,7 @@ module OoxmlParser
|
|
|
117
119
|
@parent = parent
|
|
118
120
|
end
|
|
119
121
|
|
|
122
|
+
# @return [String] result of convert of object to string
|
|
120
123
|
def to_s
|
|
121
124
|
if @red == VALUE_FOR_NONE_COLOR && @green == VALUE_FOR_NONE_COLOR && @blue == VALUE_FOR_NONE_COLOR
|
|
122
125
|
'none'
|
|
@@ -125,38 +128,46 @@ module OoxmlParser
|
|
|
125
128
|
end
|
|
126
129
|
end
|
|
127
130
|
|
|
131
|
+
# @return [String] inspect of object for debug means
|
|
128
132
|
def inspect
|
|
129
133
|
to_s
|
|
130
134
|
end
|
|
131
135
|
|
|
136
|
+
# @return [String] color in hex value
|
|
132
137
|
def to_hex
|
|
133
138
|
(@red.to_s(16).rjust(2, '0') + @green.to_s(16).rjust(2, '0') + @blue.to_s(16).rjust(2, '0')).upcase
|
|
134
139
|
end
|
|
135
140
|
|
|
136
141
|
alias to_int16 to_hex
|
|
137
142
|
|
|
143
|
+
# @return [True, False] is color default
|
|
138
144
|
def none?
|
|
139
145
|
(@red == VALUE_FOR_NONE_COLOR) && (@green == VALUE_FOR_NONE_COLOR) && (@blue == VALUE_FOR_NONE_COLOR) ||
|
|
140
146
|
(style == :nil)
|
|
141
147
|
end
|
|
142
148
|
|
|
149
|
+
# @return [True, False] is color not default
|
|
143
150
|
def any?
|
|
144
151
|
!none?
|
|
145
152
|
end
|
|
146
153
|
|
|
154
|
+
# @return [True, False] is color white
|
|
147
155
|
def white?
|
|
148
156
|
(@red == 255) && (@green == 255) && (@blue == 255)
|
|
149
157
|
end
|
|
150
158
|
|
|
159
|
+
# Method to copy object
|
|
160
|
+
# @return [Color] copied object
|
|
151
161
|
def copy
|
|
152
162
|
Color.new(@red, @green, @blue)
|
|
153
163
|
end
|
|
154
164
|
|
|
165
|
+
# Compare this object to other
|
|
166
|
+
# @param other [Object] any other object
|
|
167
|
+
# @return [True, False] result of comparision
|
|
155
168
|
def ==(other)
|
|
156
169
|
if other.is_a?(Color)
|
|
157
|
-
if
|
|
158
|
-
false
|
|
159
|
-
elsif (@red == other.red) && (@green == other.green) && (@blue == other.blue)
|
|
170
|
+
if (@red == other.red) && (@green == other.green) && (@blue == other.blue)
|
|
160
171
|
true
|
|
161
172
|
elsif (none? && other.white?) || (white? && other.none?)
|
|
162
173
|
true
|
|
@@ -190,18 +201,27 @@ module OoxmlParser
|
|
|
190
201
|
(self.red - red).abs < delta && (self.green - green).abs < delta && (self.blue - blue).abs < delta ? true : false
|
|
191
202
|
end
|
|
192
203
|
|
|
204
|
+
# Apply tint to color
|
|
205
|
+
# @param tint [Integer] tint to apply
|
|
206
|
+
# @return [void]
|
|
193
207
|
def calculate_with_tint!(tint)
|
|
194
208
|
@red += (tint.to_f * (255 - @red)).to_i
|
|
195
209
|
@green += (tint.to_f * (255 - @green)).to_i
|
|
196
210
|
@blue += (tint.to_f * (255 - @blue)).to_i
|
|
197
211
|
end
|
|
198
212
|
|
|
213
|
+
# Apply shade to color
|
|
214
|
+
# @param shade [Integer] shade to apply
|
|
215
|
+
# @return [void]
|
|
199
216
|
def calculate_with_shade!(shade)
|
|
200
217
|
@red = (@red * shade.to_f).to_i
|
|
201
218
|
@green = (@green * shade.to_f).to_i
|
|
202
219
|
@blue = (@blue * shade.to_f).to_i
|
|
203
220
|
end
|
|
204
221
|
|
|
222
|
+
# Parse color scheme data
|
|
223
|
+
# @param scheme_color_node [Nokogiri::XML:Element] node to parse
|
|
224
|
+
# @return [Color] result of parsing
|
|
205
225
|
def parse_scheme_color(scheme_color_node)
|
|
206
226
|
color = root_object.theme.color_scheme[scheme_color_node.attribute('val').value.to_sym].color
|
|
207
227
|
hls = HSLColor.rgb_to_hsl(color)
|
|
@@ -229,6 +249,9 @@ module OoxmlParser
|
|
|
229
249
|
self
|
|
230
250
|
end
|
|
231
251
|
|
|
252
|
+
# Parse color model data
|
|
253
|
+
# @param color_model_parent_node [Nokogiri::XML:Element] node to parse
|
|
254
|
+
# @return [Color] result of parsing
|
|
232
255
|
def parse_color_model(color_model_parent_node)
|
|
233
256
|
color = nil
|
|
234
257
|
tint = nil
|
|
@@ -240,9 +263,6 @@ module OoxmlParser
|
|
|
240
263
|
end
|
|
241
264
|
end
|
|
242
265
|
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
266
|
when 'srgbClr'
|
|
247
267
|
color = Color.new.parse_hex_string(color_model_node.attribute('val').value)
|
|
248
268
|
color.alpha_channel = ColorAlphaChannel.parse(color_model_node)
|
|
@@ -261,6 +281,9 @@ module OoxmlParser
|
|
|
261
281
|
self
|
|
262
282
|
end
|
|
263
283
|
|
|
284
|
+
# Parse color data
|
|
285
|
+
# @param color_node [Nokogiri::XML:Element] node to parse
|
|
286
|
+
# @return [Color] result of parsing
|
|
264
287
|
def parse_color(color_node)
|
|
265
288
|
case color_node.name
|
|
266
289
|
when 'srgbClr'
|
|
@@ -280,6 +303,7 @@ module OoxmlParser
|
|
|
280
303
|
end
|
|
281
304
|
|
|
282
305
|
class << self
|
|
306
|
+
# @return [Color] random color
|
|
283
307
|
def generate_random_color
|
|
284
308
|
Color.new(rand(256), rand(256), rand(256))
|
|
285
309
|
end
|
|
@@ -293,6 +317,8 @@ module OoxmlParser
|
|
|
293
317
|
const_array_name.map { |current_color| Color.parse_string(current_color) }
|
|
294
318
|
end
|
|
295
319
|
|
|
320
|
+
# @param index [Integer] index to get
|
|
321
|
+
# @return [Color] color by it's index
|
|
296
322
|
def get_rgb_by_color_index(index)
|
|
297
323
|
color_by_index = COLOR_INDEXED[index]
|
|
298
324
|
return :unknown if color_by_index.nil?
|
|
@@ -300,12 +326,15 @@ module OoxmlParser
|
|
|
300
326
|
color_by_index == 'n/a' ? Color.new : Color.new.parse_hex_string(color_by_index)
|
|
301
327
|
end
|
|
302
328
|
|
|
329
|
+
# Parse color from string
|
|
330
|
+
# @param str [String] string to parse
|
|
331
|
+
# @return [Color] result of parsing
|
|
303
332
|
def parse_string(str)
|
|
304
333
|
return str if str.is_a?(Color)
|
|
305
334
|
return Color.new(VALUE_FOR_NONE_COLOR, VALUE_FOR_NONE_COLOR, VALUE_FOR_NONE_COLOR) if str == 'none' || str == '' || str == 'transparent' || str.nil?
|
|
306
335
|
|
|
307
336
|
split = if str.include?('RGB (') || str.include?('rgb(')
|
|
308
|
-
str.gsub(/[(RGBrgb
|
|
337
|
+
str.gsub(/[(RGBrgb() )]/, '').split(',')
|
|
309
338
|
elsif str.include?('RGB ') || str.include?('rgb')
|
|
310
339
|
str.gsub(/RGB |rgb/, '').split(', ')
|
|
311
340
|
else
|
|
@@ -317,6 +346,9 @@ module OoxmlParser
|
|
|
317
346
|
|
|
318
347
|
alias parse parse_string
|
|
319
348
|
|
|
349
|
+
# Convert other object type to Color
|
|
350
|
+
# @param something [Object] object to convert
|
|
351
|
+
# @return [Color] result of conversion
|
|
320
352
|
def to_color(something)
|
|
321
353
|
case something
|
|
322
354
|
when SchemeColor
|
|
@@ -18,6 +18,8 @@ module OoxmlParser
|
|
|
18
18
|
# @return [Color] rgb color
|
|
19
19
|
attr_reader :rgb
|
|
20
20
|
|
|
21
|
+
# Convert OoxmlColor to other color type
|
|
22
|
+
# @return [Object] result of conversion
|
|
21
23
|
def to_color
|
|
22
24
|
return Color.get_rgb_by_color_index(indexed) if indexed
|
|
23
25
|
return ThemeColors.new(parent: self).parse_color_theme(theme, tint) if theme
|
|
@@ -26,6 +28,9 @@ module OoxmlParser
|
|
|
26
28
|
value
|
|
27
29
|
end
|
|
28
30
|
|
|
31
|
+
# Compare this object to other
|
|
32
|
+
# @param other [Object] any other object
|
|
33
|
+
# @return [True, False] result of comparision
|
|
29
34
|
def ==(other)
|
|
30
35
|
return to_color == other if other.is_a?(Color)
|
|
31
36
|
return to_color == other if other.is_a?(Symbol)
|
|
@@ -19,6 +19,9 @@ module OoxmlParser
|
|
|
19
19
|
@l = lightness
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
# Convert rgb color to hsl
|
|
23
|
+
# @param rgb_color [Color] color to convert
|
|
24
|
+
# @return [HSLColor] result of convert
|
|
22
25
|
def self.rgb_to_hsl(rgb_color)
|
|
23
26
|
hls_color = HSLColor.new
|
|
24
27
|
red = rgb_color.red.to_f # / 255.0
|
|
@@ -50,6 +53,7 @@ module OoxmlParser
|
|
|
50
53
|
end
|
|
51
54
|
|
|
52
55
|
# Chroma - The "colorfulness relative to the brightness of a similarly illuminated white".
|
|
56
|
+
# @return [Color] result
|
|
53
57
|
def to_rgb
|
|
54
58
|
chroma = (1 - (2 * @l - 1).abs) * @s
|
|
55
59
|
x = chroma * (1 - ((@h / 60.0) % 2.0 - 1).abs)
|
|
@@ -73,6 +77,10 @@ module OoxmlParser
|
|
|
73
77
|
Color.new(((rgb.red + m) * 255.0).round, ((rgb.green + m) * 255.0).round, ((rgb.blue + m) * 255.0).round)
|
|
74
78
|
end
|
|
75
79
|
|
|
80
|
+
# Get lum value of color
|
|
81
|
+
# @param tint [Integer] tint to apply
|
|
82
|
+
# @param lum [Integer] lum without tint
|
|
83
|
+
# @return [Integer] result
|
|
76
84
|
def calculate_lum_value(tint, lum)
|
|
77
85
|
if tint.nil?
|
|
78
86
|
lum
|
|
@@ -81,6 +89,9 @@ module OoxmlParser
|
|
|
81
89
|
end
|
|
82
90
|
end
|
|
83
91
|
|
|
92
|
+
# Convert to rgb with applied tint
|
|
93
|
+
# @param tint [Integer] tint to apply
|
|
94
|
+
# @return [Color] result of covert
|
|
84
95
|
def calculate_rgb_with_tint(tint)
|
|
85
96
|
self.l = calculate_lum_value(tint, @l * 255.0) / 255.0
|
|
86
97
|
to_rgb
|
|
@@ -6,6 +6,10 @@ module OoxmlParser
|
|
|
6
6
|
# @return [Hash] list of colors
|
|
7
7
|
attr_accessor :list
|
|
8
8
|
|
|
9
|
+
# Parse color theme
|
|
10
|
+
# @param theme [String] name of theme
|
|
11
|
+
# @param tint [Integer] tint of theme
|
|
12
|
+
# @return [Color] color of theme
|
|
9
13
|
def parse_color_theme(theme, tint)
|
|
10
14
|
themes_array = root_object.theme.color_scheme.values
|
|
11
15
|
# TODO: if no swap performed - incorrect color parsing. But don't know why it needed
|
|
@@ -18,6 +18,8 @@ module OoxmlParser
|
|
|
18
18
|
@content_types_list[key]
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
# Parse ContentTypes object
|
|
22
|
+
# @return [ContentTypes] result of parsing
|
|
21
23
|
def parse
|
|
22
24
|
doc = Nokogiri::XML.parse(File.open("#{OOXMLDocumentObject.path_to_folder}/[Content_Types].xml"))
|
|
23
25
|
node = doc.xpath('*').first
|
|
@@ -8,6 +8,9 @@ module OoxmlParser
|
|
|
8
8
|
# @return [String] extension
|
|
9
9
|
attr_reader :extension
|
|
10
10
|
|
|
11
|
+
# Parse ContentTypeDefault object
|
|
12
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
|
13
|
+
# @return [ContentTypeDefault] result of parsing
|
|
11
14
|
def parse(node)
|
|
12
15
|
node.attributes.each do |key, value|
|
|
13
16
|
case key
|
|
@@ -8,6 +8,9 @@ module OoxmlParser
|
|
|
8
8
|
# @return [String] part name
|
|
9
9
|
attr_reader :part_name
|
|
10
10
|
|
|
11
|
+
# Parse ContentTypeOverride object
|
|
12
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
|
13
|
+
# @return [ContentTypeOverride] result of parsing
|
|
11
14
|
def parse(node)
|
|
12
15
|
node.attributes.each do |key, value|
|
|
13
16
|
case key
|
|
@@ -29,6 +29,9 @@ module OoxmlParser
|
|
|
29
29
|
coordinates
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
# Parse range of coordinates
|
|
33
|
+
# @param arguments_string [String] data to parse
|
|
34
|
+
# @return [Array] result
|
|
32
35
|
def parser_coordinates_range(arguments_string)
|
|
33
36
|
return parse_coordinates_array(arguments_string) if arguments_string.include?(',')
|
|
34
37
|
return warn "Formulas with # is unsupported: #{arguments_string}" if arguments_string.include?('#')
|
|
@@ -133,6 +136,7 @@ module OoxmlParser
|
|
|
133
136
|
column_number > other_cell.column_number
|
|
134
137
|
end
|
|
135
138
|
|
|
139
|
+
# @return [String] result of convert of object to string
|
|
136
140
|
def to_s
|
|
137
141
|
"#{@column}#{@row} #{@list ? "list: #{@list}" : ''}"
|
|
138
142
|
end
|
|
@@ -141,6 +145,9 @@ module OoxmlParser
|
|
|
141
145
|
@column.nil? && @list.nil? && @row.nil?
|
|
142
146
|
end
|
|
143
147
|
|
|
148
|
+
# Compare this object to other
|
|
149
|
+
# @param other [Object] any other object
|
|
150
|
+
# @return [True, False] result of comparision
|
|
144
151
|
def ==(other)
|
|
145
152
|
other.is_a?(Coordinates) ? (@row == other.row && @column == other.column) : false
|
|
146
153
|
end
|
|
@@ -19,7 +19,12 @@ module OoxmlParser
|
|
|
19
19
|
@parent = parent
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
# Compare this object to other
|
|
23
|
+
# @param other [Object] any other object
|
|
24
|
+
# @return [True, False] result of comparision
|
|
22
25
|
def ==(other)
|
|
26
|
+
return false if self.class != other.class
|
|
27
|
+
|
|
23
28
|
instance_variables.each do |current_attribute|
|
|
24
29
|
next if current_attribute == :@parent
|
|
25
30
|
return false unless instance_variable_get(current_attribute) == other.instance_variable_get(current_attribute)
|
|
@@ -44,9 +49,11 @@ module OoxmlParser
|
|
|
44
49
|
attr_accessor :path_to_folder
|
|
45
50
|
|
|
46
51
|
# @param path_to_file [String] file
|
|
52
|
+
# @param ignore_system [True, False] should host system be ignored, since
|
|
53
|
+
# this method is OS-dependent
|
|
47
54
|
# @return [True, False] Check if file is protected by password on open
|
|
48
|
-
def encrypted_file?(path_to_file)
|
|
49
|
-
if Gem.win_platform?
|
|
55
|
+
def encrypted_file?(path_to_file, ignore_system: false)
|
|
56
|
+
if Gem.win_platform? || ignore_system
|
|
50
57
|
warn 'FileMagic and checking file for encryption is not supported on Windows'
|
|
51
58
|
return false
|
|
52
59
|
end
|
|
@@ -63,6 +70,9 @@ module OoxmlParser
|
|
|
63
70
|
false
|
|
64
71
|
end
|
|
65
72
|
|
|
73
|
+
# Copy this file and rename to zip
|
|
74
|
+
# @param path [String] path to file
|
|
75
|
+
# @return [String] path to result zip
|
|
66
76
|
def copy_file_and_rename_to_zip(path)
|
|
67
77
|
file_name = File.basename(path)
|
|
68
78
|
tmp_folder = Dir.mktmpdir('ruby-ooxml-parser')
|
|
@@ -75,6 +85,10 @@ module OoxmlParser
|
|
|
75
85
|
file_path
|
|
76
86
|
end
|
|
77
87
|
|
|
88
|
+
# Unzip specified file
|
|
89
|
+
# @param path_to_file [String] path to zip file
|
|
90
|
+
# @param destination [String] folder to extract
|
|
91
|
+
# @return [void]
|
|
78
92
|
def unzip_file(path_to_file, destination)
|
|
79
93
|
Zip.warn_invalid_date = false
|
|
80
94
|
Zip::File.open(path_to_file) do |zip_file|
|
|
@@ -88,14 +102,19 @@ module OoxmlParser
|
|
|
88
102
|
end
|
|
89
103
|
end
|
|
90
104
|
|
|
105
|
+
# @return [String] dir to base of file
|
|
91
106
|
def dir
|
|
92
107
|
OOXMLDocumentObject.path_to_folder + File.dirname(OOXMLDocumentObject.xmls_stack.last) + '/'
|
|
93
108
|
end
|
|
94
109
|
|
|
110
|
+
# @return [String] path to current xml file
|
|
95
111
|
def current_xml
|
|
96
112
|
OOXMLDocumentObject.path_to_folder + OOXMLDocumentObject.xmls_stack.last
|
|
97
113
|
end
|
|
98
114
|
|
|
115
|
+
# Add file to parsing stack
|
|
116
|
+
# @param path [String] path of file to add to stack
|
|
117
|
+
# @return [void]
|
|
99
118
|
def add_to_xmls_stack(path)
|
|
100
119
|
OOXMLDocumentObject.xmls_stack << if path.include?('..')
|
|
101
120
|
"#{File.dirname(OOXMLDocumentObject.xmls_stack.last)}/#{path}"
|
|
@@ -106,6 +125,9 @@ module OoxmlParser
|
|
|
106
125
|
end
|
|
107
126
|
end
|
|
108
127
|
|
|
128
|
+
# Get link to file from rels file
|
|
129
|
+
# @param id [String] file to get
|
|
130
|
+
# @return [String] result
|
|
109
131
|
def get_link_from_rels(id)
|
|
110
132
|
rels_path = dir + "_rels/#{File.basename(OOXMLDocumentObject.xmls_stack.last)}.rels"
|
|
111
133
|
raise LoadError, "Cannot find .rels file by path: #{rels_path}" unless File.exist?(rels_path)
|
|
@@ -40,14 +40,17 @@ module OoxmlParser
|
|
|
40
40
|
text.empty?
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
# @return [String] instruction applied to paragraph
|
|
43
44
|
def instruction
|
|
44
45
|
parent.instruction
|
|
45
46
|
end
|
|
46
47
|
|
|
48
|
+
# @return [True, False] is page number applyed
|
|
47
49
|
def page_number
|
|
48
50
|
parent.page_numbering?
|
|
49
51
|
end
|
|
50
52
|
|
|
53
|
+
# @return [Hyperlink] link of run
|
|
51
54
|
def link
|
|
52
55
|
parent.parent.hyperlink
|
|
53
56
|
end
|
|
@@ -29,10 +29,6 @@ module OoxmlParser
|
|
|
29
29
|
attr_accessor :shade
|
|
30
30
|
# @return [RunStyle] run style
|
|
31
31
|
attr_accessor :run_style
|
|
32
|
-
# @return [Float]
|
|
33
|
-
# This element specifies the font size which shall be applied to all
|
|
34
|
-
# complex script characters in the contents of this run when displayed
|
|
35
|
-
attr_accessor :font_size_complex
|
|
36
32
|
|
|
37
33
|
def initialize(parent: nil)
|
|
38
34
|
@font_name = ''
|
|
@@ -50,8 +46,6 @@ module OoxmlParser
|
|
|
50
46
|
case key
|
|
51
47
|
when 'sz'
|
|
52
48
|
@font_size = value.value.to_f / 100.0
|
|
53
|
-
when 'szCs'
|
|
54
|
-
@font_size_complex = node.attribute('val').value.to_i / 2.0
|
|
55
49
|
when 'spc'
|
|
56
50
|
@space = OoxmlSize.new(value.value.to_f, :one_100th_point)
|
|
57
51
|
when 'b'
|