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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +98 -0
  3. data/README.md +94 -4
  4. data/lib/ruby_pptx/action.rb +12 -4
  5. data/lib/ruby_pptx/autoshape_spec.rb +6 -2
  6. data/lib/ruby_pptx/builder.rb +3 -1
  7. data/lib/ruby_pptx/chart/categories.rb +45 -15
  8. data/lib/ruby_pptx/chart/chart.rb +168 -31
  9. data/lib/ruby_pptx/chart/combo.rb +19 -4
  10. data/lib/ruby_pptx/chart/data.rb +45 -15
  11. data/lib/ruby_pptx/chart/format.rb +229 -76
  12. data/lib/ruby_pptx/chart/workbook_writer.rb +9 -3
  13. data/lib/ruby_pptx/chart/xml_writer.rb +54 -18
  14. data/lib/ruby_pptx/chart/xy_data.rb +68 -22
  15. data/lib/ruby_pptx/dml/color.rb +27 -9
  16. data/lib/ruby_pptx/dml/effect.rb +6 -2
  17. data/lib/ruby_pptx/dml/fill.rb +42 -14
  18. data/lib/ruby_pptx/element_proxy.rb +12 -4
  19. data/lib/ruby_pptx/enum/base.rb +30 -10
  20. data/lib/ruby_pptx/enum/prog_id.rb +3 -1
  21. data/lib/ruby_pptx/geometry.rb +32 -10
  22. data/lib/ruby_pptx/image.rb +27 -9
  23. data/lib/ruby_pptx/length.rb +94 -27
  24. data/lib/ruby_pptx/media.rb +12 -4
  25. data/lib/ruby_pptx/numeric_lengths.rb +34 -9
  26. data/lib/ruby_pptx/opc/oxml.rb +7 -5
  27. data/lib/ruby_pptx/opc/pack_uri.rb +15 -5
  28. data/lib/ruby_pptx/opc/package.rb +97 -31
  29. data/lib/ruby_pptx/opc/serialized.rb +15 -5
  30. data/lib/ruby_pptx/oxml/backend.rb +585 -0
  31. data/lib/ruby_pptx/oxml/chart.rb +112 -42
  32. data/lib/ruby_pptx/oxml/content_model.rb +6 -2
  33. data/lib/ruby_pptx/oxml/dml/color.rb +6 -2
  34. data/lib/ruby_pptx/oxml/dml/fill.rb +6 -2
  35. data/lib/ruby_pptx/oxml/element.rb +138 -101
  36. data/lib/ruby_pptx/oxml/ns.rb +7 -7
  37. data/lib/ruby_pptx/oxml/presentation.rb +9 -3
  38. data/lib/ruby_pptx/oxml/section.rb +3 -1
  39. data/lib/ruby_pptx/oxml/shapes/autoshape.rb +39 -13
  40. data/lib/ruby_pptx/oxml/shapes/groupshape.rb +15 -7
  41. data/lib/ruby_pptx/oxml/shapes/other.rb +47 -16
  42. data/lib/ruby_pptx/oxml/shapes/shared.rb +96 -30
  43. data/lib/ruby_pptx/oxml/simple_types.rb +169 -52
  44. data/lib/ruby_pptx/oxml/slide.rb +25 -8
  45. data/lib/ruby_pptx/oxml/table.rb +39 -13
  46. data/lib/ruby_pptx/oxml/text.rb +122 -16
  47. data/lib/ruby_pptx/oxml/theme.rb +13 -4
  48. data/lib/ruby_pptx/package.rb +9 -3
  49. data/lib/ruby_pptx/parts/chart.rb +6 -2
  50. data/lib/ruby_pptx/parts/image.rb +12 -4
  51. data/lib/ruby_pptx/parts/media.rb +3 -1
  52. data/lib/ruby_pptx/parts/presentation.rb +15 -5
  53. data/lib/ruby_pptx/parts/slide.rb +33 -11
  54. data/lib/ruby_pptx/parts/theme.rb +3 -1
  55. data/lib/ruby_pptx/pattern_matching.rb +6 -2
  56. data/lib/ruby_pptx/presentation.rb +24 -8
  57. data/lib/ruby_pptx/section.rb +30 -10
  58. data/lib/ruby_pptx/shapes/adjustments.rb +9 -3
  59. data/lib/ruby_pptx/shapes/authoring.rb +3 -1
  60. data/lib/ruby_pptx/shapes/base.rb +74 -24
  61. data/lib/ruby_pptx/shapes/freeform.rb +36 -12
  62. data/lib/ruby_pptx/shapes/placeholder.rb +44 -15
  63. data/lib/ruby_pptx/shapes/shape.rb +91 -30
  64. data/lib/ruby_pptx/shapes/shape_tree.rb +235 -121
  65. data/lib/ruby_pptx/slide.rb +137 -46
  66. data/lib/ruby_pptx/table.rb +105 -35
  67. data/lib/ruby_pptx/text/font_metrics.rb +30 -9
  68. data/lib/ruby_pptx/text/list_style.rb +88 -0
  69. data/lib/ruby_pptx/text/text.rb +241 -59
  70. data/lib/ruby_pptx/theme.rb +30 -10
  71. data/lib/ruby_pptx/version.rb +1 -1
  72. data/lib/ruby_pptx.rb +9 -1
  73. metadata +24 -2
