openxml-docx 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/examples/drawing-ml +1 -1
  4. data/examples/image-embedding +141 -0
  5. data/examples/ochanomizu.jpg +0 -0
  6. data/lib/openxml/docx.rb +8 -0
  7. data/lib/openxml/docx/attribute_builder.rb +11 -1
  8. data/lib/openxml/docx/elements/book_fold_printing.rb +12 -0
  9. data/lib/openxml/docx/elements/book_fold_printing_sheets.rb +12 -0
  10. data/lib/openxml/docx/elements/book_fold_reverse_printing.rb +12 -0
  11. data/lib/openxml/docx/elements/drawing.rb +1 -1
  12. data/lib/openxml/docx/elements/embed_system_fonts.rb +14 -0
  13. data/lib/openxml/docx/elements/embed_true_type_fonts.rb +14 -0
  14. data/lib/openxml/docx/elements/font_alternate_name.rb +15 -0
  15. data/lib/openxml/docx/elements/font_character_set.rb +15 -0
  16. data/lib/openxml/docx/elements/font_panose_one.rb +15 -0
  17. data/lib/openxml/docx/elements/font_pitch.rb +15 -0
  18. data/lib/openxml/docx/elements/font_sig.rb +20 -0
  19. data/lib/openxml/docx/elements/save_subset_fonts.rb +14 -0
  20. data/lib/openxml/docx/elements/word_processing_drawing_anchor.rb +13 -11
  21. data/lib/openxml/docx/elements/word_processing_drawing_object_nv_properties.rb +1 -1
  22. data/lib/openxml/docx/elements/word_processing_drawing_position_h.rb +1 -11
  23. data/lib/openxml/docx/elements/word_processing_drawing_position_offset.rb +18 -1
  24. data/lib/openxml/docx/elements/word_processing_drawing_position_v.rb +1 -11
  25. data/lib/openxml/docx/elements/word_processing_drawing_wrap_coordinate.rb +26 -0
  26. data/lib/openxml/docx/elements/word_processing_drawing_wrap_polygon.rb +13 -0
  27. data/lib/openxml/docx/elements/word_processing_drawing_wrap_square.rb +17 -0
  28. data/lib/openxml/docx/elements/word_processing_drawing_wrap_through.rb +15 -0
  29. data/lib/openxml/docx/elements/word_processing_drawing_wrap_tight.rb +15 -0
  30. data/lib/openxml/docx/elements/word_processing_drawing_wrap_top_and_bottom.rb +14 -0
  31. data/lib/openxml/docx/elements/word_processing_groups_group_shape_properties.rb +13 -0
  32. data/lib/openxml/docx/elements/word_processing_groups_nv_shape_drawing_properties.rb +11 -0
  33. data/lib/openxml/docx/elements/word_processing_shapes_nv_drawing_properties.rb +17 -0
  34. data/lib/openxml/docx/package.rb +39 -13
  35. data/lib/openxml/docx/parts/document.rb +3 -2
  36. data/lib/openxml/docx/parts/fonts.rb +2 -1
  37. data/lib/openxml/docx/parts/footer.rb +2 -1
  38. data/lib/openxml/docx/parts/header.rb +2 -1
  39. data/lib/openxml/docx/parts/settings.rb +5 -0
  40. data/lib/openxml/docx/properties/tabs.rb +2 -0
  41. data/lib/openxml/docx/root_namespaces.rb +1 -1
  42. data/lib/openxml/docx/version.rb +1 -1
  43. data/lib/openxml/drawingml/elements/blip.rb +18 -0
  44. data/lib/openxml/drawingml/elements/blip_fill.rb +1 -1
  45. data/lib/openxml/drawingml/elements/fill_rectangle.rb +16 -0
  46. data/lib/openxml/drawingml/elements/graphic_frame_locks.rb +6 -6
  47. data/lib/openxml/drawingml/elements/non_visual_drawing_properties.rb +1 -1
  48. data/lib/openxml/drawingml/elements/picture_locks.rb +23 -0
  49. data/lib/openxml/drawingml/elements/picture_shape_properties.rb +13 -0
  50. data/lib/openxml/drawingml/elements/source_rectangle.rb +16 -0
  51. data/lib/openxml/drawingml/elements/stretch.rb +10 -0
  52. data/spec/elements/book_fold_printing_sheets_spec.rb +27 -0
  53. data/spec/elements/book_fold_printing_spec.rb +19 -0
  54. data/spec/elements/book_fold_reverse_printing_spec.rb +19 -0
  55. data/spec/elements/drawingml/blip_fill_spec.rb +8 -3
  56. data/spec/elements/drawingml/blip_spec.rb +47 -0
  57. data/spec/elements/drawingml/fill_rectangle_spec.rb +76 -0
  58. data/spec/elements/drawingml/graphic_frame_locks_spec.rb +47 -18
  59. data/spec/elements/drawingml/non_visual_drawing_properties_spec.rb +8 -3
  60. data/spec/elements/drawingml/non_visual_picture_drawing_properties_spec.rb +7 -2
  61. data/spec/elements/drawingml/picture_locks_spec.rb +122 -0
  62. data/spec/elements/drawingml/picture_shape_properties_spec.rb +21 -0
  63. data/spec/elements/drawingml/source_rectangle_spec.rb +76 -0
  64. data/spec/elements/drawingml/stretch_spec.rb +8 -0
  65. data/spec/elements/embed_system_fonts_spec.rb +19 -0
  66. data/spec/elements/embed_true_type_fonts_spec.rb +19 -0
  67. data/spec/elements/font_alternate_name_spec.rb +19 -0
  68. data/spec/elements/font_character_set_spec.rb +19 -0
  69. data/spec/elements/font_panose_one_spec.rb +19 -0
  70. data/spec/elements/font_pitch_spec.rb +21 -0
  71. data/spec/elements/font_sig_spec.rb +74 -0
  72. data/spec/elements/save_subset_fonts_spec.rb +19 -0
  73. data/spec/elements/word_processing_drawing_anchor_spec.rb +107 -25
  74. data/spec/elements/word_processing_drawing_object_nv_properties_spec.rb +1 -1
  75. data/spec/elements/word_processing_drawing_position_h_spec.rb +6 -5
  76. data/spec/elements/word_processing_drawing_position_v_spec.rb +6 -5
  77. data/spec/elements/word_processing_drawing_wrap_coordinate_spec.rb +40 -0
  78. data/spec/elements/word_processing_drawing_wrap_polygon_spec.rb +23 -0
  79. data/spec/elements/word_processing_drawing_wrap_square_spec.rb +65 -0
  80. data/spec/elements/word_processing_drawing_wrap_through_spec.rb +43 -0
  81. data/spec/elements/word_processing_drawing_wrap_tight_spec.rb +43 -0
  82. data/spec/elements/word_processing_drawing_wrap_top_and_bottom_spec.rb +30 -0
  83. data/spec/elements/word_processing_groups_group_shape_properties_spec.rb +21 -0
  84. data/spec/elements/word_processing_groups_nv_shape_drawing_properties_spec.rb +8 -0
  85. data/spec/elements/word_processing_shapes_nv_drawing_properties_spec.rb +64 -0
  86. data/spec/package_spec.rb +2 -2
  87. data/spec/parts/settings_spec.rb +6 -0
  88. data/spec/properties/table_border_spec.rb +2 -2
  89. data/spec/properties/table_cell_border_spec.rb +2 -2
  90. data/spec/style_spec.rb +2 -2
  91. data/spec/support/data/parts/document_with_children_part.xml +1 -1
  92. data/spec/support/data/parts/document_with_multiple_sections_part.xml +1 -1
  93. data/spec/support/data/parts/document_with_one_section_part.xml +1 -1
  94. data/spec/support/data/parts/empty_document_part.xml +1 -1
  95. data/spec/support/data/parts/settings_part.xml +1 -1
  96. data/spec/support/property_test_macros.rb +1 -1
  97. metadata +56 -2
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::SaveSubsetFonts do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :saveSubsetFonts, name: "save_subset_fonts"
7
+
8
+ for_attribute(:value) do
9
+ with_value(true) do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:saveSubsetFonts w:val=\"true\"/>"
12
+ end
13
+
14
+ with_value(:somethingElse) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ end
@@ -9,31 +9,113 @@ describe OpenXml::Docx::Elements::WordProcessingDrawingAnchor do
9
9
  it_should_output "<wp:anchor/>", assign: false
