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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/examples/drawing-ml +1 -1
- data/examples/image-embedding +141 -0
- data/examples/ochanomizu.jpg +0 -0
- data/lib/openxml/docx.rb +8 -0
- data/lib/openxml/docx/attribute_builder.rb +11 -1
- data/lib/openxml/docx/elements/book_fold_printing.rb +12 -0
- data/lib/openxml/docx/elements/book_fold_printing_sheets.rb +12 -0
- data/lib/openxml/docx/elements/book_fold_reverse_printing.rb +12 -0
- data/lib/openxml/docx/elements/drawing.rb +1 -1
- data/lib/openxml/docx/elements/embed_system_fonts.rb +14 -0
- data/lib/openxml/docx/elements/embed_true_type_fonts.rb +14 -0
- data/lib/openxml/docx/elements/font_alternate_name.rb +15 -0
- data/lib/openxml/docx/elements/font_character_set.rb +15 -0
- data/lib/openxml/docx/elements/font_panose_one.rb +15 -0
- data/lib/openxml/docx/elements/font_pitch.rb +15 -0
- data/lib/openxml/docx/elements/font_sig.rb +20 -0
- data/lib/openxml/docx/elements/save_subset_fonts.rb +14 -0
- data/lib/openxml/docx/elements/word_processing_drawing_anchor.rb +13 -11
- data/lib/openxml/docx/elements/word_processing_drawing_object_nv_properties.rb +1 -1
- data/lib/openxml/docx/elements/word_processing_drawing_position_h.rb +1 -11
- data/lib/openxml/docx/elements/word_processing_drawing_position_offset.rb +18 -1
- data/lib/openxml/docx/elements/word_processing_drawing_position_v.rb +1 -11
- data/lib/openxml/docx/elements/word_processing_drawing_wrap_coordinate.rb +26 -0
- data/lib/openxml/docx/elements/word_processing_drawing_wrap_polygon.rb +13 -0
- data/lib/openxml/docx/elements/word_processing_drawing_wrap_square.rb +17 -0
- data/lib/openxml/docx/elements/word_processing_drawing_wrap_through.rb +15 -0
- data/lib/openxml/docx/elements/word_processing_drawing_wrap_tight.rb +15 -0
- data/lib/openxml/docx/elements/word_processing_drawing_wrap_top_and_bottom.rb +14 -0
- data/lib/openxml/docx/elements/word_processing_groups_group_shape_properties.rb +13 -0
- data/lib/openxml/docx/elements/word_processing_groups_nv_shape_drawing_properties.rb +11 -0
- data/lib/openxml/docx/elements/word_processing_shapes_nv_drawing_properties.rb +17 -0
- data/lib/openxml/docx/package.rb +39 -13
- data/lib/openxml/docx/parts/document.rb +3 -2
- data/lib/openxml/docx/parts/fonts.rb +2 -1
- data/lib/openxml/docx/parts/footer.rb +2 -1
- data/lib/openxml/docx/parts/header.rb +2 -1
- data/lib/openxml/docx/parts/settings.rb +5 -0
- data/lib/openxml/docx/properties/tabs.rb +2 -0
- data/lib/openxml/docx/root_namespaces.rb +1 -1
- data/lib/openxml/docx/version.rb +1 -1
- data/lib/openxml/drawingml/elements/blip.rb +18 -0
- data/lib/openxml/drawingml/elements/blip_fill.rb +1 -1
- data/lib/openxml/drawingml/elements/fill_rectangle.rb +16 -0
- data/lib/openxml/drawingml/elements/graphic_frame_locks.rb +6 -6
- data/lib/openxml/drawingml/elements/non_visual_drawing_properties.rb +1 -1
- data/lib/openxml/drawingml/elements/picture_locks.rb +23 -0
- data/lib/openxml/drawingml/elements/picture_shape_properties.rb +13 -0
- data/lib/openxml/drawingml/elements/source_rectangle.rb +16 -0
- data/lib/openxml/drawingml/elements/stretch.rb +10 -0
- data/spec/elements/book_fold_printing_sheets_spec.rb +27 -0
- data/spec/elements/book_fold_printing_spec.rb +19 -0
- data/spec/elements/book_fold_reverse_printing_spec.rb +19 -0
- data/spec/elements/drawingml/blip_fill_spec.rb +8 -3
- data/spec/elements/drawingml/blip_spec.rb +47 -0
- data/spec/elements/drawingml/fill_rectangle_spec.rb +76 -0
- data/spec/elements/drawingml/graphic_frame_locks_spec.rb +47 -18
- data/spec/elements/drawingml/non_visual_drawing_properties_spec.rb +8 -3
- data/spec/elements/drawingml/non_visual_picture_drawing_properties_spec.rb +7 -2
- data/spec/elements/drawingml/picture_locks_spec.rb +122 -0
- data/spec/elements/drawingml/picture_shape_properties_spec.rb +21 -0
- data/spec/elements/drawingml/source_rectangle_spec.rb +76 -0
- data/spec/elements/drawingml/stretch_spec.rb +8 -0
- data/spec/elements/embed_system_fonts_spec.rb +19 -0
- data/spec/elements/embed_true_type_fonts_spec.rb +19 -0
- data/spec/elements/font_alternate_name_spec.rb +19 -0
- data/spec/elements/font_character_set_spec.rb +19 -0
- data/spec/elements/font_panose_one_spec.rb +19 -0
- data/spec/elements/font_pitch_spec.rb +21 -0
- data/spec/elements/font_sig_spec.rb +74 -0
- data/spec/elements/save_subset_fonts_spec.rb +19 -0
- data/spec/elements/word_processing_drawing_anchor_spec.rb +107 -25
- data/spec/elements/word_processing_drawing_object_nv_properties_spec.rb +1 -1
- data/spec/elements/word_processing_drawing_position_h_spec.rb +6 -5
- data/spec/elements/word_processing_drawing_position_v_spec.rb +6 -5
- data/spec/elements/word_processing_drawing_wrap_coordinate_spec.rb +40 -0
- data/spec/elements/word_processing_drawing_wrap_polygon_spec.rb +23 -0
- data/spec/elements/word_processing_drawing_wrap_square_spec.rb +65 -0
- data/spec/elements/word_processing_drawing_wrap_through_spec.rb +43 -0
- data/spec/elements/word_processing_drawing_wrap_tight_spec.rb +43 -0
- data/spec/elements/word_processing_drawing_wrap_top_and_bottom_spec.rb +30 -0
- data/spec/elements/word_processing_groups_group_shape_properties_spec.rb +21 -0
- data/spec/elements/word_processing_groups_nv_shape_drawing_properties_spec.rb +8 -0
- data/spec/elements/word_processing_shapes_nv_drawing_properties_spec.rb +64 -0
- data/spec/package_spec.rb +2 -2
- data/spec/parts/settings_spec.rb +6 -0
- data/spec/properties/table_border_spec.rb +2 -2
- data/spec/properties/table_cell_border_spec.rb +2 -2
- data/spec/style_spec.rb +2 -2
- data/spec/support/data/parts/document_with_children_part.xml +1 -1
- data/spec/support/data/parts/document_with_multiple_sections_part.xml +1 -1
- data/spec/support/data/parts/document_with_one_section_part.xml +1 -1
- data/spec/support/data/parts/empty_document_part.xml +1 -1
- data/spec/support/data/parts/settings_part.xml +1 -1
- data/spec/support/property_test_macros.rb +1 -1
- metadata +56 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 281ebe5865109648134cd7d0e38f3dece19e3bb1
|
4
|
+
data.tar.gz: 5198b7f285a17344137d32f5f53044bd44f63e87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e405e98f203bbd647a9e29a164da5c4fee1f23e64092f56e9aefd73f4f7b5fcd5d29dbd9cd3292394b571e61216b2d0a23071a0a5d9e11174e02d3fe78f85f71
|
7
|
+
data.tar.gz: 41d7848b012173dac7a9b62819586d022d02c7bc6b2a36810c7e60c555f2fed5b18c6feb89ed205ca3ebf3e52bf95517181c64af23a5ecfac8d3cd26d524de6c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
openxml-docx (0.10.
|
4
|
+
openxml-docx (0.10.1)
|
5
5
|
nokogiri
|
6
6
|
openxml-package (>= 0.2.2)
|
7
7
|
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
json (1.8.3)
|
15
15
|
method_source (0.8.2)
|
16
16
|
mini_portile2 (2.0.0)
|
17
|
-
nokogiri (1.6.7)
|
17
|
+
nokogiri (1.6.7.1)
|
18
18
|
mini_portile2 (~> 2.0.0.rc2)
|
19
19
|
openxml-package (0.2.2)
|
20
20
|
nokogiri
|
data/examples/drawing-ml
CHANGED
@@ -11,7 +11,7 @@ document = OpenXml::Docx::Package.new
|
|
11
11
|
table = Table.new
|
12
12
|
table.table_width.type = :auto
|
13
13
|
table.table_width.width = 0
|
14
|
-
table.table_layout = :fixed
|
14
|
+
table.table_layout.type = :fixed
|
15
15
|
|
16
16
|
table_cell_margins = OpenXml::Docx::Properties::TableCellMargins.new
|
17
17
|
start_margin = OpenXml::Docx::Properties::TableCellMargin.new(:start)
|
@@ -0,0 +1,141 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.push Dir.pwd + "/lib"
|
4
|
+
require "pry"
|
5
|
+
require "ox"
|
6
|
+
require "openxml/docx"
|
7
|
+
require "openxml/drawingml"
|
8
|
+
|
9
|
+
package = OpenXml::Docx::Package.new
|
10
|
+
|
11
|
+
include OpenXml::Docx::Elements
|
12
|
+
include OpenXml::DrawingML::Elements
|
13
|
+
|
14
|
+
text = Text.new("Some text that I want to include in my new OOXML document")
|
15
|
+
|
16
|
+
run = Run.new
|
17
|
+
run << text
|
18
|
+
paragraph = Paragraph.new
|
19
|
+
paragraph << run
|
20
|
+
|
21
|
+
package.document << paragraph
|
22
|
+
|
23
|
+
image_rid = package.embed_image(path: File.join(File.dirname(__FILE__), "ochanomizu.jpg"))
|
24
|
+
|
25
|
+
paragraph = Paragraph.new
|
26
|
+
run = Run.new
|
27
|
+
|
28
|
+
# This is the overall container for the drawing elements
|
29
|
+
drawing = Drawing.new
|
30
|
+
|
31
|
+
# This is the anchor that provides positioning information in Word
|
32
|
+
anchor = WordProcessingDrawingAnchor.new
|
33
|
+
anchor.allow_overlap = true
|
34
|
+
anchor.behind_document = false
|
35
|
+
anchor.layout_in_cell = true
|
36
|
+
anchor.locked = false
|
37
|
+
anchor.z_index = 1000
|
38
|
+
anchor.simple_position = false
|
39
|
+
anchor.distance_from_bottom = 0
|
40
|
+
anchor.distance_from_top = 0
|
41
|
+
anchor.distance_from_left = 0
|
42
|
+
anchor.distance_from_right = 0
|
43
|
+
|
44
|
+
# These elements are required to be children of anchor and supply the actual positioning information
|
45
|
+
simple_pos = WordProcessingDrawingSimplePosition.new
|
46
|
+
simple_pos.x = 0
|
47
|
+
simple_pos.y = 0
|
48
|
+
anchor << simple_pos
|
49
|
+
position_h = WordProcessingDrawingPositionH.new
|
50
|
+
position_h.relative_from = :column
|
51
|
+
position_offset = WordProcessingDrawingPositionOffset.new
|
52
|
+
position_offset.value = "0"
|
53
|
+
position_h << position_offset
|
54
|
+
anchor << position_h
|
55
|
+
position_v = WordProcessingDrawingPositionV.new
|
56
|
+
position_v.relative_from = :paragraph
|
57
|
+
position_offset = WordProcessingDrawingPositionOffset.new
|
58
|
+
position_offset.value = "0"
|
59
|
+
position_v << position_offset
|
60
|
+
anchor << position_v
|
61
|
+
|
62
|
+
# Extent is the size of the Object
|
63
|
+
extent = WordProcessingDrawingExtent.new
|
64
|
+
extent.extent_length = 599 * 20 # Convert pixels to EMU?
|
65
|
+
extent.extent_width = 393 * 20
|
66
|
+
anchor << extent
|
67
|
+
|
68
|
+
# One of the wrap properties is required
|
69
|
+
anchor << WordProcessingDrawingWrapNone.new
|
70
|
+
|
71
|
+
# Object (non-visual) properties are also required
|
72
|
+
doc_pr = WordProcessingDrawingObjectNvProperties.new
|
73
|
+
doc_pr.description = "ochanomizu.jpg"
|
74
|
+
doc_pr.object_name = "Ochanomizu but not from Tetsuwan Atomu"
|
75
|
+
doc_pr.id = 1
|
76
|
+
anchor << doc_pr
|
77
|
+
|
78
|
+
# This is the actual graphics object
|
79
|
+
graphic = Graphic.new
|
80
|
+
graphic_data = GraphicData.new
|
81
|
+
graphic_data.uri = "http://schemas.openxmlformats.org/drawingml/2006/picture"
|
82
|
+
pic_container = Picture.new
|
83
|
+
|
84
|
+
# Must also define the Picture's non-visual Properties
|
85
|
+
pic_nv_properties = NonVisualPictureProperties.new
|
86
|
+
nv_properties = NonVisualDrawingProperties.new
|
87
|
+
nv_properties.id = 0
|
88
|
+
nv_properties.picture_name = "Ochanomizu but not from Tetsuwan Atomu"
|
89
|
+
nv_properties.description = "ochanomizu.jpg"
|
90
|
+
pic_nv_properties << nv_properties
|
91
|
+
drawing_properties = NonVisualPictureDrawingProperties.new
|
92
|
+
picture_locks = PictureLocks.new
|
93
|
+
picture_locks.disallow_aspect_ratio_changes = true
|
94
|
+
picture_locks.disallow_arrowhead_changes = true
|
95
|
+
drawing_properties << picture_locks
|
96
|
+
pic_nv_properties << drawing_properties
|
97
|
+
pic_container << pic_nv_properties
|
98
|
+
|
99
|
+
# Blip Fill defines the picture that will fill the object's shape
|
100
|
+
blip_fill = BlipFill.new
|
101
|
+
pic_ref = Blip.new
|
102
|
+
pic_ref.embed = image_rid
|
103
|
+
stretch = Stretch.new
|
104
|
+
fill_rect = FillRectangle.new
|
105
|
+
stretch << fill_rect
|
106
|
+
blip_fill << pic_ref
|
107
|
+
blip_fill << stretch
|
108
|
+
blip_fill << SourceRectangle.new
|
109
|
+
pic_container << blip_fill
|
110
|
+
|
111
|
+
# Must also define the picture's shape properties
|
112
|
+
shape_properties = PictureShapeProperties.new
|
113
|
+
shape_properties.black_and_white_mode = :auto
|
114
|
+
preset_geometry = PresetGeometry.new
|
115
|
+
preset_geometry.preset = :rect
|
116
|
+
shape_properties << preset_geometry
|
117
|
+
transform = TransformEffect.new
|
118
|
+
offset = Offset.new
|
119
|
+
offset.x = 0
|
120
|
+
offset.y = 0
|
121
|
+
transform << offset
|
122
|
+
extent = Extents.new
|
123
|
+
extent.extent_length = 599 * 20
|
124
|
+
extent.extent_width = 393 * 20
|
125
|
+
transform << extent
|
126
|
+
shape_properties << transform
|
127
|
+
pic_container << shape_properties
|
128
|
+
|
129
|
+
graphic_data << pic_container
|
130
|
+
graphic << graphic_data
|
131
|
+
|
132
|
+
anchor << graphic
|
133
|
+
drawing << anchor
|
134
|
+
run << drawing
|
135
|
+
paragraph << run
|
136
|
+
package.document << paragraph
|
137
|
+
|
138
|
+
filename = "image_embedding_test.docx"
|
139
|
+
system "rm -f ~/Desktop/#{filename}" # -f so that we don't have an error if the file doesn't exist
|
140
|
+
package.save File.expand_path("~/Desktop/#{filename}")
|
141
|
+
exec "open ~/Desktop/#{filename}"
|
Binary file
|
data/lib/openxml/docx.rb
CHANGED
@@ -7,6 +7,7 @@ module OpenXml
|
|
7
7
|
REL_FOOTER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer".freeze
|
8
8
|
REL_FONT_TABLE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable".freeze
|
9
9
|
REL_FONT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font".freeze
|
10
|
+
REL_IMAGE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image".freeze
|
10
11
|
|
11
12
|
TYPE_STYLES = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml".freeze
|
12
13
|
TYPE_SETTINGS = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml".freeze
|
@@ -15,6 +16,13 @@ module OpenXml
|
|
15
16
|
TYPE_FONT_TABLE = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml".freeze
|
16
17
|
TYPE_XML = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml".freeze
|
17
18
|
TYPE_OBSCURED_FONT = "application/vnd.openxmlformats-officedocument.obfuscatedFont".freeze
|
19
|
+
TYPE_IMAGE = {
|
20
|
+
jpeg: "image/jpeg".freeze,
|
21
|
+
png: "image/png".freeze,
|
22
|
+
gif: "image/gif".freeze,
|
23
|
+
bmp: "image/bmp".freeze,
|
24
|
+
tiff: "image/tiff".freeze
|
25
|
+
}
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
@@ -245,7 +245,7 @@ module OpenXml
|
|
245
245
|
value = send(name)
|
246
246
|
attr_name = "#{namespace}:#{display}"
|
247
247
|
attr_name = "#{display}" if namespace.nil?
|
248
|
-
attrs[attr_name] = value
|
248
|
+
attrs[attr_name] = value unless value.nil?
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
@@ -269,6 +269,16 @@ module OpenXml
|
|
269
269
|
raise ArgumentError, message unless value =~ /[0-9A-F]{4}/
|
270
270
|
end
|
271
271
|
|
272
|
+
def long_hex_number(value)
|
273
|
+
message = "Invalid #{name}: must be an eight-digit hex number, e.g., FFAC0013"
|
274
|
+
raise ArgumentError, message unless value =~ /^[0-9A-F]{8}$/
|
275
|
+
end
|
276
|
+
|
277
|
+
def hex_string(value)
|
278
|
+
message = "Invalid #{name}: must be a string of hexadecimal numbers, e.g. FFA23C6E"
|
279
|
+
raise ArgumentError, message unless value =~ /^[0-9A-F]+$/
|
280
|
+
end
|
281
|
+
|
272
282
|
def integer(value)
|
273
283
|
message = "Invalid #{name}: must be an integer"
|
274
284
|
raise ArgumentError, message unless value.is_a?(Integer)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Elements
|
4
|
+
class FontSig < Element
|
5
|
+
namespace :w
|
6
|
+
tag :sig
|
7
|
+
|
8
|
+
with_namespace :w do
|
9
|
+
attribute :csb0, expects: :long_hex_number
|
10
|
+
attribute :csb1, expects: :long_hex_number
|
11
|
+
attribute :usb0, expects: :long_hex_number
|
12
|
+
attribute :usb1, expects: :long_hex_number
|
13
|
+
attribute :usb2, expects: :long_hex_number
|
14
|
+
attribute :usb3, expects: :long_hex_number
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -5,17 +5,19 @@ module OpenXml
|
|
5
5
|
tag :anchor
|
6
6
|
namespace :wp
|
7
7
|
|
8
|
-
attribute :
|
9
|
-
attribute :
|
10
|
-
attribute :
|
11
|
-
attribute :
|
12
|
-
attribute :
|
13
|
-
attribute :
|
14
|
-
attribute :hidden, expects: :true_or_false
|
15
|
-
attribute :
|
16
|
-
attribute :locked, expects: :true_or_false
|
17
|
-
attribute :
|
18
|
-
attribute :
|
8
|
+
attribute :allow_overlap, expects: :true_or_false, displays_as: :allowOverlap # Required
|
9
|
+
attribute :behind_document, expects: :true_or_false, displays_as: :behindDoc # Required
|
10
|
+
attribute :distance_from_bottom, expects: :positive_integer, displays_as: :distB # Optional
|
11
|
+
attribute :distance_from_left, expects: :positive_integer, displays_as: :distL # Optional
|
12
|
+
attribute :distance_from_right, expects: :positive_integer, displays_as: :distR # Optional
|
13
|
+
attribute :distance_from_top, expects: :positive_integer, displays_as: :distT # Optional
|
14
|
+
attribute :hidden, expects: :true_or_false # Optional
|
15
|
+
attribute :layout_in_cell, expects: :true_or_false, displays_as: :layoutInCell # Required
|
16
|
+
attribute :locked, expects: :true_or_false # Required
|
17
|
+
attribute :z_index, expects: :positive_integer, displays_as: :relativeHeight # Required
|
18
|
+
attribute :simple_position, expects: :true_or_false, displays_as: :simplePos # Optional
|
19
|
+
|
20
|
+
# Children elements required by spec: <docPr>, <a:graphic>, <wp:simplePos>, <wp:positionH>, <wp:positionV>, <wp:extent>, and one of the wp: wrap type tags
|
19
21
|
|
20
22
|
end
|
21
23
|
end
|