ruby_pptx 0.2.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 +65 -0
- data/README.md +11 -2
- data/lib/ruby_pptx/chart/chart.rb +91 -4
- data/lib/ruby_pptx/chart/combo.rb +10 -1
- data/lib/ruby_pptx/oxml/slide.rb +1 -0
- data/lib/ruby_pptx/oxml/text.rb +85 -1
- data/lib/ruby_pptx/shapes/shape_tree.rb +169 -99
- data/lib/ruby_pptx/slide.rb +14 -5
- data/lib/ruby_pptx/text/list_style.rb +88 -0
- data/lib/ruby_pptx/text/text.rb +149 -39
- data/lib/ruby_pptx/version.rb +1 -1
- data/lib/ruby_pptx.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: caa0d099f2d7cc089e42e00d1537c798a986ff4c2f84c8dbb0a37df3679b6cfa
|
|
4
|
+
data.tar.gz: 4f629f50f2abce8ce9ebbd9dd02d1869410a2b24c048d9a0f07b9f911557e04e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed68ccd9fc322871768eb6fab7c3e2967f040293f6cefa1f69afe6bf0d3bd2712afe829959d589102dacf059e31ba57e610d3dae98fedb656853bd17b9ae53b3
|
|
7
|
+
data.tar.gz: 92ad2c28105d022511fbabf307f2c3f5756bc3b22a868d8aa6189489e97d84cafb26748523f39cd6c1913f12b11d157163389de8a23249e4660a7ed1e53af666
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,70 @@ All notable changes to this gem are recorded here. The format follows
|
|
|
5
5
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). Before 1.0 a minor
|
|
6
6
|
version may change the public API.
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.3.0] - 2026-11-17
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `Paragraph#bullet=` sets a character bullet (`"•"`), an autonumber scheme
|
|
15
|
+
(`:arabicPeriod`), `:none`, or `nil` to inherit; `Paragraph#margin_left=`
|
|
16
|
+
and `Paragraph#indent=` give it a hanging indent. python-pptx has neither.
|
|
17
|
+
- Layouts and masters take the drawing methods slides have: `add_shape`,
|
|
18
|
+
`add_picture` (SVG with raster fallback included), `add_textbox`,
|
|
19
|
+
`add_connector`, `add_freeform`/`build_freeform` and `add_group_shape` on
|
|
20
|
+
`layout.shapes` and `master.shapes`. Every slide on the layout shows them,
|
|
21
|
+
which is how a template carries its logo and bands. Charts, tables, movies
|
|
22
|
+
and OLE objects stay slide-only. The `placeholders` views do not offer
|
|
23
|
+
these methods, since a shape added there would not be listed.
|
|
24
|
+
- `SlideMaster#text_styles` reaches the master's `p:txStyles`: `title`,
|
|
25
|
+
`body` and `other` are `ListStyle`s, and `level(n)` (0 to 8, like
|
|
26
|
+
`Paragraph#level`) or `default` gives a `ParagraphStyle` with the same
|
|
27
|
+
formatting methods as a paragraph -- alignment, spacing, `bullet`,
|
|
28
|
+
`margin_left`, `indent` and `font`. Missing levels are created in schema
|
|
29
|
+
order.
|
|
30
|
+
- `TextFrame#list_style`: the same `ListStyle` for a text body's
|
|
31
|
+
`a:lstStyle`, so a layout placeholder can set what its slides inherit.
|
|
32
|
+
- `Paragraph#add_field(:slide_number)`, `(:date_time)` or any field type
|
|
33
|
+
string such as `"datetime4"`.
|
|
34
|
+
- `TextFrame#text_direction=` with `:vertical_270` (bottom to top),
|
|
35
|
+
`:vertical`, `:stacked` and the East Asian directions.
|
|
36
|
+
- `Font#caps=` with `:all`, `:small`, `:none` or `nil`.
|
|
37
|
+
- `Slides#add(layout, footers: true)` also copies the date, footer and
|
|
38
|
+
slide-number placeholders, text included. PowerPoint only draws them where
|
|
39
|
+
the slide carries them.
|
|
40
|
+
- Shapes drawn on a layout or master get `userDrawn="1"`, as PowerPoint
|
|
41
|
+
writes it.
|
|
42
|
+
- `Chart#replace_data` rebinds scatter charts from an `XyChartData` and
|
|
43
|
+
bubble charts from a `BubbleChartData`: it rewrites each series' `c:tx`,
|
|
44
|
+
`c:xVal`, `c:yVal` and `c:bubbleSize` and keeps its formatting.
|
|
45
|
+
([#1](https://github.com/Largo/ruby_pptx/issues/1))
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
|
|
49
|
+
- `Chart#replace_data` on a chart with more than one plot (a combo chart)
|
|
50
|
+
raises `Pptx::Error` when the series count changes. Series are matched to
|
|
51
|
+
plots in document order, so fewer series used to remove whole plots --
|
|
52
|
+
leaving their secondary value axis behind -- and more series were all
|
|
53
|
+
cloned into the last plot. Rebinding with the same number of series works
|
|
54
|
+
as before. ([#2](https://github.com/Largo/ruby_pptx/issues/2))
|
|
55
|
+
- `Chart#replace_data` raises `Pptx::Error` when the data does not fit the
|
|
56
|
+
chart: `ChartData` for a scatter or bubble chart, `XyChartData` for a
|
|
57
|
+
category chart, or `XyChartData` without bubble sizes for a bubble chart.
|
|
58
|
+
|
|
59
|
+
### Fixed
|
|
60
|
+
|
|
61
|
+
- `Chart#replace_data(ChartData)` on a scatter chart wrote a `c:ser` with
|
|
62
|
+
both `c:val` and the old `c:xVal`/`c:yVal`, which PowerPoint reports as
|
|
63
|
+
unreadable content; it now raises instead. With an `XyChartData` it raised
|
|
64
|
+
`NoMethodError`. ([#1](https://github.com/Largo/ruby_pptx/issues/1))
|
|
65
|
+
- Line series in a combo chart were drawn as smoothed curves: they carried
|
|
66
|
+
no `c:smooth` of their own, which PowerPoint reads as smoothed regardless
|
|
67
|
+
of the plot's setting. Each now writes `<c:smooth val="0"/>`, as a plain
|
|
68
|
+
line chart does; `series.smooth = true` still curves one.
|
|
69
|
+
- The comment on `SlideLayout::LATENT_PLACEHOLDER_TYPES` said PowerPoint
|
|
70
|
+
shows those placeholders from the layout; it does not.
|
|
71
|
+
|
|
8
72
|
## [0.2.0] - 2026-09-28
|
|
9
73
|
|
|
10
74
|
### Added
|
|
@@ -111,6 +175,7 @@ or where matching it cannot be done. Each case is listed, with its reason, in
|
|
|
111
175
|
- Getters that write to the document in python-pptx -- data-label flags, axis
|
|
112
176
|
and chart titles -- do not here.
|
|
113
177
|
|
|
178
|
+
[0.3.0]: https://github.com/Largo/ruby_pptx/releases/tag/v0.3.0
|
|
114
179
|
[0.2.0]: https://github.com/Largo/ruby_pptx/releases/tag/v0.2.0
|
|
115
180
|
[0.1.1]: https://github.com/Largo/ruby_pptx/releases/tag/v0.1.1
|
|
116
181
|
[0.1.0]: https://github.com/Largo/ruby_pptx/releases/tag/v0.1.0
|
data/README.md
CHANGED
|
@@ -148,10 +148,19 @@ data.categories = %w[Q1 Q2 Q3]
|
|
|
148
148
|
data.add_series("Revenue", [120, 135, 150])
|
|
149
149
|
data.add_series("Margin", [0.21, 0.24, 0.22])
|
|
150
150
|
|
|
151
|
-
slide.shapes.add_combo_chart(data, at: [x, y], size: [w, h]) do |combo|
|
|
151
|
+
chart = slide.shapes.add_combo_chart(data, at: [x, y], size: [w, h]) do |combo|
|
|
152
152
|
combo.plot :column_clustered, series: "Revenue"
|
|
153
153
|
combo.plot :line, series: "Margin", secondary_axis: true
|
|
154
|
-
end
|
|
154
|
+
end.chart
|
|
155
|
+
|
|
156
|
+
# Lines are drawn straight. Smoothing is a per-series setting, as in
|
|
157
|
+
# PowerPoint's "Smoothed line" checkbox, and replace_data keeps it.
|
|
158
|
+
chart.series.last.smooth = true
|
|
159
|
+
|
|
160
|
+
# replace_data matches series to plots in order, so on a combo chart the
|
|
161
|
+
# series count must stay the same; a different count raises Pptx::Error
|
|
162
|
+
# rather than dropping a plot or its secondary axis.
|
|
163
|
+
chart.replace_data(new_data_with_two_series)
|
|
155
164
|
```
|
|
156
165
|
|
|
157
166
|
```ruby
|
|
@@ -61,9 +61,22 @@ module Pptx
|
|
|
61
61
|
# Replace this chart's categories and series with those in +chart_data+.
|
|
62
62
|
#
|
|
63
63
|
# Series-level formatting is left alone. If there are more series than
|
|
64
|
-
# before, the extra ones are cloned from the last series
|
|
65
|
-
#
|
|
66
|
-
#
|
|
64
|
+
# before, the extra ones are cloned from the last series so they inherit
|
|
65
|
+
# its formatting; if fewer, the surplus is removed from the end.
|
|
66
|
+
#
|
|
67
|
+
# The new series are matched to the existing ones in document order, plot
|
|
68
|
+
# by plot. On a chart with more than one plot (a combo chart) the series
|
|
69
|
+
# count must therefore stay the same: adding or dropping series would
|
|
70
|
+
# silently move series between plots or remove a plot with its axis and
|
|
71
|
+
# formatting, so it raises {Pptx::Error} instead.
|
|
72
|
+
#
|
|
73
|
+
# A category chart (bar, line, pie, area, ...) takes {ChartData}; a
|
|
74
|
+
# scatter chart takes {XyChartData} and a bubble chart {BubbleChartData}.
|
|
75
|
+
# Passing the wrong kind raises {Pptx::Error} rather than writing a
|
|
76
|
+
# series PowerPoint cannot read.
|
|
77
|
+
#
|
|
78
|
+
# @raise [Pptx::Error] for a data kind the chart cannot hold, or a series
|
|
79
|
+
# count change on a multi-plot chart
|
|
67
80
|
def replace_data(chart_data)
|
|
68
81
|
SeriesRewriter.new(chart_data).rewrite(@element)
|
|
69
82
|
part.workbook.replace_with(chart_data.xlsx_blob)
|
|
@@ -411,17 +424,62 @@ module Pptx
|
|
|
411
424
|
# A date category's cached serial depends on the chart's date system.
|
|
412
425
|
@date_1904 = chart_space.date1904&.val || false
|
|
413
426
|
plot_area = chart_space.chart.plotArea
|
|
427
|
+
check_data_kind(plot_area)
|
|
414
428
|
adjust_series_count(plot_area, @chart_data.series.size)
|
|
415
429
|
plot_area.series_elements.zip(@chart_data.series) do |ser, series_data|
|
|
416
|
-
rewrite_series(ser, series_data)
|
|
430
|
+
xy? ? rewrite_xy_series(ser, series_data) : rewrite_series(ser, series_data)
|
|
417
431
|
end
|
|
418
432
|
self
|
|
419
433
|
end
|
|
420
434
|
|
|
421
435
|
private
|
|
422
436
|
|
|
437
|
+
def xy?
|
|
438
|
+
@chart_data.is_a?(XyChartData)
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def bubble?
|
|
442
|
+
@chart_data.is_a?(BubbleChartData)
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
# Scatter and bubble series carry c:xVal/c:yVal(/c:bubbleSize) where a
|
|
446
|
+
# category series carries c:cat/c:val; writing one kind of data into the
|
|
447
|
+
# other kind of series leaves a c:ser PowerPoint reports as corrupt.
|
|
448
|
+
def check_data_kind(plot_area)
|
|
449
|
+
kinds = plot_area.plot_elements.map { |plot| plot_kind(plot) }.uniq
|
|
450
|
+
expected = if bubble? then :bubble
|
|
451
|
+
elsif xy? then :scatter
|
|
452
|
+
else :category
|
|
453
|
+
end
|
|
454
|
+
return if kinds.empty? || kinds == [expected]
|
|
455
|
+
|
|
456
|
+
raise Error, "cannot replace the data of a #{kinds.join("/")} chart with " \
|
|
457
|
+
"#{@chart_data.class.name}; use #{data_class_for(kinds.first)}"
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
def plot_kind(plot)
|
|
461
|
+
case plot.nsptag
|
|
462
|
+
when "c:scatterChart" then :scatter
|
|
463
|
+
when "c:bubbleChart" then :bubble
|
|
464
|
+
else :category
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
def data_class_for(kind)
|
|
469
|
+
{ scatter: "Pptx::XyChartData", bubble: "Pptx::BubbleChartData",
|
|
470
|
+
category: "Pptx::ChartData" }.fetch(kind)
|
|
471
|
+
end
|
|
472
|
+
|
|
423
473
|
def adjust_series_count(plot_area, wanted)
|
|
424
474
|
difference = wanted - plot_area.series_elements.size
|
|
475
|
+
plots = plot_area.plot_elements.size
|
|
476
|
+
if difference.nonzero? && plots > 1
|
|
477
|
+
raise Error, "cannot change the series count of a chart with #{plots} plots " \
|
|
478
|
+
"(#{plot_area.series_elements.size} series, #{wanted} given); " \
|
|
479
|
+
"series map to plots in document order, so adding or removing them " \
|
|
480
|
+
"would move series between plots or drop a plot"
|
|
481
|
+
end
|
|
482
|
+
|
|
425
483
|
if difference.positive?
|
|
426
484
|
clone_series(plot_area, difference)
|
|
427
485
|
elsif difference.negative?
|
|
@@ -463,6 +521,18 @@ module Pptx
|
|
|
463
521
|
ser.insert_cat(ser.build_from_xml(cat))
|
|
464
522
|
ser.insert_val(ser.build_from_xml(val))
|
|
465
523
|
end
|
|
524
|
+
|
|
525
|
+
def rewrite_xy_series(ser, series_data)
|
|
526
|
+
ser.remove_tx
|
|
527
|
+
ser.remove_xVal
|
|
528
|
+
ser.remove_yVal
|
|
529
|
+
ser.remove_bubbleSize
|
|
530
|
+
fragments = SeriesFragments.new(@chart_data, series_data).xy_fragments
|
|
531
|
+
ser.insert_tx(ser.build_from_xml(fragments[:tx]))
|
|
532
|
+
ser.insert_xVal(ser.build_from_xml(fragments[:x_val]))
|
|
533
|
+
ser.insert_yVal(ser.build_from_xml(fragments[:y_val]))
|
|
534
|
+
ser.insert_bubbleSize(ser.build_from_xml(fragments[:bubble_size])) if fragments[:bubble_size]
|
|
535
|
+
end
|
|
466
536
|
end
|
|
467
537
|
|
|
468
538
|
# Builds the `c:tx`, `c:cat` and `c:val` of one series as standalone XML.
|
|
@@ -482,6 +552,23 @@ module Pptx
|
|
|
482
552
|
[namespaced(tx_xml(@series)), namespaced(cat_xml(@series)), namespaced(val_xml(@series))]
|
|
483
553
|
end
|
|
484
554
|
|
|
555
|
+
# The tx, xVal, yVal and (for a bubble series) bubbleSize of a scatter or
|
|
556
|
+
# bubble series, written exactly as XyBase writes them for a new chart.
|
|
557
|
+
#
|
|
558
|
+
# @return [Hash{Symbol => String}]
|
|
559
|
+
def xy_fragments
|
|
560
|
+
fragments = {
|
|
561
|
+
tx: tx_xml(@series),
|
|
562
|
+
x_val: num_ref_xml("c:xVal", @series.x_values_ref, @series.x_values, @series.number_format),
|
|
563
|
+
y_val: num_ref_xml("c:yVal", @series.y_values_ref, @series.y_values, @series.number_format)
|
|
564
|
+
}
|
|
565
|
+
if @series.respond_to?(:bubble_sizes)
|
|
566
|
+
fragments[:bubble_size] = num_ref_xml("c:bubbleSize", @series.bubble_sizes_ref,
|
|
567
|
+
@series.bubble_sizes, @series.number_format)
|
|
568
|
+
end
|
|
569
|
+
fragments.transform_values { |fragment| namespaced(fragment) }
|
|
570
|
+
end
|
|
571
|
+
|
|
485
572
|
private
|
|
486
573
|
|
|
487
574
|
# The fragments are written for a document that already declares the chart
|
|
@@ -137,7 +137,7 @@ module Pptx
|
|
|
137
137
|
<<~XML
|
|
138
138
|
<#{plot_tag(family)}>
|
|
139
139
|
#{indent(body, 2).chomp}
|
|
140
|
-
#{indent(spec.series.map { |s|
|
|
140
|
+
#{indent(spec.series.map { |s| plot_series_xml(family, s) }.join, 2).chomp}
|
|
141
141
|
#{indent(plot_tail(family, spec), 2).chomp}
|
|
142
142
|
<c:axId val="#{cat_ax}"/>
|
|
143
143
|
<c:axId val="#{value_ax}"/>
|
|
@@ -145,6 +145,15 @@ module Pptx
|
|
|
145
145
|
XML
|
|
146
146
|
end
|
|
147
147
|
|
|
148
|
+
# PowerPoint draws a line series with no c:smooth of its own as a smoothed
|
|
149
|
+
# curve, whatever the plot-level c:smooth says, so each line series turns
|
|
150
|
+
# it off explicitly -- as LineChartWriter does for a plain line chart.
|
|
151
|
+
def plot_series_xml(family, series)
|
|
152
|
+
return series_xml(series) unless family == :line
|
|
153
|
+
|
|
154
|
+
series_xml(series, extra_after_val: %(<c:smooth val="0"/>\n))
|
|
155
|
+
end
|
|
156
|
+
|
|
148
157
|
def plot_tag(family)
|
|
149
158
|
{ bar: "c:barChart", line: "c:lineChart", area: "c:areaChart" }[family]
|
|
150
159
|
end
|
data/lib/ruby_pptx/oxml/slide.rb
CHANGED
|
@@ -215,6 +215,7 @@ module Pptx
|
|
|
215
215
|
# `p:txStyles`, the master's default text styling per outline level.
|
|
216
216
|
class CT_SlideMasterTextStyles < Element
|
|
217
217
|
tag "p:txStyles"
|
|
218
|
+
# Each style is a {CT_TextListStyle}, registered there.
|
|
218
219
|
zero_or_one "p:titleStyle", successors: %w[p:bodyStyle p:otherStyle p:extLst]
|
|
219
220
|
zero_or_one "p:bodyStyle", successors: %w[p:otherStyle p:extLst]
|
|
220
221
|
zero_or_one "p:otherStyle", successors: %w[p:extLst]
|
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
|
|
@@ -89,6 +90,7 @@ module Pptx
|
|
|
89
90
|
optional_attr "b", type: SimpleTypes::XsdBoolean
|
|
90
91
|
optional_attr "i", type: SimpleTypes::XsdBoolean
|
|
91
92
|
optional_attr "u", type: Enum::MSO_TEXT_UNDERLINE_TYPE
|
|
93
|
+
optional_attr "cap", type: SimpleTypes::XsdString
|
|
92
94
|
|
|
93
95
|
def new_gradFill
|
|
94
96
|
CT_GradientFillProperties.new_grad_fill(self)
|
|
@@ -108,6 +110,7 @@ module Pptx
|
|
|
108
110
|
optional_attr "bIns", type: SimpleTypes::ST_Coordinate32, default: Pptx::Length.emu(45_720)
|
|
109
111
|
optional_attr "anchor", type: Enum::MSO_VERTICAL_ANCHOR
|
|
110
112
|
optional_attr "wrap", type: SimpleTypes::ST_TextWrappingType
|
|
113
|
+
optional_attr "vert", type: SimpleTypes::XsdString
|
|
111
114
|
|
|
112
115
|
# @return [Pptx::Enum::MSO_AUTO_SIZE, nil] nil when inherited
|
|
113
116
|
def autofit
|
|
@@ -174,9 +177,29 @@ module Pptx
|
|
|
174
177
|
end
|
|
175
178
|
end
|
|
176
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
|
+
|
|
177
197
|
# `a:pPr`, paragraph properties.
|
|
178
198
|
class CT_TextParagraphProperties < Element
|
|
179
|
-
|
|
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
|
|
180
203
|
TAG_SEQ = %w[a:lnSpc a:spcBef a:spcAft a:buClrTx a:buClr a:buSzTx a:buSzPct
|
|
181
204
|
a:buSzPts a:buFontTx a:buFont a:buNone a:buAutoNum a:buChar
|
|
182
205
|
a:buBlip a:tabLst a:defRPr a:extLst].freeze
|
|
@@ -184,9 +207,15 @@ module Pptx
|
|
|
184
207
|
zero_or_one "a:lnSpc", successors: TAG_SEQ[1..]
|
|
185
208
|
zero_or_one "a:spcBef", successors: TAG_SEQ[2..]
|
|
186
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..]
|
|
187
214
|
zero_or_one "a:defRPr", successors: TAG_SEQ[16..]
|
|
188
215
|
optional_attr "lvl", type: SimpleTypes::ST_TextIndentLevelType, default: 0
|
|
189
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
|
|
190
219
|
|
|
191
220
|
# A Float means a number of lines; a {Pptx::Length} means a fixed
|
|
192
221
|
# distance. nil when no spacing is set.
|
|
@@ -222,6 +251,48 @@ module Pptx
|
|
|
222
251
|
remove_spcAft
|
|
223
252
|
get_or_add_spcAft.set_spc_pts(value) unless value.nil?
|
|
224
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
|
|
225
296
|
end
|
|
226
297
|
|
|
227
298
|
# `a:p`, a paragraph.
|
|
@@ -249,6 +320,18 @@ module Pptx
|
|
|
249
320
|
add_br
|
|
250
321
|
end
|
|
251
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
|
|
334
|
+
|
|
252
335
|
# Append +text+ as runs, turning each "\n" or "\v" into a line break.
|
|
253
336
|
#
|
|
254
337
|
# Breaks go *between* items, so leading text never produces one, and an
|
|
@@ -278,6 +361,7 @@ module Pptx
|
|
|
278
361
|
# axis title holds.
|
|
279
362
|
tag "p:txBody", "a:txBody", "c:txPr", "c:rich"
|
|
280
363
|
one_and_only_one "a:bodyPr"
|
|
364
|
+
zero_or_one "a:lstStyle", successors: %w[a:p]
|
|
281
365
|
one_or_more "a:p", successors: [], as: :p
|
|
282
366
|
|
|
283
367
|
# A chart's `c:txPr` holds a paragraph for its formatting alone; the
|
|
@@ -198,12 +198,12 @@ module Pptx
|
|
|
198
198
|
end
|
|
199
199
|
end
|
|
200
200
|
|
|
201
|
-
#
|
|
202
|
-
#
|
|
201
|
+
# Adding the shapes a slide, layout or master can all hold: auto shapes,
|
|
202
|
+
# pictures, text boxes, connectors, freeforms and groups. Charts, tables,
|
|
203
|
+
# movies and OLE objects need a slide and stay in {BaseGroupShapes}.
|
|
203
204
|
#
|
|
204
|
-
#
|
|
205
|
-
|
|
206
|
-
class BaseGroupShapes < BaseShapes
|
|
205
|
+
# Expects +@sp_tree+, +part+ and +shape_factory+ from the including class.
|
|
206
|
+
module ShapeAuthoring
|
|
207
207
|
# Add an auto shape.
|
|
208
208
|
#
|
|
209
209
|
# shapes.add_shape(:rounded_rectangle,
|
|
@@ -223,7 +223,7 @@ module Pptx
|
|
|
223
223
|
sp = @sp_tree.add_autoshape(id, name, Enum::MSO_SHAPE.to_xml(member),
|
|
224
224
|
left, top, width, height)
|
|
225
225
|
recalculate_extents
|
|
226
|
-
|
|
226
|
+
drawn(sp)
|
|
227
227
|
end
|
|
228
228
|
|
|
229
229
|
# Add a picture showing the image in +image_file+, which may be a path or
|
|
@@ -259,9 +259,127 @@ module Pptx
|
|
|
259
259
|
end
|
|
260
260
|
|
|
261
261
|
recalculate_extents
|
|
262
|
-
|
|
262
|
+
drawn(pic)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
# Add an empty text box.
|
|
266
|
+
#
|
|
267
|
+
# @return [Shape]
|
|
268
|
+
def add_textbox(at:, size:)
|
|
269
|
+
left, top = at
|
|
270
|
+
width, height = size
|
|
271
|
+
id = next_shape_id
|
|
272
|
+
sp = @sp_tree.add_textbox(id, "TextBox #{id - 1}", left, top, width, height)
|
|
273
|
+
recalculate_extents
|
|
274
|
+
drawn(sp)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# Add a connector between two points.
|
|
278
|
+
#
|
|
279
|
+
# A connector is stored as a bounding box with flip flags rather than as
|
|
280
|
+
# two points, so the end points are converted here.
|
|
281
|
+
#
|
|
282
|
+
# @return [Connector]
|
|
283
|
+
def add_connector(connector_type, begin_at:, end_at:)
|
|
284
|
+
member = Enum::MSO_CONNECTOR_TYPE.fetch(connector_type)
|
|
285
|
+
begin_x, begin_y = begin_at.map { |value| Length.coerce(value).emu }
|
|
286
|
+
end_x, end_y = end_at.map { |value| Length.coerce(value).emu }
|
|
287
|
+
|
|
288
|
+
id = next_shape_id
|
|
289
|
+
cxn_sp = @sp_tree.add_cxnSp(
|
|
290
|
+
id, "Connector #{id - 1}", Enum::MSO_CONNECTOR_TYPE.to_xml(member),
|
|
291
|
+
[begin_x, end_x].min, [begin_y, end_y].min,
|
|
292
|
+
(end_x - begin_x).abs, (end_y - begin_y).abs,
|
|
293
|
+
begin_x > end_x, begin_y > end_y
|
|
294
|
+
)
|
|
295
|
+
recalculate_extents
|
|
296
|
+
drawn(cxn_sp)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# Start building a freeform shape.
|
|
300
|
+
#
|
|
301
|
+
# +scale+ says how many EMU one local coordinate unit is worth, so a shape
|
|
302
|
+
# can be described in convenient numbers; pass a pair for different
|
|
303
|
+
# horizontal and vertical scales.
|
|
304
|
+
#
|
|
305
|
+
# @return [FreeformBuilder]
|
|
306
|
+
def build_freeform(start_x: 0, start_y: 0, scale: 1.0)
|
|
307
|
+
FreeformBuilder.new_builder(self, start_x, start_y, scale)
|
|
263
308
|
end
|
|
264
309
|
|
|
310
|
+
# Build a freeform shape and add it, in one call.
|
|
311
|
+
#
|
|
312
|
+
# shapes.add_freeform(at: [x, y], scale: Pptx.inches(1).emu / 100.0) do |f|
|
|
313
|
+
# f.line_to(100, 0)
|
|
314
|
+
# f.line_to(50, 100)
|
|
315
|
+
# end
|
|
316
|
+
#
|
|
317
|
+
# @return [Shape]
|
|
318
|
+
def add_freeform(at: [0, 0], start_x: 0, start_y: 0, scale: 1.0, close: true)
|
|
319
|
+
builder = build_freeform(start_x: start_x, start_y: start_y, scale: scale)
|
|
320
|
+
yield builder if block_given?
|
|
321
|
+
builder.close if close
|
|
322
|
+
builder.convert_to_shape(origin_at: at)
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
# @api private
|
|
326
|
+
# Used by FreeformBuilder, which needs to add the element and then draw
|
|
327
|
+
# into it.
|
|
328
|
+
def add_freeform_element(x, y, width, height)
|
|
329
|
+
@sp_tree.add_freeform_sp(x, y, width, height)
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
# @api private
|
|
333
|
+
def build_shape(shape_element)
|
|
334
|
+
recalculate_extents
|
|
335
|
+
drawn(shape_element)
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
# Add a group, optionally moving +shapes+ into it.
|
|
339
|
+
#
|
|
340
|
+
# The group has no position or size of its own: both follow from what it
|
|
341
|
+
# contains, and are recomputed whenever its contents change.
|
|
342
|
+
#
|
|
343
|
+
# @return [GroupShape]
|
|
344
|
+
def add_group_shape(shapes = [])
|
|
345
|
+
grp_sp = @sp_tree.add_grpSp
|
|
346
|
+
shapes.each { |shape| grp_sp.insert_element_before(shape.element, "p:extLst") }
|
|
347
|
+
grp_sp.recalculate_extents unless shapes.empty?
|
|
348
|
+
recalculate_extents
|
|
349
|
+
drawn(grp_sp)
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
private
|
|
353
|
+
|
|
354
|
+
# The proxy for a shape just added. PowerPoint marks shapes drawn on a
|
|
355
|
+
# layout or master `userDrawn`, so an including class can ask for that.
|
|
356
|
+
def drawn(element)
|
|
357
|
+
if user_drawn?
|
|
358
|
+
nv_pr = element.element_children.first&.find("p:nvPr")
|
|
359
|
+
nv_pr&.set("userDrawn", "1")
|
|
360
|
+
end
|
|
361
|
+
shape_factory(element)
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
def user_drawn?
|
|
365
|
+
false
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
# A group resizes itself around its contents; a slide, layout or master
|
|
369
|
+
# does not move.
|
|
370
|
+
def recalculate_extents
|
|
371
|
+
nil
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
# A shape collection you can add shapes to: a slide's tree, or a group
|
|
376
|
+
# within one.
|
|
377
|
+
#
|
|
378
|
+
# Adding to a group changes the group's extents, so every method here ends
|
|
379
|
+
# by recalculating them. On a slide that is a no-op.
|
|
380
|
+
class BaseGroupShapes < BaseShapes
|
|
381
|
+
include ShapeAuthoring
|
|
382
|
+
|
|
265
383
|
# Add a movie showing the video in +movie_file+.
|
|
266
384
|
#
|
|
267
385
|
# The size must be given: unlike a picture, a video is not interrogated
|
|
@@ -382,66 +500,6 @@ module Pptx
|
|
|
382
500
|
shape_factory(frame)
|
|
383
501
|
end
|
|
384
502
|
|
|
385
|
-
# Add an empty text box.
|
|
386
|
-
#
|
|
387
|
-
# @return [Shape]
|
|
388
|
-
def add_textbox(at:, size:)
|
|
389
|
-
left, top = at
|
|
390
|
-
width, height = size
|
|
391
|
-
id = next_shape_id
|
|
392
|
-
sp = @sp_tree.add_textbox(id, "TextBox #{id - 1}", left, top, width, height)
|
|
393
|
-
recalculate_extents
|
|
394
|
-
shape_factory(sp)
|
|
395
|
-
end
|
|
396
|
-
|
|
397
|
-
# Add a connector between two points.
|
|
398
|
-
#
|
|
399
|
-
# A connector is stored as a bounding box with flip flags rather than as
|
|
400
|
-
# two points, so the end points are converted here.
|
|
401
|
-
#
|
|
402
|
-
# @return [Connector]
|
|
403
|
-
def add_connector(connector_type, begin_at:, end_at:)
|
|
404
|
-
member = Enum::MSO_CONNECTOR_TYPE.fetch(connector_type)
|
|
405
|
-
begin_x, begin_y = begin_at.map { |value| Length.coerce(value).emu }
|
|
406
|
-
end_x, end_y = end_at.map { |value| Length.coerce(value).emu }
|
|
407
|
-
|
|
408
|
-
id = next_shape_id
|
|
409
|
-
cxn_sp = @sp_tree.add_cxnSp(
|
|
410
|
-
id, "Connector #{id - 1}", Enum::MSO_CONNECTOR_TYPE.to_xml(member),
|
|
411
|
-
[begin_x, end_x].min, [begin_y, end_y].min,
|
|
412
|
-
(end_x - begin_x).abs, (end_y - begin_y).abs,
|
|
413
|
-
begin_x > end_x, begin_y > end_y
|
|
414
|
-
)
|
|
415
|
-
recalculate_extents
|
|
416
|
-
shape_factory(cxn_sp)
|
|
417
|
-
end
|
|
418
|
-
|
|
419
|
-
# Start building a freeform shape.
|
|
420
|
-
#
|
|
421
|
-
# +scale+ says how many EMU one local coordinate unit is worth, so a shape
|
|
422
|
-
# can be described in convenient numbers; pass a pair for different
|
|
423
|
-
# horizontal and vertical scales.
|
|
424
|
-
#
|
|
425
|
-
# @return [FreeformBuilder]
|
|
426
|
-
def build_freeform(start_x: 0, start_y: 0, scale: 1.0)
|
|
427
|
-
FreeformBuilder.new_builder(self, start_x, start_y, scale)
|
|
428
|
-
end
|
|
429
|
-
|
|
430
|
-
# Build a freeform shape and add it, in one call.
|
|
431
|
-
#
|
|
432
|
-
# shapes.add_freeform(at: [x, y], scale: Pptx.inches(1).emu / 100.0) do |f|
|
|
433
|
-
# f.line_to(100, 0)
|
|
434
|
-
# f.line_to(50, 100)
|
|
435
|
-
# end
|
|
436
|
-
#
|
|
437
|
-
# @return [Shape]
|
|
438
|
-
def add_freeform(at: [0, 0], start_x: 0, start_y: 0, scale: 1.0, close: true)
|
|
439
|
-
builder = build_freeform(start_x: start_x, start_y: start_y, scale: scale)
|
|
440
|
-
yield builder if block_given?
|
|
441
|
-
builder.close if close
|
|
442
|
-
builder.convert_to_shape(origin_at: at)
|
|
443
|
-
end
|
|
444
|
-
|
|
445
503
|
# The loudspeaker still PowerPoint shows for a video with no poster frame.
|
|
446
504
|
def default_poster_frame
|
|
447
505
|
StringIO.new(File.binread(
|
|
@@ -457,33 +515,6 @@ module Pptx
|
|
|
457
515
|
slide_element.get_or_add_child_time_node_list.add_video(pic.shape_id)
|
|
458
516
|
end
|
|
459
517
|
|
|
460
|
-
# @api private
|
|
461
|
-
# Used by FreeformBuilder, which needs to add the element and then draw
|
|
462
|
-
# into it.
|
|
463
|
-
def add_freeform_element(x, y, width, height)
|
|
464
|
-
@sp_tree.add_freeform_sp(x, y, width, height)
|
|
465
|
-
end
|
|
466
|
-
|
|
467
|
-
# @api private
|
|
468
|
-
def build_shape(shape_element)
|
|
469
|
-
recalculate_extents
|
|
470
|
-
shape_factory(shape_element)
|
|
471
|
-
end
|
|
472
|
-
|
|
473
|
-
# Add a group, optionally moving +shapes+ into it.
|
|
474
|
-
#
|
|
475
|
-
# The group has no position or size of its own: both follow from what it
|
|
476
|
-
# contains, and are recomputed whenever its contents change.
|
|
477
|
-
#
|
|
478
|
-
# @return [GroupShape]
|
|
479
|
-
def add_group_shape(shapes = [])
|
|
480
|
-
grp_sp = @sp_tree.add_grpSp
|
|
481
|
-
shapes.each { |shape| grp_sp.insert_element_before(shape.element, "p:extLst") }
|
|
482
|
-
grp_sp.recalculate_extents unless shapes.empty?
|
|
483
|
-
recalculate_extents
|
|
484
|
-
shape_factory(grp_sp)
|
|
485
|
-
end
|
|
486
|
-
|
|
487
518
|
private
|
|
488
519
|
|
|
489
520
|
# A group resizes itself around its contents; a slide does not move.
|
|
@@ -500,11 +531,19 @@ module Pptx
|
|
|
500
531
|
class SlideShapes < BaseGroupShapes
|
|
501
532
|
# Copy the layout's placeholders onto this slide, preserving z-order.
|
|
502
533
|
#
|
|
503
|
-
#
|
|
504
|
-
# PowerPoint
|
|
505
|
-
#
|
|
506
|
-
|
|
507
|
-
|
|
534
|
+
# Date, footer and slide number are left out unless +footers+ is true:
|
|
535
|
+
# PowerPoint draws them only where the slide carries the placeholder
|
|
536
|
+
# itself, which is what switching them on in its Header & Footer dialog
|
|
537
|
+
# does. With +footers+, their text -- the slide-number field, say -- is
|
|
538
|
+
# copied from the layout too, since an empty one shows nothing.
|
|
539
|
+
def clone_layout_placeholders(slide_layout, footers: false)
|
|
540
|
+
chosen = footers ? slide_layout.placeholders.to_a : slide_layout.cloneable_placeholders
|
|
541
|
+
chosen.each do |ph|
|
|
542
|
+
sp = clone_placeholder(ph)
|
|
543
|
+
if footers && SlideLayout::LATENT_PLACEHOLDER_TYPES.include?(ph.element.ph_type)
|
|
544
|
+
copy_text_body(ph.element, sp)
|
|
545
|
+
end
|
|
546
|
+
end
|
|
508
547
|
self
|
|
509
548
|
end
|
|
510
549
|
|
|
@@ -525,6 +564,17 @@ module Pptx
|
|
|
525
564
|
def shape_factory(shape_element)
|
|
526
565
|
ShapeFactory.build_for_slide(shape_element, self)
|
|
527
566
|
end
|
|
567
|
+
|
|
568
|
+
# Replace +target+'s text body with a copy of +source+'s.
|
|
569
|
+
def copy_text_body(source, target)
|
|
570
|
+
body = source.find("p:txBody")
|
|
571
|
+
return if body.nil?
|
|
572
|
+
|
|
573
|
+
copy = target.build_from_xml(body.to_xml)
|
|
574
|
+
old = target.find("p:txBody")
|
|
575
|
+
target.remove(old) if old
|
|
576
|
+
target.insert_element_before(copy, "p:extLst")
|
|
577
|
+
end
|
|
528
578
|
end
|
|
529
579
|
|
|
530
580
|
# The shapes inside a `p:grpSp`.
|
|
@@ -540,8 +590,14 @@ module Pptx
|
|
|
540
590
|
|
|
541
591
|
# The shapes on a slide layout.
|
|
542
592
|
class LayoutShapes < BaseShapes
|
|
593
|
+
include ShapeAuthoring
|
|
594
|
+
|
|
543
595
|
private
|
|
544
596
|
|
|
597
|
+
def user_drawn?
|
|
598
|
+
true
|
|
599
|
+
end
|
|
600
|
+
|
|
545
601
|
def shape_factory(shape_element)
|
|
546
602
|
ShapeFactory.build_for_layout(shape_element, self)
|
|
547
603
|
end
|
|
@@ -549,8 +605,14 @@ module Pptx
|
|
|
549
605
|
|
|
550
606
|
# The shapes on a slide master.
|
|
551
607
|
class MasterShapes < BaseShapes
|
|
608
|
+
include ShapeAuthoring
|
|
609
|
+
|
|
552
610
|
private
|
|
553
611
|
|
|
612
|
+
def user_drawn?
|
|
613
|
+
true
|
|
614
|
+
end
|
|
615
|
+
|
|
554
616
|
def shape_factory(shape_element)
|
|
555
617
|
ShapeFactory.build_for_master(shape_element, self)
|
|
556
618
|
end
|
|
@@ -599,6 +661,10 @@ module Pptx
|
|
|
599
661
|
class LayoutPlaceholders < LayoutShapes
|
|
600
662
|
include PlaceholderAuthoring
|
|
601
663
|
|
|
664
|
+
# A placeholder view only lists placeholders, so a shape added through it
|
|
665
|
+
# would vanish from the collection it was added to.
|
|
666
|
+
private(*ShapeAuthoring.public_instance_methods)
|
|
667
|
+
|
|
602
668
|
# @return [LayoutPlaceholder, nil]
|
|
603
669
|
def by_idx(idx)
|
|
604
670
|
find { |ph| ph.element.ph_idx == idx }
|
|
@@ -619,6 +685,10 @@ module Pptx
|
|
|
619
685
|
class MasterPlaceholders < MasterShapes
|
|
620
686
|
include PlaceholderAuthoring
|
|
621
687
|
|
|
688
|
+
# A placeholder view only lists placeholders, so a shape added through it
|
|
689
|
+
# would vanish from the collection it was added to.
|
|
690
|
+
private(*ShapeAuthoring.public_instance_methods)
|
|
691
|
+
|
|
622
692
|
# @return [MasterPlaceholder, nil]
|
|
623
693
|
def by_type(ph_type)
|
|
624
694
|
find { |ph| ph.element.ph_type == ph_type }
|
data/lib/ruby_pptx/slide.rb
CHANGED
|
@@ -232,10 +232,11 @@ module Pptx
|
|
|
232
232
|
# Add a slide inheriting from +slide_layout+, and return it.
|
|
233
233
|
#
|
|
234
234
|
# The layout's placeholders are copied onto the new slide, preserving
|
|
235
|
-
# z-order
|
|
236
|
-
|
|
235
|
+
# z-order. Date, footer and slide number come along only with
|
|
236
|
+
# +footers: true+, which is what PowerPoint needs to show them.
|
|
237
|
+
def add(slide_layout, footers: false)
|
|
237
238
|
r_id, slide = part.add_slide(slide_layout)
|
|
238
|
-
slide.shapes.clone_layout_placeholders(slide_layout)
|
|
239
|
+
slide.shapes.clone_layout_placeholders(slide_layout, footers: footers)
|
|
239
240
|
@sld_id_list.add_slide_id(r_id)
|
|
240
241
|
slide
|
|
241
242
|
end
|
|
@@ -258,8 +259,8 @@ module Pptx
|
|
|
258
259
|
|
|
259
260
|
pattern_keys :name, :type, :slide_master, :shapes, :placeholders
|
|
260
261
|
|
|
261
|
-
# Placeholders
|
|
262
|
-
#
|
|
262
|
+
# Placeholders a new slide leaves out unless asked: PowerPoint shows them
|
|
263
|
+
# only where the slide carries them, which is its Header & Footer switch.
|
|
263
264
|
LATENT_PLACEHOLDER_TYPES = [
|
|
264
265
|
Enum::PP_PLACEHOLDER::DATE,
|
|
265
266
|
Enum::PP_PLACEHOLDER::FOOTER,
|
|
@@ -425,6 +426,14 @@ module Pptx
|
|
|
425
426
|
@placeholders ||= MasterPlaceholders.new(@element.spTree, self)
|
|
426
427
|
end
|
|
427
428
|
|
|
429
|
+
# The default text formatting per outline level for titles, body text and
|
|
430
|
+
# everything else, which every layout and slide under this master inherits.
|
|
431
|
+
#
|
|
432
|
+
# @return [TextStyles]
|
|
433
|
+
def text_styles
|
|
434
|
+
TextStyles.new(@element.get_or_add_txStyles)
|
|
435
|
+
end
|
|
436
|
+
|
|
428
437
|
def inspect
|
|
429
438
|
"#<Pptx::SlideMaster #{part.partname}>"
|
|
430
439
|
end
|
|
@@ -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
|
data/lib/ruby_pptx/text/text.rb
CHANGED
|
@@ -203,11 +203,123 @@ module Pptx
|
|
|
203
203
|
def body_properties
|
|
204
204
|
@element.bodyPr
|
|
205
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
|
|
206
317
|
end
|
|
207
318
|
|
|
208
319
|
# One paragraph of a text frame.
|
|
209
320
|
class Paragraph
|
|
210
321
|
include PatternMatching
|
|
322
|
+
include ParagraphFormatting
|
|
211
323
|
|
|
212
324
|
pattern_keys :text, :runs, :level, :alignment
|
|
213
325
|
|
|
@@ -236,6 +348,24 @@ module Pptx
|
|
|
236
348
|
self
|
|
237
349
|
end
|
|
238
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
|
+
|
|
239
369
|
# The text of this paragraph, with "\v" for each soft line break.
|
|
240
370
|
def text
|
|
241
371
|
@element.text
|
|
@@ -254,15 +384,6 @@ module Pptx
|
|
|
254
384
|
self
|
|
255
385
|
end
|
|
256
386
|
|
|
257
|
-
# @return [Pptx::Enum::PP_ALIGN, nil] nil when inherited
|
|
258
|
-
def alignment
|
|
259
|
-
paragraph_properties.algn
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
def alignment=(value)
|
|
263
|
-
paragraph_properties.algn = value
|
|
264
|
-
end
|
|
265
|
-
|
|
266
387
|
# Outline level, 0 for the top level.
|
|
267
388
|
def level
|
|
268
389
|
paragraph_properties.lvl
|
|
@@ -272,36 +393,6 @@ module Pptx
|
|
|
272
393
|
paragraph_properties.lvl = value
|
|
273
394
|
end
|
|
274
395
|
|
|
275
|
-
# A Float is a number of lines; a {Pptx::Length} is a fixed distance.
|
|
276
|
-
def line_spacing
|
|
277
|
-
paragraph_properties.line_spacing
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
def line_spacing=(value)
|
|
281
|
-
paragraph_properties.line_spacing = value
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
def space_before
|
|
285
|
-
paragraph_properties.space_before
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
def space_before=(value)
|
|
289
|
-
paragraph_properties.space_before = value
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
def space_after
|
|
293
|
-
paragraph_properties.space_after
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
def space_after=(value)
|
|
297
|
-
paragraph_properties.space_after = value
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
# The default character formatting for runs in this paragraph.
|
|
301
|
-
def font
|
|
302
|
-
Font.new(paragraph_properties.get_or_add_defRPr)
|
|
303
|
-
end
|
|
304
|
-
|
|
305
396
|
def inspect
|
|
306
397
|
"#<Pptx::Paragraph #{text.inspect}>"
|
|
307
398
|
end
|
|
@@ -416,6 +507,25 @@ module Pptx
|
|
|
416
507
|
@element.sz = value.nil? ? nil : Pptx::Length.coerce(value).centipoints
|
|
417
508
|
end
|
|
418
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
|
+
|
|
419
529
|
# true for a single underline, false for none, a
|
|
420
530
|
# {Pptx::Enum::MSO_UNDERLINE} member for anything fancier, nil when
|
|
421
531
|
# inherited.
|
data/lib/ruby_pptx/version.rb
CHANGED
data/lib/ruby_pptx.rb
CHANGED
|
@@ -34,6 +34,7 @@ require "ruby_pptx/dml/effect"
|
|
|
34
34
|
require "ruby_pptx/oxml/theme"
|
|
35
35
|
require "ruby_pptx/theme"
|
|
36
36
|
require "ruby_pptx/text/text"
|
|
37
|
+
require "ruby_pptx/text/list_style"
|
|
37
38
|
require "ruby_pptx/text/font_metrics"
|
|
38
39
|
require "ruby_pptx/text/fitter"
|
|
39
40
|
require "ruby_pptx/oxml/table"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby_pptx
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|
|
@@ -163,6 +163,7 @@ files:
|
|
|
163
163
|
- lib/ruby_pptx/templates/xlsx-icon.emf
|
|
164
164
|
- lib/ruby_pptx/text/fitter.rb
|
|
165
165
|
- lib/ruby_pptx/text/font_metrics.rb
|
|
166
|
+
- lib/ruby_pptx/text/list_style.rb
|
|
166
167
|
- lib/ruby_pptx/text/text.rb
|
|
167
168
|
- lib/ruby_pptx/theme.rb
|
|
168
169
|
- lib/ruby_pptx/version.rb
|