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
@@ -5,7 +5,7 @@ describe OpenXml::DrawingML::Elements::NonVisualDrawingProperties do
5
5
 
6
6
  it_should_use tag: :cNvPr, name: "non_visual_drawing_properties"
7
7
 
8
- for_attribute(:descr) do
8
+ for_attribute(:description, displays_as: :descr) do
9
9
  with_value("string") do
10
10
  it_should_assign_successfully
11
11
  it_should_output_regular_xml
@@ -17,9 +17,14 @@ describe OpenXml::DrawingML::Elements::NonVisualDrawingProperties do
17
17
  end
18
18
 
19
19
  for_attribute(:hidden) do
20
- with_values([true, false]) do
20
+ with_value(true) do
21
21
  it_should_assign_successfully
22
- it_should_output_regular_xml
22
+ it_should_output "<pic:cNvPr hidden=\"true\"/>"
23
+ end
24
+
25
+ with_value(false) do
26
+ it_should_assign_successfully
27
+ it_should_output "<pic:cNvPr hidden=\"false\"/>"
23
28
  end
24
29
 
25
30
  with_value(:not_a_boolean) do
@@ -6,9 +6,14 @@ describe OpenXml::DrawingML::Elements::NonVisualPictureDrawingProperties do
6
6
  it_should_use tag: :cNvPicPr, name: "non_visual_picture_drawing_properties"
7
7
 
8
8
  for_attribute(:preferRelativeResize) do
9
- with_values([true, false]) do
9
+ with_value(true) do
10
10
  it_should_assign_successfully
11
- it_should_output_regular_xml
11
+ it_should_output "<pic:cNvPicPr preferRelativeResize=\"true\"/>"
12
+ end
13
+
14
+ with_value(false) do
15
+ it_should_assign_successfully
16
+ it_should_output "<pic:cNvPicPr preferRelativeResize=\"false\"/>"
12
17
  end
13
18
 
14
19
  with_value(:not_a_boolean) do
