ooxml_parser 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/ooxml_parser.rb +2 -0
  4. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +3 -2
  5. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb +2 -1
  6. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group.rb +1 -1
  7. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape.rb +1 -1
  8. data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +11 -8
  9. data/lib/ooxml_parser/common_parser/common_data/colors/hsl_color.rb +12 -15
  10. data/lib/ooxml_parser/common_parser/common_data/colors/image/stretching.rb +1 -0
  11. data/lib/ooxml_parser/common_parser/common_data/colors/image/{fill_rectangle.rb → stretching/fill_rectangle.rb} +0 -0
  12. data/lib/ooxml_parser/common_parser/common_data/colors/image_fill.rb +1 -0
  13. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb +1 -2
  14. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color/linear_gradient.rb +10 -0
  15. data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +6 -1
  16. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +29 -1
  17. data/lib/ooxml_parser/common_parser/common_data/paragraph.rb +1 -0
  18. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb +1 -1
  19. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +1 -1
  20. data/lib/ooxml_parser/{pptx_parser/pptx_data/presentation/slide/shape/text_body → common_parser/common_data/paragraph}/text_field.rb +0 -0
  21. data/lib/ooxml_parser/common_parser/common_data/relationships.rb +31 -0
  22. data/lib/ooxml_parser/common_parser/common_data/relationships/relationship.rb +22 -0
  23. data/lib/ooxml_parser/common_parser/common_data/table.rb +1 -1
  24. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style.rb +1 -0
  25. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_elements.rb +1 -1
  26. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +39 -96
  27. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/merge.rb +7 -3
  28. data/lib/ooxml_parser/common_parser/common_data/table/row/row/table_row_properties.rb +1 -1
  29. data/lib/ooxml_parser/common_parser/common_data/table/table_grid.rb +1 -1
  30. data/lib/ooxml_parser/common_parser/common_data/table/table_properties.rb +5 -2
  31. data/lib/ooxml_parser/common_parser/common_data/table/table_properties/table_borders.rb +33 -0
  32. data/lib/ooxml_parser/common_parser/parser.rb +17 -0
  33. data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +15 -26
  34. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb +26 -0
  35. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_properties.rb +6 -1
  36. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +5 -5
  37. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb +9 -10
  38. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb +1 -1
  39. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/document_grid.rb +1 -1
  40. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb +6 -13
  41. data/lib/ooxml_parser/docx_parser/docx_parser.rb +3 -7
  42. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +1 -2
  43. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_comment/presentation_comment_author.rb +2 -1
  44. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme.rb +1 -1
  45. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +13 -19
  46. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/animation_effect/animation_effect.rb +2 -2
  47. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/behavior/behavior.rb +1 -0
  48. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/set_time_node.rb +2 -0
  49. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node.rb +2 -0
  50. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node/common_timing/condition.rb +2 -2
  51. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition.rb +3 -14
  52. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/{sound_action → transition}/sound_action.rb +2 -0
  53. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/{sound_action/sound → transition/sound_action}/sound.rb +1 -2
  54. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition_properties/transition_properties.rb +20 -0
  55. data/lib/ooxml_parser/pptx_parser/pptx_parser.rb +3 -7
  56. data/lib/ooxml_parser/version.rb +1 -1
  57. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +4 -3
  58. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +12 -1
  59. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row.rb +1 -1
  60. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/foreground_color.rb +2 -2
  61. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/ooxml_font.rb +2 -4
  62. data/lib/ooxml_parser/xlsx_parser/xlsx_parser.rb +3 -7
  63. metadata +10 -16
  64. data/.overcommit.yml +0 -35
  65. data/Changelog.md +0 -25
  66. data/circle.yml +0 -3
  67. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/offset.rb +0 -10
  68. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shadow.rb +0 -10
  69. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/shape_properties/extents.rb +0 -10
  70. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/shape_properties/offset.rb +0 -10
  71. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/text_body/paragraph.rb +0 -10
  72. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shapes_grouping/shapes_grouping.rb +0 -9
  73. data/ooxml_parser.gemspec +0 -30
@@ -8,10 +8,14 @@ module OoxmlParser
8
8
  @value = value
9
9
  end
10
10
 
