ooxml_parser 0.33.0 → 0.34.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 +22 -6
- 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 +21 -2
- data/lib/ooxml_parser/common_parser/parser/ooxml_file.rb +10 -0
- data/lib/ooxml_parser/docx_parser/document_structure/default_style_helper.rb +84 -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 +25 -8
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dc34421044dd53e46d0d5c355dac61acfe6bbb825381cb4c1d0aca2b5b78daf
|
4
|
+
data.tar.gz: d7ef26c1cdc5d94a7c355ae64437f23663d5c1579d651427bbac0bf83a03964e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 358fb82db492d965faeb84fcb356d18db1e04c759bd17e2cb76398abe20b353e76fb7f4359c7235f2004f4acdc440c0b1fb8bddc8b0075c65f5832caca0d8c16
|
7
|
+
data.tar.gz: e1d817d32dc5de38bb6ae960a50300068405fc079eb63f14c266a4cf472840f706e54586996b45ba80cb4af16c6615a05eafc56889a55f1289ea32fa1a551c66
|
@@ -8,6 +8,8 @@ require_relative 'graphic/docx_graphic'
|
|
8
8
|
module OoxmlParser
|
9
9
|
# Class for parsing `graphic` tags
|
10
10
|
class DocxDrawing < OOXMLDocumentObject
|
11
|
+
# @return [String] id of drawing
|
12
|
+
attr_reader :id
|
11
13
|
attr_accessor :type, :properties, :graphic
|
12
14
|
# @return [DocProperties] doc properties
|
13
15
|
attr_accessor :doc_properties
|
@@ -23,6 +25,13 @@ module OoxmlParser
|
|
23
25
|
# @param [Nokogiri::XML:Node] node with NumberingProperties
|
24
26
|
# @return [DocxDrawing] result of parsing
|
25
27
|
def parse(node)
|
28
|
+
node.attributes.each do |key, value|
|
29
|
+
case key
|
30
|
+
when 'id'
|
31
|
+
@id = value.value.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
26
35
|
node.xpath('*').each do |node_child|
|
27
36
|
case node_child.name
|
28
37
|
when 'anchor'
|
@@ -44,9 +44,13 @@ module OoxmlParser
|
|
44
44
|
node.xpath('*').each do |content_node_child|
|
45
45
|
case content_node_child.name
|
46
46
|
when 'simplePos'
|
47
|
-
@simple_position = OOXMLCoordinates.parse(content_node_child)
|
47
|
+
@simple_position = OOXMLCoordinates.new(parent: self).parse(content_node_child)
|
48
48
|
when 'extent'
|
49
|
-
@object_size = OOXMLCoordinates.
|
49
|
+
@object_size = OOXMLCoordinates.new(parent: self)
|
50
|
+
.parse(content_node_child,
|
51
|
+
x_attr: 'cx',
|
52
|
+
y_attr: 'cy',
|
53
|
+
unit: :emu)
|
50
54
|
when 'positionV'
|
51
55
|
@vertical_position = DocxDrawingPosition.new(parent: self).parse(content_node_child)
|
52
56
|
when 'positionH'
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Docx Coordinates
|
5
|
-
class OOXMLCoordinates
|
5
|
+
class OOXMLCoordinates < OOXMLDocumentObject
|
6
6
|
attr_accessor :x, :y
|
7
7
|
|
8
|
-
def initialize(x_value, y_value)
|
8
|
+
def initialize(x_value = nil, y_value = nil, parent: nil)
|
9
9
|
@x = if x_value.is_a?(OoxmlSize)
|
10
10
|
x_value
|
11
11
|
else
|
@@ -16,6 +16,7 @@ module OoxmlParser
|
|
16
16
|
else
|
17
17
|
OoxmlSize.new(y_value)
|
18
18
|
end
|
19
|
+
super(parent: parent)
|
19
20
|
end
|
20
21
|
|
21
22
|
# @return [String] result of convert of object to string
|
@@ -25,22 +26,27 @@ module OoxmlParser
|
|
25
26
|
|
26
27
|
# Compare two OOXMLCoordinates objects
|
27
28
|
# @param other [OOXMLCoordinates] other object
|
28
|
-
# @return [True, False] result of
|
29
|
+
# @return [True, False] result of comparison
|
29
30
|
def ==(other)
|
30
31
|
x == other.x && y == other.y
|
31
32
|
end
|
32
33
|
|
33
34
|
# Parse OOXMLCoordinates object
|
34
|
-
# @param
|
35
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
35
36
|
# @param x_attr [String] name of x attribute
|
36
37
|
# @param y_attr [String] name of y attribute
|
37
38
|
# @param unit [Symbol] unit in which data is stored
|
38
39
|
# @return [OOXMLCoordinates] result of parsing
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def parse(node, x_attr: 'x', y_attr: 'y', unit: :dxa)
|
41
|
+
node.attributes.each do |key, value|
|
42
|
+
case key
|
43
|
+
when x_attr
|
44
|
+
@x = OoxmlSize.new(value.value.to_f, unit)
|
45
|
+
when y_attr
|
46
|
+
@y = OoxmlSize.new(value.value.to_f, unit)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
self
|
44
50
|
end
|
45
51
|
end
|
46
52
|
end
|
data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/docx_graphic.rb
CHANGED
@@ -23,7 +23,8 @@ module OoxmlParser
|
|
23
23
|
@data = DocxPicture.new(parent: self).parse(node_child)
|
24
24
|
when 'chart'
|
25
25
|
@type = :chart
|
26
|
-
|
26
|
+
@chart_reference = ChartReference.new(parent: self).parse(node_child)
|
27
|
+
root_object.add_to_xmls_stack("#{root_object.root_subfolder}/#{root_object.get_link_from_rels(@chart_reference.id)}")
|
27
28
|
@data = Chart.new(parent: self).parse
|
28
29
|
root_object.xmls_stack.pop
|
29
30
|
when 'wgp'
|
@@ -37,13 +37,13 @@ module OoxmlParser
|
|
37
37
|
node.xpath('*').each do |node_child|
|
38
38
|
case node_child.name
|
39
39
|
when 'off'
|
40
|
-
@offset = OOXMLCoordinates.parse(node_child, unit: :emu)
|
40
|
+
@offset = OOXMLCoordinates.new(parent: self).parse(node_child, unit: :emu)
|
41
41
|
when 'ext'
|
42
|
-
@extent = OOXMLCoordinates.parse(node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
|
42
|
+
@extent = OOXMLCoordinates.new(parent: self).parse(node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
|
43
43
|
when 'chOff'
|
44
|
-
@child_offset = OOXMLCoordinates.parse(node_child, unit: :emu)
|
44
|
+
@child_offset = OOXMLCoordinates.new(parent: self).parse(node_child, unit: :emu)
|
45
45
|
when 'chExt'
|
46
|
-
@child_extent = OOXMLCoordinates.parse(node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
|
46
|
+
@child_extent = OOXMLCoordinates.new(parent: self).parse(node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
self
|
@@ -50,8 +50,6 @@ module OoxmlParser
|
|
50
50
|
# @param [Nokogiri::XML:Element] node with BordersProperties
|
51
51
|
# @return [BordersProperties] value of BordersProperties
|
52
52
|
def parse(node)
|
53
|
-
return nil if node.attribute('val').value == 'nil'
|
54
|
-
|
55
53
|
node.attributes.each do |key, value|
|
56
54
|
case key
|
57
55
|
when 'val'
|
@@ -67,6 +65,8 @@ module OoxmlParser
|
|
67
65
|
@shadow = value.value
|
68
66
|
end
|
69
67
|
end
|
68
|
+
return nil if @val == :nil
|
69
|
+
|
70
70
|
self
|
71
71
|
end
|
72
72
|
end
|
@@ -3,26 +3,27 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Helper methods for color
|
5
5
|
module ColorHelper
|
6
|
+
# @return [String] value for auto string
|
7
|
+
AUTO_STRING_VALUE = 'auto'
|
8
|
+
# @return [Regexp] regexp for hex string with 3 digits
|
9
|
+
REGEXP_THREE_DIGITS = /(.)(.)(.)/.freeze
|
10
|
+
# @return [Regexp] regexp for hex string with 6 digits
|
11
|
+
REGEXP_SIX_DIGITS = /(..)(..)(..)/.freeze
|
12
|
+
# @return [Regexp] regexp for hex string with 8 digits
|
13
|
+
REGEXP_EIGHT_DIGITS = /(..)(..)(..)(..)/.freeze
|
14
|
+
|
6
15
|
# Parse string in hex
|
7
16
|
# @param [String] hex_string with or without alpha-channel
|
8
17
|
def parse_hex_string(hex_string)
|
9
|
-
return self if
|
18
|
+
return self if AUTO_STRING_VALUE == hex_string
|
10
19
|
|
11
|
-
|
12
|
-
case char_array.length
|
20
|
+
case hex_string.length
|
13
21
|
when 3
|
14
|
-
@red =
|
15
|
-
@green = char_array[1].hex
|
16
|
-
@blue = char_array[2].hex
|
22
|
+
@red, @green, @blue = hex_string.match(REGEXP_THREE_DIGITS).captures.map(&:hex)
|
17
23
|
when 6
|
18
|
-
@red = (
|
19
|
-
@green = (char_array[2] + char_array[3]).hex
|
20
|
-
@blue = (char_array[4] + char_array[5]).hex
|
24
|
+
@red, @green, @blue = hex_string.match(REGEXP_SIX_DIGITS).captures.map(&:hex)
|
21
25
|
when 8
|
22
|
-
@alpha_channel = (
|
23
|
-
@red = (char_array[2] + char_array[3]).hex
|
24
|
-
@green = (char_array[4] + char_array[5]).hex
|
25
|
-
@blue = (char_array[6] + char_array[7]).hex
|
26
|
+
@alpha_channel, @red, @green, @blue = hex_string.match(REGEXP_EIGHT_DIGITS).captures.map(&:hex)
|
26
27
|
end
|
27
28
|
self
|
28
29
|
end
|
@@ -101,7 +101,7 @@ module OoxmlParser
|
|
101
101
|
|
102
102
|
# Compare this object to other
|
103
103
|
# @param other [Object] any other object
|
104
|
-
# @return [True, False] result of
|
104
|
+
# @return [True, False] result of comparison
|
105
105
|
def ==(other)
|
106
106
|
if other.is_a?(Color)
|
107
107
|
((@red == other.red) && (@green == other.green) && (@blue == other.blue)) ||
|
@@ -117,7 +117,7 @@ module OoxmlParser
|
|
117
117
|
# @param [Integer] delta max delta for each of specters
|
118
118
|
def looks_like?(color_to_check = nil, delta = 8)
|
119
119
|
color_to_check = color_to_check.converted_color if color_to_check.is_a?(SchemeColor)
|
120
|
-
color_to_check = color_to_check.pattern_fill.
|
120
|
+
color_to_check = color_to_check.pattern_fill.foreground_color if color_to_check.is_a?(Fill)
|
121
121
|
color_to_check = color_to_check.color.converted_color if color_to_check.is_a?(PresentationFill)
|
122
122
|
color_to_check = Color.parse(color_to_check) if color_to_check.is_a?(String)
|
123
123
|
color_to_check = Color.parse(color_to_check.to_s) if color_to_check.is_a?(Symbol)
|
@@ -128,10 +128,9 @@ module OoxmlParser
|
|
128
128
|
return false if !none? && color_to_check.none?
|
129
129
|
return true if self == color_to_check
|
130
130
|
|
131
|
-
red
|
132
|
-
|
133
|
-
|
134
|
-
(self.red - red).abs < delta && (self.green - green).abs < delta && (self.blue - blue).abs < delta
|
131
|
+
(red - color_to_check.red).abs < delta &&
|
132
|
+
(green - color_to_check.green).abs < delta &&
|
133
|
+
(blue - color_to_check.blue).abs < delta
|
135
134
|
end
|
136
135
|
|
137
136
|
# Apply tint to color
|
@@ -156,7 +155,8 @@ module OoxmlParser
|
|
156
155
|
# @param scheme_color_node [Nokogiri::XML:Element] node to parse
|
157
156
|
# @return [Color] result of parsing
|
158
157
|
def parse_scheme_color(scheme_color_node)
|
159
|
-
|
158
|
+
scheme_clr_object = ValuedChild.new(:symbol, parent: self).parse(scheme_color_node)
|
159
|
+
color_scheme_color = root_object.theme.color_scheme[scheme_clr_object.value]
|
160
160
|
return unless color_scheme_color
|
161
161
|
|
162
162
|
color = color_scheme_color.color
|
@@ -165,9 +165,11 @@ module OoxmlParser
|
|
165
165
|
scheme_color_node.xpath('*').each do |scheme_color_node_child|
|
166
166
|
case scheme_color_node_child.name
|
167
167
|
when 'lumMod'
|
168
|
-
|
168
|
+
luminance_modulation = ValuedChild.new(:float, parent: self).parse(scheme_color_node_child)
|
169
|
+
hls.l = hls.l * (luminance_modulation.value / 100_000.0)
|
169
170
|
when 'lumOff'
|
170
|
-
|
171
|
+
luminance_offset = ValuedChild.new(:float, parent: self).parse(scheme_color_node_child)
|
172
|
+
hls.l = hls.l + (luminance_offset.value / 100_000.0)
|
171
173
|
end
|
172
174
|
end
|
173
175
|
scheme_color_node.attributes.each do |key, value|
|
@@ -180,7 +182,7 @@ module OoxmlParser
|
|
180
182
|
@red = color.red
|
181
183
|
@green = color.green
|
182
184
|
@blue = color.blue
|
183
|
-
@alpha_channel = ColorAlphaChannel.parse(scheme_color_node)
|
185
|
+
@alpha_channel = ColorAlphaChannel.new(parent: self).parse(scheme_color_node).value
|
184
186
|
@scheme = scheme_name
|
185
187
|
self
|
186
188
|
end
|
@@ -200,8 +202,9 @@ module OoxmlParser
|
|
200
202
|
end
|
201
203
|
case color_model_node.name
|
202
204
|
when 'srgbClr'
|
203
|
-
|
204
|
-
color
|
205
|
+
valued_child = ValuedChild.new(:string, parent: self).parse(color_model_node)
|
206
|
+
color = Color.new.parse_hex_string(valued_child.value)
|
207
|
+
color.alpha_channel = ColorAlphaChannel.new(parent: self).parse(color_model_node).value
|
205
208
|
when 'schemeClr'
|
206
209
|
color = Color.new(parent: self).parse_scheme_color(color_model_node)
|
207
210
|
end
|
@@ -230,7 +233,8 @@ module OoxmlParser
|
|
230
233
|
color = SchemeColor.new(parent: parent)
|
231
234
|
return ValuedChild.new(:string, parent: parent).parse(color_node) unless root_object.theme
|
232
235
|
|
233
|
-
|
236
|
+
scheme_clr_object = ValuedChild.new(:symbol, parent: self).parse(color_node)
|
237
|
+
color.value = root_object.theme.color_scheme[scheme_clr_object.value].color
|
234
238
|
color.properties = ColorProperties.new(parent: color).parse(color_node)
|
235
239
|
color.converted_color = Color.new(parent: self).parse_scheme_color(color_node)
|
236
240
|
color.value.calculate_with_tint!(1.0 - color.properties.tint) if color.properties.tint
|
@@ -2,16 +2,30 @@
|
|
2
2
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Class for working with AlphaChannel
|
5
|
-
class ColorAlphaChannel
|
5
|
+
class ColorAlphaChannel < OOXMLDocumentObject
|
6
|
+
# @return [Integer] value of alpha channel
|
7
|
+
attr_reader :value
|
8
|
+
|
6
9
|
# Parse AlphaChannel value
|
7
10
|
# @param node [Nokogiri::XML::Element] node to parse
|
8
|
-
# @return [
|
9
|
-
def
|
11
|
+
# @return [ColorAlphaChannel] parsed object
|
12
|
+
def parse(node)
|
10
13
|
alpha_channel_node = node.xpath('a:alpha', 'xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main').first
|
11
14
|
alpha_channel_node = node.xpath('w14:alpha', 'xmlns:w14' => 'http://schemas.microsoft.com/office/word/2010/wordml').first if alpha_channel_node.nil?
|
12
|
-
return 100.0 if alpha_channel_node.nil?
|
13
15
|
|
14
|
-
|
16
|
+
unless alpha_channel_node
|
17
|
+
@value = 100.0
|
18
|
+
return self
|
19
|
+
end
|
20
|
+
|
21
|
+
alpha_channel_node.attributes.each do |key, value|
|
22
|
+
case key
|
23
|
+
when 'val'
|
24
|
+
@value = (value.value.to_f / 1_000.0).round(0)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
self
|
15
29
|
end
|
16
30
|
end
|
17
31
|
end
|
@@ -3,14 +3,14 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Class for color transformations
|
5
5
|
class ColorProperties < OOXMLDocumentObject
|
6
|
-
# @return [
|
7
|
-
attr_reader :
|
8
|
-
# @return [
|
9
|
-
attr_reader :
|
10
|
-
# @return [
|
11
|
-
attr_reader :
|
12
|
-
# @return [
|
13
|
-
attr_reader :
|
6
|
+
# @return [ValuedChild] alpha value of color object
|
7
|
+
attr_reader :alpha_object
|
8
|
+
# @return [ValuedChild] luminance modulation value object
|
9
|
+
attr_reader :luminance_modulation_object
|
10
|
+
# @return [ValuedChild] luminance offset value object
|
11
|
+
attr_reader :luminance_offset_object
|
12
|
+
# @return [ValuedChild] tint value object
|
13
|
+
attr_reader :tint_object
|
14
14
|
|
15
15
|
# Parse ColorProperties object
|
16
16
|
# @param node [Nokogiri::XML:Element] node to parse
|
@@ -19,16 +19,38 @@ module OoxmlParser
|
|
19
19
|
node.xpath('*').each do |node_child|
|
20
20
|
case node_child.name
|
21
21
|
when 'alpha'
|
22
|
-
@
|
22
|
+
@alpha_object = ValuedChild.new(:float, parent: self).parse(node_child)
|
23
23
|
when 'lumMod'
|
24
|
-
@
|
24
|
+
@luminance_modulation_object = ValuedChild.new(:float, parent: self).parse(node_child)
|
25
25
|
when 'lumOff'
|
26
|
-
@
|
26
|
+
@luminance_offset_object = ValuedChild.new(:float, parent: self).parse(node_child)
|
27
27
|
when 'tint'
|
28
|
-
@
|
28
|
+
@tint_object = ValuedChild.new(:float, parent: self).parse(node_child)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
self
|
32
32
|
end
|
33
|
+
|
34
|
+
# @return [Integer] alpha value
|
35
|
+
def alpha
|
36
|
+
(@alpha_object.value / 1_000.0).round
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Float] luminance modulation value
|
40
|
+
def luminance_modulation
|
41
|
+
@luminance_modulation_object.value / 100_000.0
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Float] luminance offset value
|
45
|
+
def luminance_offset
|
46
|
+
@luminance_offset_object.value / 100_000.0
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [nil, Float] tint value
|
50
|
+
def tint
|
51
|
+
return nil unless @tint_object
|
52
|
+
|
53
|
+
@tint_object.value / 100_000.0
|
54
|
+
end
|
33
55
|
end
|
34
56
|
end
|
@@ -22,8 +22,8 @@ module OoxmlParser
|
|
22
22
|
when 'blip'
|
23
23
|
@file_reference = FileReference.new(parent: self).parse(node_child)
|
24
24
|
when 'tile'
|
25
|
-
@tile = Tile.new(OOXMLCoordinates.parse(node_child, x_attr: 'tx', y_attr: 'ty'),
|
26
|
-
OOXMLCoordinates.parse(node_child, x_attr: 'sx', y_attr: 'sy'),
|
25
|
+
@tile = Tile.new(OOXMLCoordinates.new(parent: self).parse(node_child, x_attr: 'tx', y_attr: 'ty'),
|
26
|
+
OOXMLCoordinates.new(parent: self).parse(node_child, x_attr: 'sx', y_attr: 'sy'),
|
27
27
|
parent: self).parse(node_child)
|
28
28
|
end
|
29
29
|
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Class for parsing `hlinkClick`, `hyperlink` tags
|
5
5
|
class Hyperlink < OOXMLDocumentObject
|
6
|
+
# @return [String] anchor value
|
7
|
+
attr_reader :anchor
|
6
8
|
# @return [OOXMLDocumentObject] url of hyperlink
|
7
9
|
attr_accessor :url
|
8
10
|
# @return [String] tooltip value
|
@@ -42,6 +44,8 @@ module OoxmlParser
|
|
42
44
|
def parse(node)
|
43
45
|
node.attributes.each do |key, value|
|
44
46
|
case key
|
47
|
+
when 'anchor'
|
48
|
+
@anchor = value.value
|
45
49
|
when 'location'
|
46
50
|
@url = Coordinates.new.parse_string(value.value)
|
47
51
|
when 'id'
|
@@ -40,14 +40,35 @@ module OoxmlParser
|
|
40
40
|
true
|
41
41
|
end
|
42
42
|
|
43
|
+
# @param [String, Nokogiri::XML:Attribute] value to check
|
44
|
+
# @return [True, False] value of attribute
|
45
|
+
def boolean_attribute_value(value)
|
46
|
+
return true if value.to_s == '1'
|
47
|
+
return true if value.to_s == 'true'
|
48
|
+
return false if value.to_s == '0'
|
49
|
+
return false if value.to_s == 'false'
|
50
|
+
end
|
51
|
+
|
43
52
|
# @return [Nokogiri::XML::Document] result of parsing xml via nokogiri
|
44
53
|
def parse_xml(xml_path)
|
45
54
|
xml = Nokogiri::XML(File.open(xml_path), &:strict)
|
46
55
|
unless xml.errors.empty?
|
47
56
|
raise NokogiriParsingException,
|
48
|
-
|
57
|
+
parse_error_message(xml_path, xml.errors)
|
49
58
|
end
|
50
59
|
xml
|
60
|
+
rescue Nokogiri::XML::SyntaxError => e
|
61
|
+
raise NokogiriParsingException,
|
62
|
+
parse_error_message(xml_path, e)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# @param [String] xml_path path to xml
|
68
|
+
# @param [String] errors errors
|
69
|
+
# @return [String] error string
|
70
|
+
def parse_error_message(xml_path, errors)
|
71
|
+
"Nokogiri found errors in file: #{xml_path}. Errors: #{errors}"
|
51
72
|
end
|
52
73
|
end
|
53
74
|
end
|
@@ -3,16 +3,20 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Class for parsing `numPr` tags
|
5
5
|
class NumberingProperties < OOXMLDocumentObject
|
6
|
-
attr_accessor :size, :font, :symbol, :start_at, :type, :image
|
6
|
+
attr_accessor :size, :font, :symbol, :start_at, :type, :image
|
7
|
+
# @return [ValuedChild] i level
|
8
|
+
attr_reader :i_level
|
9
|
+
# @return [ValuedChild] numbering id
|
10
|
+
attr_reader :num_id
|
7
11
|
|
8
12
|
def initialize(ilvl = 0, parent: nil)
|
9
|
-
@
|
13
|
+
@default_i_level = ilvl
|
10
14
|
super(parent: parent)
|
11
15
|
end
|
12
16
|
|
13
17
|
# @return [AbstractNumbering] AbstractNumbering of current properties
|
14
18
|
def abstruct_numbering
|
15
|
-
root_object.numbering.properties_by_num_id(
|
19
|
+
root_object.numbering.properties_by_num_id(numbering_properties)
|
16
20
|
end
|
17
21
|
|
18
22
|
# Parse NumberingProperties
|
@@ -22,18 +26,30 @@ module OoxmlParser
|
|
22
26
|
node.xpath('*').each do |node_child|
|
23
27
|
case node_child.name
|
24
28
|
when 'ilvl'
|
25
|
-
@
|
29
|
+
@i_level = ValuedChild.new(:integer, parent: self).parse(node_child)
|
26
30
|
when 'numId'
|
27
|
-
@
|
31
|
+
@num_id = ValuedChild.new(:integer, parent: self).parse(node_child)
|
28
32
|
end
|
29
33
|
end
|
30
34
|
self
|
31
35
|
end
|
32
36
|
|
37
|
+
# @return [Integer] numbering properties
|
38
|
+
def numbering_properties
|
39
|
+
@num_id.value
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Integer] i-level value
|
43
|
+
def ilvl
|
44
|
+
return @default_i_level unless @i_level
|
45
|
+
|
46
|
+
@i_level.value
|
47
|
+
end
|
48
|
+
|
33
49
|
# @return [AbstractNumbering] level list of current numbering
|
34
50
|
def numbering_level_current
|
35
51
|
abstruct_numbering.level_list.each do |current_ilvl|
|
36
|
-
return current_ilvl if current_ilvl.ilvl ==
|
52
|
+
return current_ilvl if current_ilvl.ilvl == ilvl
|
37
53
|
end
|
38
54
|
nil
|
39
55
|
end
|
@@ -101,9 +101,11 @@ module OoxmlParser
|
|
101
101
|
when 'spacing'
|
102
102
|
@spacing = ParagraphSpacing.new(parent: self).parse(node_child)
|
103
103
|
when 'jc'
|
104
|
-
@
|
104
|
+
@justification_object = ValuedChild.new(:string, parent: self).parse(node_child)
|
105
|
+
@justification = value_to_symbol(@justification_object)
|
105
106
|
when 'contextualSpacing'
|
106
|
-
|
107
|
+
contextual_spacing_object = ValuedChild.new(:boolean, parent: self).parse(node_child)
|
108
|
+
@contextual_spacing = contextual_spacing_object.value
|
107
109
|
end
|
108
110
|
end
|
109
111
|
self
|
data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/run_fonts.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OoxmlParser
|
4
|
+
# Class for parsing `w:rFonts` object
|
5
|
+
class RunFonts < OOXMLDocumentObject
|
6
|
+
# @return [String] ascii font
|
7
|
+
attr_accessor :ascii
|
8
|
+
# @return [String] ascii theme value
|
9
|
+
attr_accessor :ascii_theme
|
10
|
+
|
11
|
+
# Parse RunFonts
|
12
|
+
# @param [Nokogiri::XML:Node] node with RunFonts
|
13
|
+
# @return [RunFonts] result of parsing
|
14
|
+
def parse(node)
|
15
|
+
node.attributes.each do |key, value|
|
16
|
+
case key
|
17
|
+
when 'ascii'
|
18
|
+
@ascii = value.to_s
|
19
|
+
when 'asciiTheme'
|
20
|
+
@ascii_theme = value.to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -2,10 +2,12 @@
|
|
2
2
|
|
3
3
|
require_relative 'run_properties/outline'
|
4
4
|
require_relative 'run_properties/position'
|
5
|
-
require_relative 'run_properties/
|
5
|
+
require_relative 'run_properties/run_fonts'
|
6
6
|
require_relative 'run_properties/run_spacing'
|
7
7
|
require_relative 'run_properties/run_style'
|
8
8
|
require_relative 'run_properties/shade'
|
9
|
+
require_relative 'run_properties/size'
|
10
|
+
|
9
11
|
module OoxmlParser
|
10
12
|
# Data about `rPr` object
|
11
13
|
class RunProperties < OOXMLDocumentObject
|
@@ -49,6 +51,10 @@ module OoxmlParser
|
|
49
51
|
attr_accessor :run_style
|
50
52
|
# @return [ValuedChild] ligatures type
|
51
53
|
attr_reader :ligatures
|
54
|
+
# @return [RunFonts] value of RunFonts
|
55
|
+
attr_reader :run_fonts
|
56
|
+
# @return [Nokogiri::XML:Element] raw node value
|
57
|
+
attr_reader :raw_node
|
52
58
|
|
53
59
|
def initialize(params = {})
|
54
60
|
@font_name = params.fetch(:font_name, '')
|
@@ -61,6 +67,7 @@ module OoxmlParser
|
|
61
67
|
# @param node [Nokogiri::XML:Element] node to parse
|
62
68
|
# @return [RunProperties] result of parsing
|
63
69
|
def parse(node)
|
70
|
+
@raw_node = node
|
64
71
|
@font_style = root_object.default_font_style.dup
|
65
72
|
node.attributes.each do |key, value|
|
66
73
|
case key
|
@@ -107,11 +114,12 @@ module OoxmlParser
|
|
107
114
|
when 'u'
|
108
115
|
@font_style.underlined = Underline.new(:single)
|
109
116
|
when 'vertAlign'
|
110
|
-
@
|
117
|
+
@vertical_align_object = ValuedChild.new(:symbol, parent: self).parse(node_child)
|
118
|
+
@vertical_align = @vertical_align_object.value
|
111
119
|
when 'rFont'
|
112
120
|
@font_name = node_child.attribute('val').value
|
113
121
|
when 'rFonts'
|
114
|
-
@
|
122
|
+
@run_fonts = RunFonts.new(parent: self).parse(node_child)
|
115
123
|
when 'strike'
|
116
124
|
@font_style.strike = option_enabled?(node_child)
|
117
125
|
when 'hlinkClick'
|
@@ -142,6 +150,7 @@ module OoxmlParser
|
|
142
150
|
# @return [String] name of font
|
143
151
|
def font_name
|
144
152
|
return @font_name unless @font_name.empty?
|
153
|
+
return @run_fonts.ascii if @run_fonts
|
145
154
|
|
146
155
|
root_object.default_font_typeface
|
147
156
|
end
|
@@ -39,13 +39,13 @@ module OoxmlParser
|
|
39
39
|
margin_node.xpath('*').each do |cell_margin_node|
|
40
40
|
case cell_margin_node.name
|
41
41
|
when 'left'
|
42
|
-
@left = OoxmlSize.new(
|
42
|
+
@left = OoxmlSize.new(parent: self).parse(cell_margin_node)
|
43
43
|
when 'top'
|
44
|
-
@top = OoxmlSize.new(
|
44
|
+
@top = OoxmlSize.new(parent: self).parse(cell_margin_node)
|
45
45
|
when 'right'
|
46
|
-
@right = OoxmlSize.new(
|
46
|
+
@right = OoxmlSize.new(parent: self).parse(cell_margin_node)
|
47
47
|
when 'bottom'
|
48
|
-
@bottom = OoxmlSize.new(
|
48
|
+
@bottom = OoxmlSize.new(parent: self).parse(cell_margin_node)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
self
|