@@ -0,0 +1,122 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::DrawingML::Elements::PictureLocks do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :picLocks, name: "picture_locks"
7
+
8
+ for_attribute(:hide_adjust_handles) do
9
+ with_value(true) do
10
+ it_should_assign_successfully
11
+ it_should_output "<a:picLocks noAdjustHandles=\"true\"/>"
12
+ end
13
+
14
+ with_value(:not_a_boolean) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ for_attribute(:disallow_arrowhead_changes) do
20
+ with_value(true) do
21
+ it_should_assign_successfully
22
+ it_should_output "<a:picLocks noChangeArrowheads=\"true\"/>"
23
+ end
24
+
25
+ with_value(:not_a_boolean) do
26
+ it_should_raise_an_exception
27
+ end
28
+ end
29
+
30
+ for_attribute(:disallow_aspect_ratio_changes) do
31
+ with_value(true) do
32
+ it_should_assign_successfully
33
+ it_should_output "<a:picLocks noChangeAspect=\"true\"/>"
34
+ end
35
+
36
+ with_value(:not_a_boolean) do
37
+ it_should_raise_an_exception
38
+ end
39
+ end
40
+
41
+ for_attribute(:disallow_shape_type_changes) do
42
+ with_value(true) do
43
+ it_should_assign_successfully
44
+ it_should_output "<a:picLocks noChangeShapeType=\"true\"/>"
45
+ end
46
+
47
+ with_value(:not_a_boolean) do
48
+ it_should_raise_an_exception
49
+ end
50
+ end
51
+ for_attribute(:disallow_cropping) do
52
+ with_value(true) do
53
+ it_should_assign_successfully
54
+ it_should_output "<a:picLocks noCrop=\"true\"/>"
55
+ end
56
+
57
+ with_value(:not_a_boolean) do
58
+ it_should_raise_an_exception
59
+ end
60
+ end
61
+ for_attribute(:disallow_editing_points) do
62
+ with_value(true) do
63
+ it_should_assign_successfully
64
+ it_should_output "<a:picLocks noEditPoints=\"true\"/>"
65
+ end
66
+
67
+ with_value(:not_a_boolean) do
68
+ it_should_raise_an_exception
69
+ end
70
+ end
71
+ for_attribute(:disallow_grouping) do
72
+ with_value(true) do
73
+ it_should_assign_successfully
74
+ it_should_output "<a:picLocks noGrp=\"true\"/>"
75
+ end
76
+
77
+ with_value(:not_a_boolean) do
78
+ it_should_raise_an_exception
79
+ end
80
+ end
81
+ for_attribute(:disallow_moving) do
82
+ with_value(true) do
83
+ it_should_assign_successfully
84
+ it_should_output "<a:picLocks noMove=\"true\"/>"
85
+ end
86
+
87
+ with_value(:not_a_boolean) do
88
+ it_should_raise_an_exception
89
+ end
90
+ end
91
+ for_attribute(:disallow_resizing) do
92
+ with_value(true) do
93
+ it_should_assign_successfully
94
+ it_should_output "<a:picLocks noResize=\"true\"/>"
95
+ end
96
+
97
+ with_value(:not_a_boolean) do
98
+ it_should_raise_an_exception
99
+ end
100
+ end
101
+ for_attribute(:disallow_rotation) do
102
+ with_value(true) do
103
+ it_should_assign_successfully
104
+ it_should_output "<a:picLocks noRot=\"true\"/>"
105
+ end
106
+
107
+ with_value(:not_a_boolean) do
108
+ it_should_raise_an_exception
109
+ end
110
+ end
111
+ for_attribute(:disallow_selection) do
112
+ with_value(true) do
113
+ it_should_assign_successfully
114
+ it_should_output "<a:picLocks noSelect=\"true\"/>"
115
+ end
116
+
117
+ with_value(:not_a_boolean) do
118
+ it_should_raise_an_exception
119
+ end
120
+ end
121
+
122
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::DrawingML::Elements::PictureShapeProperties do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :spPr, name: "picture_shape_properties"
7
+
8
+ for_attribute(:black_and_white_mode) do
9
+ %i(auto black blackGray blackWhite clr gray grayWhite hidden invGray ltGray white).each do |good_value|
10
+ with_value(good_value) do
11
+ it_should_assign_successfully
12
+ it_should_output "<pic:spPr bwMode=\"#{good_value}\"/>"
13
+ end
14
+ end
15
+
16
+ with_value(:disallowed_value) do
17
+ it_should_raise_an_exception
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,76 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::DrawingML::Elements::SourceRectangle do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :srcRect, name: "source_rectangle"
7
+
8
+ for_attribute(:bottom_offset) do
9
+ with_value("10%") do
10
+ it_should_assign_successfully
11
+ it_should_output "<a:srcRect b=\"10%\"/>"
12
+ end
13
+
14
+ with_value("10.1%") do
15
+ it_should_assign_successfully
16
+ it_should_output "<a:srcRect b=\"10.1%\"/>"
17
+ end
18
+
19
+ with_values(["10", 10, "%"]) do
20
+ it_should_raise_an_exception
21
+ end
22
+ end
23
+
24
+ for_attribute(:left_offset) do
25
+ with_value("10%") do
26
+ it_should_assign_successfully
27
+ it_should_output "<a:srcRect l=\"10%\"/>"
28
+ end
29
+
30
+ with_value("10.1%") do
31
+ it_should_assign_successfully
32
+ it_should_output "<a:srcRect l=\"10.1%\"/>"
33
+ end
34
+
35
+ with_values(["10", 10, "%"]) do
36
+ it_should_raise_an_exception
37
+ end
38
+ end
39
+
40
+ for_attribute(:right_offset) do
41
+ with_value("10%") do
42
+ it_should_assign_successfully
43
+ it_should_output "<a:srcRect r=\"10%\"/>"
44
+ end
45
+
46
+ with_value("10.1%") do
47
+ it_should_assign_successfully
48
+ it_should_output "<a:srcRect r=\"10.1%\"/>"
49
+ end
50
+
51
+ with_values(["10", 10, "%"]) do
52
+ it_should_raise_an_exception
53
+ end
54
+ end
55
+
56
+ for_attribute(:top_offset) do
57
+ with_value("10%") do
58
+ it_should_assign_successfully
59
+ it_should_output "<a:srcRect t=\"10%\"/>"
60
+ end
61
+
62
+ with_value("10.1%") do
63
+ it_should_assign_successfully
64
+ it_should_output "<a:srcRect t=\"10.1%\"/>"
65
+ end
66
+
67
+ with_values(["10", 10, "%"]) do
68
+ it_should_raise_an_exception
69
+ end
70
+ end
71
+
72
+ with_no_attributes_set do
73
+ it_should_output "<a:srcRect/>", assign: false
74
+ end
75
+
76
+ end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::DrawingML::Elements::Stretch do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :stretch, name: "stretch"
7
+
8
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::EmbedSystemFonts do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :embedSystemFonts, name: "embed_system_fonts"
7
+
8
+ for_attribute(:value) do
9
+ with_value(true) do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:embedSystemFonts w:val=\"true\"/>"
12
+ end
13
+
14
+ with_value(:somethingElse) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::EmbedTrueTypeFonts do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :embedTrueTypeFonts, name: "embed_true_type_fonts"
7
+
8
+ for_attribute(:value) do
9
+ with_value(true) do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:embedTrueTypeFonts w:val=\"true\"/>"
12
+ end
13
+
14
+ with_value(:somethingElse) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::FontAlternateName do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :altName, name: "font_alternate_name"
7
+
8
+ for_attribute(:value) do
9
+ with_value("String Font Name") do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:altName w:val=\"String Font Name\"/>"
12
+ end
13
+
14
+ with_value(:somethingElse) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::FontCharacterSet do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :charset, name: "font_character_set"
7
+
8
+ for_attribute(:character_set) do
9
+ with_value("String") do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:charset w:characterSet=\"String\"/>"
12
+ end
13
+
14
+ with_value(:somethingElse) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::FontPanoseOne do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :panose1, name: "font_panose_one"
7
+
8
+ for_attribute(:value) do
9
+ with_value("ABCDE1234567890") do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:panose1 w:val=\"ABCDE1234567890\"/>"
12
+ end
13
+
14
+ with_value("Not a string of hex digits") do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::FontPitch do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :pitch, name: "font_pitch"
7
+
8
+ for_attribute(:value) do
9
+ %i(default fixed variable).each do |good_value|
10
+ with_value(good_value) do
11
+ it_should_assign_successfully
12
+ it_should_output "<w:pitch w:val=\"#{good_value}\"/>"
13
+ end
14
+ end
15
+
16
+ with_value(:bad_value) do
17
+ it_should_raise_an_exception
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,74 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::FontSig do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :sig, name: "font_sig"
7
+
8
+ for_attribute(:csb0) do
9
+ with_value("F0E1B2E3") do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:sig w:csb0=\"F0E1B2E3\"/>"
12
+ end
13
+
14
+ with_values(["FF","Not Hex","FFFFFFFFFF"]) do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ for_attribute(:csb1) do
20
+ with_value("F0E1B2E3") do
21
+ it_should_assign_successfully
22
+ it_should_output "<w:sig w:csb1=\"F0E1B2E3\"/>"
23
+ end
24
+
25
+ with_values(["FF","Not Hex","FFFFFFFFFF"]) do
26
+ it_should_raise_an_exception
27
+ end
28
+ end
29
+
30
+ for_attribute(:usb0) do
31
+ with_value("F0E1B2E3") do
32
+ it_should_assign_successfully
33
+ it_should_output "<w:sig w:usb0=\"F0E1B2E3\"/>"
34
+ end
35
+
36
+ with_values(["FF","Not Hex","FFFFFFFFFF"]) do
37
+ it_should_raise_an_exception
38
+ end
39
+ end
40
+
41
+ for_attribute(:usb1) do
42
+ with_value("F0E1B2E3") do
43
+ it_should_assign_successfully
44
+ it_should_output "<w:sig w:usb1=\"F0E1B2E3\"/>"
45
+ end
46
+
47
+ with_values(["FF","Not Hex","FFFFFFFFFF"]) do
48
+ it_should_raise_an_exception
49
+ end
50
+ end
51
+
52
+ for_attribute(:usb2) do
53
+ with_value("F0E1B2E3") do
54
+ it_should_assign_successfully
55
+ it_should_output "<w:sig w:usb2=\"F0E1B2E3\"/>"
56
+ end
57
+
58
+ with_values(["FF","Not Hex","FFFFFFFFFF"]) do
59
+ it_should_raise_an_exception
60
+ end
61
+ end
62
+
63
+ for_attribute(:usb3) do
64
+ with_value("F0E1B2E3") do
65
+ it_should_assign_successfully
66
+ it_should_output "<w:sig w:usb3=\"F0E1B2E3\"/>"
67
+ end
68
+
69
+ with_values(["FF","Not Hex","FFFFFFFFFF"]) do
70
+ it_should_raise_an_exception
71
+ end
72
+ end
73
+
74
+ end