@@ -23,11 +23,15 @@ module Pptx
23
23
  cache[real] ||= new(real)
24
24
  end
25
25
 
26
- def clear_cache = cache.clear
26
+ def clear_cache
27
+ cache.clear
28
+ end
27
29
 
28
30
  private
29
31
 
30
- def cache = @cache ||= {}
32
+ def cache
33
+ @cache ||= {}
34
+ end
31
35
  end
32
36
 
33
37
  # @param path [String] a .ttf or .otf file
@@ -64,7 +68,9 @@ module Pptx
64
68
  [to_emu(box[2] - left, point_size), to_emu(box[3] - box[1], point_size)]
65
69
  end
66
70
 
67
- def inspect = "#<Pptx::FontMetrics #{File.basename(@path)} upem=#{@units_per_em}>"
71
+ def inspect
72
+ "#<Pptx::FontMetrics #{File.basename(@path)} upem=#{@units_per_em}>"
73
+ end
68
74
 
69
75
  private
70
76
 
@@ -87,8 +93,13 @@ module Pptx
87
93
  left && [left, bottom, right, top]
88
94
  end
89
95
 
90
- def min(a, b) = a.nil? || b < a ? b : a
91
- def max(a, b) = a.nil? || b > a ? b : a
96
+ def min(a, b)
97
+ a.nil? || b < a ? b : a
98
+ end
99
+
100
+ def max(a, b)
101
+ a.nil? || b > a ? b : a
102
+ end
92
103
 
93
104
  # Font units are relative to the em square, so scaling by the point size
94
105
  # gives points, which are 1/72 inch by definition.
@@ -96,7 +107,9 @@ module Pptx
96
107
  (units * point_size / @units_per_em.to_f / POINTS_PER_INCH * EMU_PER_INCH).to_i
97
108
  end
98
109
 
99
- def glyph_id(codepoint) = @cmap[codepoint] || 0
110
+ def glyph_id(codepoint)
111
+ @cmap[codepoint] || 0
112
+ end
100
113
 
101
114
  # A font may store one advance for a run of trailing glyphs, in which case
102
115
  # hmtx is truncated and the last entry stands for all of them.
@@ -142,9 +155,17 @@ module Pptx
142
155
  @index_to_loc_format.zero? ? u16(base + (index * 2)) * 2 : u32(base + (index * 4))
143
156
  end
144
157
 
145
- def u16(at) = @data.byteslice(at, 2).unpack1("n")
146
- def s16(at) = @data.byteslice(at, 2).unpack1("s>")
147
- def u32(at) = @data.byteslice(at, 4).unpack1("N")
158
+ def u16(at)
159
+ @data.byteslice(at, 2).unpack1("n")
160
+ end
161
+
162
+ def s16(at)
163
+ @data.byteslice(at, 2).unpack1("s>")
164
+ end
165
+
166
+ def u32(at)
167
+ @data.byteslice(at, 4).unpack1("N")
168
+ end
148
169
 
149
170
  def read_table_directory
