ooxml_parser 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +17 -1
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/chart_style.rb +4 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis.rb +9 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis/scaling.rb +20 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +3 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_body_properties/ooxml_shape_body_properties.rb +8 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties/text_box.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/color.rb +11 -20
- data/lib/ooxml_parser/common_parser/common_data/color/color_helper.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb +57 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +3 -6
- data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +17 -1
- data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +12 -1
- data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +4 -4
- data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object/ooxml_document_object_helper.rb +30 -1
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb +5 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +9 -1
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/text.rb +23 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +0 -1
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tabs.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/{tab_list/presentation_tab.rb → tabs/tab.rb} +17 -4
- data/lib/ooxml_parser/common_parser/common_data/table.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style.rb +31 -37
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties.rb +4 -0
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties/table_style_properties_helper.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb +4 -4
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/border.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/table/table_properties.rb +1 -16
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +14 -7
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comment.rb +2 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments_extended.rb +39 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments_extended/comment_extended.rb +24 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb +9 -12
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +1 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +51 -73
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/delimeter.rb +2 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_helper.rb +8 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +8 -56
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb +2 -12
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/inserted.rb +15 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb +30 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_properties.rb +28 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/structured_document_tag.rb +26 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +1 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +10 -10
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_margins.rb +9 -16
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb +11 -9
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +5 -2
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +1 -3
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +35 -24
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/common_slide_data.rb +26 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/common_slide_data/shape_tree.rb +33 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/connection_shape.rb +5 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/graphic_frame/graphic_frame.rb +2 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/presentation_notes.rb +21 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/shapes_grouping.rb +2 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb +3 -3
- data/lib/ooxml_parser/version.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb +20 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill/pattern_fill.rb +2 -2
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb +5 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +10 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/ole_objects.rb +18 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part.rb +7 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/autofilter.rb +34 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/autofilter/filter_column.rb +28 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension.rb +5 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/sparkline_groups.rb +31 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/sparkline_groups/sparkline_group.rb +113 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/table_style_info.rb +41 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb +5 -11
- metadata +31 -14
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tab_list.rb +0 -36
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tabs/paragraph_tab.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 071bdcbc2fb31371918e97a11e168bcdd849a3a606d880a6f8f29f03d3fc54c9
|
4
|
+
data.tar.gz: 48631f0dcb24d64688065bbb226d8e0c3dd13f18473a680aa33fcf284751b195
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 175a3bb85a4c2b85cf577c498c50c021c180c9054440451a55b81d93752eb6211908e2309738dc8486ab0adfdd0cdcd3f5afbf75910226141f179ae878c62e6a
|
7
|
+
data.tar.gz: 031f7cf2aa5d53223df37d425fa0050a5ff875d3646ea5e82c56064262927ac728d5ed6563c557a9fc74d8da6f3a1b34ce230ed41b536914450ee7efe2a58831
|
data/README.md
CHANGED
@@ -4,7 +4,23 @@ _ooxml_parser_ is a Ooxml files (docx, xlsx, pptx) parser written in Ruby.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
1. Install `magic` lib, required by `ruby-filemagic`
|
8
|
+
Mac OS:
|
9
|
+
```
|
10
|
+
brew install libmagic
|
11
|
+
```
|
12
|
+
Debian-Based Linux:
|
13
|
+
```
|
14
|
+
sudo apt-get install libmagic-dev
|
15
|
+
```
|
16
|
+
Centos-Based Linux:
|
17
|
+
```
|
18
|
+
sudo yum install file-devel
|
19
|
+
```
|
20
|
+
2. Install gem by command:
|
21
|
+
```
|
22
|
+
gem install ooxml_parser
|
23
|
+
```
|
8
24
|
|
9
25
|
## Usage
|
10
26
|
|
data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/chart_style.rb
CHANGED
@@ -2,6 +2,8 @@ module OoxmlParser
|
|
2
2
|
# Chart Style
|
3
3
|
class ChartStyle < OOXMLDocumentObject
|
4
4
|
attr_accessor :style_number
|
5
|
+
# @return [OleObject] ole object
|
6
|
+
attr_accessor :ole_object
|
5
7
|
|
6
8
|
# Parse ChartStyle
|
7
9
|
# @param [Nokogiri::XML:Node] node with Relationships
|
@@ -11,6 +13,8 @@ module OoxmlParser
|
|
11
13
|
case node_child.name
|
12
14
|
when 'style'
|
13
15
|
@style_number = node_child.attribute('val').value.to_i
|
16
|
+
when 'oleObject'
|
17
|
+
@ole_object = OleObject.new(parent: self).parse(node_child)
|
14
18
|
end
|
15
19
|
end
|
16
20
|
self
|
@@ -1,8 +1,13 @@
|
|
1
|
+
require_relative 'chart_axis/scaling'
|
1
2
|
require_relative 'chart_axis_title'
|
2
3
|
module OoxmlParser
|
3
4
|
# Parsing Chart axis tags 'catAx', 'valAx'
|
4
5
|
class ChartAxis < OOXMLDocumentObject
|
5
6
|
attr_accessor :title, :display, :position, :major_grid_lines, :minor_grid_lines
|
7
|
+
# @return [Scaling] scaling attribute
|
8
|
+
attr_reader :scaling
|
9
|
+
# @return [ValuedChild] the position of the tick labels
|
10
|
+
attr_reader :tick_label_position
|
6
11
|
|
7
12
|
def initialize(title = ChartAxisTitle.new,
|
8
13
|
display = true,
|
@@ -30,6 +35,10 @@ module OoxmlParser
|
|
30
35
|
@major_grid_lines = true
|
31
36
|
when 'minorGridlines'
|
32
37
|
@minor_grid_lines = true
|
38
|
+
when 'scaling'
|
39
|
+
@scaling = Scaling.new(parent: self).parse(node_child)
|
40
|
+
when 'tickLblPos'
|
41
|
+
@tick_label_position = ValuedChild.new(:symbol, parent: self).parse(node_child)
|
33
42
|
when 'axPos'
|
34
43
|
@position = value_to_symbol(node_child.attribute('val'))
|
35
44
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OoxmlParser
|
2
|
+
# Parsing Scaling tag 'scaling'
|
3
|
+
class Scaling < OOXMLDocumentObject
|
4
|
+
# @return [ValuedChild] orientation value
|
5
|
+
attr_reader :orientation
|
6
|
+
|
7
|
+
# Parse Scaling object
|
8
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
9
|
+
# @return [Scaling] result of parsing
|
10
|
+
def parse(node)
|
11
|
+
node.xpath('*').each do |node_child|
|
12
|
+
case node_child.name
|
13
|
+
when 'orientation'
|
14
|
+
@orientation = ValuedChild.new(:symbol, parent: self).parse(node_child)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -63,7 +63,7 @@ module OoxmlParser
|
|
63
63
|
when :percent
|
64
64
|
OoxmlSize.new(@value * 100_000, :one_100000th_percent)
|
65
65
|
when :pct
|
66
|
-
OoxmlSize.new(@value *
|
66
|
+
OoxmlSize.new(@value * 100_000 / 50, :one_100000th_percent)
|
67
67
|
when :one_1000th_percent
|
68
68
|
OoxmlSize.new(@value * 100, :one_100000th_percent)
|
69
69
|
else
|
@@ -15,9 +15,10 @@ module OoxmlParser
|
|
15
15
|
@resource_id = value.value
|
16
16
|
end
|
17
17
|
end
|
18
|
-
return self
|
18
|
+
return self unless @resource_id
|
19
|
+
return self if @resource_id.empty?
|
19
20
|
@path = OOXMLDocumentObject.get_link_from_rels(@resource_id)
|
20
|
-
if @path.empty?
|
21
|
+
if !@path || @path.empty?
|
21
22
|
warn "Cant find path to media file by id: #{@resource_id}"
|
22
23
|
return self
|
23
24
|
end
|
@@ -6,6 +6,10 @@ module OoxmlParser
|
|
6
6
|
attr_accessor :margins, :anchor, :wrap, :preset_text_warp
|
7
7
|
# @return [Symbol] Vertical Text
|
8
8
|
attr_accessor :vertical
|
9
|
+
# @return [Symbol] Number of Columns
|
10
|
+
attr_reader :number_columns
|
11
|
+
# @return [Symbol] Spacing between columns
|
12
|
+
attr_reader :space_columns
|
9
13
|
|
10
14
|
alias vertical_align anchor
|
11
15
|
|
@@ -25,6 +29,10 @@ module OoxmlParser
|
|
25
29
|
@anchor = value_to_symbol(value)
|
26
30
|
when 'vert'
|
27
31
|
@vertical = value_to_symbol(value)
|
32
|
+
when 'numCol'
|
33
|
+
@number_columns = value.value.to_i
|
34
|
+
when 'spcCol'
|
35
|
+
@space_columns = OoxmlSize.new(value.value.to_f, :emu)
|
28
36
|
end
|
29
37
|
end
|
30
38
|
node.xpath('*').each do |node_child|
|
@@ -13,7 +13,7 @@ module OoxmlParser
|
|
13
13
|
when 'p'
|
14
14
|
DocumentStructure.default_paragraph_style = DocxParagraph.new
|
15
15
|
DocumentStructure.default_paragraph_style.spacing = Spacing.new(0, 0.35, 1.15, :multiple)
|
16
|
-
elements << DocumentStructure.default_paragraph_style.
|
16
|
+
elements << DocumentStructure.default_paragraph_style.dup.parse(textbox_element, i, parent: parent)
|
17
17
|
when 'tbl'
|
18
18
|
elements << Table.new(parent: parent).parse(textbox_element, i)
|
19
19
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Border Properties Data
|
2
2
|
module OoxmlParser
|
3
3
|
class BordersProperties < OOXMLDocumentObject
|
4
|
-
attr_accessor :color, :space, :sz, :val, :
|
4
|
+
attr_accessor :color, :space, :sz, :val, :shadow, :frame, :side
|
5
5
|
|
6
6
|
def initialize(color = :auto, sz = 0, val = :none, space = 0, parent: nil)
|
7
7
|
@color = color
|
@@ -28,7 +28,7 @@ module OoxmlParser
|
|
28
28
|
|
29
29
|
def visible?
|
30
30
|
return false if nil?
|
31
|
-
|
31
|
+
val != 'none'
|
32
32
|
end
|
33
33
|
|
34
34
|
# Parse BordersProperties
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'color/color_helper'
|
2
|
+
require_relative 'color/ooxml_color'
|
2
3
|
require_relative 'colors/color_alpha_channel'
|
3
4
|
require_relative 'colors/hsl_color'
|
4
5
|
require_relative 'colors/scheme_color'
|
@@ -13,7 +14,7 @@ module OoxmlParser
|
|
13
14
|
# List of color duplicated from `OpenXML Sdk IndexedColors` class
|
14
15
|
# See https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.indexedcolors.aspx
|
15
16
|
COLOR_INDEXED =
|
16
|
-
%w
|
17
|
+
%w[
|
17
18
|
000000
|
18
19
|
FFFFFF
|
19
20
|
FF0000
|
@@ -80,7 +81,7 @@ module OoxmlParser
|
|
80
81
|
333333
|
81
82
|
n/a
|
82
83
|
n/a
|
83
|
-
|
84
|
+
].freeze
|
84
85
|
|
85
86
|
# @return [Integer] Value of Red Part
|
86
87
|
attr_accessor :red
|
@@ -133,7 +134,12 @@ module OoxmlParser
|
|
133
134
|
alias to_int16 to_hex
|
134
135
|
|
135
136
|
def none?
|
136
|
-
(@red == VALUE_FOR_NONE_COLOR) && (@green == VALUE_FOR_NONE_COLOR) && (@blue == VALUE_FOR_NONE_COLOR)
|
137
|
+
(@red == VALUE_FOR_NONE_COLOR) && (@green == VALUE_FOR_NONE_COLOR) && (@blue == VALUE_FOR_NONE_COLOR) ||
|
138
|
+
(style == :nil)
|
139
|
+
end
|
140
|
+
|
141
|
+
def any?
|
142
|
+
!none?
|
137
143
|
end
|
138
144
|
|
139
145
|
def white?
|
@@ -171,7 +177,8 @@ module OoxmlParser
|
|
171
177
|
color_to_check = Color.parse(color_to_check.to_s) if color_to_check.is_a?(Symbol)
|
172
178
|
color_to_check = Color.parse(color_to_check.value) if color_to_check.is_a?(DocxColor)
|
173
179
|
return true if none? && color_to_check.nil?
|
174
|
-
return
|
180
|
+
return true if none? && color_to_check.none?
|
181
|
+
return false if none? && color_to_check.any?
|
175
182
|
return false if !none? && color_to_check.none?
|
176
183
|
return true if self == color_to_check
|
177
184
|
red = color_to_check.red
|
@@ -253,22 +260,6 @@ module OoxmlParser
|
|
253
260
|
end
|
254
261
|
end
|
255
262
|
|
256
|
-
def parse_color_tag(node)
|
257
|
-
return if node.nil?
|
258
|
-
node.attributes.each do |key, value|
|
259
|
-
case key
|
260
|
-
when 'val'
|
261
|
-
return Color.new.parse_hex_string(value.value.to_s)
|
262
|
-
when 'theme'
|
263
|
-
return ThemeColors.parse_color_theme(node)
|
264
|
-
when 'rgb'
|
265
|
-
return Color.new.parse_hex_string(value.value.to_s)
|
266
|
-
when 'indexed'
|
267
|
-
return Color.get_rgb_by_color_index(value.value.to_i)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
263
|
def parse_scheme_color(scheme_color_node)
|
273
264
|
color = ThemeColors.list[scheme_color_node.attribute('val').value.to_sym]
|
274
265
|
hls = HSLColor.rgb_to_hsl(color)
|
@@ -3,7 +3,7 @@ module ColorHelper
|
|
3
3
|
# Parse string in hex
|
4
4
|
# @param [String] hex_string with or without alpha-channel
|
5
5
|
def parse_hex_string(hex_string)
|
6
|
-
return self if
|
6
|
+
return self if %w[auto null].include?(hex_string)
|
7
7
|
|
8
8
|
char_array = hex_string.split(//)
|
9
9
|
if char_array.length == 3
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module OoxmlParser
|
2
|
+
# Class for parsing `color` tag
|
3
|
+
class OoxmlColor < OOXMLDocumentObject
|
4
|
+
# @return [Color] value of color
|
5
|
+
attr_reader :value
|
6
|
+
# @return [Symbol] theme color name
|
7
|
+
attr_reader :theme_color
|
8
|
+
# @return [Symbol] theme shade
|
9
|
+
attr_reader :theme_shade
|
10
|
+
# @return [Integer] theme index
|
11
|
+
attr_reader :theme
|
12
|
+
# @return [Float] tint
|
13
|
+
attr_reader :tint
|
14
|
+
# @return [Float] Indexed id
|
15
|
+
attr_reader :indexed
|
16
|
+
# @return [Color] rgb color
|
17
|
+
attr_reader :rgb
|
18
|
+
|
19
|
+
def to_color
|
20
|
+
return Color.get_rgb_by_color_index(indexed) if indexed
|
21
|
+
return ThemeColors.parse_color_theme(theme, tint) if theme
|
22
|
+
return rgb if rgb
|
23
|
+
value
|
24
|
+
end
|
25
|
+
|
26
|
+
def ==(other)
|
27
|
+
return to_color == other if other.is_a?(Color)
|
28
|
+
return to_color == other if other.is_a?(Symbol)
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
# Parse Hyperlink object
|
33
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
34
|
+
# @return [Hyperlink] result of parsing
|
35
|
+
def parse(node)
|
36
|
+
node.attributes.each do |key, value|
|
37
|
+
case key
|
38
|
+
when 'val'
|
39
|
+
@value = Color.new.parse_hex_string(value.value.to_s)
|
40
|
+
when 'themeColor'
|
41
|
+
@theme_color = value.value.to_sym
|
42
|
+
when 'themeShade'
|
43
|
+
@theme_shade = Integer("0x#{value.value}")
|
44
|
+
when 'theme'
|
45
|
+
@theme = value.value.to_i
|
46
|
+
when 'tint'
|
47
|
+
@tint = value.value.to_f
|
48
|
+
when 'indexed'
|
49
|
+
@indexed = value.value.to_i
|
50
|
+
when 'rgb'
|
51
|
+
@rgb = Color.new.parse_hex_string(value.value)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
self
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -5,16 +5,13 @@ module OoxmlParser
|
|
5
5
|
# @return [Hash] list of colors
|
6
6
|
attr_accessor :list
|
7
7
|
|
8
|
-
def parse_color_theme(
|
8
|
+
def parse_color_theme(theme, tint)
|
9
9
|
themes_array = ThemeColors.list.to_a
|
10
10
|
# TODO: if no swap performed - incorrect color parsing. But don't know why it needed
|
11
11
|
themes_array[0], themes_array[1] = themes_array[1], themes_array[0]
|
12
12
|
themes_array[2], themes_array[3] = themes_array[3], themes_array[2]
|
13
|
-
hls = HSLColor.rgb_to_hsl(themes_array[
|
14
|
-
tint = 0
|
15
|
-
unless color_theme_node.attribute('tint').nil?
|
16
|
-
tint = color_theme_node.attribute('tint').value.to_f
|
17
|
-
end
|
13
|
+
hls = HSLColor.rgb_to_hsl(themes_array[theme][1])
|
14
|
+
tint = 0 if tint.nil?
|
18
15
|
hls.calculate_rgb_with_tint(tint)
|
19
16
|
end
|
20
17
|
end
|
@@ -27,10 +27,14 @@ module OoxmlParser
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def parser_coordinates_range(arguments_string)
|
30
|
+
return parse_coordinates_array(arguments_string) if arguments_string.include?(',')
|
31
|
+
return warn "Formulas with # is unsupported: #{arguments_string}" if arguments_string.include?('#')
|
32
|
+
return warn 'Formulas consists from `!` only' if arguments_string == '!'
|
30
33
|
sheet_name = 'Sheet1'
|
31
34
|
|
32
35
|
if arguments_string.include?('!')
|
33
|
-
sheet_name
|
36
|
+
sheet_name = arguments_string.match(/.*!/).to_s
|
37
|
+
arguments_string = arguments_string.sub(sheet_name, '')
|
34
38
|
end
|
35
39
|
|
36
40
|
range = arguments_string.split(':')
|
@@ -70,6 +74,18 @@ module OoxmlParser
|
|
70
74
|
arguments_array
|
71
75
|
end
|
72
76
|
|
77
|
+
# Parse array of coordinates
|
78
|
+
# @param arguments_string [String] string
|
79
|
+
# @return [Array] result
|
80
|
+
def parse_coordinates_array(arguments_string)
|
81
|
+
result = []
|
82
|
+
coord_array = arguments_string.split(',')
|
83
|
+
coord_array.each do |current_coord|
|
84
|
+
result << parser_coordinates_range(current_coord)
|
85
|
+
end
|
86
|
+
result
|
87
|
+
end
|
88
|
+
|
73
89
|
# This method check is argument contains coordinate
|
74
90
|
# @param [String] string
|
75
91
|
def coordinates?(string)
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module OoxmlParser
|
2
2
|
# Class for parsing `hlinkClick`, `hyperlink` tags
|
3
3
|
class Hyperlink < OOXMLDocumentObject
|
4
|
-
attr_accessor :url, :tooltip, :coordinates, :
|
4
|
+
attr_accessor :url, :tooltip, :coordinates, :highlight_click, :action
|
5
5
|
attr_accessor :action_link
|
6
6
|
attr_accessor :id
|
7
|
+
# @return [Array<ParagraphRun>] run of paragraph
|
8
|
+
attr_reader :runs
|
7
9
|
|
8
10
|
def initialize(link = nil,
|
9
11
|
tooltip = nil,
|
@@ -13,6 +15,7 @@ module OoxmlParser
|
|
13
15
|
@tooltip = tooltip
|
14
16
|
@coordinates = coordinates
|
15
17
|
@parent = parent
|
18
|
+
@runs = []
|
16
19
|
end
|
17
20
|
|
18
21
|
alias link url
|
@@ -41,6 +44,14 @@ module OoxmlParser
|
|
41
44
|
@highlight_click = attribute_enabled?(value)
|
42
45
|
end
|
43
46
|
end
|
47
|
+
|
48
|
+
node.xpath('*').each do |node_child|
|
49
|
+
case node_child.name
|
50
|
+
when 'r'
|
51
|
+
@runs << ParagraphRun.new(parent: self).parse(node_child)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
44
55
|
case @action_link
|
45
56
|
when 'ppaction://hlinkshowjump?jump=previousslide'
|
46
57
|
@action = :previous_slide
|
@@ -17,9 +17,7 @@ module OoxmlParser
|
|
17
17
|
def ==(other)
|
18
18
|
instance_variables.each do |current_attribute|
|
19
19
|
next if current_attribute == :@parent
|
20
|
-
unless instance_variable_get(current_attribute) == other.instance_variable_get(current_attribute)
|
21
|
-
return false
|
22
|
-
end
|
20
|
+
return false unless instance_variable_get(current_attribute) == other.instance_variable_get(current_attribute)
|
23
21
|
end
|
24
22
|
true
|
25
23
|
end
|
@@ -42,7 +40,9 @@ module OoxmlParser
|
|
42
40
|
# Support of Encrtypted status in `file` util was introduced in file v5.20
|
43
41
|
# but LTS version of ubuntu before 16.04 uses older `file` and it return `Composite Document`
|
44
42
|
# https://github.com/file/file/blob/master/ChangeLog#L217
|
45
|
-
if file_result.include?('encrypted') ||
|
43
|
+
if file_result.include?('encrypted') ||
|
44
|
+
file_result.include?('Composite Document File V2 Document, No summary info') ||
|
45
|
+
file_result.include?('application/CDFV2-corrupt')
|
46
46
|
warn("File #{path_to_file} is encrypted. Can't parse it")
|
47
47
|
return true
|
48
48
|
end
|
@@ -1,6 +1,28 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
1
|
# Module for helper methods for OOXMLDocumentObject
|
3
2
|
module OoxmlDocumentObjectHelper
|
3
|
+
# Convert object to hash
|
4
|
+
# @return [Hash]
|
5
|
+
def to_hash
|
6
|
+
result_hash = {}
|
7
|
+
instance_variables.each do |current_attribute|
|
8
|
+
next if current_attribute == :@parent
|
9
|
+
attribute_value = instance_variable_get(current_attribute)
|
10
|
+
next unless attribute_value
|
11
|
+
if attribute_value.is_a?(Array)
|
12
|
+
attribute_value.each_with_index do |object_element, index|
|
13
|
+
result_hash["#{current_attribute}_#{index}".to_sym] = object_element.to_hash
|
14
|
+
end
|
15
|
+
else
|
16
|
+
result_hash[current_attribute.to_sym] = if attribute_value.respond_to?(:to_hash)
|
17
|
+
attribute_value.to_hash
|
18
|
+
else
|
19
|
+
attribute_value.to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
result_hash
|
24
|
+
end
|
25
|
+
|
4
26
|
private
|
5
27
|
|
6
28
|
VALUE_TO_SYMBOL_HASH = { l: :left,
|
@@ -13,6 +35,7 @@ module OoxmlDocumentObjectHelper
|
|
13
35
|
tl: :top_left,
|
14
36
|
br: :bottom_right,
|
15
37
|
bl: :bottom_left,
|
38
|
+
contentLocked: :content_locked,
|
16
39
|
dist: :distributed,
|
17
40
|
tb: :horizontal,
|
18
41
|
rl: :rotate_on_90,
|
@@ -44,6 +67,8 @@ module OoxmlDocumentObjectHelper
|
|
44
67
|
mediumDashDotDot: :medium_dash_dot_dot,
|
45
68
|
lgDashDot: :large_dash_dot,
|
46
69
|
lgDashDotDot: :large_dash_dot_dot,
|
70
|
+
sdtLocked: :sdt_locked,
|
71
|
+
sdtContentLocked: :sdt_content_locked,
|
47
72
|
sysDash: :system_dash,
|
48
73
|
sysDot: :system_dot,
|
49
74
|
sysDashDot: :system_dash_dot,
|
@@ -58,7 +83,11 @@ module OoxmlDocumentObjectHelper
|
|
58
83
|
tbRl: :top_to_bottom_right_to_left,
|
59
84
|
btLr: :bottom_to_top_left_to_right,
|
60
85
|
singlelevel: :single_level,
|
86
|
+
maxMin: :max_min,
|
87
|
+
middleDot: :middle_dot,
|
88
|
+
minMax: :min_max,
|
61
89
|
multilevel: :multi_level,
|
90
|
+
nextTo: :next_to,
|
62
91
|
hybridMultilevel: :hybrid_multi_level,
|
63
92
|
rnd: :round,
|
64
93
|
sq: :square }.freeze
|