11
- def self.parse_merge_hash(hash)
11
+ # Parse Merge data
12
+ # @param [Nokogiri::XML:Element] node with Merge data
13
+ # @return [CellMerge] value of CellMerge
14
+ def self.parse(node)
12
15
  merge = CellMerge.new
13
- merge.type = hash['type']
14
- merge.count_of_merged_cells = hash['count_of_merged_cells']
16
+ merge.count_of_merged_cells = node.attribute('count_rows_in_span').nil? ? nil : node.attribute('count_rows_in_span').value
17
+ merge.value = node.attribute('val').nil? ? nil : node.attribute('val').value.to_sym
18
+ merge.type = node.attribute('type').nil? ? nil : node.attribute('type').value.to_sym
15
19
  merge
16
20
  end
17
21
  end
@@ -1,6 +1,6 @@
1
1
  module OoxmlParser
2
2
  # Class for describing Table Row Properties
3
- class TableRowProperties
3
+ class TableRowProperties < OOXMLDocumentObject
4
4
  # @return [Float] Table Row Height
5
5
  attr_accessor :height
6
6
 
@@ -1,5 +1,5 @@
1
1
  module OoxmlParser
2
- class TableGrid
2
+ class TableGrid < OOXMLDocumentObject
3
3
  attr_accessor :columns, :mass_of_width_cells
4
4
 
5
5
  def initialize(columns = [])
@@ -3,6 +3,7 @@ require_relative 'properties/table_cell_margin'
3
3
  require_relative 'properties/table_look'
4
4
  require_relative 'properties/table_style'
5
5
  require_relative 'properties/table_position'
6
+ require_relative 'table_properties/table_borders'
6
7
  module OoxmlParser
7
8
  class TableProperties < OOXMLDocumentObject
8
9
  attr_accessor :jc, :table_width, :shd, :table_borders, :table_properties, :table_positon, :table_cell_margin, :table_indent, :stretching, :table_style, :row_banding_size,
@@ -16,7 +17,7 @@ module OoxmlParser
16
17
  @jc = :left
17
18
  @shd = nil
18
19
  @stretching = true
19
- @table_borders = Borders.new
20
+ @table_borders = TableBorders.new
20
21
  @table_properties = nil
21
22
  @table_width = nil
22
23
  @grid_column = nil
@@ -30,7 +31,7 @@ module OoxmlParser
30
31
  table.table_width = @table_width
31
32
  table.shd = @shd
32
33
  table.stretching = @stretching
33
- table.table_borders = @table_borders.copy
34
+ table.table_borders = @table_borders
34
35
  table.table_properties = @table_properties
35
36
  table.table_cell_margin = @table_cell_margin
36
37
  table.table_indent = @table_indent
@@ -46,6 +47,8 @@ module OoxmlParser
46
47
  case table_props_node_child.name
47
48
  when 'tableStyleId'
48
49
  table_properties.style = TableStyle.parse(style_id: table_props_node_child.text)
50
+ when 'tblBorders'
51
+ table_properties.table_borders = TableBorders.parse(table_props_node_child)
49
52
  when 'tblStyle'
50
53
  style = DocxParagraphRun.get_style_by_id(table_props_node_child.attribute('val').value)
51
54
  next if style.nil?
