ruby_pptx 0.1.0 → 0.3.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 +98 -0
- data/README.md +94 -4
- 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 +168 -31
- data/lib/ruby_pptx/chart/combo.rb +19 -4
- 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 +25 -8
- data/lib/ruby_pptx/oxml/table.rb +39 -13
- data/lib/ruby_pptx/oxml/text.rb +122 -16
- 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 +235 -121
- data/lib/ruby_pptx/slide.rb +137 -46
- data/lib/ruby_pptx/table.rb +105 -35
- data/lib/ruby_pptx/text/font_metrics.rb +30 -9
- data/lib/ruby_pptx/text/list_style.rb +88 -0
- data/lib/ruby_pptx/text/text.rb +241 -59
- data/lib/ruby_pptx/theme.rb +30 -10
- data/lib/ruby_pptx/version.rb +1 -1
- data/lib/ruby_pptx.rb +9 -1
- metadata +24 -2
data/lib/ruby_pptx/oxml/text.rb
CHANGED
|
@@ -6,6 +6,7 @@ require "ruby_pptx/oxml/simple_types"
|
|
|
6
6
|
require "ruby_pptx/oxml/dml/fill"
|
|
7
7
|
require "ruby_pptx/enum/text"
|
|
8
8
|
require "ruby_pptx/enum/lang"
|
|
9
|
+
require "securerandom"
|
|
9
10
|
|
|
10
11
|
module Pptx
|
|
11
12
|
module Oxml
|
|
@@ -24,7 +25,9 @@ module Pptx
|
|
|
24
25
|
zero_or_one "a:rPr", successors: %w[a:t]
|
|
25
26
|
one_and_only_one "a:t"
|
|
26
27
|
|
|
27
|
-
def text
|
|
28
|
+
def text
|
|
29
|
+
t.text
|
|
30
|
+
end
|
|
28
31
|
|
|
29
32
|
def text=(value)
|
|
30
33
|
t.text = CT_RegularTextRun.escape_control_chars(value.to_s)
|
|
@@ -46,7 +49,9 @@ module Pptx
|
|
|
46
49
|
# A break carries no text of its own; it *is* the line feed, which we
|
|
47
50
|
# report as a vertical tab to match how PowerPoint puts it on the
|
|
48
51
|
# clipboard.
|
|
49
|
-
def text
|
|
52
|
+
def text
|
|
53
|
+
"\v"
|
|
54
|
+
end
|
|
50
55
|
end
|
|
51
56
|
|
|
52
57
|
# `a:fld`, a slide-number or date field.
|
|
@@ -55,7 +60,9 @@ module Pptx
|
|
|
55
60
|
zero_or_one "a:rPr", successors: %w[a:pPr a:t]
|
|
56
61
|
zero_or_one "a:t", successors: []
|
|
57
62
|
|
|
58
|
-
def text
|
|
63
|
+
def text
|
|
64
|
+
t&.text.to_s
|
|
65
|
+
end
|
|
59
66
|
end
|
|
60
67
|
|
|
61
68
|
# `a:latin`, `a:ea`, `a:cs` and `a:sym`: a typeface reference.
|
|
@@ -83,8 +90,11 @@ module Pptx
|
|
|
83
90
|
optional_attr "b", type: SimpleTypes::XsdBoolean
|
|
84
91
|
optional_attr "i", type: SimpleTypes::XsdBoolean
|
|
85
92
|
optional_attr "u", type: Enum::MSO_TEXT_UNDERLINE_TYPE
|
|
93
|
+
optional_attr "cap", type: SimpleTypes::XsdString
|
|
86
94
|
|
|
87
|
-
def new_gradFill
|
|
95
|
+
def new_gradFill
|
|
96
|
+
CT_GradientFillProperties.new_grad_fill(self)
|
|
97
|
+
end
|
|
88
98
|
end
|
|
89
99
|
|
|
90
100
|
# `a:bodyPr`, the properties of a text body: margins, anchoring, autofit.
|
|
@@ -100,6 +110,7 @@ module Pptx
|
|
|
100
110
|
optional_attr "bIns", type: SimpleTypes::ST_Coordinate32, default: Pptx::Length.emu(45_720)
|
|
101
111
|
optional_attr "anchor", type: Enum::MSO_VERTICAL_ANCHOR
|
|
102
112
|
optional_attr "wrap", type: SimpleTypes::ST_TextWrappingType
|
|
113
|
+
optional_attr "vert", type: SimpleTypes::XsdString
|
|
103
114
|
|
|
104
115
|
# @return [Pptx::Enum::MSO_AUTO_SIZE, nil] nil when inherited
|
|
105
116
|
def autofit
|
|
@@ -166,9 +177,29 @@ module Pptx
|
|
|
166
177
|
end
|
|
167
178
|
end
|
|
168
179
|
|
|
180
|
+
# `a:buNone`, no bullet, even where the master would draw one.
|
|
181
|
+
class CT_TextNoBullet < Element
|
|
182
|
+
tag "a:buNone"
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# `a:buAutoNum`, an automatically numbered bullet ("1.", "a)", ...).
|
|
186
|
+
class CT_TextAutonumberBullet < Element
|
|
187
|
+
tag "a:buAutoNum"
|
|
188
|
+
required_attr "type", type: SimpleTypes::XsdString
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# `a:buChar`, a character bullet.
|
|
192
|
+
class CT_TextCharBullet < Element
|
|
193
|
+
tag "a:buChar"
|
|
194
|
+
required_attr "char", type: SimpleTypes::XsdString
|
|
195
|
+
end
|
|
196
|
+
|
|
169
197
|
# `a:pPr`, paragraph properties.
|
|
170
198
|
class CT_TextParagraphProperties < Element
|
|
171
|
-
|
|
199
|
+
# A list style's default and per-level paragraph properties share the
|
|
200
|
+
# content model of a paragraph's own `a:pPr`.
|
|
201
|
+
LEVEL_TAGS = (1..9).map { |n| "a:lvl#{n}pPr" }.freeze
|
|
202
|
+
tag "a:pPr", "a:defPPr", *LEVEL_TAGS
|
|
172
203
|
TAG_SEQ = %w[a:lnSpc a:spcBef a:spcAft a:buClrTx a:buClr a:buSzTx a:buSzPct
|
|
173
204
|
a:buSzPts a:buFontTx a:buFont a:buNone a:buAutoNum a:buChar
|
|
174
205
|
a:buBlip a:tabLst a:defRPr a:extLst].freeze
|
|
@@ -176,9 +207,15 @@ module Pptx
|
|
|
176
207
|
zero_or_one "a:lnSpc", successors: TAG_SEQ[1..]
|
|
177
208
|
zero_or_one "a:spcBef", successors: TAG_SEQ[2..]
|
|
178
209
|
zero_or_one "a:spcAft", successors: TAG_SEQ[3..]
|
|
210
|
+
# The three bullet kinds are one choice; the setter keeps only one.
|
|
211
|
+
zero_or_one "a:buNone", successors: TAG_SEQ[13..]
|
|
212
|
+
zero_or_one "a:buAutoNum", successors: TAG_SEQ[13..]
|
|
213
|
+
zero_or_one "a:buChar", successors: TAG_SEQ[13..]
|
|
179
214
|
zero_or_one "a:defRPr", successors: TAG_SEQ[16..]
|
|
180
215
|
optional_attr "lvl", type: SimpleTypes::ST_TextIndentLevelType, default: 0
|
|
181
216
|
optional_attr "algn", type: Enum::PP_PARAGRAPH_ALIGNMENT
|
|
217
|
+
optional_attr "marL", type: SimpleTypes::ST_Coordinate32
|
|
218
|
+
optional_attr "indent", type: SimpleTypes::ST_Coordinate32
|
|
182
219
|
|
|
183
220
|
# A Float means a number of lines; a {Pptx::Length} means a fixed
|
|
184
221
|
# distance. nil when no spacing is set.
|
|
@@ -197,19 +234,65 @@ module Pptx
|
|
|
197
234
|
value.is_a?(Pptx::Length) ? spacing.set_spc_pts(value) : spacing.set_spc_pct(value)
|
|
198
235
|
end
|
|
199
236
|
|
|
200
|
-
def space_before
|
|
237
|
+
def space_before
|
|
238
|
+
spcBef&.spcPts&.val
|
|
239
|
+
end
|
|
201
240
|
|
|
202
241
|
def space_before=(value)
|
|
203
242
|
remove_spcBef
|
|
204
243
|
get_or_add_spcBef.set_spc_pts(value) unless value.nil?
|
|
205
244
|
end
|
|
206
245
|
|
|
207
|
-
def space_after
|
|
246
|
+
def space_after
|
|
247
|
+
spcAft&.spcPts&.val
|
|
248
|
+
end
|
|
208
249
|
|
|
209
250
|
def space_after=(value)
|
|
210
251
|
remove_spcAft
|
|
211
252
|
get_or_add_spcAft.set_spc_pts(value) unless value.nil?
|
|
212
253
|
end
|
|
254
|
+
|
|
255
|
+
# A String for a character bullet, :none, a Symbol naming an autonumber
|
|
256
|
+
# scheme (e.g. :arabicPeriod), or nil when the bullet is inherited.
|
|
257
|
+
def bullet
|
|
258
|
+
return buChar.char if buChar
|
|
259
|
+
return :none if buNone
|
|
260
|
+
|
|
261
|
+
buAutoNum&.type&.to_sym
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def bullet=(value)
|
|
265
|
+
remove_buNone
|
|
266
|
+
remove_buAutoNum
|
|
267
|
+
remove_buChar
|
|
268
|
+
case value
|
|
269
|
+
when nil then nil
|
|
270
|
+
when :none then get_or_add_buNone
|
|
271
|
+
when String then get_or_add_buChar.char = value
|
|
272
|
+
when Symbol then get_or_add_buAutoNum.type = value.to_s
|
|
273
|
+
else raise ArgumentError, "bullet must be a String, a Symbol or nil, got #{value.inspect}"
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
# A list style: default paragraph properties per outline level. The same
|
|
279
|
+
# content model serves a text body's `a:lstStyle` and a master's
|
|
280
|
+
# `p:titleStyle`, `p:bodyStyle` and `p:otherStyle`.
|
|
281
|
+
class CT_TextListStyle < Element
|
|
282
|
+
tag "a:lstStyle", "p:titleStyle", "p:bodyStyle", "p:otherStyle"
|
|
283
|
+
TAG_SEQ = ["a:defPPr", *CT_TextParagraphProperties::LEVEL_TAGS, "a:extLst"].freeze
|
|
284
|
+
|
|
285
|
+
TAG_SEQ[0..-2].each_with_index do |child, i|
|
|
286
|
+
zero_or_one child, successors: TAG_SEQ[(i + 1)..]
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# The `a:lvlNpPr` for outline level +level+, counted from 0 like
|
|
290
|
+
# `a:pPr/@lvl`, created if it is missing.
|
|
291
|
+
def get_or_add_level(level)
|
|
292
|
+
raise ArgumentError, "outline level must be 0 to 8, got #{level.inspect}" unless (0..8).cover?(level)
|
|
293
|
+
|
|
294
|
+
public_send("get_or_add_lvl#{level + 1}pPr")
|
|
295
|
+
end
|
|
213
296
|
end
|
|
214
297
|
|
|
215
298
|
# `a:p`, a paragraph.
|
|
@@ -223,7 +306,9 @@ module Pptx
|
|
|
223
306
|
CONTENT_TAGS = %w[a:r a:br a:fld].freeze
|
|
224
307
|
|
|
225
308
|
# A run is created with its required `a:t` already in place.
|
|
226
|
-
def new_r
|
|
309
|
+
def new_r
|
|
310
|
+
build_from_xml(%(<a:r #{Ns.nsdecls("a")}><a:t/></a:r>))
|
|
311
|
+
end
|
|
227
312
|
|
|
228
313
|
def add_run(text = nil)
|
|
229
314
|
run = add_r
|
|
@@ -231,7 +316,21 @@ module Pptx
|
|
|
231
316
|
run
|
|
232
317
|
end
|
|
233
318
|
|
|
234
|
-
def add_line_break
|
|
319
|
+
def add_line_break
|
|
320
|
+
add_br
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Append a field PowerPoint fills in when it draws the slide, such as
|
|
324
|
+
# "slidenum" or "datetime1". +placeholder+ is the text shown by readers
|
|
325
|
+
# that do not evaluate fields.
|
|
326
|
+
def add_field(type, placeholder)
|
|
327
|
+
fld = build_from_xml(
|
|
328
|
+
%(<a:fld #{Ns.nsdecls("a")} id="{#{SecureRandom.uuid.upcase}}" type="#{type}"><a:t/></a:fld>)
|
|
329
|
+
)
|
|
330
|
+
fld.t.text = placeholder
|
|
331
|
+
insert_element_before(fld, "a:endParaRPr")
|
|
332
|
+
fld
|
|
333
|
+
end
|
|
235
334
|
|
|
236
335
|
# Append +text+ as runs, turning each "\n" or "\v" into a line break.
|
|
237
336
|
#
|
|
@@ -248,12 +347,12 @@ module Pptx
|
|
|
248
347
|
# The `a:r`, `a:br` and `a:fld` children, in document order.
|
|
249
348
|
def content_children
|
|
250
349
|
tags = CONTENT_TAGS.map { |t| Ns.qn(t) }
|
|
251
|
-
|
|
252
|
-
.select { |c| tags.include?(Ns.clark_name_of(c)) }
|
|
253
|
-
.map { |c| Element.wrap(c) }
|
|
350
|
+
element_children.select { |c| tags.include?(c.clark_name) }
|
|
254
351
|
end
|
|
255
352
|
|
|
256
|
-
def text
|
|
353
|
+
def text
|
|
354
|
+
content_children.map(&:text).join
|
|
355
|
+
end
|
|
257
356
|
end
|
|
258
357
|
|
|
259
358
|
# `p:txBody`, `a:txBody` and `c:txPr`: a body of text.
|
|
@@ -262,12 +361,15 @@ module Pptx
|
|
|
262
361
|
# axis title holds.
|
|
263
362
|
tag "p:txBody", "a:txBody", "c:txPr", "c:rich"
|
|
264
363
|
one_and_only_one "a:bodyPr"
|
|
364
|
+
zero_or_one "a:lstStyle", successors: %w[a:p]
|
|
265
365
|
one_or_more "a:p", successors: [], as: :p
|
|
266
366
|
|
|
267
367
|
# A chart's `c:txPr` holds a paragraph for its formatting alone; the
|
|
268
368
|
# default run properties of that first paragraph are where a chart,
|
|
269
369
|
# axis, legend or data-label font lives.
|
|
270
|
-
def defRPr
|
|
370
|
+
def defRPr
|
|
371
|
+
p_list.first.get_or_add_pPr.get_or_add_defRPr
|
|
372
|
+
end
|
|
271
373
|
|
|
272
374
|
# The `c:txPr` a chart element gains when its font is first set.
|
|
273
375
|
TXPR_XML = <<~XML.freeze
|
|
@@ -284,10 +386,14 @@ module Pptx
|
|
|
284
386
|
|
|
285
387
|
class << self
|
|
286
388
|
# A `p:txBody` with one empty paragraph, built in +context+'s document.
|
|
287
|
-
def new_element(context)
|
|
389
|
+
def new_element(context)
|
|
390
|
+
context.build_from_xml(txbody_xml)
|
|
391
|
+
end
|
|
288
392
|
|
|
289
393
|
# A standalone `p:txBody`, for callers with no element to build from.
|
|
290
|
-
def parse_new
|
|
394
|
+
def parse_new
|
|
395
|
+
Element.parse(txbody_xml)
|
|
396
|
+
end
|
|
291
397
|
|
|
292
398
|
def txbody_xml
|
|
293
399
|
<<~XML
|
data/lib/ruby_pptx/oxml/theme.rb
CHANGED
|
@@ -20,10 +20,17 @@ module Pptx
|
|
|
20
20
|
one_and_only_one "a:themeElements"
|
|
21
21
|
required_attr "name", type: SimpleTypes::XsdString
|
|
22
22
|
|
|
23
|
-
def self.new_default
|
|
23
|
+
def self.new_default
|
|
24
|
+
Oxml.parse_from_template("theme")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def clrScheme
|
|
28
|
+
themeElements.clrScheme
|
|
29
|
+
end
|
|
24
30
|
|
|
25
|
-
def
|
|
26
|
-
|
|
31
|
+
def fontScheme
|
|
32
|
+
themeElements.fontScheme
|
|
33
|
+
end
|
|
27
34
|
end
|
|
28
35
|
|
|
29
36
|
# `a:themeElements`, the four schemes that make up a theme.
|
|
@@ -83,7 +90,9 @@ module Pptx
|
|
|
83
90
|
one_and_only_one "a:ea"
|
|
84
91
|
one_and_only_one "a:cs"
|
|
85
92
|
|
|
86
|
-
def typeface
|
|
93
|
+
def typeface
|
|
94
|
+
latin.typeface
|
|
95
|
+
end
|
|
87
96
|
|
|
88
97
|
def typeface=(value)
|
|
89
98
|
latin.typeface = value
|
data/lib/ruby_pptx/package.rb
CHANGED
|
@@ -22,7 +22,9 @@ module Pptx
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def presentation_part
|
|
25
|
+
def presentation_part
|
|
26
|
+
main_document_part
|
|
27
|
+
end
|
|
26
28
|
|
|
27
29
|
# The media part holding +video+, created if the package has no part with
|
|
28
30
|
# the same content. Matched by SHA-1, as images are.
|
|
@@ -41,10 +43,14 @@ module Pptx
|
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
# The next free `/ppt/media/imageN.<ext>` partname, reusing gaps.
|
|
44
|
-
def next_image_partname(ext)
|
|
46
|
+
def next_image_partname(ext)
|
|
47
|
+
next_media_like_partname("image", ext)
|
|
48
|
+
end
|
|
45
49
|
|
|
46
50
|
# The next free `/ppt/media/mediaN.<ext>` partname, reusing gaps.
|
|
47
|
-
def next_media_partname(ext)
|
|
51
|
+
def next_media_partname(ext)
|
|
52
|
+
next_media_like_partname("media", ext)
|
|
53
|
+
end
|
|
48
54
|
|
|
49
55
|
private
|
|
50
56
|
|
|
@@ -39,9 +39,13 @@ module Pptx
|
|
|
39
39
|
part
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
def chart
|
|
42
|
+
def chart
|
|
43
|
+
@chart ||= Chart.new(element, self)
|
|
44
|
+
end
|
|
43
45
|
|
|
44
|
-
def workbook
|
|
46
|
+
def workbook
|
|
47
|
+
@workbook ||= ChartWorkbook.new(element, self)
|
|
48
|
+
end
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
# The embedded workbook behind a chart.
|
|
@@ -20,15 +20,23 @@ module Pptx
|
|
|
20
20
|
@source_filename = source_filename
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def image
|
|
23
|
+
def image
|
|
24
|
+
@image ||= Image.from_blob(blob, @source_filename)
|
|
25
|
+
end
|
|
24
26
|
|
|
25
|
-
def ext
|
|
27
|
+
def ext
|
|
28
|
+
partname.ext
|
|
29
|
+
end
|
|
26
30
|
|
|
27
31
|
# The name PowerPoint shows in the alt-text/description field: the file
|
|
28
32
|
# the image came from, or a generic name when it came from a stream.
|
|
29
|
-
def desc
|
|
33
|
+
def desc
|
|
34
|
+
@source_filename || "image.#{ext}"
|
|
35
|
+
end
|
|
30
36
|
|
|
31
|
-
def sha1
|
|
37
|
+
def sha1
|
|
38
|
+
image.sha1
|
|
39
|
+
end
|
|
32
40
|
|
|
33
41
|
# Resolve a requested size against the image's native size.
|
|
34
42
|
#
|
|
@@ -11,7 +11,9 @@ module Pptx
|
|
|
11
11
|
# The presentation part, `/ppt/presentation.xml`; the package's main
|
|
12
12
|
# document part.
|
|
13
13
|
class PresentationPart < Opc::XmlPart
|
|
14
|
-
def presentation
|
|
14
|
+
def presentation
|
|
15
|
+
@presentation ||= Presentation.new(element, self)
|
|
16
|
+
end
|
|
15
17
|
|
|
16
18
|
# Create a blank slide part inheriting from +slide_layout+.
|
|
17
19
|
#
|
|
@@ -22,7 +24,9 @@ module Pptx
|
|
|
22
24
|
[r_id, slide_part.slide]
|
|
23
25
|
end
|
|
24
26
|
|
|
25
|
-
def core_properties
|
|
27
|
+
def core_properties
|
|
28
|
+
package.core_properties
|
|
29
|
+
end
|
|
26
30
|
|
|
27
31
|
# The presentation's notes master, created from the default template on
|
|
28
32
|
# first use.
|
|
@@ -38,9 +42,13 @@ module Pptx
|
|
|
38
42
|
part
|
|
39
43
|
end
|
|
40
44
|
|
|
41
|
-
def related_slide(r_id)
|
|
45
|
+
def related_slide(r_id)
|
|
46
|
+
related_part(r_id).slide
|
|
47
|
+
end
|
|
42
48
|
|
|
43
|
-
def related_slide_master(r_id)
|
|
49
|
+
def related_slide_master(r_id)
|
|
50
|
+
related_part(r_id).slide_master
|
|
51
|
+
end
|
|
44
52
|
|
|
45
53
|
# The slide with presentation-wide id +slide_id+.
|
|
46
54
|
#
|
|
@@ -73,7 +81,9 @@ module Pptx
|
|
|
73
81
|
Opc::PackURI.new("/ppt/slides/slide#{count + 1}.xml")
|
|
74
82
|
end
|
|
75
83
|
|
|
76
|
-
def save(path_or_stream)
|
|
84
|
+
def save(path_or_stream)
|
|
85
|
+
package.save(path_or_stream)
|
|
86
|
+
end
|
|
77
87
|
end
|
|
78
88
|
end
|
|
79
89
|
end
|
|
@@ -12,7 +12,9 @@ module Pptx
|
|
|
12
12
|
# and the notes master.
|
|
13
13
|
class BaseSlidePart < Opc::XmlPart
|
|
14
14
|
# The internal name of this slide.
|
|
15
|
-
def name
|
|
15
|
+
def name
|
|
16
|
+
element.cSld.name
|
|
17
|
+
end
|
|
16
18
|
|
|
17
19
|
# Create a chart part for +chart_data+ and relate this slide to it.
|
|
18
20
|
#
|
|
@@ -81,7 +83,9 @@ module Pptx
|
|
|
81
83
|
part
|
|
82
84
|
end
|
|
83
85
|
|
|
84
|
-
def slide
|
|
86
|
+
def slide
|
|
87
|
+
@slide ||= Slide.new(element, self)
|
|
88
|
+
end
|
|
85
89
|
|
|
86
90
|
# The layout part this slide inherits from.
|
|
87
91
|
def slide_layout
|
|
@@ -89,9 +93,13 @@ module Pptx
|
|
|
89
93
|
end
|
|
90
94
|
|
|
91
95
|
# The presentation-wide id of this slide.
|
|
92
|
-
def slide_id
|
|
96
|
+
def slide_id
|
|
97
|
+
package.presentation_part.slide_id_for(self)
|
|
98
|
+
end
|
|
93
99
|
|
|
94
|
-
def notes_slide?
|
|
100
|
+
def notes_slide?
|
|
101
|
+
rels.any? { |r| r.reltype == Opc::RELATIONSHIP_TYPE::NOTES_SLIDE }
|
|
102
|
+
end
|
|
95
103
|
|
|
96
104
|
# This slide's notes slide, created on first use.
|
|
97
105
|
def notes_slide
|
|
@@ -117,7 +125,9 @@ module Pptx
|
|
|
117
125
|
part
|
|
118
126
|
end
|
|
119
127
|
|
|
120
|
-
def slide_layout
|
|
128
|
+
def slide_layout
|
|
129
|
+
@slide_layout ||= SlideLayout.new(element, self)
|
|
130
|
+
end
|
|
121
131
|
|
|
122
132
|
def slide_master
|
|
123
133
|
part_related_by(Opc::RELATIONSHIP_TYPE::SLIDE_MASTER).slide_master
|
|
@@ -143,10 +153,14 @@ module Pptx
|
|
|
143
153
|
part
|
|
144
154
|
end
|
|
145
155
|
|
|
146
|
-
def slide_master
|
|
156
|
+
def slide_master
|
|
157
|
+
@slide_master ||= SlideMaster.new(element, self)
|
|
158
|
+
end
|
|
147
159
|
|
|
148
160
|
# The theme this master draws its colours and fonts from.
|
|
149
|
-
def theme_part
|
|
161
|
+
def theme_part
|
|
162
|
+
part_related_by(Opc::RELATIONSHIP_TYPE::THEME)
|
|
163
|
+
end
|
|
150
164
|
|
|
151
165
|
# Add +slide_layout_part+ to this master's layout list.
|
|
152
166
|
#
|
|
@@ -159,7 +173,9 @@ module Pptx
|
|
|
159
173
|
r_id
|
|
160
174
|
end
|
|
161
175
|
|
|
162
|
-
def related_slide_layout(r_id)
|
|
176
|
+
def related_slide_layout(r_id)
|
|
177
|
+
related_part(r_id).slide_layout
|
|
178
|
+
end
|
|
163
179
|
|
|
164
180
|
private
|
|
165
181
|
|
|
@@ -192,7 +208,9 @@ module Pptx
|
|
|
192
208
|
part
|
|
193
209
|
end
|
|
194
210
|
|
|
195
|
-
def notes_master
|
|
211
|
+
def notes_master
|
|
212
|
+
@notes_master ||= NotesMaster.new(element, self)
|
|
213
|
+
end
|
|
196
214
|
end
|
|
197
215
|
|
|
198
216
|
# A notes-slide part, `/ppt/notesSlides/notesSlideN.xml`.
|
|
@@ -213,9 +231,13 @@ module Pptx
|
|
|
213
231
|
part
|
|
214
232
|
end
|
|
215
233
|
|
|
216
|
-
def notes_slide
|
|
234
|
+
def notes_slide
|
|
235
|
+
@notes_slide ||= NotesSlide.new(element, self)
|
|
236
|
+
end
|
|
217
237
|
|
|
218
|
-
def notes_master
|
|
238
|
+
def notes_master
|
|
239
|
+
part_related_by(Opc::RELATIONSHIP_TYPE::NOTES_MASTER).notes_master
|
|
240
|
+
end
|
|
219
241
|
end
|
|
220
242
|
end
|
|
221
243
|
end
|
|
@@ -20,7 +20,9 @@ module Pptx
|
|
|
20
20
|
# Only the keys a pattern actually asks for are computed, so matching on a
|
|
21
21
|
# shape's name does not walk its text.
|
|
22
22
|
module PatternMatching
|
|
23
|
-
def self.included(base)
|
|
23
|
+
def self.included(base)
|
|
24
|
+
base.extend(ClassMethods)
|
|
25
|
+
end
|
|
24
26
|
|
|
25
27
|
# A member reads as its name; anything else is passed through.
|
|
26
28
|
def self.for_pattern(value)
|
|
@@ -45,6 +47,8 @@ module Pptx
|
|
|
45
47
|
# means enumerating all of it, which is the opposite of the lazy wrapping
|
|
46
48
|
# everything else here does. Use it where the whole list is wanted anyway.
|
|
47
49
|
module DeconstructToArray
|
|
48
|
-
def deconstruct
|
|
50
|
+
def deconstruct
|
|
51
|
+
to_a
|
|
52
|
+
end
|
|
49
53
|
end
|
|
50
54
|
end
|
|
@@ -42,7 +42,9 @@ module Pptx
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
# A new presentation based on the built-in default template.
|
|
45
|
-
def new_default
|
|
45
|
+
def new_default
|
|
46
|
+
Presentation.open(nil)
|
|
47
|
+
end
|
|
46
48
|
|
|
47
49
|
def default_template_path
|
|
48
50
|
File.expand_path("templates/default.pptx", __dir__)
|
|
@@ -55,7 +57,9 @@ module Pptx
|
|
|
55
57
|
].freeze
|
|
56
58
|
|
|
57
59
|
# The Dublin Core metadata for this presentation.
|
|
58
|
-
def core_properties
|
|
60
|
+
def core_properties
|
|
61
|
+
part.core_properties
|
|
62
|
+
end
|
|
59
63
|
|
|
60
64
|
# The slides in this presentation.
|
|
61
65
|
def slides
|
|
@@ -74,32 +78,44 @@ module Pptx
|
|
|
74
78
|
# The notes master, created from the default template on first use.
|
|
75
79
|
#
|
|
76
80
|
# @return [NotesMaster]
|
|
77
|
-
def notes_master
|
|
81
|
+
def notes_master
|
|
82
|
+
part.notes_master_part.notes_master
|
|
83
|
+
end
|
|
78
84
|
|
|
79
85
|
# The first slide master, which is the only one in most presentations.
|
|
80
|
-
def slide_master
|
|
86
|
+
def slide_master
|
|
87
|
+
slide_masters[0]
|
|
88
|
+
end
|
|
81
89
|
|
|
82
90
|
# The layouts of the first slide master.
|
|
83
91
|
#
|
|
84
92
|
# A presentation may have several masters, each with its own layouts; this
|
|
85
93
|
# is a convenience for the common case of one.
|
|
86
|
-
def slide_layouts
|
|
94
|
+
def slide_layouts
|
|
95
|
+
slide_master.slide_layouts
|
|
96
|
+
end
|
|
87
97
|
|
|
88
98
|
# The sections grouping this presentation's slides.
|
|
89
99
|
#
|
|
90
100
|
# Sections are a PowerPoint 2010 extension; a presentation with none has
|
|
91
101
|
# an empty collection and writes no extension element.
|
|
92
|
-
def sections
|
|
102
|
+
def sections
|
|
103
|
+
@sections ||= Sections.new(self)
|
|
104
|
+
end
|
|
93
105
|
|
|
94
106
|
# @return [Length, nil] nil when the presentation defines no slide size
|
|
95
|
-
def slide_width
|
|
107
|
+
def slide_width
|
|
108
|
+
@element.sldSz&.cx
|
|
109
|
+
end
|
|
96
110
|
|
|
97
111
|
def slide_width=(width)
|
|
98
112
|
@element.get_or_add_sldSz.cx = width
|
|
99
113
|
end
|
|
100
114
|
|
|
101
115
|
# @return [Length, nil]
|
|
102
|
-
def slide_height
|
|
116
|
+
def slide_height
|
|
117
|
+
@element.sldSz&.cy
|
|
118
|
+
end
|
|
103
119
|
|
|
104
120
|
def slide_height=(height)
|
|
105
121
|
@element.get_or_add_sldSz.cy = height
|