150
171
  raise Error, "#{@path} is not a TrueType or OpenType font" unless sfnt_version?
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby_pptx/text/text"
4
+
5
+ module Pptx
6
+ # One outline level of a list style: the formatting a paragraph at that
7
+ # level gets unless it says otherwise.
8
+ #
9
+ # master.text_styles.body.level(0).tap do |l1|
10
+ # l1.bullet = "•"
11
+ # l1.margin_left = Pptx.inches(0.5)
12
+ # l1.indent = -Pptx.inches(0.5)
13
+ # l1.font.size = Pptx.pt(37)
14
+ # end
15
+ class ParagraphStyle
16
+ include ParagraphFormatting
17
+
18
+ attr_reader :element
19
+
20
+ def initialize(ppr)
21
+ @element = ppr
22
+ end
23
+
24
+ def inspect
25
+ "#<Pptx::ParagraphStyle #{@element.nsptag}>"
26
+ end
27
+
28
+ private
29
+
30
+ def paragraph_properties
31
+ @element
32
+ end
33
+ end
34
+
35
+ # A list style: a {ParagraphStyle} per outline level, 0 to 8.
36
+ class ListStyle
37
+ attr_reader :element
38
+
39
+ def initialize(element)
40
+ @element = element
41
+ end
42
+
43
+ # The style for outline level +level+, counted from 0 like
44
+ # {Paragraph#level}. Created empty -- inheriting everything -- if the
45
+ # style had none.
46
+ #
47
+ # @return [ParagraphStyle]
48
+ def level(level)
49
+ ParagraphStyle.new(@element.get_or_add_level(level))
50
+ end
51
+
52
+ # The properties that apply at every level before the level's own.
53
+ def default
54
+ ParagraphStyle.new(@element.get_or_add_defPPr)
55
+ end
56
+
57
+ def inspect
58
+ "#<Pptx::ListStyle #{@element.nsptag}>"
59
+ end
60
+ end
61
+
62
+ # A master's text styles: one for titles, one for body placeholders and
63
+ # one for everything else (text boxes, shapes, tables).
64
+ class TextStyles
65
+ attr_reader :element
66
+
67
+ def initialize(tx_styles)
68
+ @element = tx_styles
69
+ end
70
+
71
+ # @return [ListStyle]
72
+ def title
73
+ ListStyle.new(@element.get_or_add_titleStyle)
74
+ end
75
+
76
+ def body
77
+ ListStyle.new(@element.get_or_add_bodyStyle)
78
+ end
79
+
80
+ def other
81
+ ListStyle.new(@element.get_or_add_otherStyle)
82
+ end
83
+
84
+ def inspect
85
+ "#<Pptx::TextStyles>"
86
+ end
87
+ end
88
+ end
@@ -31,19 +31,27 @@ module Pptx
31
31
  @parent = parent
32
32
  end
33
33
 
34
- def part = @parent.part
34
+ def part
35
+ @parent.part
36
+ end
35
37
 
36
38
  # The paragraphs of this text frame; there is always at least one.
37
39
  #
38
40
  # @return [Array<Paragraph>]
39
- def paragraphs = @element.p_list.map { |p| Paragraph.new(p, self) }
41
+ def paragraphs
42
+ @element.p_list.map { |p| Paragraph.new(p, self) }
43
+ end
40
44
 
41
45
  # Append an empty paragraph and return it.
42
- def add_paragraph = Paragraph.new(@element.add_p, self)
46
+ def add_paragraph
47
+ Paragraph.new(@element.add_p, self)
48
+ end
43
49
 
44
50
  # All the text, with "\n" between paragraphs and "\v" for each soft line
45
51
  # break.
46
- def text = paragraphs.map(&:text).join("\n")
52
+ def text
53
+ paragraphs.map(&:text).join("\n")
54
+ end
47
55
 
48
56
  # Replace all text. Each "\n" starts a new paragraph, each "\v" a soft
49
57
  # line break within one.
@@ -62,39 +70,51 @@ module Pptx
62
70
  self
63
71
  end
64
72
 
65
- def margin_left = body_properties.lIns
73
+ def margin_left
74
+ body_properties.lIns
75
+ end
66
76
 
67
77
  def margin_left=(value)
68
78
  body_properties.lIns = value
69
79
  end
70
80
 
71
- def margin_right = body_properties.rIns
81
+ def margin_right
82
+ body_properties.rIns
83
+ end
72
84
 
73
85
  def margin_right=(value)
74
86
  body_properties.rIns = value
75
87
  end
76
88
 
77
- def margin_top = body_properties.tIns
89
+ def margin_top
90
+ body_properties.tIns
91
+ end
78
92
 
79
93
  def margin_top=(value)
80
94
  body_properties.tIns = value