@@ -0,0 +1,33 @@
1
+ module OoxmlParser
2
+ # Class for describing Table Border Propertie
3
+ class TableBorders < OOXMLDocumentObject
4
+ # @return [BordersProperties] left border propertie
5
+ attr_accessor :left
6
+ # @return [BordersProperties] right border propertie
7
+ attr_accessor :right
8
+ # @return [BordersProperties] top border propertie
9
+ attr_accessor :top
10
+ # @return [BordersProperties] bottom border propertie
11
+ attr_accessor :bottom
12
+
13
+ # Parse Table Borders data
14
+ # @param [Nokogiri::XML:Element] node with Table Borders data
15
+ # @return [TableBorders] value of Table Borders data
16
+ def self.parse(node)
17
+ borders = TableBorders.new
18
+ node.xpath('*').each do |cell_borders_node|
19
+ case cell_borders_node.name
20
+ when 'left'
21
+ borders.left = BordersProperties.parse(cell_borders_node)
22
+ when 'top'
23
+ borders.top = BordersProperties.parse(cell_borders_node)
24
+ when 'right'
25
+ borders.right = BordersProperties.parse(cell_borders_node)
26
+ when 'bottom'
27
+ borders.bottom = BordersProperties.parse(cell_borders_node)
28
+ end
29
+ end
30
+ borders
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module OoxmlParser
2
+ class Parser
3
+ # Base method to parse document of any type
4
+ # @param path_to_file [String] file
5
+ # @return [CommonDocumentStructure] structure of doc
6
+ def self.parse(path_to_file)
7
+ return nil if OOXMLDocumentObject.encrypted_file?(path_to_file)
8
+ path_to_zip_file = OOXMLDocumentObject.copy_file_and_rename_to_zip(path_to_file)
9
+ OOXMLDocumentObject.path_to_folder = path_to_zip_file.sub(File.basename(path_to_zip_file), '')
10
+ OOXMLDocumentObject.unzip_file(path_to_zip_file, OOXMLDocumentObject.path_to_folder)
11
+ model = yield
12
+ model.file_path = path_to_file
13
+ FileUtils.remove_dir(OOXMLDocumentObject.path_to_folder)
14
+ model
15
+ end
16
+ end
17
+ end
@@ -1,8 +1,10 @@
1
1
  # noinspection RubyInstanceMethodNamingConvention
2
2
  require_relative 'document_structure/comment'
3
3
  require_relative 'document_structure/docx_paragraph'
4
+ require_relative 'document_structure/document_background'
4
5
  require_relative 'document_structure/document_properties'
5
6
  require_relative 'document_structure/document_style'
7
+ require_relative 'document_structure/header_footer'
6
8
  require_relative 'document_structure/page_properties/page_properties'
7
9
  module OoxmlParser
8
10
  class DocumentStructure < CommonDocumentStructure
@@ -21,6 +23,15 @@ module OoxmlParser
21
23
  @document_styles = []
22
24
  end
23
25
 
26
+ def ==(other)
27
+ @elements == other.elements &&
28
+ @page_properties == other.page_properties &&
29
+ @notes == other.notes &&
30
+ @background == other.background &&
31
+ @document_properties == other.document_properties &&
32
+ @comments == other.comments
33
+ end
34
+
24
35
  def difference(other)
25
36
  Hash.object_to_hash(self).diff(Hash.object_to_hash(other))
26
37
  end
@@ -108,9 +119,8 @@ module OoxmlParser
108
119
  !document_style_by_name(name).nil?
109
120
  end
110
121
 
111
- def self.parse(path)
122
+ def self.parse
112
123
  OOXMLDocumentObject.root_subfolder = 'word/'
113
- OOXMLDocumentObject.path_to_folder = path
114
124
  OOXMLDocumentObject.xmls_stack = []
115
125
  OOXMLDocumentObject.namespace_prefix = 'w'
116
126
  @comments = []
@@ -138,28 +148,7 @@ module OoxmlParser
138
148
  doc = Nokogiri::XML(File.open(OOXMLDocumentObject.current_xml))
139
149
  doc.search('//w:document').each do |document|
140
150
  document.xpath('w:background').each do |background|
141
- doc_structure.background = DocumentBackground.new
142
- doc_structure.background.color1 = Color.from_int16(background.attribute('color').value)
143
- background.xpath('v:background').each do |second_color|
144
- unless second_color.attribute('targetscreensize').nil?
145
- doc_structure.background.size = second_color.attribute('targetscreensize').value.sub(',', 'x')
146
- end
147
- second_color.xpath('v:fill').each do |fill|
148
- if !fill.attribute('color2').nil?
149
- doc_structure.background.color2 = Color.from_int16(fill.attribute('color2').value.split(' ').first.delete('#'))
150
- doc_structure.background.type = fill.attribute('type').value
151
- elsif !fill.attribute('id').nil?
152
- path_to_image = path + 'word/' + ParserDocxHelper.get_link_from_rels(fill.attribute('id').value, path)
153
- image_name = File.basename(path_to_image)
154
- doc_structure.background.image = path + File.basename(path) + '/' + image_name
155
- unless File.exist?(doc_structure.background.image.sub(File.basename(doc_structure.background.image), ''))
156
- FileUtils.mkdir(doc_structure.background.image.sub(File.basename(doc_structure.background.image), ''))
157
- end
158
- FileUtils.cp path_to_image, doc_structure.background.image
159
- doc_structure.background.type = 'image'
160
- end
161
- end
162
- end
151
+ doc_structure.background = DocumentBackground.parse(background)
163
152
  end
