ruby_pptx 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/README.md +83 -2
- data/lib/ruby_pptx/action.rb +12 -4
- data/lib/ruby_pptx/autoshape_spec.rb +6 -2
- data/lib/ruby_pptx/builder.rb +3 -1
- data/lib/ruby_pptx/chart/categories.rb +45 -15
- data/lib/ruby_pptx/chart/chart.rb +77 -27
- data/lib/ruby_pptx/chart/combo.rb +9 -3
- data/lib/ruby_pptx/chart/data.rb +45 -15
- data/lib/ruby_pptx/chart/format.rb +229 -76
- data/lib/ruby_pptx/chart/workbook_writer.rb +9 -3
- data/lib/ruby_pptx/chart/xml_writer.rb +54 -18
- data/lib/ruby_pptx/chart/xy_data.rb +68 -22
- data/lib/ruby_pptx/dml/color.rb +27 -9
- data/lib/ruby_pptx/dml/effect.rb +6 -2
- data/lib/ruby_pptx/dml/fill.rb +42 -14
- data/lib/ruby_pptx/element_proxy.rb +12 -4
- data/lib/ruby_pptx/enum/base.rb +30 -10
- data/lib/ruby_pptx/enum/prog_id.rb +3 -1
- data/lib/ruby_pptx/geometry.rb +32 -10
- data/lib/ruby_pptx/image.rb +27 -9
- data/lib/ruby_pptx/length.rb +94 -27
- data/lib/ruby_pptx/media.rb +12 -4
- data/lib/ruby_pptx/numeric_lengths.rb +34 -9
- data/lib/ruby_pptx/opc/oxml.rb +7 -5
- data/lib/ruby_pptx/opc/pack_uri.rb +15 -5
- data/lib/ruby_pptx/opc/package.rb +97 -31
- data/lib/ruby_pptx/opc/serialized.rb +15 -5
- data/lib/ruby_pptx/oxml/backend.rb +585 -0
- data/lib/ruby_pptx/oxml/chart.rb +112 -42
- data/lib/ruby_pptx/oxml/content_model.rb +6 -2
- data/lib/ruby_pptx/oxml/dml/color.rb +6 -2
- data/lib/ruby_pptx/oxml/dml/fill.rb +6 -2
- data/lib/ruby_pptx/oxml/element.rb +138 -101
- data/lib/ruby_pptx/oxml/ns.rb +7 -7
- data/lib/ruby_pptx/oxml/presentation.rb +9 -3
- data/lib/ruby_pptx/oxml/section.rb +3 -1
- data/lib/ruby_pptx/oxml/shapes/autoshape.rb +39 -13
- data/lib/ruby_pptx/oxml/shapes/groupshape.rb +15 -7
- data/lib/ruby_pptx/oxml/shapes/other.rb +47 -16
- data/lib/ruby_pptx/oxml/shapes/shared.rb +96 -30
- data/lib/ruby_pptx/oxml/simple_types.rb +169 -52
- data/lib/ruby_pptx/oxml/slide.rb +24 -8
- data/lib/ruby_pptx/oxml/table.rb +39 -13
- data/lib/ruby_pptx/oxml/text.rb +37 -15
- data/lib/ruby_pptx/oxml/theme.rb +13 -4
- data/lib/ruby_pptx/package.rb +9 -3
- data/lib/ruby_pptx/parts/chart.rb +6 -2
- data/lib/ruby_pptx/parts/image.rb +12 -4
- data/lib/ruby_pptx/parts/media.rb +3 -1
- data/lib/ruby_pptx/parts/presentation.rb +15 -5
- data/lib/ruby_pptx/parts/slide.rb +33 -11
- data/lib/ruby_pptx/parts/theme.rb +3 -1
- data/lib/ruby_pptx/pattern_matching.rb +6 -2
- data/lib/ruby_pptx/presentation.rb +24 -8
- data/lib/ruby_pptx/section.rb +30 -10
- data/lib/ruby_pptx/shapes/adjustments.rb +9 -3
- data/lib/ruby_pptx/shapes/authoring.rb +3 -1
- data/lib/ruby_pptx/shapes/base.rb +74 -24
- data/lib/ruby_pptx/shapes/freeform.rb +36 -12
- data/lib/ruby_pptx/shapes/placeholder.rb +44 -15
- data/lib/ruby_pptx/shapes/shape.rb +91 -30
- data/lib/ruby_pptx/shapes/shape_tree.rb +66 -22
- data/lib/ruby_pptx/slide.rb +123 -41
- data/lib/ruby_pptx/table.rb +105 -35
- data/lib/ruby_pptx/text/font_metrics.rb +30 -9
- data/lib/ruby_pptx/text/text.rb +108 -36
- data/lib/ruby_pptx/theme.rb +30 -10
- data/lib/ruby_pptx/version.rb +1 -1
- data/lib/ruby_pptx.rb +8 -1
- metadata +22 -1
|
@@ -25,10 +25,14 @@ module Pptx
|
|
|
25
25
|
one_and_only_one "p:spPr"
|
|
26
26
|
|
|
27
27
|
# The `a:blip` inside this picture's fill.
|
|
28
|
-
def blip
|
|
28
|
+
def blip
|
|
29
|
+
xpath("./p:blipFill/a:blip").first
|
|
30
|
+
end
|
|
29
31
|
|
|
30
32
|
# The relationship id of the image this picture shows, or nil.
|
|
31
|
-
def blip_rId
|
|
33
|
+
def blip_rId
|
|
34
|
+
blip&.embed
|
|
35
|
+
end
|
|
32
36
|
|
|
33
37
|
# Cropping, as a fraction of the image cropped from each side. Reading
|
|
34
38
|
# gives 0.0 when there is no `a:srcRect`; writing creates one.
|
|
@@ -39,9 +43,13 @@ module Pptx
|
|
|
39
43
|
end
|
|
40
44
|
end
|
|
41
45
|
|
|
42
|
-
def ln
|
|
46
|
+
def ln
|
|
47
|
+
spPr.ln
|
|
48
|
+
end
|
|
43
49
|
|
|
44
|
-
def get_or_add_ln
|
|
50
|
+
def get_or_add_ln
|
|
51
|
+
spPr.get_or_add_ln
|
|
52
|
+
end
|
|
45
53
|
|
|
46
54
|
# Crop so an image of +image_size+ fills +view_size+ exactly when
|
|
47
55
|
# stretched with its aspect ratio kept: the excess is cut equally from
|
|
@@ -80,7 +88,9 @@ module Pptx
|
|
|
80
88
|
end
|
|
81
89
|
|
|
82
90
|
# A movie is a `p:pic` whose non-visual properties name a video file.
|
|
83
|
-
def movie?
|
|
91
|
+
def movie?
|
|
92
|
+
!xpath("./p:nvPicPr/p:nvPr/a:videoFile").empty?
|
|
93
|
+
end
|
|
84
94
|
|
|
85
95
|
# A `p:pic` displaying the image related by +r_id+.
|
|
86
96
|
def self.new_pic(id, name, desc, r_id, x, y, cx, cy)
|
|
@@ -276,28 +286,49 @@ module Pptx
|
|
|
276
286
|
"http://schemas.openxmlformats.org/presentationml/2006/ole"
|
|
277
287
|
|
|
278
288
|
# A graphic frame keeps its transform directly, not under `p:spPr`.
|
|
279
|
-
def xfrm
|
|
289
|
+
def xfrm
|
|
290
|
+
find("p:xfrm")
|
|
291
|
+
end
|
|
280
292
|
|
|
281
|
-
def get_or_add_xfrm
|
|
293
|
+
def get_or_add_xfrm
|
|
294
|
+
xfrm
|
|
295
|
+
end
|
|
282
296
|
|
|
283
|
-
def graphic_data_uri
|
|
297
|
+
def graphic_data_uri
|
|
298
|
+
xpath("./a:graphic/a:graphicData/@uri").first&.value
|
|
299
|
+
end
|
|
284
300
|
|
|
285
301
|
# The relationship id of the chart part this frame refers to.
|
|
286
|
-
def chart_rId
|
|
302
|
+
def chart_rId
|
|
303
|
+
xpath("./a:graphic/a:graphicData/c:chart/@r:id").first&.value
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
def table?
|
|
307
|
+
graphic_data_uri == URI_TABLE
|
|
308
|
+
end
|
|
287
309
|
|
|
288
|
-
def
|
|
289
|
-
|
|
310
|
+
def chart?
|
|
311
|
+
graphic_data_uri == URI_CHART
|
|
312
|
+
end
|
|
290
313
|
|
|
291
314
|
# The `a:tbl` inside this frame, or nil when it holds something else.
|
|
292
|
-
def tbl
|
|
315
|
+
def tbl
|
|
316
|
+
xpath("./a:graphic/a:graphicData/a:tbl").first
|
|
317
|
+
end
|
|
293
318
|
|
|
294
|
-
def ole_object?
|
|
319
|
+
def ole_object?
|
|
320
|
+
graphic_data_uri == URI_OLE_OBJECT
|
|
321
|
+
end
|
|
295
322
|
|
|
296
323
|
# The `p:oleObj` inside this frame, or nil.
|
|
297
|
-
def oleObj
|
|
324
|
+
def oleObj
|
|
325
|
+
xpath("./a:graphic/a:graphicData/p:oleObj").first
|
|
326
|
+
end
|
|
298
327
|
|
|
299
328
|
# An OLE object carries its file (`p:embed`) or points elsewhere for it.
|
|
300
|
-
def embedded_ole_object?
|
|
329
|
+
def embedded_ole_object?
|
|
330
|
+
!xpath("./a:graphic/a:graphicData/p:oleObj/p:embed").empty?
|
|
331
|
+
end
|
|
301
332
|
|
|
302
333
|
class << self
|
|
303
334
|
# A frame holding an OLE object shown as an icon: the embedded file is
|
|
@@ -379,7 +410,7 @@ module Pptx
|
|
|
379
410
|
graphic_data = frame.xpath("./a:graphic/a:graphicData").first
|
|
380
411
|
graphic_data.set("uri", URI_CHART)
|
|
381
412
|
graphic_data.append(
|
|
382
|
-
graphic_data.
|
|
413
|
+
graphic_data.import(CT_Chart.new_chart(r_id))
|
|
383
414
|
)
|
|
384
415
|
frame
|
|
385
416
|
end
|
|
@@ -14,44 +14,58 @@ module Pptx
|
|
|
14
14
|
# Position and size live in an `a:xfrm` grandchild that may be absent, so
|
|
15
15
|
# the accessors here read through to it and create it only on write.
|
|
16
16
|
module BaseShapeElement
|
|
17
|
-
def x
|
|
17
|
+
def x
|
|
18
|
+
xfrm_attr(:x)
|
|
19
|
+
end
|
|
18
20
|
|
|
19
21
|
def x=(value)
|
|
20
22
|
set_xfrm_attr(:x, value)
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
def y
|
|
25
|
+
def y
|
|
26
|
+
xfrm_attr(:y)
|
|
27
|
+
end
|
|
24
28
|
|
|
25
29
|
def y=(value)
|
|
26
30
|
set_xfrm_attr(:y, value)
|
|
27
31
|
end
|
|
28
32
|
|
|
29
|
-
def cx
|
|
33
|
+
def cx
|
|
34
|
+
xfrm_attr(:cx)
|
|
35
|
+
end
|
|
30
36
|
|
|
31
37
|
def cx=(value)
|
|
32
38
|
set_xfrm_attr(:cx, value)
|
|
33
39
|
end
|
|
34
40
|
|
|
35
|
-
def cy
|
|
41
|
+
def cy
|
|
42
|
+
xfrm_attr(:cy)
|
|
43
|
+
end
|
|
36
44
|
|
|
37
45
|
def cy=(value)
|
|
38
46
|
set_xfrm_attr(:cy, value)
|
|
39
47
|
end
|
|
40
48
|
|
|
41
|
-
def flipH
|
|
49
|
+
def flipH
|
|
50
|
+
!xfrm_attr(:flipH).nil? && xfrm_attr(:flipH)
|
|
51
|
+
end
|
|
42
52
|
|
|
43
53
|
def flipH=(value)
|
|
44
54
|
set_xfrm_attr(:flipH, value)
|
|
45
55
|
end
|
|
46
56
|
|
|
47
|
-
def flipV
|
|
57
|
+
def flipV
|
|
58
|
+
!xfrm_attr(:flipV).nil? && xfrm_attr(:flipV)
|
|
59
|
+
end
|
|
48
60
|
|
|
49
61
|
def flipV=(value)
|
|
50
62
|
set_xfrm_attr(:flipV, value)
|
|
51
63
|
end
|
|
52
64
|
|
|
53
65
|
# Clockwise rotation in degrees; 0.0 when not set.
|
|
54
|
-
def rot
|
|
66
|
+
def rot
|
|
67
|
+
xfrm&.rot || 0.0
|
|
68
|
+
end
|
|
55
69
|
|
|
56
70
|
def rot=(value)
|
|
57
71
|
get_or_add_xfrm.rot = value
|
|
@@ -59,29 +73,56 @@ module Pptx
|
|
|
59
73
|
|
|
60
74
|
# The `a:xfrm` grandchild, or nil. `p:grpSp` overrides this, since its
|
|
61
75
|
# transform hangs off `p:grpSpPr` rather than `p:spPr`.
|
|
62
|
-
def xfrm
|
|
76
|
+
def xfrm
|
|
77
|
+
spPr.xfrm
|
|
78
|
+
end
|
|
63
79
|
|
|
64
|
-
def get_or_add_xfrm
|
|
80
|
+
def get_or_add_xfrm
|
|
81
|
+
spPr.get_or_add_xfrm
|
|
82
|
+
end
|
|
65
83
|
|
|
66
|
-
def shape_id
|
|
84
|
+
def shape_id
|
|
85
|
+
nvXxPr.cNvPr.id
|
|
86
|
+
end
|
|
67
87
|
|
|
68
|
-
def shape_name
|
|
88
|
+
def shape_name
|
|
89
|
+
nvXxPr.cNvPr.name
|
|
90
|
+
end
|
|
69
91
|
|
|
70
|
-
def txBody
|
|
92
|
+
def txBody
|
|
93
|
+
find("p:txBody")
|
|
94
|
+
end
|
|
71
95
|
|
|
72
|
-
def placeholder?
|
|
96
|
+
def placeholder?
|
|
97
|
+
!ph.nil?
|
|
98
|
+
end
|
|
73
99
|
|
|
74
100
|
# The `p:ph` descendant marking this as a placeholder, or nil.
|
|
75
|
-
def ph
|
|
101
|
+
def ph
|
|
102
|
+
xpath("./*[1]/p:nvPr/p:ph").first
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def ph_idx
|
|
106
|
+
require_ph.idx
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def ph_orient
|
|
110
|
+
require_ph.orient
|
|
111
|
+
end
|
|
76
112
|
|
|
77
|
-
def
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
113
|
+
def ph_sz
|
|
114
|
+
require_ph.sz
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def ph_type
|
|
118
|
+
require_ph.type
|
|
119
|
+
end
|
|
81
120
|
|
|
82
121
|
# The non-visual properties element, whose tag varies by shape type
|
|
83
122
|
# (`p:nvSpPr`, `p:nvPicPr`, ...). It is always the first child.
|
|
84
|
-
def nvXxPr
|
|
123
|
+
def nvXxPr
|
|
124
|
+
xpath("./*[1]").first
|
|
125
|
+
end
|
|
85
126
|
|
|
86
127
|
private
|
|
87
128
|
|
|
@@ -135,25 +176,33 @@ module Pptx
|
|
|
135
176
|
optional_attr "flipH", type: SimpleTypes::XsdBoolean, default: false
|
|
136
177
|
optional_attr "flipV", type: SimpleTypes::XsdBoolean, default: false
|
|
137
178
|
|
|
138
|
-
def x
|
|
179
|
+
def x
|
|
180
|
+
off&.x
|
|
181
|
+
end
|
|
139
182
|
|
|
140
183
|
def x=(value)
|
|
141
184
|
get_or_add_off.x = value
|
|
142
185
|
end
|
|
143
186
|
|
|
144
|
-
def y
|
|
187
|
+
def y
|
|
188
|
+
off&.y
|
|
189
|
+
end
|
|
145
190
|
|
|
146
191
|
def y=(value)
|
|
147
192
|
get_or_add_off.y = value
|
|
148
193
|
end
|
|
149
194
|
|
|
150
|
-
def cx
|
|
195
|
+
def cx
|
|
196
|
+
ext&.cx
|
|
197
|
+
end
|
|
151
198
|
|
|
152
199
|
def cx=(value)
|
|
153
200
|
get_or_add_ext.cx = value
|
|
154
201
|
end
|
|
155
202
|
|
|
156
|
-
def cy
|
|
203
|
+
def cy
|
|
204
|
+
ext&.cy
|
|
205
|
+
end
|
|
157
206
|
|
|
158
207
|
def cy=(value)
|
|
159
208
|
get_or_add_ext.cy = value
|
|
@@ -239,9 +288,13 @@ module Pptx
|
|
|
239
288
|
optional_attr "w", type: SimpleTypes::ST_LineWidth, default: Pptx::Length.emu(0)
|
|
240
289
|
|
|
241
290
|
# The fill layer names this differently; both point at the same group.
|
|
242
|
-
def eg_fillProperties
|
|
291
|
+
def eg_fillProperties
|
|
292
|
+
eg_lineFillProperties
|
|
293
|
+
end
|
|
243
294
|
|
|
244
|
-
def prstDash_val
|
|
295
|
+
def prstDash_val
|
|
296
|
+
prstDash&.val
|
|
297
|
+
end
|
|
245
298
|
|
|
246
299
|
def prstDash_val=(value)
|
|
247
300
|
remove_custDash
|
|
@@ -269,14 +322,27 @@ module Pptx
|
|
|
269
322
|
zero_or_one "a:ln", successors: TAG_SEQ[10..]
|
|
270
323
|
zero_or_one "a:effectLst", successors: TAG_SEQ[11..]
|
|
271
324
|
|
|
272
|
-
def x
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
325
|
+
def x
|
|
326
|
+
xfrm&.x
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def y
|
|
330
|
+
xfrm&.y
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
def cx
|
|
334
|
+
xfrm&.cx
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
def cy
|
|
338
|
+
xfrm&.cy
|
|
339
|
+
end
|
|
276
340
|
|
|
277
341
|
# A new gradient starts from PowerPoint's default rather than empty; an
|
|
278
342
|
# `a:gradFill` with no stops draws nothing.
|
|
279
|
-
def new_gradFill
|
|
343
|
+
def new_gradFill
|
|
344
|
+
CT_GradientFillProperties.new_grad_fill(self)
|
|
345
|
+
end
|
|
280
346
|
end
|
|
281
347
|
|
|
282
348
|
# `p:grpSpPr`, the properties of a group shape or shape tree.
|