81
95
  end
82
96
 
83
- def margin_bottom = body_properties.bIns
97
+ def margin_bottom
98
+ body_properties.bIns
99
+ end
84
100
 
85
101
  def margin_bottom=(value)
86
102
  body_properties.bIns = value
87
103
  end
88
104
 
89
105
  # @return [Pptx::Enum::MSO_ANCHOR, nil] nil when inherited
90
- def vertical_anchor = body_properties.anchor
106
+ def vertical_anchor
107
+ body_properties.anchor
108
+ end
91
109
 
92
110
  def vertical_anchor=(value)
93
111
  body_properties.anchor = value
94
112
  end
95
113
 
96
114
  # @return [Pptx::Enum::MSO_AUTO_SIZE, nil] nil when inherited
97
- def auto_size = body_properties.autofit
115
+ def auto_size
116
+ body_properties.autofit
117
+ end
98
118
 
99
119
  def auto_size=(value)
100
120
  body_properties.autofit = value
@@ -154,7 +174,9 @@ module Pptx
154
174
  [@parent.width - margin_left - margin_right, @parent.height - margin_top - margin_bottom]
155
175
  end
156
176
 
157
- def inspect = "#<Pptx::TextFrame #{text.inspect}>"
177
+ def inspect
178
+ "#<Pptx::TextFrame #{text.inspect}>"
179
+ end
158
180
 
159
181
  private
160
182
 
@@ -178,12 +200,126 @@ module Pptx
178
200
  end
179
201
  end
180
202
 
181
- def body_properties = @element.bodyPr
203
+ def body_properties
204
+ @element.bodyPr
205
+ end
206
+
207
+ public
208
+
209
+ TEXT_DIRECTIONS = {
210
+ horizontal: "horz", vertical: "vert", vertical_270: "vert270", stacked: "wordArtVert",
211
+ east_asian_vertical: "eaVert", mongolian_vertical: "mongolianVert",
212
+ stacked_right_to_left: "wordArtVertRtl"
213
+ }.freeze
214
+
215
+ # Which way the text runs: :horizontal, :vertical (top to bottom, turned
216
+ # 90 degrees), :vertical_270 (bottom to top), :stacked, or one of the East
217
+ # Asian directions. nil when inherited.
218
+ def text_direction
219
+ TEXT_DIRECTIONS.key(body_properties.vert)
220
+ end
221
+
222
+ def text_direction=(value)
223
+ body_properties.vert =
224
+ if value.nil? then nil
225
+ else
226
+ TEXT_DIRECTIONS.fetch(value) do
227
+ raise ArgumentError, "text_direction must be one of #{TEXT_DIRECTIONS.keys.inspect} or nil, " \
228
+ "got #{value.inspect}"
229
+ end
230
+ end
231
+ end
232
+
233
+ # The default paragraph formatting per outline level for this text
234
+ # body. On a layout or master placeholder, this is what slides inherit.
235
+ #
236
+ # @return [ListStyle]
237
+ def list_style
238
+ ListStyle.new(@element.get_or_add_lstStyle)
239
+ end
240
+ end
241
+
242
+ # Paragraph formatting shared by a paragraph and by a style level: both
243
+ # are an `a:pPr`-shaped element, so both read and write the same way.
244
+ #
245
+ # Expects +paragraph_properties+ to return that element.
246
+ module ParagraphFormatting
247
+ # @return [Pptx::Enum::PP_ALIGN, nil] nil when inherited
248
+ def alignment
249
+ paragraph_properties.algn
250
+ end
251
+
252
+ def alignment=(value)
253
+ paragraph_properties.algn = value
254
+ end
255
+
256
+ # A Float is a number of lines; a {Pptx::Length} is a fixed distance.
257
+ def line_spacing
258
+ paragraph_properties.line_spacing
259
+ end
260
+
261
+ def line_spacing=(value)
262
+ paragraph_properties.line_spacing = value
263
+ end
264
+
265
+ def space_before
266
+ paragraph_properties.space_before
267
+ end
268
+
269
+ def space_before=(value)
270
+ paragraph_properties.space_before = value
271
+ end
272
+
273
+ def space_after
274
+ paragraph_properties.space_after
275
+ end
276
+
277
+ def space_after=(value)
278
+ paragraph_properties.space_after = value
279
+ end
280
+
281
+ # The bullet: a String such as "•" for a character bullet, :none to
282
+ # suppress the one the master would draw, an autonumber scheme such as
283
+ # :arabicPeriod ("1.") or :alphaLcParenR ("a)"), or nil to inherit.
284
+ def bullet
285
+ paragraph_properties.bullet
286
+ end
287
+
288
+ def bullet=(value)
289
+ paragraph_properties.bullet = value
290
+ end
291
+
292
+ # Distance from the left edge of the text box to the text, as a
293
+ # {Pptx::Length}; nil when inherited.
294
+ def margin_left
295
+ paragraph_properties.marL
296
+ end
297
+
298
+ def margin_left=(value)
299
+ paragraph_properties.marL = value
300
+ end
301
+
302
+ # Offset of the first line from {#margin_left}. Negative gives a hanging
303
+ # indent, where the bullet sits in the margin: margin_left 0.25", indent
304
+ # -0.25". nil when inherited.
305
+ def indent
306
+ paragraph_properties.indent
307
+ end
308
+
309
+ def indent=(value)
310
+ paragraph_properties.indent = value
311
+ end
312
+
313
+ # The default character formatting for runs in this paragraph.
314
+ def font
315
+ Font.new(paragraph_properties.get_or_add_defRPr)
316
+ end
182
317
  end
