ooxml_parser 0.32.0 → 0.34.0
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/common_parser/common_data/alternate_content/drawing/docx_drawing.rb +9 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_properties.rb +6 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb +15 -9
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/docx_graphic.rb +2 -1
- 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 +1 -1
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_size.rb +4 -4
- data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/color/color_helper.rb +14 -13
- data/lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb +4 -0
- data/lib/ooxml_parser/common_parser/common_data/color.rb +17 -13
- data/lib/ooxml_parser/common_parser/common_data/colors/color_alpha_channel.rb +19 -5
- data/lib/ooxml_parser/common_parser/common_data/colors/color_properties.rb +34 -12
- data/lib/ooxml_parser/common_parser/common_data/colors/image_fill.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +4 -0
- data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +22 -1
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/numbering_properties.rb +18 -4
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb +4 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/run_fonts.rb +26 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +12 -3
- data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +4 -4
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +14 -4
- data/lib/ooxml_parser/common_parser/common_data/table/table_properties.rb +3 -2
- data/lib/ooxml_parser/common_parser/common_data/underline.rb +22 -1
- data/lib/ooxml_parser/common_parser/common_data/valued_child.rb +14 -0
- data/lib/ooxml_parser/common_parser/parser/ooxml_file.rb +10 -0
- data/lib/ooxml_parser/docx_parser/document_structure/default_style_helper.rb +79 -0
- data/lib/ooxml_parser/docx_parser/document_structure/document_background.rb +6 -1
- data/lib/ooxml_parser/docx_parser/document_structure/document_style.rb +9 -3
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula/accent.rb +9 -2
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula/bar.rb +9 -3
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula/group_char.rb +25 -4
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula/matrix.rb +2 -1
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb +25 -19
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/field_char.rb +22 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb +3 -1
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/checkbox/checkbox_state.rb +26 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/checkbox.rb +35 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/combobox/list_item.rb +26 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/combobox.rb +28 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/dropdown_list.rb +27 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/form_properties.rb +48 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/form_text_properties/form_text_comb.rb +26 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/form_text_properties/form_text_format.rb +30 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/form_text_properties.rb +45 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties.rb +25 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb +6 -5
- data/lib/ooxml_parser/docx_parser/document_structure/header_footer.rb +14 -2
- data/lib/ooxml_parser/docx_parser/document_structure/page_properties/columns.rb +2 -2
- data/lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb +10 -11
- data/lib/ooxml_parser/docx_parser/document_structure/page_properties/page_properties/header_footer_reference.rb +27 -0
- data/lib/ooxml_parser/docx_parser/document_structure/page_properties/page_properties/page_borders.rb +26 -0
- data/lib/ooxml_parser/docx_parser/document_structure/page_properties/page_properties.rb +20 -12
- data/lib/ooxml_parser/docx_parser/document_structure/styles/document_defaults/paragraph_properties_default.rb +3 -0
- data/lib/ooxml_parser/docx_parser/document_structure/styles.rb +6 -0
- data/lib/ooxml_parser/docx_parser/document_structure.rb +2 -69
- data/lib/ooxml_parser/pptx_parser/presentation/presentation_comments/presentation_comment.rb +1 -1
- data/lib/ooxml_parser/pptx_parser/presentation/slide/graphic_frame/graphic_frame/chart_reference.rb +22 -0
- data/lib/ooxml_parser/pptx_parser/presentation/slide/graphic_frame/graphic_frame.rb +4 -1
- data/lib/ooxml_parser/version.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/workbook/pivot_table_definition/location.rb +6 -6
- data/lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/cell_style/protection.rb +2 -2
- data/lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb +5 -5
- data/lib/ooxml_parser/xlsx_parser/workbook/workbook_properties.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/workbook/worksheet/sheet_view.rb +2 -2
- data/lib/ooxml_parser/xlsx_parser/workbook/worksheet/table_part.rb +9 -1
- data/lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_column_properties.rb +2 -2
- data/lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer.rb +4 -4
- data/lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb +2 -1
- data/lib/ooxml_parser/xlsx_parser/workbook.rb +1 -1
- metadata +18 -3
data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/combobox.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'combobox/list_item'
|
|
4
|
+
module OoxmlParser
|
|
5
|
+
# Class for parsing `comboBox` tag
|
|
6
|
+
class ComboBox < OOXMLDocumentObject
|
|
7
|
+
# @return [Array<ListItem>] combobox items
|
|
8
|
+
attr_reader :list_items
|
|
9
|
+
|
|
10
|
+
def initialize(parent: nil)
|
|
11
|
+
@list_items = []
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Parse ComboBox object
|
|
16
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
|
17
|
+
# @return [ComboBox] result of parsing
|
|
18
|
+
def parse(node)
|
|
19
|
+
node.xpath('*').each do |node_child|
|
|
20
|
+
case node_child.name
|
|
21
|
+
when 'listItem'
|
|
22
|
+
@list_items << ListItem.new(parent: self).parse(node_child)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
self
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OoxmlParser
|
|
4
|
+
# Class for parsing `dropDownList` tag
|
|
5
|
+
class DropdownList < OOXMLDocumentObject
|
|
6
|
+
# @return [Array<ListItem>] dropdown items
|
|
7
|
+
attr_reader :list_items
|
|
8
|
+
|
|
9
|
+
def initialize(parent: nil)
|
|
10
|
+
@list_items = []
|
|
11
|
+
super
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Parse DropdownList object
|
|
15
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
|
16
|
+
# @return [DropdownList] result of parsing
|
|
17
|
+
def parse(node)
|
|
18
|
+
node.xpath('*').each do |node_child|
|
|
19
|
+
case node_child.name
|
|
20
|
+
when 'listItem'
|
|
21
|
+
@list_items << ListItem.new(parent: self).parse(node_child)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
self
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OoxmlParser
|
|
4
|
+
# Class for parsing `formPr` tag
|
|
5
|
+
class FormProperties < OOXMLDocumentObject
|
|
6
|
+
# @return [String] field key
|
|
7
|
+
attr_reader :key
|
|
8
|
+
# @return [String] text of tooltip
|
|
9
|
+
attr_reader :help_text
|
|
10
|
+
# @return [True, False] specifies if field is required
|
|
11
|
+
attr_reader :required
|
|
12
|
+
# @return [Shade] shade of field
|
|
13
|
+
attr_reader :shade
|
|
14
|
+
# @return [BordersProperties] border of field
|
|
15
|
+
attr_reader :border
|
|
16
|
+
|
|
17
|
+
def initialize(parent: nil)
|
|
18
|
+
@required = false
|
|
19
|
+
super
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Parse FormProperties object
|
|
23
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
|
24
|
+
# @return [FormProperties] result of parsing
|
|
25
|
+
def parse(node)
|
|
26
|
+
node.attributes.each do |key, value|
|
|
27
|
+
case key
|
|
28
|
+
when 'key'
|
|
29
|
+
@key = value.value
|
|
30
|
+
when 'helpText'
|
|
31
|
+
@help_text = value.value
|
|
32
|
+
when 'required'
|
|
33
|
+
@required = boolean_attribute_value(value)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
node.xpath('*').each do |node_child|
|
|
38
|
+
case node_child.name
|
|
39
|
+
when 'shd'
|
|
40
|
+
@shade = Shade.new(parent: self).parse(node_child)
|
|
41
|
+
when 'border'
|
|
42
|
+
@border = BordersProperties.new(parent: self).parse(node_child)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
self
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OoxmlParser
|
|
4
|
+
# Class for parsing `comb` tag
|
|
5
|
+
class FormTextComb < OOXMLDocumentObject
|
|
6
|
+
# @return [OoxmlSize] field width
|
|
7
|
+
attr_reader :width
|
|
8
|
+
# @return [Symbol] width rule
|
|
9
|
+
attr_reader :width_rule
|
|
10
|
+
|
|
11
|
+
# Parse FormTextComb object
|
|
12
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
|
13
|
+
# @return [FormTextComb] result of parsing
|
|
14
|
+
def parse(node)
|
|
15
|
+
node.attributes.each do |key, value|
|
|
16
|
+
case key
|
|
17
|
+
when 'width'
|
|
18
|
+
@width = OoxmlSize.new(value.value.to_f)
|
|
19
|
+
when 'wRule'
|
|
20
|
+
@width_rule = value.value.to_sym
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
self
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OoxmlParser
|
|
4
|
+
# Class for parsing `format` tag
|
|
5
|
+
class FormTextFormat < OOXMLDocumentObject
|
|
6
|
+
# @return [Symbol] format type
|
|
7
|
+
attr_reader :type
|
|
8
|
+
# @return [String] value for custom formats
|
|
9
|
+
attr_reader :value
|
|
10
|
+
# @return [String] allowed symbols
|
|
11
|
+
attr_reader :symbols
|
|
12
|
+
|
|
13
|
+
# Parse FormTextFormat object
|
|
14
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
|
15
|
+
# @return [FormTextFormat] result of parsing
|
|
16
|
+
def parse(node)
|
|
17
|
+
node.attributes.each do |key, value|
|
|
18
|
+
case key
|
|
19
|
+
when 'type'
|
|
20
|
+
@type = value.value.to_sym
|
|
21
|
+
when 'val'
|
|
22
|
+
@value = value.value
|
|
23
|
+
when 'symbols'
|
|
24
|
+
@symbols = value.value
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
self
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'form_text_properties/form_text_comb'
|
|
4
|
+
require_relative 'form_text_properties/form_text_format'
|
|
5
|
+
module OoxmlParser
|
|
6
|
+
# Class for parsing `textFormPr` tag
|
|
7
|
+
class FormTextProperties < OOXMLDocumentObject
|
|
8
|
+
# @return [True, False] specifies if field is multiline
|
|
9
|
+
attr_reader :multiline
|
|
10
|
+
# @return [True, False] specifies if size of field should be autofit
|
|
11
|
+
attr_reader :autofit
|
|
12
|
+
# @return [FormTextComb] parameters of text justification
|
|
13
|
+
attr_reader :comb
|
|
14
|
+
# @return [ValuedChild] characters limit
|
|
15
|
+
attr_reader :maximum_characters
|
|
16
|
+
# @return [FormTextFormat] text format
|
|
17
|
+
attr_reader :format
|
|
18
|
+
|
|
19
|
+
# Parse FormTextProperties object
|
|
20
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
|
21
|
+
# @return [FormTextProperties] result of parsing
|
|
22
|
+
def parse(node)
|
|
23
|
+
node.attributes.each do |key, value|
|
|
24
|
+
case key
|
|
25
|
+
when 'multiLine'
|
|
26
|
+
@multiline = boolean_attribute_value(value)
|
|
27
|
+
when 'autoFit'
|
|
28
|
+
@autofit = boolean_attribute_value(value)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
node.xpath('*').each do |node_child|
|
|
33
|
+
case node_child.name
|
|
34
|
+
when 'comb'
|
|
35
|
+
@comb = FormTextComb.new(parent: self).parse(node_child)
|
|
36
|
+
when 'maxCharacters'
|
|
37
|
+
@maximum_characters = ValuedChild.new(:integer, parent: self).parse(node_child)
|
|
38
|
+
when 'format'
|
|
39
|
+
@format = FormTextFormat.new(parent: self).parse(node_child)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
self
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'sdt_properties/form_properties'
|
|
4
|
+
require_relative 'sdt_properties/form_text_properties'
|
|
5
|
+
require_relative 'sdt_properties/combobox'
|
|
6
|
+
require_relative 'sdt_properties/dropdown_list'
|
|
7
|
+
require_relative 'sdt_properties/checkbox'
|
|
3
8
|
module OoxmlParser
|
|
4
9
|
# Class for parsing `w:sdtPr` tags
|
|
5
10
|
class SDTProperties < OOXMLDocumentObject
|
|
@@ -9,6 +14,16 @@ module OoxmlParser
|
|
|
9
14
|
attr_reader :tag
|
|
10
15
|
# @return [ValuedChild] Locking Setting
|
|
11
16
|
attr_reader :lock
|
|
17
|
+
# @return [ComboBox] combobox
|
|
18
|
+
attr_reader :combobox
|
|
19
|
+
# @return [DropdownList] dropdown list
|
|
20
|
+
attr_reader :dropdown_list
|
|
21
|
+
# @return [CheckBox] checkbox
|
|
22
|
+
attr_reader :checkbox
|
|
23
|
+
# @return [FormProperties] form properties
|
|
24
|
+
attr_reader :form_properties
|
|
25
|
+
# @return [FormTextProperties] properties of text in form
|
|
26
|
+
attr_reader :form_text_properties
|
|
12
27
|
|
|
13
28
|
# Parse SDTProperties object
|
|
14
29
|
# @param node [Nokogiri::XML:Element] node to parse
|
|
@@ -22,6 +37,16 @@ module OoxmlParser
|
|
|
22
37
|
@tag = ValuedChild.new(:string, parent: self).parse(node_child)
|
|
23
38
|
when 'lock'
|
|
24
39
|
@lock = ValuedChild.new(:symbol, parent: self).parse(node_child)
|
|
40
|
+
when 'comboBox'
|
|
41
|
+
@combobox = ComboBox.new(parent: self).parse(node_child)
|
|
42
|
+
when 'dropDownList'
|
|
43
|
+
@dropdown_list = DropdownList.new(parent: self).parse(node_child)
|
|
44
|
+
when 'checkbox'
|
|
45
|
+
@checkbox = CheckBox.new(parent: self).parse(node_child)
|
|
46
|
+
when 'formPr'
|
|
47
|
+
@form_properties = FormProperties.new(parent: self).parse(node_child)
|
|
48
|
+
when 'textFormPr'
|
|
49
|
+
@form_text_properties = FormTextProperties.new(parent: self).parse(node_child)
|
|
25
50
|
end
|
|
26
51
|
end
|
|
27
52
|
self
|
|
@@ -147,10 +147,10 @@ module OoxmlParser
|
|
|
147
147
|
@hyperlink = Hyperlink.new(parent: self).parse(node_child)
|
|
148
148
|
character_style = default_character_style.dup
|
|
149
149
|
character_style.parent = self
|
|
150
|
-
if
|
|
150
|
+
if @hyperlink.id
|
|
151
151
|
character_style.link = Hyperlink.new(parent: character_style).parse(node_child)
|
|
152
|
-
elsif
|
|
153
|
-
character_style.link =
|
|
152
|
+
elsif @hyperlink.anchor
|
|
153
|
+
character_style.link = @hyperlink.anchor
|
|
154
154
|
end
|
|
155
155
|
node_child.xpath('w:r').each do |r_tag|
|
|
156
156
|
character_style.parse(r_tag, char_number, parent: self)
|
|
@@ -208,8 +208,9 @@ module OoxmlParser
|
|
|
208
208
|
when 'numPr'
|
|
209
209
|
@numbering = NumberingProperties.new(parent: self).parse(node_child)
|
|
210
210
|
when 'jc'
|
|
211
|
-
@
|
|
212
|
-
@align =
|
|
211
|
+
@justification_object = ValuedChild.new(:string, parent: self).parse(node_child)
|
|
212
|
+
@align = @justification_object.value.to_sym unless @justification_object.value.nil?
|
|
213
|
+
@align = :justify if @justification_object.value == 'both'
|
|
213
214
|
when 'spacing'
|
|
214
215
|
@valued_spacing = ParagraphSpacing.new(parent: self).parse(node_child)
|
|
215
216
|
@spacing = @spacing.fetch_from_valued_spacing(@valued_spacing)
|
|
@@ -45,11 +45,23 @@ module OoxmlParser
|
|
|
45
45
|
# @param [Nokogiri::XML:Node] node with HeaderFooter
|
|
46
46
|
# @return [HeaderFooter] result of parsing
|
|
47
47
|
def parse(node)
|
|
48
|
-
|
|
48
|
+
node.attributes.each do |key, value|
|
|
49
|
+
case key
|
|
50
|
+
when 'id'
|
|
51
|
+
@id = value.value.to_i
|
|
52
|
+
end
|
|
53
|
+
end
|
|
49
54
|
parse_type(node)
|
|
50
55
|
doc = parse_xml(root_object.unpacked_folder + xml_path)
|
|
51
56
|
doc.search(xpath_for_search).each do |footnote|
|
|
52
|
-
|
|
57
|
+
footnote_id = nil
|
|
58
|
+
footnote.attributes.each do |key, value|
|
|
59
|
+
case key
|
|
60
|
+
when 'id'
|
|
61
|
+
footnote_id = value.value.to_i
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
next unless footnote_id == @id
|
|
53
65
|
|
|
54
66
|
paragraph_number = 0
|
|
55
67
|
footnote.xpath('w:p').each do |paragraph|
|
|
@@ -36,9 +36,9 @@ module OoxmlParser
|
|
|
36
36
|
when 'num'
|
|
37
37
|
@count = value.value.to_i
|
|
38
38
|
when 'sep'
|
|
39
|
-
@separator =
|
|
39
|
+
@separator = boolean_attribute_value(value)
|
|
40
40
|
when 'equalWidth'
|
|
41
|
-
@equal_width =
|
|
41
|
+
@equal_width = boolean_attribute_value(value)
|
|
42
42
|
when 'space'
|
|
43
43
|
@space = OoxmlSize.new(value.value.to_f)
|
|
44
44
|
end
|
|
@@ -13,15 +13,14 @@ module OoxmlParser
|
|
|
13
13
|
# Parse note data
|
|
14
14
|
# @param params [Hash] data to parse
|
|
15
15
|
# @return [Note] result of parsing
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if note.type.include?('footer')
|
|
16
|
+
def parse(params)
|
|
17
|
+
@type = params[:type]
|
|
18
|
+
@assigned_to = params[:assigned_to]
|
|
19
|
+
@parent = params[:parent]
|
|
20
|
+
doc = parse_xml(file_path(params[:target]))
|
|
21
|
+
if @type.include?('footer')
|
|
23
22
|
xpath_note = '//w:ftr'
|
|
24
|
-
elsif
|
|
23
|
+
elsif @type.include?('header')
|
|
25
24
|
xpath_note = '//w:hdr'
|
|
26
25
|
end
|
|
27
26
|
doc.search(xpath_note).each do |ftr|
|
|
@@ -29,15 +28,15 @@ module OoxmlParser
|
|
|
29
28
|
ftr.xpath('*').each do |sub_element|
|
|
30
29
|
case sub_element.name
|
|
31
30
|
when 'p'
|
|
32
|
-
|
|
31
|
+
@elements << params[:default_paragraph].dup.parse(sub_element, number, params[:default_character], parent: self)
|
|
33
32
|
number += 1
|
|
34
33
|
when 'tbl'
|
|
35
|
-
|
|
34
|
+
@elements << Table.new(parent: self).parse(sub_element, number)
|
|
36
35
|
number += 1
|
|
37
36
|
end
|
|
38
37
|
end
|
|
39
38
|
end
|
|
40
|
-
|
|
39
|
+
self
|
|
41
40
|
end
|
|
42
41
|
|
|
43
42
|
# @param target [String] name of target
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OoxmlParser
|
|
4
|
+
# Class for parsing `w:headerReference`,
|
|
5
|
+
# `w:footerReference` object
|
|
6
|
+
class HeaderFooterReference < OOXMLDocumentObject
|
|
7
|
+
# @return [String] id of reference
|
|
8
|
+
attr_accessor :id
|
|
9
|
+
# @return [String] type of reference
|
|
10
|
+
attr_accessor :type
|
|
11
|
+
|
|
12
|
+
# Parse HeaderFooterReference
|
|
13
|
+
# @param [Nokogiri::XML:Node] node with HeaderFooterReference
|
|
14
|
+
# @return [HeaderFooterReference] result of parsing
|
|
15
|
+
def parse(node)
|
|
16
|
+
node.attributes.each do |key, value|
|
|
17
|
+
case key
|
|
18
|
+
when 'id'
|
|
19
|
+
@id = value.to_s
|
|
20
|
+
when 'type'
|
|
21
|
+
@type = value.to_s
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
self
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/ooxml_parser/docx_parser/document_structure/page_properties/page_properties/page_borders.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OoxmlParser
|
|
4
|
+
# Class for parsing `w:pgBorders` PageBorders object
|
|
5
|
+
class PageBorders < OOXMLDocumentObject
|
|
6
|
+
# @return [Symbol] display value
|
|
7
|
+
attr_reader :display
|
|
8
|
+
# @return [Symbol] offset from value
|
|
9
|
+
attr_reader :offset_from
|
|
10
|
+
|
|
11
|
+
# Parse PageBorders
|
|
12
|
+
# @param [Nokogiri::XML:Node] node with PageBorders
|
|
13
|
+
# @return [PageBorders] result of parsing
|
|
14
|
+
def parse(node)
|
|
15
|
+
node.attributes.each do |key, value|
|
|
16
|
+
case key
|
|
17
|
+
when 'display'
|
|
18
|
+
@display = value.value.to_sym
|
|
19
|
+
when 'offsetFrom'
|
|
20
|
+
@offset_from = value.value.to_sym
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
self
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -6,6 +6,9 @@ require_relative 'page_size'
|
|
|
6
6
|
require_relative 'page_margins'
|
|
7
7
|
require_relative 'columns'
|
|
8
8
|
require_relative 'note'
|
|
9
|
+
require_relative 'page_properties/header_footer_reference'
|
|
10
|
+
require_relative 'page_properties/page_borders'
|
|
11
|
+
|
|
9
12
|
module OoxmlParser
|
|
10
13
|
# Class for data of PageProperties
|
|
11
14
|
class PageProperties < OOXMLDocumentObject
|
|
@@ -30,9 +33,10 @@ module OoxmlParser
|
|
|
30
33
|
when 'pgSz'
|
|
31
34
|
@size = PageSize.new.parse(pg_size_subnode)
|
|
32
35
|
when 'pgBorders'
|
|
36
|
+
page_borders_object = PageBorders.new(parent: self).parse(pg_size_subnode)
|
|
33
37
|
page_borders = Borders.new
|
|
34
|
-
page_borders.display =
|
|
35
|
-
page_borders.offset_from =
|
|
38
|
+
page_borders.display = page_borders_object.display if page_borders_object.display
|
|
39
|
+
page_borders.offset_from = page_borders_object.offset_from if page_borders_object.offset_from
|
|
36
40
|
pg_size_subnode.xpath('w:bottom').each do |bottom|
|
|
37
41
|
page_borders.bottom = BordersProperties.new(parent: page_borders).parse(bottom)
|
|
38
42
|
end
|
|
@@ -47,15 +51,18 @@ module OoxmlParser
|
|
|
47
51
|
end
|
|
48
52
|
@page_borders = page_borders
|
|
49
53
|
when 'type'
|
|
50
|
-
@
|
|
54
|
+
@type_object = ValuedChild.new(:string, parent: self).parse(pg_size_subnode)
|
|
55
|
+
@type = @type_object.value
|
|
51
56
|
when 'pgMar'
|
|
52
57
|
@margins = PageMargins.new(parent: self).parse(pg_size_subnode)
|
|
53
58
|
when 'pgNumType'
|
|
54
59
|
@num_type = pg_size_subnode.attribute('fmt').value unless pg_size_subnode.attribute('fmt').nil?
|
|
55
60
|
when 'formProt'
|
|
56
|
-
|
|
61
|
+
form_prot_object = ValuedChild.new(:string, parent: self).parse(pg_size_subnode)
|
|
62
|
+
@form_prot = form_prot_object.value
|
|
57
63
|
when 'textDirection'
|
|
58
|
-
|
|
64
|
+
text_directon_object = ValuedChild.new(:string, parent: self).parse(pg_size_subnode)
|
|
65
|
+
@text_direction = text_directon_object.value
|
|
59
66
|
when 'docGrid'
|
|
60
67
|
@document_grid = DocumentGrid.new(parent: self).parse(pg_size_subnode)
|
|
61
68
|
when 'titlePg'
|
|
@@ -63,14 +70,15 @@ module OoxmlParser
|
|
|
63
70
|
when 'cols'
|
|
64
71
|
@columns = Columns.new.parse(pg_size_subnode)
|
|
65
72
|
when 'headerReference', 'footerReference'
|
|
66
|
-
|
|
73
|
+
reference = HeaderFooterReference.new(parent: self).parse(pg_size_subnode)
|
|
74
|
+
target = root_object.get_link_from_rels(reference.id)
|
|
67
75
|
root_object.add_to_xmls_stack("word/#{target}")
|
|
68
|
-
note = Note.parse(default_paragraph: default_paragraph,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
note = Note.new.parse(default_paragraph: default_paragraph,
|
|
77
|
+
default_character: default_character,
|
|
78
|
+
target: target,
|
|
79
|
+
assigned_to: reference.type,
|
|
80
|
+
type: File.basename(target).sub('.xml', ''),
|
|
81
|
+
parent: self)
|
|
74
82
|
@notes << note
|
|
75
83
|
root_object.xmls_stack.pop
|
|
76
84
|
when 'footnotePr'
|
|
@@ -5,11 +5,14 @@ module OoxmlParser
|
|
|
5
5
|
class ParagraphPropertiesDefault < OOXMLDocumentObject
|
|
6
6
|
# @return [ParagraphProperties] properties of run
|
|
7
7
|
attr_accessor :paragraph_properties
|
|
8
|
+
# @return [Nokogiri::XML:Element] raw node of tag
|
|
9
|
+
attr_reader :raw_node
|
|
8
10
|
|
|
9
11
|
# Parse ParagraphPropertiesDefault object
|
|
10
12
|
# @param node [Nokogiri::XML:Element] node to parse
|
|
11
13
|
# @return [ParagraphPropertiesDefault] result of parsing
|
|
12
14
|
def parse(node)
|
|
15
|
+
@raw_node = node
|
|
13
16
|
node.xpath('*').each do |node_child|
|
|
14
17
|
case node_child.name
|
|
15
18
|
when 'pPr'
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'document_structure/comments'
|
|
4
4
|
require_relative 'document_structure/comments_extended'
|
|
5
|
+
require_relative 'document_structure/default_style_helper'
|
|
5
6
|
require_relative 'document_structure/docx_paragraph'
|
|
6
7
|
require_relative 'document_structure/document_background'
|
|
7
8
|
require_relative 'document_structure/document_properties'
|
|
@@ -15,6 +16,7 @@ require_relative 'document_structure/styles'
|
|
|
15
16
|
module OoxmlParser
|
|
16
17
|
# Basic class for DocumentStructure
|
|
17
18
|
class DocumentStructure < CommonDocumentStructure
|
|
19
|
+
include DefaultStyleHelper
|
|
18
20
|
include DocumentStyleHelper
|
|
19
21
|
include DocumentStructureHelpers
|
|
20
22
|
# @return [Array<OOXMLDocumentObject>] list of elements
|
|
@@ -211,75 +213,6 @@ module OoxmlParser
|
|
|
211
213
|
self
|
|
212
214
|
end
|
|
213
215
|
|
|
214
|
-
# Parse default style
|
|
215
|
-
# @return [void]
|
|
216
|
-
def parse_default_style
|
|
217
|
-
doc = parse_xml("#{root_object.unpacked_folder}word/styles.xml")
|
|
218
|
-
doc.search('//w:style').each do |style|
|
|
219
|
-
next if style.attribute('default').nil?
|
|
220
|
-
|
|
221
|
-
if (style.attribute('default').value == '1' ||
|
|
222
|
-
style.attribute('default').value == 'on' ||
|
|
223
|
-
style.attribute('default').value == 'true') &&
|
|
224
|
-
style.attribute('type').value == 'paragraph'
|
|
225
|
-
style.xpath('w:pPr').each do |paragraph_pr_tag|
|
|
226
|
-
DocumentStructure.default_paragraph_style = DocxParagraph.new.parse_paragraph_style(paragraph_pr_tag, DocumentStructure.default_run_style)
|
|
227
|
-
end
|
|
228
|
-
style.xpath('w:rPr').each do |character_pr_tag|
|
|
229
|
-
DocumentStructure.default_run_style.parse_properties(character_pr_tag)
|
|
230
|
-
end
|
|
231
|
-
elsif (style.attribute('default').value == '1' ||
|
|
232
|
-
style.attribute('default').value == 'on' ||
|
|
233
|
-
style.attribute('default').value == 'true') &&
|
|
234
|
-
style.attribute('type').value == 'character'
|
|
235
|
-
style.xpath('w:rPr').each do |character_pr_tag|
|
|
236
|
-
DocumentStructure.default_run_style.parse_properties(character_pr_tag)
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
DocumentStructure.default_table_paragraph_style = DocumentStructure.default_paragraph_style.dup
|
|
241
|
-
DocumentStructure.default_table_paragraph_style.spacing = Spacing.new(0, 0, 1, :auto)
|
|
242
|
-
DocumentStructure.default_table_run_style = DocumentStructure.default_run_style.dup
|
|
243
|
-
doc.search('//w:style').each do |style|
|
|
244
|
-
next if style.attribute('default').nil?
|
|
245
|
-
next unless (style.attribute('default').value == '1' ||
|
|
246
|
-
style.attribute('default').value == 'on' ||
|
|
247
|
-
style.attribute('default').value == 'true') &&
|
|
248
|
-
style.attribute('type').value == 'table'
|
|
249
|
-
|
|
250
|
-
style.xpath('w:rPr').each do |table_character_pr_tag|
|
|
251
|
-
DocumentStructure.default_table_run_style.parse_properties(table_character_pr_tag)
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
# Perform parsing styles.xml
|
|
257
|
-
def parse_styles
|
|
258
|
-
file = "#{root_object.unpacked_folder}/word/styles.xml"
|
|
259
|
-
DocumentStructure.default_paragraph_style = DocxParagraph.new(parent: self)
|
|
260
|
-
DocumentStructure.default_table_paragraph_style = DocxParagraph.new(parent: self)
|
|
261
|
-
DocumentStructure.default_run_style = DocxParagraphRun.new(parent: self)
|
|
262
|
-
DocumentStructure.default_table_run_style = DocxParagraphRun.new(parent: self)
|
|
263
|
-
|
|
264
|
-
return unless File.exist?(file)
|
|
265
|
-
|
|
266
|
-
doc = parse_xml(file)
|
|
267
|
-
# TODO: Remove this old way parsing in favor of doc_structure.styles.document_defaults
|
|
268
|
-
doc.search('//w:docDefaults').each do |doc_defaults|
|
|
269
|
-
doc_defaults.xpath('w:pPrDefault').each do |p_pr_defaults|
|
|
270
|
-
DocumentStructure.default_paragraph_style = DocxParagraph.new(parent: self).parse(p_pr_defaults, 0)
|
|
271
|
-
end
|
|
272
|
-
doc_defaults.xpath('w:rPrDefault').each do |r_pr_defaults|
|
|
273
|
-
r_pr_defaults.xpath('w:rPr').each do |r_pr|
|
|
274
|
-
DocumentStructure.default_run_style = DocxParagraphRun.new(parent: self).parse_properties(r_pr)
|
|
275
|
-
end
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
parse_default_style
|
|
279
|
-
@numbering = Numbering.new(parent: self).parse
|
|
280
|
-
@styles = Styles.new(parent: self).parse
|
|
281
|
-
end
|
|
282
|
-
|
|
283
216
|
class << self
|
|
284
217
|
attr_accessor :default_table_run_style, :default_table_paragraph_style, :default_paragraph_style, :default_run_style
|
|
285
218
|
end
|
data/lib/ooxml_parser/pptx_parser/presentation/presentation_comments/presentation_comment.rb
CHANGED
|
@@ -28,7 +28,7 @@ module OoxmlParser
|
|
|
28
28
|
node.xpath('*').each do |node_child|
|
|
29
29
|
case node_child.name
|
|
30
30
|
when 'pos'
|
|
31
|
-
@position = OOXMLCoordinates.
|
|
31
|
+
@position = OOXMLCoordinates.new(parent: self).parse(node_child)
|
|
32
32
|
when 'text'
|
|
33
33
|
@text = node_child.text.to_s
|
|
34
34
|
end
|
data/lib/ooxml_parser/pptx_parser/presentation/slide/graphic_frame/graphic_frame/chart_reference.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OoxmlParser
|
|
4
|
+
# Class for parsing `c:chart` object
|
|
5
|
+
class ChartReference < OOXMLDocumentObject
|
|
6
|
+
# @return [String] id of the chart
|
|
7
|
+
attr_reader :id
|
|
8
|
+
|
|
9
|
+
# Parse ChartReference
|
|
10
|
+
# @param [Nokogiri::XML:Node] node with ChartReference
|
|
11
|
+
# @return [ChartReference] result of parsing
|
|
12
|
+
def parse(node)
|
|
13
|
+
node.attributes.each do |key, value|
|
|
14
|
+
case key
|
|
15
|
+
when 'id'
|
|
16
|
+
@id = value.value.to_s
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
self
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'graphic_frame/chart_reference'
|
|
4
|
+
|
|
3
5
|
module OoxmlParser
|
|
4
6
|
# Class for parsing `graphicFrame`
|
|
5
7
|
class GraphicFrame < OOXMLDocumentObject
|
|
@@ -30,7 +32,8 @@ module OoxmlParser
|
|
|
30
32
|
when 'tbl'
|
|
31
33
|
graphic_data << Table.new(parent: self).parse(graphic_node_child)
|
|
32
34
|
when 'chart'
|
|
33
|
-
|
|
35
|
+
@chart_reference = ChartReference.new(parent: self).parse(graphic_node_child)
|
|
36
|
+
root_object.add_to_xmls_stack(root_object.get_link_from_rels(@chart_reference.id))
|
|
34
37
|
graphic_data << Chart.new(parent: self).parse
|
|
35
38
|
root_object.xmls_stack.pop
|
|
36
39
|
when 'oleObj'
|