10
10
  end
11
11
 
12
- true_false_attributes = %i(allowOverlap behindDoc hidden layoutInCell locked)
13
- true_false_attributes.each do |attr|
14
- for_attribute(attr) do
15
- with_value(true) do
16
- it_should_assign_successfully
17
- it_should_output_regular_xml
18
- end
19
-
20
- with_value("") do
21
- it_should_raise_an_exception
22
- end
23
- end
24
- end
25
-
26
- positive_integer_attributes = %i(distB distL distR distT relativeHeight)
27
- positive_integer_attributes.each do |attr|
28
- for_attribute(attr) do
29
- with_value(1234)do
30
- it_should_assign_successfully
31
- it_should_output_regular_xml
32
- end
33
-
34
- with_value(-1234) do
35
- it_should_raise_an_exception
36
- end
12
+ for_attribute(:allow_overlap) do
13
+ with_value(true) do
14
+ it_should_assign_successfully
15
+ it_should_output "<wp:anchor allowOverlap=\"true\"/>"
16
+ end
17
+
18
+ with_value("") do
19
+ it_should_raise_an_exception
20
+ end
21
+ end
22
+
23
+ for_attribute(:behind_document) do
24
+ with_value(true) do
25
+ it_should_assign_successfully
26
+ it_should_output "<wp:anchor behindDoc=\"true\"/>"
27
+ end
28
+
29
+ with_value("") do
30
+ it_should_raise_an_exception
31
+ end
32
+ end
33
+
34
+ for_attribute(:hidden) do
35
+ with_value(true) do
36
+ it_should_assign_successfully
37
+ it_should_output "<wp:anchor hidden=\"true\"/>"
38
+ end
39
+
40
+ with_value("") do
41
+ it_should_raise_an_exception
42
+ end
43
+ end
44
+
45
+ for_attribute(:layout_in_cell) do
46
+ with_value(true) do
47
+ it_should_assign_successfully
48
+ it_should_output "<wp:anchor layoutInCell=\"true\"/>"
49
+ end
50
+
51
+ with_value("") do
52
+ it_should_raise_an_exception
53
+ end
54
+ end
55
+
56
+ for_attribute(:locked) do
57
+ with_value(true) do
58
+ it_should_assign_successfully
59
+ it_should_output "<wp:anchor locked=\"true\"/>"
60
+ end
61
+
62
+ with_value("") do
63
+ it_should_raise_an_exception
64
+ end
65
+ end
66
+
67
+ for_attribute(:distance_from_bottom) do
68
+ with_value(1234)do
69
+ it_should_assign_successfully
70
+ it_should_output "<wp:anchor distB=\"1234\"/>"
71
+ end
72
+
73
+ with_value(-1234) do
74
+ it_should_raise_an_exception
75
+ end
76
+ end
77
+
78
+ for_attribute(:distance_from_left) do
79
+ with_value(1234)do
80
+ it_should_assign_successfully
81
+ it_should_output "<wp:anchor distL=\"1234\"/>"
82
+ end
83
+
84
+ with_value(-1234) do
85
+ it_should_raise_an_exception
86
+ end
87
+ end
88
+
89
+ for_attribute(:distance_from_right) do
90
+ with_value(1234)do
91
+ it_should_assign_successfully
92
+ it_should_output "<wp:anchor distR=\"1234\"/>"
93
+ end
94
+
95
+ with_value(-1234) do
96
+ it_should_raise_an_exception
97
+ end
98
+ end
99
+
100
+ for_attribute(:distance_from_top) do
101
+ with_value(1234)do
102
+ it_should_assign_successfully
103
+ it_should_output "<wp:anchor distT=\"1234\"/>"
104
+ end
105
+
106
+ with_value(-1234) do
107
+ it_should_raise_an_exception
108
+ end
109
+ end
110
+
111
+ for_attribute(:z_index) do
112
+ with_value(1234)do
113
+ it_should_assign_successfully
114
+ it_should_output "<wp:anchor relativeHeight=\"1234\"/>"
115
+ end
116
+
117
+ with_value(-1234) do
118
+ it_should_raise_an_exception
37
119
  end