183
318
 
184
319
  # One paragraph of a text frame.
185
320
  class Paragraph
186
321
  include PatternMatching
322
+ include ParagraphFormatting
187
323
 
188
324
  pattern_keys :text, :runs, :level, :alignment
189
325
 
@@ -194,20 +330,46 @@ module Pptx
194
330
  @parent = parent
195
331
  end
196
332
 
197
- def part = @parent.part
333
+ def part
334
+ @parent.part
335
+ end
198
336
 
199
337
  # @return [Array<Run>]
200
- def runs = @element.r_list.map { |r| Run.new(r, self) }
338
+ def runs
339
+ @element.r_list.map { |r| Run.new(r, self) }
340
+ end
201
341
 
202
- def add_run(text = nil) = Run.new(@element.add_run(text), self)
342
+ def add_run(text = nil)
343
+ Run.new(@element.add_run(text), self)
344
+ end
203
345
 
204
346
  def add_line_break
205
347
  @element.add_line_break
206
348
  self
207
349
  end
208
350
 
351
+ FIELD_TYPES = { slide_number: ["slidenum", "‹#›"], date_time: ["datetime1", ""] }.freeze
352
+
353
+ # Append a field PowerPoint fills in when it draws the slide:
354
+ # :slide_number, :date_time, or a field type string such as "datetime4".
355
+ # A slide number only shows in a slide-number placeholder or a text box
356
+ # on the slide itself.
357
+ #
358
+ # @return [self]
359
+ def add_field(type)
360
+ field_type, placeholder = FIELD_TYPES.fetch(type) do
361
+ raise ArgumentError, "unknown field #{type.inspect}" unless type.is_a?(String)
362
+
363
+ [type, ""]
364
+ end
365
+ @element.add_field(field_type, placeholder)
366
+ self
367
+ end
368
+
209
369
  # The text of this paragraph, with "\v" for each soft line break.
210
- def text = @element.text
370
+ def text
371
+ @element.text
372
+ end
211
373
 
212
374
  # Replace this paragraph's text, turning "\v" (or "\n") into line breaks
213
375
  # rather than new paragraphs -- a paragraph cannot contain another.
@@ -222,47 +384,24 @@ module Pptx
222
384
  self
223
385
  end
224
386
 
225
- # @return [Pptx::Enum::PP_ALIGN, nil] nil when inherited
226
- def alignment = paragraph_properties.algn
227
-
228
- def alignment=(value)
229
- paragraph_properties.algn = value
230
- end
231
-
232
387
  # Outline level, 0 for the top level.
233
- def level = paragraph_properties.lvl
388
+ def level
389
+ paragraph_properties.lvl
390
+ end
234
391
 
235
392
  def level=(value)
236
393
  paragraph_properties.lvl = value
237
394
  end
238
395
 