164
153
  document.xpath('w:body').each do |body|
165
154
  body.xpath('*').each do |element|
@@ -215,10 +204,10 @@ module OoxmlParser
215
204
  @default_table_properties = TableProperties.parse(table_pr_tag)
216
205
  end
217
206
  style.xpath('w:pPr').each do |table_paragraph_pr_tag|
218
- DocxParagraph.parse_paragraph_style(table_paragraph_pr_tag, @default_table_paragraph, @default_table_character)
207
+ DocxParagraph.parse_paragraph_style(table_paragraph_pr_tag, DocumentStructure.default_table_paragraph_style, DocumentStructure.default_table_run_style)
219
208
  end
220
209
  style.xpath('w:rPr').each do |table_character_pr_tag|
221
- DocxParagraphRun.parse(table_character_pr_tag, @default_table_character, @default_character)
210
+ DocxParagraphRun.parse(table_character_pr_tag, DocumentStructure.default_table_run_style, @default_character)
222
211
  end
223
212
  end
224
213
  end
@@ -1,4 +1,5 @@
1
1
  module OoxmlParser
2
+ # Class for describing Document Background `w:background`
2
3
  class DocumentBackground
3
4
  attr_accessor :color1, :size, :color2, :image, :type
4
5
 
@@ -6,5 +7,30 @@ module OoxmlParser
6
7
  @color1 = color1
7
8
  @type = type
8
9
  end
10
+
11
+ # Parse DocumentBackground object
12
+ # @param node [Nokogiri::XML:Element] node to parse
13
+ # @return [DocumentBackground] result of parsing
14
+ def self.parse(node)
15
+ background = DocumentBackground.new
16
+ background.color1 = Color.from_int16(node.attribute('color').value)
17
+ node.xpath('v:background').each do |second_color|
18
+ unless second_color.attribute('targetscreensize').nil?
19
+ background.size = second_color.attribute('targetscreensize').value.sub(',', 'x')
20
+ end
21
+ second_color.xpath('v:fill').each do |fill|
22
+ if !fill.attribute('color2').nil?
23
+ background.color2 = Color.from_int16(fill.attribute('color2').value.split(' ').first.delete('#'))
24
+ background.type = fill.attribute('type').value
25
+ elsif !fill.attribute('id').nil?
26
+ path_to_media_file = OOXMLDocumentObject.get_link_from_rels(fill.attribute('id').value)
27
+ path_to_image = OOXMLDocumentObject.copy_media_file("#{OOXMLDocumentObject.root_subfolder}/#{path_to_media_file.gsub('..', '')}")
28
+ background.image = path_to_image
29
+ background.type = 'image'
30
+ end
31
+ end
32
+ end
33
+ background
34
+ end
9
35
  end
10
36
  end
@@ -12,7 +12,12 @@ module OoxmlParser
12
12
  # @return [DocumentProperties]
13
13
  def self.parse
14
14
  properties = DocumentProperties.new
15
- doc_props = XmlSimple.xml_in(File.open("#{OOXMLDocumentObject.path_to_folder}docProps/app.xml"))
15
+ properties_file = "#{OOXMLDocumentObject.path_to_folder}docProps/app.xml"
16
+ unless File.exist?(properties_file)
17
+ warn "There is no 'docProps/app.xml' in docx. It may be some problem with it"
18
+ return properties
19
+ end
20
+ doc_props = XmlSimple.xml_in(File.open(properties_file))
16
21
  properties.pages = doc_props['Pages'].first.to_i unless doc_props['Pages'].nil?
17
22
  properties.words = doc_props['Words'].first.to_i unless doc_props['Words'].nil?
18
23
  properties
@@ -332,21 +332,21 @@ module OoxmlParser
332
332
  end
333
333
  when 'footnoteReference'
334
334
  character_style.footnote = HeaderFooter.new(:header)
335
- character_style.footnote.id = r_node_child.attribute('id').value
335
+ character_style.footnote.id = r_node_child.attribute('id').value.to_i
336
336
  character_style.footnote.parse('footnote', character_style.footnote.id, @default_paragraph, @default_character)
