ooxml_parser 0.6.0 → 0.8.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.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +6 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/series.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/series/series_text.rb +0 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb +1 -20
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_distance_from_text.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_properties.rb +51 -4
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb +4 -1
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +4 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_picture.rb +0 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/ooxml_text_box.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_color_scheme.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/docx_custom_geometry/docx_shape_line_path/docx_shape_line_element.rb +0 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_line.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties.rb +12 -4
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_size.rb +10 -3
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_properties.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/color.rb +45 -79
- data/lib/ooxml_parser/common_parser/common_data/color/color_helper.rb +4 -3
- data/lib/ooxml_parser/common_parser/common_data/color/color_indexes.list +66 -0
- data/lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb +5 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/color_properties.rb +8 -2
- data/lib/ooxml_parser/common_parser/common_data/colors/hsl_color.rb +11 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/scheme_color.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +4 -0
- data/lib/ooxml_parser/common_parser/common_data/content_types.rb +2 -0
- data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_default.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_override.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +7 -0
- data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +14 -3
- data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +28 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +31 -15
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/outline.rb +4 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering_properties.rb +2 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +16 -13
- data/lib/ooxml_parser/common_parser/common_data/table.rb +2 -0
- data/lib/ooxml_parser/common_parser/common_data/table/margins/paragraph_margins.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +7 -0
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties/table_style_properties_helper.rb +4 -4
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +4 -5
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/borders.rb +6 -0
- data/lib/ooxml_parser/common_parser/common_data/table/table_grid.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/underline.rb +7 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +41 -9
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments/comment.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +2 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +25 -8
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/bookmark_end.rb +1 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/comment_range_start.rb +1 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/pre_sub_superscript.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +13 -3
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb +4 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb +0 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb +4 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +8 -4
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/numbering.rb +5 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/columns.rb +3 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +6 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_size.rb +1 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/styles.rb +2 -0
- data/lib/ooxml_parser/docx_parser/docx_parser.rb +3 -0
- data/lib/ooxml_parser/name.rb +1 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +2 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +5 -2
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb +15 -1
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_parser.rb +4 -1
- data/lib/ooxml_parser/version.rb +2 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +21 -2
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/chartsheet.rb +3 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache.rb +41 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition.rb +37 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source.rb +33 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source/worksheet_source.rb +26 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet.rb +2 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/xf.rb +5 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb +2 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb +3 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +5 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb +4 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb +4 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_parser.rb +3 -0
- metadata +65 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07201a9a59d3d4b457115c2faf6c3e419eb9322064c25e8d793adb7439cd70ba
|
4
|
+
data.tar.gz: 18fe77d063dc4e6ef7554abcec151ab5987eb1754a6dcba80cbc258092e3a460
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4583846a0c88a4dbb30c2ad727c3f444f15ef340904532cdc106b0cad70eaa2ee71ca5f8cdc6e26adac38e0caed12ca78519499b5a4391d7b0e9869a418488e
|
7
|
+
data.tar.gz: 35385dccda157dd0fef6d22c9ce0dde82630ab5861513eaee733f379532388722449fd993ff69327ca2b66f95b2219646d21bfa7b75439b6085db5cd1500fa22
|
data/lib/ooxml_parser.rb
CHANGED
@@ -41,6 +41,9 @@ module OoxmlParser
|
|
41
41
|
@parent = parent
|
42
42
|
end
|
43
43
|
|
44
|
+
# Parse properties of Chart
|
45
|
+
# @param chart_prop_node [Nokogiri::XML:Element] node to parse
|
46
|
+
# @return [void]
|
44
47
|
def parse_properties(chart_prop_node)
|
45
48
|
chart_prop_node.xpath('*').each do |chart_props_node_child|
|
46
49
|
case chart_props_node_child.name
|
@@ -71,6 +74,9 @@ module OoxmlParser
|
|
71
74
|
extend Gem::Deprecate
|
72
75
|
deprecate :data, 'series points interface', 2020, 1
|
73
76
|
|
77
|
+
# Parse Chart
|
78
|
+
# @param parent [OOOXMLDocumentObject] parent of chart
|
79
|
+
# @return [Chart] result of parsing
|
74
80
|
def self.parse(parent: nil)
|
75
81
|
chart = Chart.new(parent: parent)
|
76
82
|
chart_xml = chart.parse_xml(OOXMLDocumentObject.current_xml)
|
@@ -11,7 +11,7 @@ module OoxmlParser
|
|
11
11
|
attr_reader :order
|
12
12
|
# @return [SeriesText] text of series
|
13
13
|
attr_accessor :text
|
14
|
-
# @return [
|
14
|
+
# @return [SeriesText] categories of chart
|
15
15
|
attr_accessor :categories
|
16
16
|
# @return [DisplayLabelsProperties]
|
17
17
|
attr_accessor :display_labels
|
@@ -35,7 +35,7 @@ module OoxmlParser
|
|
35
35
|
when 'tx'
|
36
36
|
@text = SeriesText.new(parent: self).parse(node_child)
|
37
37
|
when 'cat'
|
38
|
-
@categories =
|
38
|
+
@categories = SeriesText.new(parent: self).parse(node_child)
|
39
39
|
when 'dLbls'
|
40
40
|
@display_labels = DisplayLabelsProperties.new(parent: self).parse(node_child)
|
41
41
|
when 'val'
|
@@ -30,34 +30,15 @@ module OoxmlParser
|
|
30
30
|
when 'inline'
|
31
31
|
@type = :inline
|
32
32
|
end
|
33
|
-
@properties.distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node_child)
|
34
|
-
@properties.wrap = DocxWrapDrawing.new(parent: self).parse(node_child)
|
35
|
-
node_child.attributes.each do |key, value|
|
36
|
-
case key
|
37
|
-
when 'relativeHeight'
|
38
|
-
@properties.relative_height = value.value.to_i
|
39
|
-
end
|
40
|
-
end
|
41
33
|
node_child.xpath('*').each do |content_node_child|
|
42
34
|
case content_node_child.name
|
43
|
-
when 'simplePos'
|
44
|
-
@properties.simple_position = OOXMLCoordinates.parse(content_node_child)
|
45
|
-
when 'extent'
|
46
|
-
@properties.object_size = OOXMLCoordinates.parse(content_node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
|
47
35
|
when 'graphic'
|
48
36
|
@graphic = DocxGraphic.new(parent: self).parse(content_node_child)
|
49
|
-
when 'positionV'
|
50
|
-
@properties.vertical_position = DocxDrawingPosition.new(parent: self).parse(content_node_child)
|
51
|
-
when 'positionH'
|
52
|
-
@properties.horizontal_position = DocxDrawingPosition.new(parent: self).parse(content_node_child)
|
53
|
-
when 'sizeRelH'
|
54
|
-
@properties.size_relative_horizontal = SizeRelativeHorizontal.new(parent: self).parse(content_node_child)
|
55
|
-
when 'sizeRelV'
|
56
|
-
@properties.size_relative_vertical = SizeRelativeVertical.new(parent: self).parse(content_node_child)
|
57
37
|
when 'docPr'
|
58
38
|
@doc_properties = DocProperties.new(parent: self).parse(content_node_child)
|
59
39
|
end
|
60
40
|
end
|
41
|
+
@properties.parse(node_child)
|
61
42
|
end
|
62
43
|
self
|
63
44
|
end
|
@@ -5,6 +5,9 @@ module OoxmlParser
|
|
5
5
|
class DocxDrawingDistanceFromText < OOXMLDocumentObject
|
6
6
|
attr_accessor :top, :bottom, :left, :right
|
7
7
|
|
8
|
+
# Parse DocxDrawingDistanceFromText object
|
9
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
10
|
+
# @return [DocxDrawingDistanceFromText] result of parsing
|
8
11
|
def parse(node)
|
9
12
|
node.attributes.each do |key, value|
|
10
13
|
case key
|
@@ -8,9 +8,56 @@ require_relative 'docx_wrap_drawing'
|
|
8
8
|
module OoxmlParser
|
9
9
|
# Docx Drawing Properties
|
10
10
|
class DocxDrawingProperties < OOXMLDocumentObject
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
# @return [DocxDrawingDistanceFromText] distance from text
|
12
|
+
attr_reader :distance_from_text
|
13
|
+
# @return [DocxWrapDrawing] wrap of drawing
|
14
|
+
attr_reader :wrap
|
15
|
+
# @return [Integer] relative height of object
|
16
|
+
attr_reader :relative_height
|
17
|
+
# @return [OOXMLCoordinates] simple position of object
|
18
|
+
attr_reader :simple_position
|
19
|
+
# @return [OOXMLCoordinates] size of object
|
20
|
+
attr_reader :object_size
|
21
|
+
# @return [DocxDrawingPosition] vertical position
|
22
|
+
attr_reader :vertical_position
|
23
|
+
# @return [DocxDrawingPosition] horizontal position
|
24
|
+
attr_reader :horizontal_position
|
25
|
+
# @return [SizeRelativeHorizontal] size of drawing relative to horizontal
|
26
|
+
attr_reader :size_relative_horizontal
|
27
|
+
# @return [SizeRelativeVertical] size of drawing relative to vertical
|
28
|
+
attr_reader :size_relative_vertical
|
29
|
+
|
30
|
+
# Parse DocxDrawingProperties
|
31
|
+
# @param [Nokogiri::XML:Node] node with DocxDrawingProperties
|
32
|
+
# @return [DocxDrawingProperties] result of parsing
|
33
|
+
def parse(node)
|
34
|
+
@distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node)
|
35
|
+
@wrap = DocxWrapDrawing.new(parent: self).parse(node)
|
36
|
+
|
37
|
+
node.attributes.each do |key, value|
|
38
|
+
case key
|
39
|
+
when 'relativeHeight'
|
40
|
+
@relative_height = value.value.to_i
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
node.xpath('*').each do |content_node_child|
|
45
|
+
case content_node_child.name
|
46
|
+
when 'simplePos'
|
47
|
+
@simple_position = OOXMLCoordinates.parse(content_node_child)
|
48
|
+
when 'extent'
|
49
|
+
@object_size = OOXMLCoordinates.parse(content_node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
|
50
|
+
when 'positionV'
|
51
|
+
@vertical_position = DocxDrawingPosition.new(parent: self).parse(content_node_child)
|
52
|
+
when 'positionH'
|
53
|
+
@horizontal_position = DocxDrawingPosition.new(parent: self).parse(content_node_child)
|
54
|
+
when 'sizeRelH'
|
55
|
+
@size_relative_horizontal = SizeRelativeHorizontal.new(parent: self).parse(content_node_child)
|
56
|
+
when 'sizeRelV'
|
57
|
+
@size_relative_vertical = SizeRelativeVertical.new(parent: self).parse(content_node_child)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
self
|
61
|
+
end
|
15
62
|
end
|
16
63
|
end
|
@@ -28,6 +28,9 @@ module OoxmlParser
|
|
28
28
|
self
|
29
29
|
end
|
30
30
|
|
31
|
+
# Compare this object to other
|
32
|
+
# @param other [Object] any other object
|
33
|
+
# @return [True, False] result of comparision
|
31
34
|
def ==(other)
|
32
35
|
(to_base_unit.value - other.to_base_unit.value).abs < 10**(OoxmlParser.configuration.accuracy + 2)
|
33
36
|
end
|
@@ -40,7 +43,7 @@ module OoxmlParser
|
|
40
43
|
# @return [String] string representation of size
|
41
44
|
def to_s(unit = :centimeter)
|
42
45
|
converted = to_unit(unit)
|
43
|
-
"#{converted.value} #{converted.unit}"
|
46
|
+
"#{converted.value.to_f} #{converted.unit}"
|
44
47
|
end
|
45
48
|
|
46
49
|
# Convert all values to one same base unit
|
@@ -10,6 +10,9 @@ module OoxmlParser
|
|
10
10
|
# @return [String] content of file
|
11
11
|
attr_accessor :content
|
12
12
|
|
13
|
+
# Parse FileReference object
|
14
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
15
|
+
# @return [FileReference] result of parsing
|
13
16
|
def parse(node)
|
14
17
|
node.attributes.each do |key, value|
|
15
18
|
case key
|
@@ -26,6 +29,7 @@ module OoxmlParser
|
|
26
29
|
return self
|
27
30
|
end
|
28
31
|
return self if @path == 'NULL'
|
32
|
+
return self if @path.match?(URI::DEFAULT_PARSER.make_regexp)
|
29
33
|
|
30
34
|
full_path_to_file = OOXMLDocumentObject.path_to_folder + OOXMLDocumentObject.root_subfolder + @path.gsub('..', '')
|
31
35
|
if File.exist?(full_path_to_file)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Class for parsing `txbx` tags
|
5
5
|
class OOXMLTextBox < OOXMLDocumentObject
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :elements
|
7
7
|
|
8
8
|
def initialize(parent: nil)
|
9
9
|
@elements = []
|
@@ -21,8 +21,6 @@ module OoxmlParser
|
|
21
21
|
@elements << DocxParagraph.new(parent: self).parse(node_child, index)
|
22
22
|
when 'tbl'
|
23
23
|
@elements << Table.new(parent: self).parse(node_child, index)
|
24
|
-
when 'bodyPr'
|
25
|
-
@properties = OOXMLShapeBodyProperties.new(parent: self).parse(node_child)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
self
|
@@ -10,8 +10,18 @@ require_relative 'custom_geometry/ooxml_custom_geometry'
|
|
10
10
|
module OoxmlParser
|
11
11
|
# DOCX Shape Properties
|
12
12
|
class DocxShapeProperties < OOXMLDocumentObject
|
13
|
-
|
14
|
-
|
13
|
+
# @return [DocxShapeSize] size of shape
|
14
|
+
attr_reader :shape_size
|
15
|
+
# @return [PresetGeometry] preset geometry of object
|
16
|
+
attr_reader :preset_geometry
|
17
|
+
# @return [DocxColor] color of object
|
18
|
+
attr_reader :fill_color
|
19
|
+
# @return [DocxShapeLine] line info
|
20
|
+
attr_reader :line
|
21
|
+
# @return [PresetGeometry] is some geometry custom
|
22
|
+
attr_reader :custom_geometry
|
23
|
+
# @return [BlipFill] BlipFill data
|
24
|
+
attr_reader :blip_fill
|
15
25
|
|
16
26
|
alias transform shape_size
|
17
27
|
alias fill fill_color
|
@@ -33,8 +43,6 @@ module OoxmlParser
|
|
33
43
|
@shape_size = DocxShapeSize.new(parent: self).parse(node_child)
|
34
44
|
when 'prstGeom'
|
35
45
|
@preset_geometry = PresetGeometry.new(parent: self).parse(node_child)
|
36
|
-
when 'txbx'
|
37
|
-
@text_box = TextBox.parse_list(node_child)
|
38
46
|
when 'ln'
|
39
47
|
@line = DocxShapeLine.new(parent: self).parse(node_child)
|
40
48
|
when 'blipFill'
|
@@ -3,9 +3,16 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Docx Shape Size
|
5
5
|
class DocxShapeSize < OOXMLDocumentObject
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# @return [OoxmlSize] rotation info
|
7
|
+
attr_reader :rotation
|
8
|
+
# @return [OOXMLCoordinates] offset info
|
9
|
+
attr_reader :offset
|
10
|
+
# @return [OOXMLCoordinates] extent info
|
11
|
+
attr_reader :extent
|
12
|
+
# @return [OOXMLCoordinates] child offset
|
13
|
+
attr_reader :child_offset
|
14
|
+
# @return [OOXMLCoordinates] child extent
|
15
|
+
attr_reader :child_extent
|
9
16
|
# @return [True, False] is image flipped horizontally
|
10
17
|
attr_reader :flip_horizontal
|
11
18
|
# @return [True, False] is image flipped vertically
|
data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb
CHANGED
@@ -6,7 +6,7 @@ require_relative 'group/old_docx_group'
|
|
6
6
|
module OoxmlParser
|
7
7
|
# Fallback DOCX Picture
|
8
8
|
class OldDocxPicture < OOXMLDocumentObject
|
9
|
-
attr_accessor :data, :type
|
9
|
+
attr_accessor :data, :type
|
10
10
|
|
11
11
|
# Parse OldDocxPicture object
|
12
12
|
# @param node [Nokogiri::XML:Element] node to parse
|
@@ -20,8 +20,6 @@ module OoxmlParser
|
|
20
20
|
when 'group'
|
21
21
|
@type = :group
|
22
22
|
@data = OldDocxGroup.new(parent: self).parse(node_child)
|
23
|
-
when 'style'
|
24
|
-
@style_number = node_child.attribute('val').value.to_i
|
25
23
|
end
|
26
24
|
end
|
27
25
|
self
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Fallback DOCX Shape Properties
|
5
5
|
class OldDocxShapeProperties < OOXMLDocumentObject
|
6
|
-
attr_accessor :fill_color, :
|
6
|
+
attr_accessor :fill_color, :stroke_color, :stroke_weight
|
7
7
|
|
8
8
|
# Parse OldDocxShapeProperties object
|
9
9
|
# @param node [Nokogiri::XML:Element] node to parse
|
@@ -13,8 +13,6 @@ module OoxmlParser
|
|
13
13
|
case key
|
14
14
|
when 'fillcolor'
|
15
15
|
@fill_color = Color.new(parent: self).parse_hex_string(value.value.delete('#'))
|
16
|
-
when 'opacity'
|
17
|
-
@opacity = value.value.to_f
|
18
16
|
when 'strokecolor'
|
19
17
|
@stroke_color = Color.new(parent: self).parse_hex_string(value.value.delete('#'))
|
20
18
|
when 'strokeweight'
|
@@ -27,12 +27,15 @@ module OoxmlParser
|
|
27
27
|
size.zero? && val == :none
|
28
28
|
end
|
29
29
|
|
30
|
+
# @return [String] result of convert of object to string
|
30
31
|
def to_s
|
31
32
|
return '' if nil?
|
32
33
|
|
33
34
|
"borders color: #{@color}, size: #{size}, space: #{@space}, value: #{@val}"
|
34
35
|
end
|
35
36
|
|
37
|
+
# Method to copy object
|
38
|
+
# @return [BordersProperties] copied object
|
36
39
|
def copy
|
37
40
|
BordersProperties.new(@color, size, @val, @space)
|
38
41
|
end
|
@@ -12,79 +12,6 @@ module OoxmlParser
|
|
12
12
|
# Class for Color in RGB
|
13
13
|
class Color < OOXMLDocumentObject
|
14
14
|
include ColorHelper
|
15
|
-
# @return [Array] Deprecated Indexed colors
|
16
|
-
# List of color duplicated from `OpenXML Sdk IndexedColors` class
|
17
|
-
# See https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.indexedcolors.aspx
|
18
|
-
COLOR_INDEXED =
|
19
|
-
%w[
|
20
|
-
000000
|
21
|
-
FFFFFF
|
22
|
-
FF0000
|
23
|
-
00FF00
|
24
|
-
0000FF
|
25
|
-
FFFF00
|
26
|
-
FF00FF
|
27
|
-
00FFFF
|
28
|
-
000000
|
29
|
-
FFFFFF
|
30
|
-
FF0000
|
31
|
-
00FF00
|
32
|
-
0000FF
|
33
|
-
FFFF00
|
34
|
-
FF00FF
|
35
|
-
00FFFF
|
36
|
-
800000
|
37
|
-
008000
|
38
|
-
000080
|
39
|
-
808000
|
40
|
-
800080
|
41
|
-
008080
|
42
|
-
C0C0C0
|
43
|
-
808080
|
44
|
-
9999FF
|
45
|
-
993366
|
46
|
-
FFFFCC
|
47
|
-
CCFFFF
|
48
|
-
660066
|
49
|
-
FF8080
|
50
|
-
0066CC
|
51
|
-
CCCCFF
|
52
|
-
000080
|
53
|
-
FF00FF
|
54
|
-
FFFF00
|
55
|
-
00FFFF
|
56
|
-
800080
|
57
|
-
800000
|
58
|
-
008080
|
59
|
-
0000FF
|
60
|
-
00CCFF
|
61
|
-
CCFFFF
|
62
|
-
CCFFCC
|
63
|
-
FFFF99
|
64
|
-
99CCFF
|
65
|
-
FF99CC
|
66
|
-
CC99FF
|
67
|
-
FFCC99
|
68
|
-
3366FF
|
69
|
-
33CCCC
|
70
|
-
99CC00
|
71
|
-
FFCC00
|
72
|
-
FF9900
|
73
|
-
FF6600
|
74
|
-
666699
|
75
|
-
969696
|
76
|
-
003366
|
77
|
-
339966
|
78
|
-
003300
|
79
|
-
333300
|
80
|
-
993300
|
81
|
-
993366
|
82
|
-
333399
|
83
|
-
333333
|
84
|
-
n/a
|
85
|
-
n/a
|
86
|
-
].freeze
|
87
|
-
|
88
15
|
# @return [Integer] Value of Red Part
|
89
16
|
attr_accessor :red
|
90
17
|
# @return [Integer] Value of Green Part
|
@@ -103,7 +30,7 @@ module OoxmlParser
|
|
103
30
|
|
104
31
|
alias set_alpha_channel alpha_channel=
|
105
32
|
|
106
|
-
|
33
|
+
# @return [ColorProperties] properties of color
|
107
34
|
attr_accessor :properties
|
108
35
|
|
109
36
|
# Value of color if non selected
|
@@ -119,6 +46,7 @@ module OoxmlParser
|
|
119
46
|
@parent = parent
|
120
47
|
end
|
121
48
|
|
49
|
+
# @return [String] result of convert of object to string
|
122
50
|
def to_s
|
123
51
|
if @red == VALUE_FOR_NONE_COLOR && @green == VALUE_FOR_NONE_COLOR && @blue == VALUE_FOR_NONE_COLOR
|
124
52
|
'none'
|
@@ -127,33 +55,43 @@ module OoxmlParser
|
|
127
55
|
end
|
128
56
|
end
|
129
57
|
|
58
|
+
# @return [String] inspect of object for debug means
|
130
59
|
def inspect
|
131
60
|
to_s
|
132
61
|
end
|
133
62
|
|
63
|
+
# @return [String] color in hex value
|
134
64
|
def to_hex
|
135
65
|
(@red.to_s(16).rjust(2, '0') + @green.to_s(16).rjust(2, '0') + @blue.to_s(16).rjust(2, '0')).upcase
|
136
66
|
end
|
137
67
|
|
138
68
|
alias to_int16 to_hex
|
139
69
|
|
70
|
+
# @return [True, False] is color default
|
140
71
|
def none?
|
141
72
|
(@red == VALUE_FOR_NONE_COLOR) && (@green == VALUE_FOR_NONE_COLOR) && (@blue == VALUE_FOR_NONE_COLOR) ||
|
142
73
|
(style == :nil)
|
143
74
|
end
|
144
75
|
|
76
|
+
# @return [True, False] is color not default
|
145
77
|
def any?
|
146
78
|
!none?
|
147
79
|
end
|
148
80
|
|
81
|
+
# @return [True, False] is color white
|
149
82
|
def white?
|
150
83
|
(@red == 255) && (@green == 255) && (@blue == 255)
|
151
84
|
end
|
152
85
|
|
86
|
+
# Method to copy object
|
87
|
+
# @return [Color] copied object
|
153
88
|
def copy
|
154
89
|
Color.new(@red, @green, @blue)
|
155
90
|
end
|
156
91
|
|
92
|
+
# Compare this object to other
|
93
|
+
# @param other [Object] any other object
|
94
|
+
# @return [True, False] result of comparision
|
157
95
|
def ==(other)
|
158
96
|
if other.is_a?(Color)
|
159
97
|
if (@red == other.red) && (@green == other.green) && (@blue == other.blue)
|
@@ -190,18 +128,27 @@ module OoxmlParser
|
|
190
128
|
(self.red - red).abs < delta && (self.green - green).abs < delta && (self.blue - blue).abs < delta ? true : false
|
191
129
|
end
|
192
130
|
|
131
|
+
# Apply tint to color
|
132
|
+
# @param tint [Integer] tint to apply
|
133
|
+
# @return [void]
|
193
134
|
def calculate_with_tint!(tint)
|
194
135
|
@red += (tint.to_f * (255 - @red)).to_i
|
195
136
|
@green += (tint.to_f * (255 - @green)).to_i
|
196
137
|
@blue += (tint.to_f * (255 - @blue)).to_i
|
197
138
|
end
|
198
139
|
|
140
|
+
# Apply shade to color
|
141
|
+
# @param shade [Integer] shade to apply
|
142
|
+
# @return [void]
|
199
143
|
def calculate_with_shade!(shade)
|
200
144
|
@red = (@red * shade.to_f).to_i
|
201
145
|
@green = (@green * shade.to_f).to_i
|
202
146
|
@blue = (@blue * shade.to_f).to_i
|
203
147
|
end
|
204
148
|
|
149
|
+
# Parse color scheme data
|
150
|
+
# @param scheme_color_node [Nokogiri::XML:Element] node to parse
|
151
|
+
# @return [Color] result of parsing
|
205
152
|
def parse_scheme_color(scheme_color_node)
|
206
153
|
color = root_object.theme.color_scheme[scheme_color_node.attribute('val').value.to_sym].color
|
207
154
|
hls = HSLColor.rgb_to_hsl(color)
|
@@ -229,6 +176,9 @@ module OoxmlParser
|
|
229
176
|
self
|
230
177
|
end
|
231
178
|
|
179
|
+
# Parse color model data
|
180
|
+
# @param color_model_parent_node [Nokogiri::XML:Element] node to parse
|
181
|
+
# @return [Color] result of parsing
|
232
182
|
def parse_color_model(color_model_parent_node)
|
233
183
|
color = nil
|
234
184
|
tint = nil
|
@@ -240,9 +190,6 @@ module OoxmlParser
|
|
240
190
|
end
|
241
191
|
end
|
242
192
|
case color_model_node.name
|
243
|
-
when 'scrgbClr'
|
244
|
-
color = Color.new(color_model_node.attribute('r').value.to_i, color_model_node.attribute('g').value.to_i, color_model_node.attribute('b').value.to_i)
|
245
|
-
color.alpha_channel = ColorAlphaChannel.parse(color_model_node)
|
246
193
|
when 'srgbClr'
|
247
194
|
color = Color.new.parse_hex_string(color_model_node.attribute('val').value)
|
248
195
|
color.alpha_channel = ColorAlphaChannel.parse(color_model_node)
|
@@ -261,6 +208,9 @@ module OoxmlParser
|
|
261
208
|
self
|
262
209
|
end
|
263
210
|
|
211
|
+
# Parse color data
|
212
|
+
# @param color_node [Nokogiri::XML:Element] node to parse
|
213
|
+
# @return [Color] result of parsing
|
264
214
|
def parse_color(color_node)
|
265
215
|
case color_node.name
|
266
216
|
when 'srgbClr'
|
@@ -280,6 +230,7 @@ module OoxmlParser
|
|
280
230
|
end
|
281
231
|
|
282
232
|
class << self
|
233
|
+
# @return [Color] random color
|
283
234
|
def generate_random_color
|
284
235
|
Color.new(rand(256), rand(256), rand(256))
|
285
236
|
end
|
@@ -293,19 +244,31 @@ module OoxmlParser
|
|
293
244
|
const_array_name.map { |current_color| Color.parse_string(current_color) }
|
294
245
|
end
|
295
246
|
|
247
|
+
# @param index [Integer] index to get
|
248
|
+
# @return [Color] color by it's index
|
296
249
|
def get_rgb_by_color_index(index)
|
297
|
-
color_by_index =
|
250
|
+
color_by_index = color_indexes[index]
|
298
251
|
return :unknown if color_by_index.nil?
|
299
252
|
|
300
253
|
color_by_index == 'n/a' ? Color.new : Color.new.parse_hex_string(color_by_index)
|
301
254
|
end
|
302
255
|
|
256
|
+
# @return [Array] Deprecated Indexed colors
|
257
|
+
# List of color duplicated from `OpenXML Sdk IndexedColors` class
|
258
|
+
# See https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.indexedcolors.aspx
|
259
|
+
def color_indexes
|
260
|
+
@color_indexes ||= File.readlines("#{__dir__}/color/color_indexes.list", chomp: true)
|
261
|
+
end
|
262
|
+
|
263
|
+
# Parse color from string
|
264
|
+
# @param str [String] string to parse
|
265
|
+
# @return [Color] result of parsing
|
303
266
|
def parse_string(str)
|
304
267
|
return str if str.is_a?(Color)
|
305
268
|
return Color.new(VALUE_FOR_NONE_COLOR, VALUE_FOR_NONE_COLOR, VALUE_FOR_NONE_COLOR) if str == 'none' || str == '' || str == 'transparent' || str.nil?
|
306
269
|
|
307
270
|
split = if str.include?('RGB (') || str.include?('rgb(')
|
308
|
-
str.gsub(/[(RGBrgb
|
271
|
+
str.gsub(/[(RGBrgb() )]/, '').split(',')
|
309
272
|
elsif str.include?('RGB ') || str.include?('rgb')
|
310
273
|
str.gsub(/RGB |rgb/, '').split(', ')
|
311
274
|
else
|
@@ -317,6 +280,9 @@ module OoxmlParser
|
|
317
280
|
|
318
281
|
alias parse parse_string
|
319
282
|
|
283
|
+
# Convert other object type to Color
|
284
|
+
# @param something [Object] object to convert
|
285
|
+
# @return [Color] result of conversion
|
320
286
|
def to_color(something)
|
321
287
|
case something
|
322
288
|
when SchemeColor
|