239
- # A Float is a number of lines; a {Pptx::Length} is a fixed distance.
240
- def line_spacing = paragraph_properties.line_spacing
241
-
242
- def line_spacing=(value)
243
- paragraph_properties.line_spacing = value
244
- end
245
-
246
- def space_before = paragraph_properties.space_before
247
-
248
- def space_before=(value)
249
- paragraph_properties.space_before = value
250
- end
251
-
252
- def space_after = paragraph_properties.space_after
253
-
254
- def space_after=(value)
255
- paragraph_properties.space_after = value
396
+ def inspect
397
+ "#<Pptx::Paragraph #{text.inspect}>"
256
398
  end
257
399
 
258
- # The default character formatting for runs in this paragraph.
259
- def font = Font.new(paragraph_properties.get_or_add_defRPr)
260
-
261
- def inspect = "#<Pptx::Paragraph #{text.inspect}>"
262
-
263
400
  private
264
401
 
265
- def paragraph_properties = @element.get_or_add_pPr
402
+ def paragraph_properties
403
+ @element.get_or_add_pPr
404
+ end
266
405
  end
267
406
 
268
407
  # A run: a span of text sharing one set of character properties.
@@ -278,27 +417,39 @@ module Pptx
278
417
  @parent = parent
279
418
  end
280
419
 
281
- def part = @parent.part
420
+ def part
421
+ @parent.part
422
+ end
282
423
 
283
- def text = @element.text
424
+ def text
425
+ @element.text
426
+ end
284
427
 
285
428
  def text=(value)
286
429
  @element.text = value
287
430
  end
288
431
 
289
- def font = Font.new(@element.get_or_add_rPr)
432
+ def font
433
+ Font.new(@element.get_or_add_rPr)
434
+ end
290
435
 
291
436
  # What happens when this run of text is clicked.
292
- def click_action = @click_action ||= ActionSetting.new(@element.get_or_add_rPr, self)
437
+ def click_action
438
+ @click_action ||= ActionSetting.new(@element.get_or_add_rPr, self)
439
+ end
293
440
 
294
441
  # The URL this run links to, or nil.
295
- def hyperlink = click_action.url
442
+ def hyperlink
443
+ click_action.url
444
+ end
296
445
 
297
446
  def hyperlink=(url)
298
447
  click_action.address = url
299
448
  end
300
449
 
301
- def inspect = "#<Pptx::Run #{text.inspect}>"
450
+ def inspect
451
+ "#<Pptx::Run #{text.inspect}>"
452
+ end
302
453
  end
303
454
 
304
455
  # Character formatting: typeface, size, weight, colour.
@@ -317,20 +468,26 @@ module Pptx
317
468
  @element = r_pr
318
469
  end
319
470
 
320
- def bold = @element.b
471
+ def bold
472
+ @element.b
473
+ end
321
474
 
322
475
  def bold=(value)
323
476
  @element.b = value
324
477
  end
325
478
 
326
- def italic = @element.i
479
+ def italic
480
+ @element.i
481
+ end
327
482
 
328
483
  def italic=(value)
329
484
  @element.i = value
330
485
  end
331
486
 
332
487
  # The typeface name, or nil when inherited from the theme.
333
- def name = @element.latin&.typeface
488
+ def name
489
+ @element.latin&.typeface
490
+ end
334
491
 
335
492
  def name=(value)
336
493
  if value.nil?
@@ -350,6 +507,25 @@ module Pptx
350
507
  @element.sz = value.nil? ? nil : Pptx::Length.coerce(value).centipoints
351
508
  end
352
509
 
510
+ CAPS = { all: "all", small: "small", none: "none" }.freeze
511
+
512
+ # :all for capitals, :small for small capitals, :none to turn an
513
+ # inherited setting off, nil when inherited. Only the display changes;
514
+ # the text keeps its case.
515
+ def caps
516
+ CAPS.key(@element.cap)
517
+ end
518
+
519
+ def caps=(value)
520
+ @element.cap =
521
+ if value.nil? then nil
522
+ else
523
+ CAPS.fetch(value) do
524
+ raise ArgumentError, "caps must be :all, :small, :none or nil, got #{value.inspect}"
525
+ end
526
+ end
527
+ end
528
+
353
529
  # true for a single underline, false for none, a
354
530
  # {Pptx::Enum::MSO_UNDERLINE} member for anything fancier, nil when
355
531
  # inherited.
@@ -372,14 +548,18 @@ module Pptx
372
548
  end
373
549
 
374
550
  # @return [Pptx::Enum::MSO_LANGUAGE_ID, nil]
375
- def language = @element.lang
551
+ def language
552
+ @element.lang
553
+ end
376
554
 