38
120
  end
39
121
 
@@ -42,7 +42,7 @@ describe OpenXml::Docx::Elements::WordProcessingDrawingObjectNvProperties do
42
42
  end
43
43
  end
44
44
 
45
- for_attribute(:property_name, displays_as: :name) do
45
+ for_attribute(:object_name, displays_as: :name) do
46
46
  with_value("valid")do
47
47
  it_should_assign_successfully
48
48
  it_should_output_regular_xml
@@ -5,11 +5,12 @@ describe OpenXml::Docx::Elements::WordProcessingDrawingPositionH do
5
5
 
6
6
  it_should_use tag: :positionH, name: "word_processing_drawing_position_h"
7
7
 
8
- for_attribute(:relativeFrom) do
9
- allowed = %i(character column insideMargin leftMargin margin outsideMargin page rightMargin)
10
- with_values(allowed) do
11
- it_should_assign_successfully
12
- it_should_output_regular_xml
8
+ for_attribute(:relative_from) do
9
+ %i(character column insideMargin leftMargin margin outsideMargin page rightMargin).each do |good_value|
10
+ with_value(good_value) do
11
+ it_should_assign_successfully
12
+ it_should_output "<wp:positionH relativeFrom=\"#{good_value}\"/>"
13
+ end
13
14
  end