337
337
  when 'endnoteReference'
338
338
  character_style.endnote = HeaderFooter.new(:footer)
339
- character_style.endnote.id = r_node_child.attribute('id').value
339
+ character_style.endnote.id = r_node_child.attribute('id').value.to_i
340
340
  character_style.endnote.parse('endnote', character_style.endnote.id, @default_paragraph, @default_character)
341
341
  when 'pict'
342
342
  r_node_child.xpath('*').each do |pict_node_child|
343
343
  case pict_node_child.name
344
344
  when 'shape'
345
- character_style.shape = Shape.parse(pict_node_child, :shape, OOXMLDocumentObject.path_to_folder)
345
+ character_style.shape = Shape.parse(pict_node_child, :shape)
346
346
  when 'rect'
347
- character_style.shape = Shape.parse(pict_node_child, :rectangle, OOXMLDocumentObject.path_to_folder)
347
+ character_style.shape = Shape.parse(pict_node_child, :rectangle)
348
348
  when 'oval'
349
- character_style.shape = Shape.parse(pict_node_child, :oval, OOXMLDocumentObject.path_to_folder)
349
+ character_style.shape = Shape.parse(pict_node_child, :oval)
350
350
  when 'shapetype'
351
351
  end
352
352
  end
@@ -9,31 +9,30 @@ module OoxmlParser
9
9
  @elements = elements
10
10
  end
11
11
 
12
- def self.parse(shape_node, type, path)
12
+ def self.parse(shape_node, type)
13
13
  shape = Shape.new
14
14
  shape.type = type
15
15
  shape_node.attribute('style').value.to_s.split(';').each do |property|
16
- case
17
- when property.include?('margin-top')
16
+ if property.include?('margin-top')
18
17
  shape.properties.margins.top = property.split(':').last
19
- when property.include?('margin-left')
18
+ elsif property.include?('margin-left')
20
19
  shape.properties.margins.left = property.split(':').last
21
- when property.include?('margin-right')
20
+ elsif property.include?('margin-right')
22
21
  shape.properties.margins.right = property.split(':').last
23
- when property.include?('width')
22
+ elsif property.include?('width')
24
23
  shape.properties.size.width = property.split(':').last
25
- when property.include?('height')
24
+ elsif property.include?('height')
26
25
  shape.properties.size.height = property.split(':').last
27
- when property.include?('z-index')
26
+ elsif property.include?('z-index')
28
27
  shape.properties.z_index = property.split(':').last
29
- when property.include?('position')
28
+ elsif property.include?('position')
30
29
  shape.properties.position = property.split(':').last
31
30
  end
32
31
  end
33
32
  shape.properties.fill_color = Color.from_int16(shape_node.attribute('fillcolor').value.to_s.sub('#', '').split(' ').first) unless shape_node.attribute('fillcolor').nil?
34
33
  shape.properties.stroke.weight = shape_node.attribute('strokeweight').value unless shape_node.attribute('strokeweight').nil?
35
34
  shape.properties.stroke.color = Color.from_int16(shape_node.attribute('strokecolor').value.to_s.sub('#', '').split(' ').first) unless shape_node.attribute('strokecolor').nil?
36
- shape.elements = TextBox.parse_list(shape_node.xpath('v:textbox').first, path) unless shape_node.xpath('v:textbox').first.nil?
35
+ shape.elements = TextBox.parse_list(shape_node.xpath('v:textbox').first) unless shape_node.xpath('v:textbox').first.nil?
37
36
  shape
38
37
  end
39
38
  end
@@ -29,7 +29,7 @@ module OoxmlParser
29
29
  when 'yAlign'
30
30
  frame_properties.vertical_align = value.value.to_sym
31
31
  when 'anchorLock'
32
- frame_properties.anchor_lock = OOXMLDocumentObject.option_enabled?(frame_pr_node, anchorLock)
32
+ frame_properties.anchor_lock = OOXMLDocumentObject.option_enabled?(frame_pr_node, 'anchorLock')
33
33
  when 'vSpace'
34
34
  frame_properties.vertical_space = (value.value.to_f / 566.9).round(2)
35
35
  when 'hSpace'
@@ -1,5 +1,5 @@
1
1
  module OoxmlParser
