ooxml_parser 0.33.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.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 +21 -13
- 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/form_properties.rb +1 -1
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties/form_text_properties.rb +2 -2
- 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 +9 -3
|
@@ -4,7 +4,7 @@ require_relative 'grid_span'
|
|
|
4
4
|
module OoxmlParser
|
|
5
5
|
# Class for parsing 'w:tcPr' element
|
|
6
6
|
class CellProperties < OOXMLDocumentObject
|
|
7
|
-
attr_accessor :fill, :color, :borders, :text_direction, :anchor, :table_cell_width, :borders_properties
|
|
7
|
+
attr_accessor :fill, :color, :borders, :text_direction, :anchor, :table_cell_width, :borders_properties
|
|
8
8
|
# @return [GridSpan] data about grid span
|
|
9
9
|
attr_accessor :grid_span
|
|
10
10
|
# @return [TableMargins] margins
|
|
@@ -22,6 +22,8 @@ module OoxmlParser
|
|
|
22
22
|
# width is set to auto or pct, then the content of the cell will not wrap.
|
|
23
23
|
# > ECMA-376, 3rd Edition (June, 2011), Fundamentals and Markup Language Reference 17.4.30.
|
|
24
24
|
attr_accessor :no_wrap
|
|
25
|
+
# @return [ValuedChild] vertical align type
|
|
26
|
+
attr_reader :vertical_align_object
|
|
25
27
|
|
|
26
28
|
alias table_cell_borders borders_properties
|
|
27
29
|
|
|
@@ -38,15 +40,16 @@ module OoxmlParser
|
|
|
38
40
|
when 'vMerge'
|
|
39
41
|
@vertical_merge = ValuedChild.new(:symbol, parent: self).parse(node_child)
|
|
40
42
|
when 'vAlign'
|
|
41
|
-
@
|
|
43
|
+
@vertical_align_object = ValuedChild.new(:symbol, parent: self).parse(node_child)
|
|
42
44
|
when 'gridSpan'
|
|
43
45
|
@grid_span = GridSpan.new(parent: self).parse(node_child)
|
|
44
46
|
when 'tcW'
|
|
45
|
-
@table_cell_width = OoxmlSize.new(node_child
|
|
47
|
+
@table_cell_width = OoxmlSize.new.parse(node_child)
|
|
46
48
|
when 'tcMar'
|
|
47
49
|
@table_cell_margin = TableMargins.new(parent: self).parse(node_child)
|
|
48
50
|
when 'textDirection'
|
|
49
|
-
@
|
|
51
|
+
@text_direction_object = ValuedChild.new(:string, parent: self).parse(node_child)
|
|
52
|
+
@text_direction = value_to_symbol(@text_direction_object)
|
|
50
53
|
when 'noWrap'
|
|
51
54
|
@no_wrap = option_enabled?(node_child)
|
|
52
55
|
when 'shd'
|
|
@@ -85,5 +88,12 @@ module OoxmlParser
|
|
|
85
88
|
end
|
|
86
89
|
self
|
|
87
90
|
end
|
|
91
|
+
|
|
92
|
+
# @return [nil, Symbol] vertical align of cell
|
|
93
|
+
def vertical_align
|
|
94
|
+
return nil unless @vertical_align_object
|
|
95
|
+
|
|
96
|
+
@vertical_align_object.value
|
|
97
|
+
end
|
|
88
98
|
end
|
|
89
99
|
end
|
|
@@ -59,7 +59,8 @@ module OoxmlParser
|
|
|
59
59
|
when 'tblW'
|
|
60
60
|
@table_width = OoxmlSize.new.parse(node_child)
|
|
61
61
|
when 'jc'
|
|
62
|
-
@
|
|
62
|
+
@justification_object = ValuedChild.new(:symbol, parent: self).parse(node_child)
|
|
63
|
+
@jc = @justification_object.value
|
|
63
64
|
when 'shd'
|
|
64
65
|
@shade = Shade.new(parent: self).parse(node_child)
|
|
65
66
|
when 'solidFill'
|
|
@@ -67,7 +68,7 @@ module OoxmlParser
|
|
|
67
68
|
when 'tblLook'
|
|
68
69
|
@table_look = TableLook.new(parent: self).parse(node_child)
|
|
69
70
|
when 'tblInd'
|
|
70
|
-
@table_indent = OoxmlSize.new(
|
|
71
|
+
@table_indent = OoxmlSize.new(parent: self).parse(node_child)
|
|
71
72
|
when 'tblpPr'
|
|
72
73
|
@table_positon = TablePosition.new(parent: self).parse(node_child)
|
|
73
74
|
when 'tblCellMar'
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
module OoxmlParser
|
|
4
4
|
# Class for parsing `u` tags
|
|
5
5
|
class Underline < OOXMLDocumentObject
|
|
6
|
-
attr_accessor :style
|
|
6
|
+
attr_accessor :style
|
|
7
|
+
# @return [Color] color of underline
|
|
8
|
+
attr_accessor :color
|
|
9
|
+
# @return [Symbol] value of underline
|
|
10
|
+
attr_reader :value
|
|
7
11
|
|
|
8
12
|
def initialize(style = :none, color = nil, parent: nil)
|
|
9
13
|
@style = style == 'single' ? :single : style
|
|
@@ -38,6 +42,8 @@ module OoxmlParser
|
|
|
38
42
|
# @param node [Nokogiri::XML:Element] node to parse
|
|
39
43
|
# @return [Underline] result of parsing
|
|
40
44
|
def parse(node)
|
|
45
|
+
parse_attributes(node) if node.is_a?(Nokogiri::XML::Element)
|
|
46
|
+
|
|
41
47
|
case node
|
|
42
48
|
when 'sng'
|
|
43
49
|
@style = :single
|
|
@@ -46,5 +52,20 @@ module OoxmlParser
|
|
|
46
52
|
end
|
|
47
53
|
self
|
|
48
54
|
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# Parse attributes
|
|
59
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
|
60
|
+
def parse_attributes(node)
|
|
61
|
+
node.attributes.each do |key, value|
|
|
62
|
+
case key
|
|
63
|
+
when 'color'
|
|
64
|
+
@color = Color.new(parent: self).parse_hex_string(value.value)
|
|
65
|
+
when 'val'
|
|
66
|
+
@value = value.value.to_sym
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
49
70
|
end
|
|
50
71
|
end
|
|
@@ -23,9 +23,23 @@ module OoxmlParser
|
|
|
23
23
|
@value = value.value.to_s if type == :string
|
|
24
24
|
@value = value_to_symbol(value) if type == :symbol
|
|
25
25
|
@value = value.value.to_i if type == :integer
|
|
26
|
+
@value = value.value.to_f if type == :float
|
|
27
|
+
@value = parse_boolean(value.value.to_s) if type == :boolean
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
self
|
|
29
31
|
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
# Handle boolean value
|
|
36
|
+
# @param [String] value to parse
|
|
37
|
+
# @return [Boolean] result
|
|
38
|
+
def parse_boolean(value)
|
|
39
|
+
return true if value == '1'
|
|
40
|
+
return true if value == 'true'
|
|
41
|
+
return false if value == '0'
|
|
42
|
+
return false if value == 'false'
|
|
43
|
+
end
|
|
30
44
|
end
|
|
31
45
|
end
|
|
@@ -56,6 +56,7 @@ module OoxmlParser
|
|
|
56
56
|
# @param password [String] password to file
|
|
57
57
|
# @return [OoxmlFile] path to decrypted file
|
|
58
58
|
def decrypt(password)
|
|
59
|
+
check_decryption_support
|
|
59
60
|
file_name = File.basename(@path)
|
|
60
61
|
tmp_folder = Dir.mktmpdir('ruby-ooxml-parser')
|
|
61
62
|
decrypted_path = "#{tmp_folder}/#{file_name}"
|
|
@@ -64,5 +65,14 @@ module OoxmlParser
|
|
|
64
65
|
|
|
65
66
|
OoxmlFile.new(decrypted_path)
|
|
66
67
|
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
# Check if file can be decrypted
|
|
72
|
+
# @return [Boolean] is file encrypted
|
|
73
|
+
def check_decryption_support
|
|
74
|
+
# Because of https://github.com/woodbusy/ooxml_decrypt/issues/6
|
|
75
|
+
raise NotImplementedError, 'Cannot decrypt file on `jruby` platform' if RUBY_PLATFORM == 'java'
|
|
76
|
+
end
|
|
67
77
|
end
|
|
68
78
|
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OoxmlParser
|
|
4
|
+
# Helper methods for parsing default style
|
|
5
|
+
module DefaultStyleHelper
|
|
6
|
+
# Parse default style
|
|
7
|
+
# @return [void]
|
|
8
|
+
def parse_default_style
|
|
9
|
+
parse_default_paragraph_style
|
|
10
|
+
parse_default_character_style
|
|
11
|
+
DocumentStructure.default_table_paragraph_style = DocumentStructure.default_paragraph_style.dup
|
|
12
|
+
DocumentStructure.default_table_paragraph_style.spacing = Spacing.new(0, 0, 1, :auto)
|
|
13
|
+
DocumentStructure.default_table_run_style = DocumentStructure.default_run_style.dup
|
|
14
|
+
parse_default_table_style
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Perform parsing styles.xml
|
|
18
|
+
def parse_styles
|
|
19
|
+
file = "#{root_object.unpacked_folder}/word/styles.xml"
|
|
20
|
+
DocumentStructure.default_paragraph_style = DocxParagraph.new(parent: self)
|
|
21
|
+
DocumentStructure.default_table_paragraph_style = DocxParagraph.new(parent: self)
|
|
22
|
+
DocumentStructure.default_run_style = DocxParagraphRun.new(parent: self)
|
|
23
|
+
DocumentStructure.default_table_run_style = DocxParagraphRun.new(parent: self)
|
|
24
|
+
|
|
25
|
+
return unless File.exist?(file)
|
|
26
|
+
|
|
27
|
+
@styles = Styles.new(parent: self).parse
|
|
28
|
+
@numbering = Numbering.new(parent: self).parse
|
|
29
|
+
|
|
30
|
+
if @styles&.document_defaults&.paragraph_properties_default
|
|
31
|
+
DocumentStructure.default_paragraph_style = DocxParagraph.new(parent: self)
|
|
32
|
+
.parse(@styles.document_defaults
|
|
33
|
+
.paragraph_properties_default
|
|
34
|
+
.raw_node, 0)
|
|
35
|
+
end
|
|
36
|
+
if @styles&.document_defaults&.run_properties_default
|
|
37
|
+
DocumentStructure.default_run_style = DocxParagraphRun.new(parent: self)
|
|
38
|
+
.parse_properties(@styles
|
|
39
|
+
.document_defaults
|
|
40
|
+
.run_properties_default
|
|
41
|
+
.run_properties
|
|
42
|
+
.raw_node)
|
|
43
|
+
end
|
|
44
|
+
parse_default_style
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
# Parse default paragraph style
|
|
50
|
+
def parse_default_paragraph_style
|
|
51
|
+
return unless @styles&.default_style(:paragraph)&.paragraph_properties_node
|
|
52
|
+
|
|
53
|
+
DocxParagraph.new.parse_paragraph_style(@styles.default_style(:paragraph)
|
|
54
|
+
.paragraph_properties_node,
|
|
55
|
+
DocumentStructure.default_run_style)
|
|
56
|
+
DocumentStructure.default_run_style
|
|
57
|
+
.parse_properties(@styles.default_style(:paragraph)
|
|
58
|
+
.run_properties_node)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Parse default character style
|
|
62
|
+
def parse_default_character_style
|
|
63
|
+
return unless @styles&.default_style(:character)&.run_properties_node
|
|
64
|
+
|
|
65
|
+
DocumentStructure.default_run_style
|
|
66
|
+
.parse_properties(@styles.default_style(:character)
|
|
67
|
+
.run_properties_node)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Parse default table style
|
|
71
|
+
def parse_default_table_style
|
|
72
|
+
return unless @styles&.default_style(:table)&.run_properties_node
|
|
73
|
+
|
|
74
|
+
DocumentStructure.default_table_run_style
|
|
75
|
+
.parse_properties(@styles.default_style(:table)
|
|
76
|
+
.run_properties_node)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -19,7 +19,12 @@ module OoxmlParser
|
|
|
19
19
|
# @param node [Nokogiri::XML:Element] node to parse
|
|
20
20
|
# @return [DocumentBackground] result of parsing
|
|
21
21
|
def parse(node)
|
|
22
|
-
|
|
22
|
+
node.attributes.each do |key, value|
|
|
23
|
+
case key
|
|
24
|
+
when 'color'
|
|
25
|
+
@color1 = Color.new(parent: self).parse_hex_string(value.value)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
23
28
|
node.xpath('v:background').each do |second_color|
|
|
24
29
|
@size = second_color.attribute('targetscreensize').value.sub(',', 'x') unless second_color.attribute('targetscreensize').nil?
|
|
25
30
|
second_color.xpath('*').each do |node_child|
|
|
@@ -39,6 +39,8 @@ module OoxmlParser
|
|
|
39
39
|
# Used to determine if current style is visible in style list in editors
|
|
40
40
|
# According to http://www.wordarticles.com/Articles/WordStyles/LatentStyles.php
|
|
41
41
|
attr_accessor :q_format
|
|
42
|
+
# @return [Nokogiri::XML:Element] raw node value
|
|
43
|
+
attr_reader :raw_node
|
|
42
44
|
|
|
43
45
|
alias visible? q_format
|
|
44
46
|
|
|
@@ -61,6 +63,7 @@ module OoxmlParser
|
|
|
61
63
|
# Parse single document style
|
|
62
64
|
# @return [DocumentStyle]
|
|
63
65
|
def parse(node)
|
|
66
|
+
@raw_node = node
|
|
64
67
|
node.attributes.each do |key, value|
|
|
65
68
|
case key
|
|
66
69
|
when 'type'
|
|
@@ -74,11 +77,14 @@ module OoxmlParser
|
|
|
74
77
|
node.xpath('*').each do |subnode|
|
|
75
78
|
case subnode.name
|
|
76
79
|
when 'name'
|
|
77
|
-
@
|
|
80
|
+
@name_object = ValuedChild.new(:string, parent: self).parse(subnode)
|
|
81
|
+
@name = @name_object.value
|
|
78
82
|
when 'basedOn'
|
|
79
|
-
@
|
|
83
|
+
@based_on_object = ValuedChild.new(:string, parent: self).parse(subnode)
|
|
84
|
+
@based_on = @based_on_object.value
|
|
80
85
|
when 'next'
|
|
81
|
-
@
|
|
86
|
+
@next_style_object = ValuedChild.new(:string, parent: self).parse(subnode)
|
|
87
|
+
@next_style = @next_style_object.value
|
|
82
88
|
when 'rPr'
|
|
83
89
|
@run_properties_node = subnode
|
|
84
90
|
@run_properties = DocxParagraphRun.new(parent: self).parse_properties(@run_properties_node)
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
module OoxmlParser
|
|
4
4
|
# Class for `acc` data
|
|
5
5
|
class Accent < OOXMLDocumentObject
|
|
6
|
-
|
|
6
|
+
# @return [ValuedChild] symbol object
|
|
7
|
+
attr_reader :symbol_object
|
|
8
|
+
attr_accessor :element
|
|
7
9
|
|
|
8
10
|
# Parse Accent object
|
|
9
11
|
# @param node [Nokogiri::XML:Element] node to parse
|
|
@@ -15,7 +17,7 @@ module OoxmlParser
|
|
|
15
17
|
node_child.xpath('*').each do |node_child_child|
|
|
16
18
|
case node_child_child.name
|
|
17
19
|
when 'chr'
|
|
18
|
-
@
|
|
20
|
+
@symbol_object = ValuedChild.new(:string, parent: self).parse(node_child_child)
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
end
|
|
@@ -23,5 +25,10 @@ module OoxmlParser
|
|
|
23
25
|
@element = DocxFormula.new(parent: self).parse(node)
|
|
24
26
|
self
|
|
25
27
|
end
|
|
28
|
+
|
|
29
|
+
# @return [String] symbol value
|
|
30
|
+
def symbol
|
|
31
|
+
@symbol_object.value
|
|
32
|
+
end
|
|
26
33
|
end
|
|
27
34
|
end
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
module OoxmlParser
|
|
4
4
|
# Class for `bar` data
|
|
5
5
|
class Bar < OOXMLDocumentObject
|
|
6
|
-
|
|
6
|
+
# @return [ValuedChild] position object
|
|
7
|
+
attr_reader :position_object
|
|
8
|
+
attr_accessor :element
|
|
7
9
|
|
|
8
10
|
def initialize(parent: nil)
|
|
9
|
-
@position = :bottom
|
|
10
11
|
super
|
|
11
12
|
end
|
|
12
13
|
|
|
@@ -20,7 +21,7 @@ module OoxmlParser
|
|
|
20
21
|
node_child.xpath('*').each do |node_child_child|
|
|
21
22
|
case node_child_child.name
|
|
22
23
|
when 'pos'
|
|
23
|
-
@
|
|
24
|
+
@position_object = ValuedChild.new(:symbol, parent: self).parse(node_child_child)
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
27
|
end
|
|
@@ -28,5 +29,10 @@ module OoxmlParser
|
|
|
28
29
|
@element = DocxFormula.new(parent: self).parse(node)
|
|
29
30
|
self
|
|
30
31
|
end
|
|
32
|
+
|
|
33
|
+
# @return [Symbol] position of bar
|
|
34
|
+
def position
|
|
35
|
+
@position_object.value
|
|
36
|
+
end
|
|
31
37
|
end
|
|
32
38
|
end
|
data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula/group_char.rb
CHANGED
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
module OoxmlParser
|
|
4
4
|
# Class for `groupChr` data
|
|
5
5
|
class GroupChar < OOXMLDocumentObject
|
|
6
|
-
|
|
6
|
+
# @return [ValuedChild] symbol object
|
|
7
|
+
attr_reader :symbol_object
|
|
8
|
+
# @return [ValuedChild] position object
|
|
9
|
+
attr_reader :position_object
|
|
10
|
+
# @return [ValuedChild] vertical align object
|
|
11
|
+
attr_reader :vertical_align_object
|
|
12
|
+
attr_accessor :element
|
|
7
13
|
|
|
8
14
|
# Parse GroupChar object
|
|
9
15
|
# @param node [Nokogiri::XML:Element] node to parse
|
|
@@ -15,11 +21,11 @@ module OoxmlParser
|
|
|
15
21
|
node_child.xpath('*').each do |node_child_child|
|
|
16
22
|
case node_child_child.name
|
|
17
23
|
when 'chr'
|
|
18
|
-
@
|
|
24
|
+
@symbol_object = ValuedChild.new(:string, parent: self).parse(node_child_child)
|
|
19
25
|
when 'pos'
|
|
20
|
-
@
|
|
26
|
+
@position_object = ValuedChild.new(:string, parent: self).parse(node_child_child)
|
|
21
27
|
when 'vertJc'
|
|
22
|
-
@
|
|
28
|
+
@vertical_align_object = ValuedChild.new(:string, parent: self).parse(node_child_child)
|
|
23
29
|
end
|
|
24
30
|
end
|
|
25
31
|
end
|
|
@@ -27,5 +33,20 @@ module OoxmlParser
|
|
|
27
33
|
@element = DocxFormula.new(parent: self).parse(node)
|
|
28
34
|
self
|
|
29
35
|
end
|
|
36
|
+
|
|
37
|
+
# @return [String] symbol value
|
|
38
|
+
def symbol
|
|
39
|
+
@symbol_object.value
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @return [String] position value
|
|
43
|
+
def position
|
|
44
|
+
@position_object.value
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @return [String] vertical align value
|
|
48
|
+
def vertical_align
|
|
49
|
+
@vertical_align_object.value
|
|
50
|
+
end
|
|
30
51
|
end
|
|
31
52
|
end
|
|
@@ -22,7 +22,8 @@ module OoxmlParser
|
|
|
22
22
|
mcs.xpath('m:mc').each do |mc|
|
|
23
23
|
mc.xpath('m:mcPr').each do |mc_pr|
|
|
24
24
|
mc_pr.xpath('m:count').each do |count|
|
|
25
|
-
|
|
25
|
+
count_object = ValuedChild.new(:integer, parent: self).parse(count)
|
|
26
|
+
columns_count = count_object.value
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
29
|
end
|
|
@@ -11,33 +11,40 @@ module OoxmlParser
|
|
|
11
11
|
node.xpath('*').each do |node_child|
|
|
12
12
|
case node_child.name
|
|
13
13
|
when 'rFonts'
|
|
14
|
+
run_fonts = RunFonts.new(parent: self).parse(node_child)
|
|
14
15
|
node_child.attributes.each do |font_attribute, value|
|
|
15
16
|
case font_attribute
|
|
16
17
|
when 'asciiTheme'
|
|
17
|
-
theme = node_child.attribute('asciiTheme').value
|
|
18
18
|
next unless root_object.theme
|
|
19
19
|
|
|
20
|
-
self.font = root_object.theme.font_scheme.major_font.latin.typeface if
|
|
21
|
-
self.font = root_object.theme.font_scheme.minor_font.latin.typeface if
|
|
20
|
+
self.font = root_object.theme.font_scheme.major_font.latin.typeface if run_fonts.ascii_theme.include?('major')
|
|
21
|
+
self.font = root_object.theme.font_scheme.minor_font.latin.typeface if run_fonts.ascii_theme.include?('minor')
|
|
22
22
|
when 'ascii'
|
|
23
23
|
self.font = value.value
|
|
24
24
|
break
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
when 'sz'
|
|
28
|
-
|
|
28
|
+
@size_object = ValuedChild.new(:integer, parent: self).parse(node_child)
|
|
29
|
+
self.size = @size_object.value.to_i / 2.0
|
|
29
30
|
when 'highlight'
|
|
30
|
-
|
|
31
|
+
@highlight_object = ValuedChild.new(:string, parent: self).parse(node_child)
|
|
32
|
+
self.highlight = @highlight_object.value
|
|
31
33
|
when 'vertAlign'
|
|
32
|
-
|
|
34
|
+
@vertical_align_object = ValuedChild.new(:symbol, parent: self).parse(node_child)
|
|
35
|
+
self.vertical_align = @vertical_align_object.value
|
|
33
36
|
when 'effect'
|
|
34
|
-
|
|
37
|
+
@effect_object = ValuedChild.new(:string, parent: self).parse(node_child)
|
|
38
|
+
self.effect = @effect_object.value
|
|
35
39
|
when 'position'
|
|
36
|
-
|
|
40
|
+
@position_object = ValuedChild.new(:integer, parent: self).parse(node_child)
|
|
41
|
+
self.position = (@position_object.value.to_f / (28.0 + (1.0 / 3.0)) / 2.0).round(1)
|
|
37
42
|
when 'em'
|
|
38
|
-
|
|
43
|
+
@em_object = ValuedChild.new(:string, parent: self).parse(node_child)
|
|
44
|
+
self.em = @em_object.value
|
|
39
45
|
when 'spacing'
|
|
40
|
-
|
|
46
|
+
@spacing_object = RunSpacing.new(parent: self).parse(node_child)
|
|
47
|
+
self.spacing = (@spacing_object.value.value.to_f / 566.9).round(1)
|
|
41
48
|
when 'textFill'
|
|
42
49
|
self.text_fill = TextFill.new(parent: self).parse(node_child)
|
|
43
50
|
when 'textOutline'
|
|
@@ -98,12 +105,13 @@ module OoxmlParser
|
|
|
98
105
|
# @param node [Nokogiri::XML:Element] node to parse
|
|
99
106
|
# @return [nil]
|
|
100
107
|
def parse_underline(node)
|
|
108
|
+
underline_object = Underline.new.parse(node)
|
|
101
109
|
font_style.underlined = Underline.new
|
|
102
110
|
|
|
103
|
-
return unless
|
|
111
|
+
return unless underline_object.value
|
|
104
112
|
|
|
105
|
-
font_style.underlined.style =
|
|
106
|
-
font_style.underlined.color =
|
|
113
|
+
font_style.underlined.style = underline_object.value
|
|
114
|
+
font_style.underlined.color = underline_object.color if underline_object.color
|
|
107
115
|
end
|
|
108
116
|
end
|
|
109
117
|
end
|
data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/field_char.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OoxmlParser
|
|
4
|
+
# Class for parsing `w:fldChar` object
|
|
5
|
+
class FieldChar < OOXMLDocumentObject
|
|
6
|
+
# @return [Symbol] type of field char
|
|
7
|
+
attr_accessor :type
|
|
8
|
+
|
|
9
|
+
# Parse FieldChar
|
|
10
|
+
# @param [Nokogiri::XML:Node] node with FieldChar
|
|
11
|
+
# @return [FieldChar] result of parsing
|
|
12
|
+
def parse(node)
|
|
13
|
+
node.attributes.each do |key, value|
|
|
14
|
+
case key
|
|
15
|
+
when 'fldCharType'
|
|
16
|
+
@type = value.value.to_sym
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
self
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'docx_paragraph_run/docx_paragraph_run_helpers'
|
|
4
|
+
require_relative 'docx_paragraph_run/field_char'
|
|
4
5
|
require_relative 'docx_paragraph_run/instruction_text'
|
|
5
6
|
require_relative 'docx_paragraph_run/object'
|
|
6
7
|
require_relative 'docx_paragraph_run/text_outline'
|
|
@@ -103,7 +104,8 @@ module OoxmlParser
|
|
|
103
104
|
@text = '*PAGE NUMBER*'
|
|
104
105
|
end
|
|
105
106
|
when 'fldChar'
|
|
106
|
-
@
|
|
107
|
+
@field_char_object = FieldChar.new(parent: self).parse(node_child)
|
|
108
|
+
@fld_char = @field_char_object.type
|
|
107
109
|
when 't'
|
|
108
110
|
@text += node_child.text
|
|
109
111
|
when 'noBreakHyphen'
|
|
@@ -23,9 +23,9 @@ module OoxmlParser
|
|
|
23
23
|
node.attributes.each do |key, value|
|
|
24
24
|
case key
|
|
25
25
|
when 'multiLine'
|
|
26
|
-
@multiline =
|
|
26
|
+
@multiline = boolean_attribute_value(value)
|
|
27
27
|
when 'autoFit'
|
|
28
|
-
@autofit =
|
|
28
|
+
@autofit = boolean_attribute_value(value)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -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
|