14
15
 
15
16
  with_value(:notRight) do
@@ -5,11 +5,12 @@ describe OpenXml::Docx::Elements::WordProcessingDrawingPositionV do
5
5
 
6
6
  it_should_use tag: :positionV, name: "word_processing_drawing_position_v"
7
7
 
8
- for_attribute(:relativeFrom) do
9
- allowed = %i(bottomMargin insideMargin line margin outsideMargin page paragraph topMargin)
10
- with_values(allowed) do
11
- it_should_assign_successfully
12
- it_should_output_regular_xml
8
+ for_attribute(:relative_from) do
9
+ %i(bottomMargin insideMargin line margin outsideMargin page paragraph topMargin).each do |good_value|
10
+ with_value(good_value) do
11
+ it_should_assign_successfully
12
+ it_should_output "<wp:positionV relativeFrom=\"#{good_value}\"/>"
13
+ end
13
14
  end
14
15
 
15
16
  with_value(:notRight) do
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::WordProcessingDrawingWrapCoordinate do
4
+ include ElementTestMacros
5
+
6
+ %i(start lineTo).each do |good_tag|
7
+ for_attribute(:x) do
8
+ with_value(1) do
9
+ it_should_assign_successfully good_tag
10
+ it_should_output "<wp:#{good_tag} x=\"1\"/>", good_tag
11
+ end
12
+
13
+ with_value(-1) do
14
+ it_should_assign_successfully good_tag
15
+ it_should_output "<wp:#{good_tag} x=\"-1\"/>", good_tag
16
+ end
17
+
18
+ with_value(20.5) do
19
+ it_should_raise_an_exception
20
+ end
21
+ end
22
+
23
+ for_attribute(:y) do
24
+ with_value(1) do
25
+ it_should_assign_successfully good_tag
26
+ it_should_output "<wp:#{good_tag} y=\"1\"/>", good_tag
27
+ end
28
+
29
+ with_value(-1) do
30
+ it_should_assign_successfully good_tag
31
+ it_should_output "<wp:#{good_tag} y=\"-1\"/>", good_tag
32
+ end
33
+
34
+ with_value(20.5) do
35
+ it_should_raise_an_exception
36
+ end
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::WordProcessingDrawingWrapPolygon do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :wrapPolygon, name: "word_processing_drawing_wrap_polygon"
7
+
8
+ for_attribute(:edited) do
9
+ with_value(true) do
10
+ it_should_assign_successfully
11
+ it_should_output "<wp:wrapPolygon edited=\"true\"/>"
12
+ end
13
+
14
+ with_value(:no_good) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ with_no_attributes_set do
20
+ it_should_output "<wp:wrapPolygon/>", assign: false
21
+ end
22
+
23
+ end
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::WordProcessingDrawingWrapSquare do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :wrapSquare, name: "word_processing_drawing_wrap_square"
7
+
8
+ for_attribute(:distance_from_bottom) do
9
+ with_value(1) do
10
+ it_should_assign_successfully
11
+ it_should_output "<wp:wrapSquare distB=\"1\"/>"
12
+ end
13
+
14
+ with_value(-1) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ for_attribute(:distance_from_left) do
20
+ with_value(1) do
21
+ it_should_assign_successfully
22
+ it_should_output "<wp:wrapSquare distL=\"1\"/>"
23
+ end
24
+
25
+ with_value(-1) do
26
+ it_should_raise_an_exception
27
+ end
28
+ end
29
+
30
+ for_attribute(:distance_from_right) do
31
+ with_value(1) do
32
+ it_should_assign_successfully
33
+ it_should_output "<wp:wrapSquare distR=\"1\"/>"
34
+ end
35
+
36
+ with_value(-1) do
37
+ it_should_raise_an_exception
38
+ end
39
+ end
40
+
41
+ for_attribute(:distance_from_top) do
42
+ with_value(1) do
43
+ it_should_assign_successfully
44
+ it_should_output "<wp:wrapSquare distT=\"1\"/>"
45
+ end
46
+
47
+ with_value(-1) do
48
+ it_should_raise_an_exception
49
+ end
50
+ end
51
+
52
+ for_attribute(:wrap_text) do
53
+ %i(bothSides largest left right).each do |good_value|
54
+ with_value(good_value) do
55
+ it_should_assign_successfully
56
+ it_should_output "<wp:wrapSquare wrapText=\"#{good_value}\"/>"
57
+ end
58
+
59
+ with_value(:bad_value) do
60
+ it_should_raise_an_exception
61
+ end
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::WordProcessingDrawingWrapThrough do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :wrapThrough, name: "word_processing_drawing_wrap_through"
7
+
8
+ for_attribute(:distance_from_left) do
9
+ with_value(1) do
10
+ it_should_assign_successfully
11
+ it_should_output "<wp:wrapThrough distL=\"1\"/>"
12
+ end
13
+
14
+ with_value(-1) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ for_attribute(:distance_from_right) do
20
+ with_value(1) do
21
+ it_should_assign_successfully
22
+ it_should_output "<wp:wrapThrough distR=\"1\"/>"
23
+ end
24
+
25
+ with_value(-1) do
26
+ it_should_raise_an_exception
27
+ end
28
+ end
29
+
30
+ for_attribute(:wrap_text) do
31
+ %i(bothSides largest left right).each do |good_value|
32
+ with_value(good_value) do
33
+ it_should_assign_successfully
34
+ it_should_output "<wp:wrapThrough wrapText=\"#{good_value}\"/>"
35
+ end
36
+
37
+ with_value(:bad_value) do
38
+ it_should_raise_an_exception
39
+ end
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::WordProcessingDrawingWrapTight do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :wrapTight, name: "word_processing_drawing_wrap_tight"
7
+
8
+ for_attribute(:distance_from_left) do
9
+ with_value(1) do
10
+ it_should_assign_successfully
11
+ it_should_output "<wp:wrapTight distL=\"1\"/>"
12
+ end
13
+
14
+ with_value(-1) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ for_attribute(:distance_from_right) do
20
+ with_value(1) do
21
+ it_should_assign_successfully
22
+ it_should_output "<wp:wrapTight distR=\"1\"/>"
23
+ end
24
+
25
+ with_value(-1) do
26
+ it_should_raise_an_exception
27
+ end
28
+ end
29
+
30
+ for_attribute(:wrap_text) do
31
+ %i(bothSides largest left right).each do |good_value|
32
+ with_value(good_value) do
33
+ it_should_assign_successfully
34
+ it_should_output "<wp:wrapTight wrapText=\"#{good_value}\"/>"
35
+ end
36
+
37
+ with_value(:bad_value) do
38
+ it_should_raise_an_exception
39
+ end
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::WordProcessingDrawingWrapTopAndBottom do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :wrapTopAndBottom, name: "word_processing_drawing_wrap_top_and_bottom"
7
+
8
+ for_attribute(:distance_from_bottom) do
9
+ with_value(1) do
10
+ it_should_assign_successfully
11
+ it_should_output "<wp:wrapTopAndBottom distB=\"1\"/>"
12
+ end
13
+
14
+ with_value(-1) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ for_attribute(:distance_from_top) do
20
+ with_value(1) do
21
+ it_should_assign_successfully
22
+ it_should_output "<wp:wrapTopAndBottom distT=\"1\"/>"
23
+ end
24
+
25
+ with_value(-1) do
26
+ it_should_raise_an_exception
27
+ end
28
+ end
29
+
30
+ end