377
555
  def language=(value)
378
556
  @element.lang = value
379
557
  end
380
558
 
381
559
  # The fill of the text itself.
382
- def fill = @fill ||= FillFormat.from_fill_parent(@element)
560
+ def fill
561
+ @fill ||= FillFormat.from_fill_parent(@element)
562
+ end
383
563
 
384
564
  # The text colour. Accessing it makes the fill solid, since a colour has
385
565
  # to live on some fill.
@@ -388,6 +568,8 @@ module Pptx
388
568
  fill.fore_color
389
569
  end
390
570
 
391
- def inspect = "#<Pptx::Font name=#{name.inspect} size=#{size&.pt} bold=#{bold.inspect}>"
571
+ def inspect
572
+ "#<Pptx::Font name=#{name.inspect} size=#{size&.pt} bold=#{bold.inspect}>"
573
+ end
392
574
  end
393
575
  end
@@ -17,7 +17,9 @@ module Pptx
17
17
  # are inherited from the base theme and not editable here; writing a
18
18
  # coherent set by hand is a design exercise, not a configuration one.
19
19
  class Theme < PartElementProxy
20
- def name = @element.name
20
+ def name
21
+ @element.name
22
+ end
21
23
 
22
24
  def name=(value)
23
25
  # PowerPoint shows the theme name in three places and expects them to
@@ -28,12 +30,18 @@ module Pptx
28
30
  end
29
31
 
30
32
  # @return [ThemeColors]
31
- def colors = @colors ||= ThemeColors.new(@element.clrScheme, self)
33
+ def colors
34
+ @colors ||= ThemeColors.new(@element.clrScheme, self)
35
+ end
32
36
 
33
37
  # @return [ThemeFonts]
34
- def fonts = @fonts ||= ThemeFonts.new(@element.fontScheme, self)
38
+ def fonts
39
+ @fonts ||= ThemeFonts.new(@element.fontScheme, self)
40
+ end
35
41
 
36
- def inspect = "#<Pptx::Theme #{name.inspect}>"
42
+ def inspect
43
+ "#<Pptx::Theme #{name.inspect}>"
44
+ end
37
45
  end
38
46
 
39
47
  # The twelve theme colours, addressed by name.
@@ -50,7 +58,9 @@ module Pptx
50
58
  NAMES = Oxml::CT_ColorScheme::SLOTS.map(&:to_sym).freeze
51
59
 
52
60
  # @return [Pptx::ColorFormat]
53
- def [](name) = ColorFormat.from_color_choice_parent(@element.slot(name))
61
+ def [](name)
62
+ ColorFormat.from_color_choice_parent(@element.slot(name))
63
+ end
54
64
 
55
65
  def each
56
66
  return enum_for(:each) { NAMES.size } unless block_given?
@@ -71,9 +81,13 @@ module Pptx
71
81
  self
72
82
  end
73
83
 
74
- def names = NAMES
84
+ def names
85
+ NAMES
86
+ end
75
87
 
76
- def inspect = "#<Pptx::ThemeColors #{NAMES.size} colours>"
88
+ def inspect
89
+ "#<Pptx::ThemeColors #{NAMES.size} colours>"
90
+ end
77
91
  end
78
92
 
79
93
  # The heading and body typefaces of a theme.
@@ -81,18 +95,24 @@ module Pptx
81
95
  # PowerPoint calls these "major" and "minor"; they are what `+mj-lt` and
82
96
  # `+mn-lt` resolve to in placeholder text.
83
97
  class ThemeFonts < ParentedElementProxy
84
- def major = @element.majorFont.typeface
98
+ def major
99
+ @element.majorFont.typeface
100
+ end
85
101
 
86
102
  def major=(value)
87
103
  @element.majorFont.typeface = value
88
104
  end
89
105
 
90
- def minor = @element.minorFont.typeface
106
+ def minor
107
+ @element.minorFont.typeface
108
+ end
91
109
 
92
110
  def minor=(value)
93
111
  @element.minorFont.typeface = value
94
112
  end
95
113
 
96
- def inspect = "#<Pptx::ThemeFonts major=#{major.inspect} minor=#{minor.inspect}>"
114
+ def inspect
115
+ "#<Pptx::ThemeFonts major=#{major.inspect} minor=#{minor.inspect}>"
116
+ end
97
117
  end
98
118
  end