2
- class DocumentGrid
2
+ class DocumentGrid < OOXMLDocumentObject
3
3
  attr_accessor :type, :line_pitch, :char_space
4
4
 
5
5
  def initialize(type = nil, line_pitch = nil, char_space = nil)
@@ -28,10 +28,10 @@ module OoxmlParser
28
28
  sect_pr.xpath('w:pgBorders').each do |pg_borders|
29
29
  page_borders = Borders.new
30
30
  unless pg_borders.attribute('display').nil?
31
- page_borders.display = pg_borders.attribute('display').value
31
+ page_borders.display = pg_borders.attribute('display').value.to_sym
32
32
  end
33
33
  unless pg_borders.attribute('offsetFrom').nil?
34
- page_borders.offset_from = pg_borders.attribute('offsetFrom').value
34
+ page_borders.offset_from = pg_borders.attribute('offsetFrom').value.to_sym
35
35
  end
36
36
  pg_borders.xpath('w:bottom').each do |bottom|
37
37
  page_borders.bottom = BordersProperties.parse(bottom)
@@ -45,7 +45,7 @@ module OoxmlParser
45
45
  pg_borders.xpath('w:right').each do |right|
46
46
  page_borders.bottom = BordersProperties.parse(right)
47
47
  end
48
- page_properties.page_border = page_borders
48
+ page_properties.page_borders = page_borders
49
49
  end
50
50
  sect_pr.xpath('w:type').each do |type|
51
51
  page_properties.type = type.attribute('val').value
@@ -68,17 +68,10 @@ module OoxmlParser
68
68
  sect_pr.xpath('w:cols').each do |columns_grid|
69
69
  page_properties.columns = Columns.parse(columns_grid)
70
70
  end
71
- sect_pr.xpath('w:headerReference').each do |header_reference|
72
- target = OOXMLDocumentObject.get_link_from_rels(header_reference.attribute('id').value)
71
+ sect_pr.xpath('w:headerReference', 'w:footerReference').each do |doc_edge_reference|
72
+ target = OOXMLDocumentObject.get_link_from_rels(doc_edge_reference.attribute('id').value)
73
73
  OOXMLDocumentObject.add_to_xmls_stack("word/#{target}")
74
- note = Note.parse(default_paragraph, default_character, target, header_reference.attribute('type').value, File.basename(target).sub('.xml', ''))
75
- page_properties.notes << note
76
- OOXMLDocumentObject.xmls_stack.pop
77
- end
78
- sect_pr.xpath('w:footerReference').each do |footer_reference|
79
- target = OOXMLDocumentObject.get_link_from_rels(footer_reference.attribute('id').value)
80
- OOXMLDocumentObject.add_to_xmls_stack("word/#{target}")
81
- note = Note.parse(default_paragraph, default_character, target, footer_reference.attribute('type').value, File.basename(target).sub('.xml', ''))
74
+ note = Note.parse(default_paragraph, default_character, target, doc_edge_reference.attribute('type').value, File.basename(target).sub('.xml', ''))
82
75
  page_properties.notes << note
83
76
  OOXMLDocumentObject.xmls_stack.pop
84
77
  end
@@ -4,13 +4,9 @@ require_relative 'docx_data/document_structure'
4
4
  module OoxmlParser
5
5
  class DocxParser
6
6
  def self.parse_docx(path_to_file)
7
- path_to_zip_file = OOXMLDocumentObject.copy_file_and_rename_to_zip(path_to_file)
8
- OOXMLDocumentObject.unzip_file(path_to_zip_file, path_to_zip_file.sub(File.basename(path_to_zip_file), ''))
9
- OOXMLDocumentObject.path_to_folder = path_to_zip_file.sub(File.basename(path_to_zip_file), '')
10
- docx_model = DocumentStructure.parse(OOXMLDocumentObject.path_to_folder)
11
- docx_model.file_path = path_to_file
12
- FileUtils.remove_dir(OOXMLDocumentObject.path_to_folder)
13
- docx_model
7
+ Parser.parse(path_to_file) do
8
+ DocumentStructure.parse
9
+ end
14
10
  end
15
11
  end
16
12
  end
@@ -12,8 +12,7 @@ module OoxmlParser
12
12
  @comments = comments
13
13
  end
14
14
 
15
- def self.parse(path_to_folder)
16
- OOXMLDocumentObject.path_to_folder = path_to_folder
15
+ def self.parse
17
16
  OOXMLDocumentObject.root_subfolder = 'ppt/'
18
17
  OOXMLDocumentObject.xmls_stack = []
19
18
  OOXMLDocumentObject.namespace_prefix = 'a'
@@ -17,7 +17,8 @@ module OoxmlParser
17
17
  end
18
18
  doc.xpath('p:cmAuthorLst/p:cmAuthor').each do |author_node|
19
19
  comment_authors[author_node.attribute('id').value] = PresentationCommentAuthor.new(
20
- author_node.attribute('id').value, author_node.attribute('name').value, author_node.attribute('initials').value)
20
+ author_node.attribute('id').value, author_node.attribute('name').value, author_node.attribute('initials').value
21
+ )
21
22
  end
22
23
  comment_authors
23
24
  end
@@ -17,7 +17,7 @@ module OoxmlParser
17
17
  end
18
18
  doc = Nokogiri::XML(File.open(OOXMLDocumentObject.current_xml))
19
19
  doc.xpath('a:theme').each do |theme_node|
20
- OOXMLDocumentObject.theme.name = theme_node.attribute('name').value
20
+ OOXMLDocumentObject.theme.name = theme_node.attribute('name').value if theme_node.attribute('name')
21
21
  theme_node.xpath('a:themeElements/*').each do |theme_element_node|
22
22
  case theme_element_node.name
23
23
  when 'clrScheme'
@@ -20,20 +20,26 @@ module OoxmlParser
20
20
  @elements.select { |cur_element| cur_element.is_a?(GraphicFrame) }
21
21
  end
22
22
 
23
- def content_horizontal_align(object, slide_size)
24
- transform = nil
23
+ # Get transform property of object, by object type
24
+ # @param object [Symbol] type of object: :image, :chart, :table, :shape
25
+ # @return [OOXMLDocumentObject] needed object
26
+ def transform_of_object(object)
25
27
  case object
26
28
  when :image
27
- transform = elements.find { |e| e.is_a? Picture }.properties.transform
29
+ return elements.find { |e| e.is_a? Picture }.properties.transform
28
30
  when :chart
29
- transform = elements.find { |e| e.is_a? GraphicFrame }.transform
31
+ return elements.find { |e| e.is_a? GraphicFrame }.transform
30
32
  when :table
31
- transform = elements.find { |e| e.is_a? GraphicFrame }.transform
33
+ return elements.find { |e| e.is_a? GraphicFrame }.transform
32
34
  when :shape
33
- transform = elements.find { |e| !e.shape_properties.preset.nil? }.shape_properties.transform
35
+ return elements.find { |e| !e.shape_properties.preset.nil? }.shape_properties.transform
34
36
  else
35
37
  raise "Dont know this type object - #{object}"
36
38
  end
39
+ end
40
+
41
+ def content_horizontal_align(object, slide_size)
42
+ transform = transform_of_object(object)
37
43
  return :left if transform.offset.x == 0
38
44
  return :center if ((slide_size.width / 2) - (transform.extents.x / 2)).round(1) == transform.offset.x.round(1)
39
45
  return :right if (slide_size.width - transform.extents.x).round(1) == transform.offset.x.round(1)
@@ -41,19 +47,7 @@ module OoxmlParser
41
47
  end
42
48
 
43
49
  def content_vertical_align(object, slide_size)
44
- transform = nil
45
- case object
46
- when :image
47
- transform = elements.find { |e| e.is_a? Picture }.properties.transform
48
- when :chart
49
- transform = elements.find { |e| e.is_a? GraphicFrame }.transform
50
- when :table
51
- transform = elements.find { |e| e.is_a? GraphicFrame }.transform
52
- when :shape
53
- transform = elements.find { |e| !e.shape_properties.preset.nil? }.shape_properties.transform
54
- else
55
- raise "Dont know this type object - #{object}"
56
- end
50
+ transform = transform_of_object(object)
57
51
  return :top if transform.offset.y == 0
58
52
  return :middle if ((slide_size.height / 2) - (transform.extents.y / 2)).round(1) == transform.offset.y.round(1)
59
53
  return :bottom if (slide_size.height - transform.extents.y).round(1) == transform.offset.y.round(1)