ruby_pptx 0.3.0 → 0.3.1
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 +45 -0
- data/lib/ruby_pptx/chart/chart.rb +15 -6
- data/lib/ruby_pptx/chart/combo.rb +4 -4
- data/lib/ruby_pptx/chart/format.rb +38 -18
- data/lib/ruby_pptx/chart/workbook_writer.rb +1 -1
- data/lib/ruby_pptx/chart/xml_writer.rb +22 -13
- data/lib/ruby_pptx/dml/color.rb +3 -0
- data/lib/ruby_pptx/oxml/chart.rb +29 -13
- data/lib/ruby_pptx/oxml/dml/color.rb +8 -2
- data/lib/ruby_pptx/oxml/dml/fill.rb +18 -0
- data/lib/ruby_pptx/oxml/element.rb +17 -1
- data/lib/ruby_pptx/oxml/ns.rb +37 -0
- data/lib/ruby_pptx/oxml/section.rb +1 -1
- data/lib/ruby_pptx/oxml/shapes/autoshape.rb +4 -4
- data/lib/ruby_pptx/oxml/shapes/groupshape.rb +1 -0
- data/lib/ruby_pptx/oxml/shapes/other.rb +7 -7
- data/lib/ruby_pptx/oxml/shapes/shared.rb +3 -3
- data/lib/ruby_pptx/oxml/simple_types.rb +29 -3
- data/lib/ruby_pptx/oxml/text.rb +5 -3
- data/lib/ruby_pptx/section.rb +3 -0
- data/lib/ruby_pptx/shapes/shape.rb +23 -16
- data/lib/ruby_pptx/shapes/shape_tree.rb +33 -0
- data/lib/ruby_pptx/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a89128951cc815c8b3c79ddd5b685070a33407456e1800839990d4a1c6fa5129
|
|
4
|
+
data.tar.gz: e6b79c4e74492155f421798b1f0d020733702ad8a076786bb6e4edc497bb79fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1888573c92314a536c759036395144ff773c612d901c7610439631eab5d202570c5c6388f377a3480621d38853eeb858272f157900f1deee83d44179f4512219
|
|
7
|
+
data.tar.gz: 46ab4c96c2672e3f323b1a67224f36ae02c6719881a52229ad812dc908398962be5e600617735d0fb4cc21d08c6dbeab3ce3c90fa5252e17b47ac73b88f180a3
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,50 @@ version may change the public API.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.1] - 2026-11-18
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
Found by fuzzing the writer against the Open XML SDK's validator
|
|
15
|
+
(`.claude/skills/ooxml-fuzz`); each wrote XML the schema rejects:
|
|
16
|
+
|
|
17
|
+
- A new pattern colour (`fore_color`/`back_color` on a patterned fill) and a
|
|
18
|
+
new gradient stop list (an outline gradient's `gradient_stops`) start from
|
|
19
|
+
python-pptx's defaults instead of empty.
|
|
20
|
+
- A refused value no longer leaves a half-written element: `theme_color =
|
|
21
|
+
:MIXED`, a `:MIXED` data-label position, a non-positive `major_unit` and
|
|
22
|
+
the like raise and leave the XML as it was. `chart_style=` and `bullet=`
|
|
23
|
+
keep their old value when refused.
|
|
24
|
+
- Control characters and U+FFFE/U+FFFF in names, core properties, notes,
|
|
25
|
+
sections, chart text and theme names raise `ArgumentError` instead of
|
|
26
|
+
producing a package PowerPoint cannot open. Run text still escapes them.
|
|
27
|
+
- `gap_width=` and `overlap=` raise `Pptx::Error` on plots other than bar
|
|
28
|
+
and column (`bubble_scale=` on plots other than bubble), and a bubble
|
|
29
|
+
series' `marker` raises, instead of writing elements those charts cannot
|
|
30
|
+
hold.
|
|
31
|
+
- Data labels on a line chart with markers are written in schema order.
|
|
32
|
+
- `chart_style=` on a radar chart replaces its style rather than adding a
|
|
33
|
+
second one.
|
|
34
|
+
- `bullet=` checks an autonumber scheme against the schema's list.
|
|
35
|
+
- `gradient_angle=` writes a whole turn (720, -360) as 0.
|
|
36
|
+
- A shape, chart, movie or OLE object with a negative size or one past
|
|
37
|
+
2,147,483,647 EMU raises `ArgumentError` before anything is added, and so
|
|
38
|
+
does a group that would grow that large. `width=` and `height=` raise
|
|
39
|
+
`RangeError` for such a size, and a connector end that would land that far
|
|
40
|
+
away (`begin_connect`, `end_x=`, ...) raises before anything moves.
|
|
41
|
+
- Chart axis ids are no longer negative; `c:axId` and `c:crossAx` are
|
|
42
|
+
unsigned. The ids python-pptx writes negative are written without the sign.
|
|
43
|
+
([#3](https://github.com/Largo/ruby_pptx/issues/3))
|
|
44
|
+
- Radar chart series no longer end in a `c:smooth`, which radar series
|
|
45
|
+
cannot hold. ([#3](https://github.com/Largo/ruby_pptx/issues/3))
|
|
46
|
+
- Smooth scatter charts (`:xy_scatter_smooth`,
|
|
47
|
+
`:xy_scatter_smooth_no_markers`) draw curves: their series now say
|
|
48
|
+
`<c:smooth val="1"/>`. They said `0`, so the lines came out straight.
|
|
49
|
+
- `major_unit=` and `minor_unit=` refuse NaN with `RangeError`.
|
|
50
|
+
- `brightness=` with any value but 0 raised `ArgumentError` ("wrong number
|
|
51
|
+
of arguments") instead of adding the `a:lumMod`/`a:lumOff` adjustment. It
|
|
52
|
+
now writes what python-pptx writes.
|
|
53
|
+
|
|
10
54
|
## [0.3.0] - 2026-11-17
|
|
11
55
|
|
|
12
56
|
### Added
|
|
@@ -175,6 +219,7 @@ or where matching it cannot be done. Each case is listed, with its reason, in
|
|
|
175
219
|
- Getters that write to the document in python-pptx -- data-label flags, axis
|
|
176
220
|
and chart titles -- do not here.
|
|
177
221
|
|
|
222
|
+
[0.3.1]: https://github.com/Largo/ruby_pptx/releases/tag/v0.3.1
|
|
178
223
|
[0.3.0]: https://github.com/Largo/ruby_pptx/releases/tag/v0.3.0
|
|
179
224
|
[0.2.0]: https://github.com/Largo/ruby_pptx/releases/tag/v0.2.0
|
|
180
225
|
[0.1.1]: https://github.com/Largo/ruby_pptx/releases/tag/v0.1.1
|
|
@@ -41,8 +41,10 @@ module Pptx
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def chart_style=(value)
|
|
44
|
+
Oxml::SimpleTypes::ST_Style.validate(value) unless value.nil? # before the old style goes
|
|
44
45
|
@element.remove_style
|
|
45
|
-
@element.
|
|
46
|
+
@element.remove_style_alternate_content
|
|
47
|
+
@element.set_child(:style, value) unless value.nil?
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
# The default font for all text in the chart, created on first use.
|
|
@@ -118,7 +120,7 @@ module Pptx
|
|
|
118
120
|
case value
|
|
119
121
|
when nil, false
|
|
120
122
|
chart_element.remove_title
|
|
121
|
-
chart_element.
|
|
123
|
+
chart_element.set_child(:autoTitleDeleted, true)
|
|
122
124
|
when true then chart_element.get_or_add_title
|
|
123
125
|
else ChartTitle.new(chart_element.get_or_add_title).text = value
|
|
124
126
|
end
|
|
@@ -370,7 +372,7 @@ module Pptx
|
|
|
370
372
|
end
|
|
371
373
|
|
|
372
374
|
def invert_if_negative=(value)
|
|
373
|
-
@element.
|
|
375
|
+
@element.set_child(:invertIfNegative, value ? true : false)
|
|
374
376
|
end
|
|
375
377
|
end
|
|
376
378
|
|
|
@@ -385,7 +387,7 @@ module Pptx
|
|
|
385
387
|
end
|
|
386
388
|
|
|
387
389
|
def smooth=(value)
|
|
388
|
-
@element.
|
|
390
|
+
@element.set_child(:smooth, value ? true : false)
|
|
389
391
|
end
|
|
390
392
|
end
|
|
391
393
|
|
|
@@ -408,6 +410,13 @@ module Pptx
|
|
|
408
410
|
end
|
|
409
411
|
|
|
410
412
|
class BubbleSeriesView < XySeriesView
|
|
413
|
+
# python-pptx's BubbleSeries inherits a marker from XySeries, but a
|
|
414
|
+
# bubble series (CT_BubbleSer) cannot hold one: writing it made the chart
|
|
415
|
+
# invalid. The method stays, so the API keeps python-pptx's shape.
|
|
416
|
+
def marker
|
|
417
|
+
raise Error, "a bubble series has no marker; its bubbles are sized by the data"
|
|
418
|
+
end
|
|
419
|
+
|
|
411
420
|
def points
|
|
412
421
|
counts = [@element.xVal_ptCount_val, @element.yVal_ptCount_val, @element.bubbleSize_ptCount_val]
|
|
413
422
|
ChartPoints.new(@element, counts.min)
|
|
@@ -496,8 +505,8 @@ module Pptx
|
|
|
496
505
|
next_index = plot_area.series_elements.size
|
|
497
506
|
count.times do |offset|
|
|
498
507
|
copy = last.parent.import(last)
|
|
499
|
-
copy.
|
|
500
|
-
copy.
|
|
508
|
+
copy.set_child(:idx, next_index + offset)
|
|
509
|
+
copy.set_child(:order, next_index + offset)
|
|
501
510
|
last.add_next_sibling(copy)
|
|
502
511
|
last = copy
|
|
503
512
|
end
|
|
@@ -90,10 +90,10 @@ module Pptx
|
|
|
90
90
|
# category axis with it -- a hidden one, since the categories are already
|
|
91
91
|
# drawn by the primary pair.
|
|
92
92
|
class ComboChartWriter < ChartXmlWriter::Base
|
|
93
|
-
CAT_AX_ID = "
|
|
94
|
-
VAL_AX_ID = "
|
|
95
|
-
SECONDARY_CAT_AX_ID = "
|
|
96
|
-
SECONDARY_VAL_AX_ID = "
|
|
93
|
+
CAT_AX_ID = "2068027336"
|
|
94
|
+
VAL_AX_ID = "2113994440"
|
|
95
|
+
SECONDARY_CAT_AX_ID = "2068027337"
|
|
96
|
+
SECONDARY_VAL_AX_ID = "2113994441"
|
|
97
97
|
|
|
98
98
|
def initialize(builder)
|
|
99
99
|
super(nil, builder.chart_data)
|
|
@@ -41,7 +41,7 @@ module Pptx
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def position=(value)
|
|
44
|
-
@element.
|
|
44
|
+
@element.set_child(:legendPos, Enum::XL_LEGEND_POSITION.fetch(value))
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
# How far the legend is shifted sideways, as a fraction of the chart
|
|
@@ -65,7 +65,7 @@ module Pptx
|
|
|
65
65
|
if value.nil?
|
|
66
66
|
@element.remove_overlay
|
|
67
67
|
else
|
|
68
|
-
@element.
|
|
68
|
+
@element.set_child(:overlay, value ? true : false)
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
|
|
@@ -160,7 +160,7 @@ module Pptx
|
|
|
160
160
|
@element.remove_lblOffset
|
|
161
161
|
return if value == 100
|
|
162
162
|
|
|
163
|
-
@element.
|
|
163
|
+
@element.set_child(:lblOffset, value)
|
|
164
164
|
end
|
|
165
165
|
end
|
|
166
166
|
|
|
@@ -185,7 +185,7 @@ module Pptx
|
|
|
185
185
|
raise ArgumentError, "visible must be true or false, got #{value.inspect}"
|
|
186
186
|
end
|
|
187
187
|
|
|
188
|
-
@element.
|
|
188
|
+
@element.set_child(:delete, !value)
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
def major_gridlines?
|
|
@@ -263,7 +263,7 @@ module Pptx
|
|
|
263
263
|
end
|
|
264
264
|
|
|
265
265
|
def tick_label_position=(value)
|
|
266
|
-
@element.
|
|
266
|
+
@element.set_child(:tickLblPos, Enum::XL_TICK_LABEL_POSITION.fetch(value))
|
|
267
267
|
end
|
|
268
268
|
|
|
269
269
|
# The labels along the axis.
|
|
@@ -350,9 +350,9 @@ module Pptx
|
|
|
350
350
|
axis.remove_crosses
|
|
351
351
|
axis.remove_crossesAt
|
|
352
352
|
if member == Enum::XL_AXIS_CROSSES::CUSTOM
|
|
353
|
-
axis.
|
|
353
|
+
axis.set_child(:crossesAt, 0.0)
|
|
354
354
|
else
|
|
355
|
-
axis.
|
|
355
|
+
axis.set_child(:crosses, member)
|
|
356
356
|
end
|
|
357
357
|
end
|
|
358
358
|
|
|
@@ -365,7 +365,7 @@ module Pptx
|
|
|
365
365
|
axis = cross_axis
|
|
366
366
|
axis.remove_crosses
|
|
367
367
|
axis.remove_crossesAt
|
|
368
|
-
axis.
|
|
368
|
+
axis.set_child(:crossesAt, value) unless value.nil?
|
|
369
369
|
end
|
|
370
370
|
|
|
371
371
|
# The distance between major tick marks, or nil when automatic.
|
|
@@ -375,7 +375,7 @@ module Pptx
|
|
|
375
375
|
|
|
376
376
|
def major_unit=(value)
|
|
377
377
|
@element.remove_majorUnit
|
|
378
|
-
@element.
|
|
378
|
+
@element.set_child(:majorUnit, value) unless value.nil?
|
|
379
379
|
end
|
|
380
380
|
|
|
381
381
|
def minor_unit
|
|
@@ -384,7 +384,7 @@ module Pptx
|
|
|
384
384
|
|
|
385
385
|
def minor_unit=(value)
|
|
386
386
|
@element.remove_minorUnit
|
|
387
|
-
@element.
|
|
387
|
+
@element.set_child(:minorUnit, value) unless value.nil?
|
|
388
388
|
end
|
|
389
389
|
|
|
390
390
|
private
|
|
@@ -457,7 +457,7 @@ module Pptx
|
|
|
457
457
|
if value.nil?
|
|
458
458
|
@element.remove_dLblPos
|
|
459
459
|
else
|
|
460
|
-
@element.
|
|
460
|
+
@element.set_child(:dLblPos, Enum::XL_DATA_LABEL_POSITION.fetch(value))
|
|
461
461
|
end
|
|
462
462
|
end
|
|
463
463
|
|
|
@@ -501,7 +501,7 @@ module Pptx
|
|
|
501
501
|
if value.nil?
|
|
502
502
|
@ser.dLbl_for_point(@idx)&.remove_dLblPos
|
|
503
503
|
else
|
|
504
|
-
label_element.
|
|
504
|
+
label_element.set_child(:dLblPos, Enum::XL_DATA_LABEL_POSITION.fetch(value))
|
|
505
505
|
end
|
|
506
506
|
end
|
|
507
507
|
|
|
@@ -532,7 +532,7 @@ module Pptx
|
|
|
532
532
|
def size=(value)
|
|
533
533
|
marker = @element.get_or_add_marker
|
|
534
534
|
marker.remove_size
|
|
535
|
-
marker.
|
|
535
|
+
marker.set_child(:size, value) unless value.nil?
|
|
536
536
|
end
|
|
537
537
|
|
|
538
538
|
# @return [Pptx::Enum::Member, nil] a member of XL_MARKER_STYLE
|
|
@@ -543,7 +543,7 @@ module Pptx
|
|
|
543
543
|
def style=(value)
|
|
544
544
|
marker = @element.get_or_add_marker
|
|
545
545
|
marker.remove_symbol
|
|
546
|
-
marker.
|
|
546
|
+
marker.set_child(:symbol, Enum::XL_MARKER_STYLE.fetch(value)) unless value.nil?
|
|
547
547
|
end
|
|
548
548
|
end
|
|
549
549
|
|
|
@@ -629,8 +629,18 @@ module Pptx
|
|
|
629
629
|
@element.gapWidth&.val || 150
|
|
630
630
|
end
|
|
631
631
|
|
|
632
|
+
# Which plots may carry each option. python-pptx puts gap width and
|
|
633
|
+
# overlap on its BarPlot only and bubble scale on BubblePlot; written
|
|
634
|
+
# into any other plot they make the chart invalid.
|
|
635
|
+
OPTION_PLOTS = {
|
|
636
|
+
gap_width: %w[c:barChart c:bar3DChart c:ofPieChart],
|
|
637
|
+
overlap: %w[c:barChart],
|
|
638
|
+
bubble_scale: %w[c:bubbleChart]
|
|
639
|
+
}.freeze
|
|
640
|
+
|
|
632
641
|
def gap_width=(value)
|
|
633
|
-
|
|
642
|
+
require_option!(:gap_width)
|
|
643
|
+
@element.set_child(:gapWidth, value)
|
|
634
644
|
end
|
|
635
645
|
|
|
636
646
|
# How far bars in a group overlap, -100 to 100. Zero is written by
|
|
@@ -640,10 +650,11 @@ module Pptx
|
|
|
640
650
|
end
|
|
641
651
|
|
|
642
652
|
def overlap=(value)
|
|
653
|
+
require_option!(:overlap)
|
|
643
654
|
if value.zero?
|
|
644
655
|
@element.remove_overlap
|
|
645
656
|
else
|
|
646
|
-
@element.
|
|
657
|
+
@element.set_child(:overlap, value)
|
|
647
658
|
end
|
|
648
659
|
end
|
|
649
660
|
|
|
@@ -654,8 +665,9 @@ module Pptx
|
|
|
654
665
|
|
|
655
666
|
# nil returns to the default.
|
|
656
667
|
def bubble_scale=(value)
|
|
668
|
+
require_option!(:bubble_scale)
|
|
657
669
|
@element.remove_bubbleScale
|
|
658
|
-
@element.
|
|
670
|
+
@element.set_child(:bubbleScale, value) unless value.nil?
|
|
659
671
|
end
|
|
660
672
|
|
|
661
673
|
# Whether each data point gets its own colour, as a pie does. An absent
|
|
@@ -665,7 +677,7 @@ module Pptx
|
|
|
665
677
|
end
|
|
666
678
|
|
|
667
679
|
def vary_by_categories=(value)
|
|
668
|
-
@element.
|
|
680
|
+
@element.set_child(:varyColors, value ? true : false)
|
|
669
681
|
end
|
|
670
682
|
|
|
671
683
|
# Whether this plot shows data labels at all.
|
|
@@ -693,6 +705,14 @@ module Pptx
|
|
|
693
705
|
def inspect
|
|
694
706
|
"#<Pptx::ChartPlot #{@element.nsptag}>"
|
|
695
707
|
end
|
|
708
|
+
|
|
709
|
+
private
|
|
710
|
+
|
|
711
|
+
def require_option!(option)
|
|
712
|
+
return if OPTION_PLOTS.fetch(option).include?(@element.nsptag)
|
|
713
|
+
|
|
714
|
+
raise Error, "a #{@element.nsptag} plot has no #{option.to_s.tr("_", " ")}"
|
|
715
|
+
end
|
|
696
716
|
end
|
|
697
717
|
|
|
698
718
|
# The categories of a plot, read back from the chart's cached values.
|
|
@@ -288,7 +288,7 @@ module Pptx
|
|
|
288
288
|
end
|
|
289
289
|
|
|
290
290
|
def escape(text)
|
|
291
|
-
text.
|
|
291
|
+
Oxml.xml_text(text).gsub("&", "&").gsub("<", "<").gsub(">", ">")
|
|
292
292
|
end
|
|
293
293
|
|
|
294
294
|
def all_series_xml(&)
|
|
@@ -298,8 +298,12 @@ module Pptx
|
|
|
298
298
|
|
|
299
299
|
# `c:barChart`: clustered, stacked and 100% stacked bars and columns.
|
|
300
300
|
class BarChartWriter < Base
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
# The axis ids here and in every other family are python-pptx's with
|
|
302
|
+
# the sign dropped. python-pptx writes some negative, which `c:axId` and
|
|
303
|
+
# `c:crossAx` (xsd:unsignedInt, at most 2**31 - 1 in Office) do not
|
|
304
|
+
# allow. Only the pairing of each axId with its crossAx matters.
|
|
305
|
+
CAT_AX_ID = "2068027336"
|
|
306
|
+
VAL_AX_ID = "2113994440"
|
|
303
307
|
|
|
304
308
|
BAR_TYPES = %i[BAR_CLUSTERED BAR_STACKED BAR_STACKED_100].freeze
|
|
305
309
|
|
|
@@ -606,8 +610,8 @@ module Pptx
|
|
|
606
610
|
|
|
607
611
|
# `c:scatterChart`, points at (x, y) with optional lines.
|
|
608
612
|
class XyChartWriter < XyBase
|
|
609
|
-
X_AX_ID = "
|
|
610
|
-
Y_AX_ID = "
|
|
613
|
+
X_AX_ID = "2128940872"
|
|
614
|
+
Y_AX_ID = "2129643912"
|
|
611
615
|
|
|
612
616
|
SMOOTH_TYPES = %i[XY_SCATTER_SMOOTH XY_SCATTER_SMOOTH_NO_MARKERS].freeze
|
|
613
617
|
NO_MARKER_TYPES = %i[XY_SCATTER_LINES_NO_MARKERS XY_SCATTER_SMOOTH_NO_MARKERS].freeze
|
|
@@ -667,19 +671,25 @@ module Pptx
|
|
|
667
671
|
XML
|
|
668
672
|
end
|
|
669
673
|
|
|
674
|
+
# The series' own c:smooth decides whether its line is curved;
|
|
675
|
+
# scatterStyle only names the chart type.
|
|
676
|
+
def smooth_xml
|
|
677
|
+
%(<c:smooth val="#{SMOOTH_TYPES.include?(chart_type.name) ? 1 : 0}"/>\n)
|
|
678
|
+
end
|
|
679
|
+
|
|
670
680
|
def series_blocks
|
|
671
681
|
all_series_xml do |series|
|
|
672
682
|
xy_series_xml(series,
|
|
673
683
|
extra_after_tx: line_suppression_xml + marker_none_xml,
|
|
674
|
-
extra_after_values:
|
|
684
|
+
extra_after_values: smooth_xml)
|
|
675
685
|
end
|
|
676
686
|
end
|
|
677
687
|
end
|
|
678
688
|
|
|
679
689
|
# `c:bubbleChart`, points at (x, y) sized by a third value.
|
|
680
690
|
class BubbleChartWriter < XyBase
|
|
681
|
-
X_AX_ID = "
|
|
682
|
-
Y_AX_ID = "
|
|
691
|
+
X_AX_ID = "2115720072"
|
|
692
|
+
Y_AX_ID = "2115723560"
|
|
683
693
|
|
|
684
694
|
def xml
|
|
685
695
|
<<~XML
|
|
@@ -736,8 +746,8 @@ module Pptx
|
|
|
736
746
|
|
|
737
747
|
# `c:areaChart`, filled bands under each series.
|
|
738
748
|
class AreaChartWriter < Base
|
|
739
|
-
CAT_AX_ID = "
|
|
740
|
-
VAL_AX_ID = "
|
|
749
|
+
CAT_AX_ID = "2101159928"
|
|
750
|
+
VAL_AX_ID = "2100718248"
|
|
741
751
|
|
|
742
752
|
GROUPINGS = {
|
|
743
753
|
AREA: "standard", AREA_STACKED: "stacked", AREA_STACKED_100: "percentStacked"
|
|
@@ -835,7 +845,7 @@ module Pptx
|
|
|
835
845
|
# `c:radarChart`, values plotted on spokes around a centre.
|
|
836
846
|
class RadarChartWriter < Base
|
|
837
847
|
CAT_AX_ID = "2073612648"
|
|
838
|
-
VAL_AX_ID = "
|
|
848
|
+
VAL_AX_ID = "2112772216"
|
|
839
849
|
|
|
840
850
|
# A radar chart carries a style hint PowerPoint 2007 did not understand,
|
|
841
851
|
# so it is written inside an AlternateContent block with a plain
|
|
@@ -934,8 +944,7 @@ module Pptx
|
|
|
934
944
|
|
|
935
945
|
def series_blocks
|
|
936
946
|
all_series_xml do |series|
|
|
937
|
-
series_xml(series, extra_before_cat: marker_none_xml
|
|
938
|
-
extra_after_val: %(<c:smooth val="0"/>\n))
|
|
947
|
+
series_xml(series, extra_before_cat: marker_none_xml)
|
|
939
948
|
end
|
|
940
949
|
end
|
|
941
950
|
end
|
data/lib/ruby_pptx/dml/color.rb
CHANGED
|
@@ -124,7 +124,10 @@ module Pptx
|
|
|
124
124
|
element.val
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
+
# Raises ArgumentError for a member with no theme colour behind it
|
|
128
|
+
# (NOT_THEME_COLOR, MIXED) before anything is written.
|
|
127
129
|
def theme_color=(value)
|
|
130
|
+
Enum::MSO_THEME_COLOR.to_xml(value)
|
|
128
131
|
@parent.get_or_change_to_schemeClr.val = Enum::MSO_THEME_COLOR.fetch(value)
|
|
129
132
|
end
|
|
130
133
|
|
data/lib/ruby_pptx/oxml/chart.rb
CHANGED
|
@@ -220,8 +220,8 @@ module Pptx
|
|
|
220
220
|
end
|
|
221
221
|
|
|
222
222
|
def horz_offset=(offset)
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
set_child(:xMode, SimpleTypes::ST_LayoutMode::FACTOR)
|
|
224
|
+
set_child(:x, offset)
|
|
225
225
|
end
|
|
226
226
|
end
|
|
227
227
|
|
|
@@ -306,7 +306,7 @@ module Pptx
|
|
|
306
306
|
|
|
307
307
|
def maximum=(value)
|
|
308
308
|
remove_max
|
|
309
|
-
|
|
309
|
+
set_child(:max, value) unless value.nil?
|
|
310
310
|
end
|
|
311
311
|
|
|
312
312
|
def minimum
|
|
@@ -315,7 +315,7 @@ module Pptx
|
|
|
315
315
|
|
|
316
316
|
def minimum=(value)
|
|
317
317
|
remove_min
|
|
318
|
-
|
|
318
|
+
set_child(:min, value) unless value.nil?
|
|
319
319
|
end
|
|
320
320
|
end
|
|
321
321
|
|
|
@@ -353,7 +353,7 @@ module Pptx
|
|
|
353
353
|
scaling.remove_orientation
|
|
354
354
|
return unless value == SimpleTypes::ST_Orientation::MAX_MIN
|
|
355
355
|
|
|
356
|
-
scaling.
|
|
356
|
+
scaling.set_child(:orientation, value)
|
|
357
357
|
end
|
|
358
358
|
|
|
359
359
|
def new_title
|
|
@@ -683,14 +683,19 @@ module Pptx
|
|
|
683
683
|
tag "c:barChart", "c:lineChart", "c:pieChart", "c:doughnutChart",
|
|
684
684
|
"c:areaChart", "c:radarChart", "c:scatterChart", "c:bubbleChart", "c:area3DChart"
|
|
685
685
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
686
|
+
# Everything any plot type allows after its series and data labels.
|
|
687
|
+
# One list serves them all because no two of these appear in a
|
|
688
|
+
# different order in different plots; missing `c:marker` and
|
|
689
|
+
# `c:smooth` put a line chart's labels after them, out of order.
|
|
690
|
+
AFTER_DLBLS = %w[c:dropLines c:hiLowLines c:upDownBars c:marker c:smooth c:gapWidth
|
|
691
|
+
c:gapDepth c:overlap c:serLines c:shape c:firstSliceAng c:holeSize
|
|
692
|
+
c:bubble3D c:bubbleScale c:showNegBubbles c:sizeRepresents
|
|
693
|
+
c:axId c:extLst].freeze
|
|
694
|
+
|
|
695
|
+
zero_or_one "c:barDir", successors: ["c:grouping", "c:varyColors", "c:ser", "c:dLbls", *AFTER_DLBLS]
|
|
696
|
+
zero_or_one "c:grouping", successors: ["c:varyColors", "c:ser", "c:dLbls", *AFTER_DLBLS]
|
|
697
|
+
zero_or_one "c:varyColors", successors: ["c:ser", "c:dLbls", *AFTER_DLBLS]
|
|
698
|
+
zero_or_one "c:dLbls", successors: AFTER_DLBLS
|
|
694
699
|
zero_or_one "c:gapWidth", successors: %w[c:overlap c:serLines c:axId c:extLst]
|
|
695
700
|
zero_or_one "c:overlap", successors: %w[c:serLines c:axId c:extLst]
|
|
696
701
|
zero_or_one "c:bubbleScale", successors: %w[c:showNegBubbles c:sizeRepresents c:axId
|
|
@@ -837,6 +842,17 @@ module Pptx
|
|
|
837
842
|
def series_elements
|
|
838
843
|
xpath("./c:chart/c:plotArea/*/c:ser")
|
|
839
844
|
end
|
|
845
|
+
|
|
846
|
+
# The radar template, like PowerPoint, carries its style in an
|
|
847
|
+
# `mc:AlternateContent` -- `c14:style`, falling back to `c:style`.
|
|
848
|
+
# Setting a style has to replace that too, or the chart ends up with
|
|
849
|
+
# two styles and the second is out of schema order.
|
|
850
|
+
def remove_style_alternate_content
|
|
851
|
+
element_children
|
|
852
|
+
.select { |child| child.clark_name.end_with?("}AlternateContent") }
|
|
853
|
+
.select { |child| child.xpath(".//c:style").any? }
|
|
854
|
+
.each { |child| remove(child) }
|
|
855
|
+
end
|
|
840
856
|
end
|
|
841
857
|
|
|
842
858
|
# `c:externalData`, the link from a chart to its embedded workbook.
|
|
@@ -34,15 +34,21 @@ module Pptx
|
|
|
34
34
|
|
|
35
35
|
private
|
|
36
36
|
|
|
37
|
+
# Built, given its value, then inserted, so a refused value adds
|
|
38
|
+
# nothing. Not through get_or_add_*: that calls add_lumMod with no
|
|
39
|
+
# argument, which is the one-argument method above, not the generated
|
|
40
|
+
# adder.
|
|
37
41
|
def add_lumMod_element(value)
|
|
38
|
-
el =
|
|
42
|
+
el = new_lumMod
|
|
39
43
|
el.val = value
|
|
44
|
+
insert_lumMod(el)
|
|
40
45
|
el
|
|
41
46
|
end
|
|
42
47
|
|
|
43
48
|
def add_lumOff_element(value)
|
|
44
|
-
el =
|
|
49
|
+
el = new_lumOff
|
|
45
50
|
el.val = value
|
|
51
|
+
insert_lumOff(el)
|
|
46
52
|
el
|
|
47
53
|
end
|
|
48
54
|
end
|
|
@@ -77,6 +77,14 @@ module Pptx
|
|
|
77
77
|
def self.new_grad_fill(context)
|
|
78
78
|
context.build_from_xml(DEFAULT_XML)
|
|
79
79
|
end
|
|
80
|
+
|
|
81
|
+
# python-pptx's `_new_gsLst`: a stop list starts with the default's two
|
|
82
|
+
# stops, since `a:gsLst` needs at least two. An outline's gradient
|
|
83
|
+
# starts empty, so asking for its stops is what creates the list.
|
|
84
|
+
def new_gsLst
|
|
85
|
+
stops = DEFAULT_XML[%r{<a:gsLst>.*</a:gsLst>}m]
|
|
86
|
+
build_from_xml(stops.sub("<a:gsLst>", "<a:gsLst #{Ns.nsdecls("a")}>"))
|
|
87
|
+
end
|
|
80
88
|
end
|
|
81
89
|
|
|
82
90
|
# `a:blip`, the image reference inside a picture fill.
|
|
@@ -136,6 +144,16 @@ module Pptx
|
|
|
136
144
|
zero_or_one "a:fgClr", successors: %w[a:bgClr]
|
|
137
145
|
zero_or_one "a:bgClr", successors: []
|
|
138
146
|
optional_attr "prst", type: Enum::MSO_PATTERN_TYPE
|
|
147
|
+
|
|
148
|
+
# A colour slot must hold a colour, so each starts with python-pptx's:
|
|
149
|
+
# black in front, white behind. An empty `a:fgClr` is schema-invalid.
|
|
150
|
+
def new_fgClr
|
|
151
|
+
build_from_xml(%(<a:fgClr #{Ns.nsdecls("a")}><a:srgbClr val="000000"/></a:fgClr>))
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def new_bgClr
|
|
155
|
+
build_from_xml(%(<a:bgClr #{Ns.nsdecls("a")}><a:srgbClr val="FFFFFF"/></a:bgClr>))
|
|
156
|
+
end
|
|
139
157
|
end
|
|
140
158
|
end
|
|
141
159
|
end
|
|
@@ -255,7 +255,7 @@ module Pptx
|
|
|
255
255
|
end
|
|
256
256
|
|
|
257
257
|
def text=(value)
|
|
258
|
-
BACKEND.set_text(@node, value
|
|
258
|
+
BACKEND.set_text(@node, Oxml.xml_text(value))
|
|
259
259
|
end
|
|
260
260
|
|
|
261
261
|
# Declare +prefix+ on this element even if nothing uses it yet.
|
|
@@ -282,8 +282,24 @@ module Pptx
|
|
|
282
282
|
BACKEND.get_attribute_ns(@node, local, Ns.nsuri(pfx))
|
|
283
283
|
end
|
|
284
284
|
|
|
285
|
+
# Set attribute +attr+ of optional child +name+, creating the child if
|
|
286
|
+
# it is absent. When the value is refused -- out of range, not a member
|
|
287
|
+
# of the enumeration -- a child created for it is removed again, so a
|
|
288
|
+
# rejected assignment never leaves an element without its required
|
|
289
|
+
# attribute behind.
|
|
290
|
+
def set_child(name, value, attr: :val)
|
|
291
|
+
existing = public_send(name)
|
|
292
|
+
child = existing || public_send("get_or_add_#{name}")
|
|
293
|
+
child.public_send("#{attr}=", value)
|
|
294
|
+
child
|
|
295
|
+
rescue StandardError
|
|
296
|
+
public_send("remove_#{name}") if existing.nil? && child
|
|
297
|
+
raise
|
|
298
|
+
end
|
|
299
|
+
|
|
285
300
|
def set(attr_name, value)
|
|
286
301
|
pfx, local = prefixed_attr_parts(attr_name)
|
|
302
|
+
Oxml.xml_text(value)
|
|
287
303
|
if pfx
|
|
288
304
|
BACKEND.set_attribute_ns(@node, pfx, local, Ns.nsuri(pfx), value.to_s)
|
|
289
305
|
else
|
data/lib/ruby_pptx/oxml/ns.rb
CHANGED
|
@@ -9,6 +9,43 @@ module Pptx
|
|
|
9
9
|
# - prefixed, `"p:cSld"` -- how the spec and this code talk
|
|
10
10
|
# - Clark, `"{http://...}cSld"` -- unambiguous, used as registry keys
|
|
11
11
|
# - a backend node, name + namespace -- what the parser hands back
|
|
12
|
+
# Characters XML 1.0 allows in a document. Anything else -- C0 controls
|
|
13
|
+
# other than tab, newline and carriage return, U+FFFE and U+FFFF -- makes
|
|
14
|
+
# the part unparseable, and PowerPoint refuses the whole file.
|
|
15
|
+
XML_CHAR_INVALID = /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/
|
|
16
|
+
|
|
17
|
+
# +text+ unchanged, or ArgumentError when it holds a character XML cannot
|
|
18
|
+
# carry. lxml raises the same way under python-pptx; run text is the one
|
|
19
|
+
# place that escapes control characters instead (as `_xHHHH_`).
|
|
20
|
+
def self.xml_text(text)
|
|
21
|
+
text = text.to_s
|
|
22
|
+
unless text.valid_encoding?
|
|
23
|
+
raise ArgumentError, "not XML compatible: #{text.encoding} string has invalid bytes"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
if (bad = text[XML_CHAR_INVALID])
|
|
27
|
+
raise ArgumentError, format("not XML compatible: contains U+%04X in %p", bad.ord, text[0, 60])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
text
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# The largest extent Office reads: a shape's width and height are 32-bit
|
|
34
|
+
# signed in PowerPoint and in the Open XML SDK's schema, though
|
|
35
|
+
# ST_PositiveCoordinate itself would allow more. 2,349 inches.
|
|
36
|
+
MAX_EXTENT = 2_147_483_647
|
|
37
|
+
|
|
38
|
+
# The `cx="…" cy="…"` attributes of an `a:ext`, or ArgumentError for a
|
|
39
|
+
# size no consumer can read -- negative, or past {MAX_EXTENT}.
|
|
40
|
+
def self.ext_attrs(cx, cy)
|
|
41
|
+
[cx, cy].each do |value|
|
|
42
|
+
next if value.to_i.between?(0, MAX_EXTENT)
|
|
43
|
+
|
|
44
|
+
raise ArgumentError, "shape width and height must be 0 to #{MAX_EXTENT} EMU, got #{value.to_i}"
|
|
45
|
+
end
|
|
46
|
+
%(cx="#{cx.to_i}" cy="#{cy.to_i}")
|
|
47
|
+
end
|
|
48
|
+
|
|
12
49
|
module Ns
|
|
13
50
|
NSMAP = {
|
|
14
51
|
"a" => "http://schemas.openxmlformats.org/drawingml/2006/main",
|
|
@@ -178,7 +178,7 @@ module Pptx
|
|
|
178
178
|
<p:spPr>
|
|
179
179
|
<a:xfrm>
|
|
180
180
|
<a:off x="#{x.to_i}" y="#{y.to_i}"/>
|
|
181
|
-
<a:ext
|
|
181
|
+
<a:ext #{Oxml.ext_attrs(cx, cy)}/>
|
|
182
182
|
</a:xfrm>
|
|
183
183
|
<a:prstGeom prst="#{prst}">
|
|
184
184
|
<a:avLst/>
|
|
@@ -209,7 +209,7 @@ module Pptx
|
|
|
209
209
|
<p:spPr>
|
|
210
210
|
<a:xfrm>
|
|
211
211
|
<a:off x="#{x.to_i}" y="#{y.to_i}"/>
|
|
212
|
-
<a:ext
|
|
212
|
+
<a:ext #{Oxml.ext_attrs(cx, cy)}/>
|
|
213
213
|
</a:xfrm>
|
|
214
214
|
<a:custGeom>
|
|
215
215
|
<a:avLst/>
|
|
@@ -244,7 +244,7 @@ module Pptx
|
|
|
244
244
|
<p:spPr>
|
|
245
245
|
<a:xfrm>
|
|
246
246
|
<a:off x="#{x.to_i}" y="#{y.to_i}"/>
|
|
247
|
-
<a:ext
|
|
247
|
+
<a:ext #{Oxml.ext_attrs(cx, cy)}/>
|
|
248
248
|
</a:xfrm>
|
|
249
249
|
<a:prstGeom prst="rect">
|
|
250
250
|
<a:avLst/>
|
|
@@ -263,7 +263,7 @@ module Pptx
|
|
|
263
263
|
end
|
|
264
264
|
|
|
265
265
|
def escape(text)
|
|
266
|
-
text.
|
|
266
|
+
Oxml.xml_text(text).gsub("&", "&").gsub("<", "<").gsub('"', """)
|
|
267
267
|
end
|
|
268
268
|
|
|
269
269
|
DEFAULT_STYLE = <<~XML
|
|
@@ -112,7 +112,7 @@ module Pptx
|
|
|
112
112
|
<p:spPr>
|
|
113
113
|
<a:xfrm>
|
|
114
114
|
<a:off x="#{x.to_i}" y="#{y.to_i}"/>
|
|
115
|
-
<a:ext
|
|
115
|
+
<a:ext #{Oxml.ext_attrs(cx, cy)}/>
|
|
116
116
|
</a:xfrm>
|
|
117
117
|
<a:prstGeom prst="rect">
|
|
118
118
|
<a:avLst/>
|
|
@@ -156,7 +156,7 @@ module Pptx
|
|
|
156
156
|
<p:spPr>
|
|
157
157
|
<a:xfrm>
|
|
158
158
|
<a:off x="#{x.to_i}" y="#{y.to_i}"/>
|
|
159
|
-
<a:ext
|
|
159
|
+
<a:ext #{Oxml.ext_attrs(cx, cy)}/>
|
|
160
160
|
</a:xfrm>
|
|
161
161
|
<a:prstGeom prst="rect">
|
|
162
162
|
<a:avLst/>
|
|
@@ -167,7 +167,7 @@ module Pptx
|
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
def self.escape(text)
|
|
170
|
-
text.
|
|
170
|
+
Oxml.xml_text(text).gsub("&", "&").gsub("<", "<").gsub(">", ">").gsub('"', """)
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
private
|
|
@@ -238,7 +238,7 @@ module Pptx
|
|
|
238
238
|
<p:spPr>
|
|
239
239
|
<a:xfrm#{flip}>
|
|
240
240
|
<a:off x="#{x.to_i}" y="#{y.to_i}"/>
|
|
241
|
-
<a:ext
|
|
241
|
+
<a:ext #{Oxml.ext_attrs(cx, cy)}/>
|
|
242
242
|
</a:xfrm>
|
|
243
243
|
<a:prstGeom prst="#{prst}">
|
|
244
244
|
<a:avLst/>
|
|
@@ -346,7 +346,7 @@ module Pptx
|
|
|
346
346
|
</p:nvGraphicFramePr>
|
|
347
347
|
<p:xfrm>
|
|
348
348
|
<a:off x="#{x.to_i}" y="#{y.to_i}"/>
|
|
349
|
-
<a:ext
|
|
349
|
+
<a:ext #{Oxml.ext_attrs(cx, cy)}/>
|
|
350
350
|
</p:xfrm>
|
|
351
351
|
<a:graphic>
|
|
352
352
|
<a:graphicData uri="#{URI_OLE_OBJECT}">
|
|
@@ -367,7 +367,7 @@ module Pptx
|
|
|
367
367
|
<p:spPr>
|
|
368
368
|
<a:xfrm>
|
|
369
369
|
<a:off x="#{x.to_i}" y="#{y.to_i}"/>
|
|
370
|
-
<a:ext
|
|
370
|
+
<a:ext #{Oxml.ext_attrs(cx, cy)}/>
|
|
371
371
|
</a:xfrm>
|
|
372
372
|
<a:prstGeom prst="rect">
|
|
373
373
|
<a:avLst/>
|
|
@@ -395,7 +395,7 @@ module Pptx
|
|
|
395
395
|
</p:nvGraphicFramePr>
|
|
396
396
|
<p:xfrm>
|
|
397
397
|
<a:off x="#{x.to_i}" y="#{y.to_i}"/>
|
|
398
|
-
<a:ext
|
|
398
|
+
<a:ext #{Oxml.ext_attrs(cx, cy)}/>
|
|
399
399
|
</p:xfrm>
|
|
400
400
|
<a:graphic>
|
|
401
401
|
<a:graphicData/>
|
|
@@ -156,8 +156,8 @@ module Pptx
|
|
|
156
156
|
# only its own half.
|
|
157
157
|
class CT_PositiveSize2D < Element
|
|
158
158
|
tag "a:ext", "a:chExt"
|
|
159
|
-
required_attr "cx", type: SimpleTypes::
|
|
160
|
-
required_attr "cy", type: SimpleTypes::
|
|
159
|
+
required_attr "cx", type: SimpleTypes::ST_Extent
|
|
160
|
+
required_attr "cy", type: SimpleTypes::ST_Extent
|
|
161
161
|
# -- the extension-list form --
|
|
162
162
|
optional_attr "uri", type: SimpleTypes::XsdString
|
|
163
163
|
end
|
|
@@ -298,7 +298,7 @@ module Pptx
|
|
|
298
298
|
|
|
299
299
|
def prstDash_val=(value)
|
|
300
300
|
remove_custDash
|
|
301
|
-
|
|
301
|
+
set_child(:prstDash, value)
|
|
302
302
|
end
|
|
303
303
|
end
|
|
304
304
|
|
|
@@ -255,8 +255,24 @@ module Pptx
|
|
|
255
255
|
class ST_AxisUnit < XsdDouble
|
|
256
256
|
def self.validate(value)
|
|
257
257
|
super
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
# Written as a negated test so NaN, which compares false either way, is refused.
|
|
259
|
+
raise RangeError, "must be positive numeric value, got #{value}" unless value > 0.0
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# `a:buAutoNum@type`: the numbering schemes ISO/IEC 29500-1 lists.
|
|
264
|
+
class ST_TextAutonumberScheme < XsdStringEnumeration
|
|
265
|
+
SCHEMES = %w[
|
|
266
|
+
alphaLcParenBoth alphaUcParenBoth alphaLcParenR alphaUcParenR alphaLcPeriod alphaUcPeriod
|
|
267
|
+
arabicParenBoth arabicParenR arabicPeriod arabicPlain
|
|
268
|
+
romanLcParenBoth romanUcParenBoth romanLcParenR romanUcParenR romanLcPeriod romanUcPeriod
|
|
269
|
+
circleNumDbPlain circleNumWdBlackPlain circleNumWdWhitePlain arabicDbPeriod arabicDbPlain
|
|
270
|
+
ea1ChsPeriod ea1ChsPlain ea1ChtPeriod ea1ChtPlain ea1JpnChsDbPeriod ea1JpnKorPlain
|
|
271
|
+
ea1JpnKorPeriod arabic1Minus arabic2Minus hebrew2Minus
|
|
272
|
+
thaiAlphaPeriod thaiAlphaParenR thaiAlphaParenBoth thaiNumPeriod thaiNumParenR thaiNumParenBoth
|
|
273
|
+
hindiAlphaPeriod hindiNumPeriod hindiNumParenR hindiAlpha1Period
|
|
274
|
+
].freeze
|
|
275
|
+
values(**SCHEMES.to_h { |s| [s.gsub(/([a-z])([A-Z0-9])/, '\\1_\\2').upcase.to_sym, s] })
|
|
260
276
|
end
|
|
261
277
|
|
|
262
278
|
class ST_BarDir < XsdStringEnumeration
|
|
@@ -480,6 +496,14 @@ module Pptx
|
|
|
480
496
|
end
|
|
481
497
|
end
|
|
482
498
|
|
|
499
|
+
# `cx`/`cy` of `a:ext` and `a:chExt`: an ST_PositiveCoordinate no
|
|
500
|
+
# larger than Office reads ({Oxml::MAX_EXTENT}).
|
|
501
|
+
class ST_Extent < ST_PositiveCoordinate
|
|
502
|
+
def self.validate(value)
|
|
503
|
+
validate_int_in_range(value, 0, Oxml::MAX_EXTENT)
|
|
504
|
+
end
|
|
505
|
+
end
|
|
506
|
+
|
|
483
507
|
# `a:lin@ang`: positive angles less than 360 degrees.
|
|
484
508
|
class ST_PositiveFixedAngle < ST_Angle
|
|
485
509
|
def self.convert_to_xml(degrees)
|
|
@@ -488,7 +512,9 @@ module Pptx
|
|
|
488
512
|
elsif degrees > 0.0
|
|
489
513
|
degrees %= 360
|
|
490
514
|
end
|
|
491
|
-
|
|
515
|
+
# Normalized again after rounding: 720 degrees, or 359.99999, would
|
|
516
|
+
# otherwise come out as 21600000, which the type excludes.
|
|
517
|
+
(round_half_even(degrees * DEGREE_INCREMENTS) % (360 * DEGREE_INCREMENTS)).to_s
|
|
492
518
|
end
|
|
493
519
|
end
|
|
494
520
|
|
data/lib/ruby_pptx/oxml/text.rb
CHANGED
|
@@ -167,13 +167,13 @@ module Pptx
|
|
|
167
167
|
# Spacing as a multiple of line height, e.g. 1.75 lines.
|
|
168
168
|
def set_spc_pct(value)
|
|
169
169
|
remove_spcPts
|
|
170
|
-
|
|
170
|
+
set_child(:spcPct, value)
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
# Spacing as a fixed distance.
|
|
174
174
|
def set_spc_pts(value)
|
|
175
175
|
remove_spcPct
|
|
176
|
-
|
|
176
|
+
set_child(:spcPts, value)
|
|
177
177
|
end
|
|
178
178
|
end
|
|
179
179
|
|
|
@@ -185,7 +185,7 @@ module Pptx
|
|
|
185
185
|
# `a:buAutoNum`, an automatically numbered bullet ("1.", "a)", ...).
|
|
186
186
|
class CT_TextAutonumberBullet < Element
|
|
187
187
|
tag "a:buAutoNum"
|
|
188
|
-
required_attr "type", type: SimpleTypes::
|
|
188
|
+
required_attr "type", type: SimpleTypes::ST_TextAutonumberScheme
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
# `a:buChar`, a character bullet.
|
|
@@ -262,6 +262,8 @@ module Pptx
|
|
|
262
262
|
end
|
|
263
263
|
|
|
264
264
|
def bullet=(value)
|
|
265
|
+
# Checked first, so a refused scheme leaves the old bullet in place.
|
|
266
|
+
SimpleTypes::ST_TextAutonumberScheme.validate(value.to_s) if value.is_a?(Symbol) && value != :none
|
|
265
267
|
remove_buNone
|
|
266
268
|
remove_buAutoNum
|
|
267
269
|
remove_buChar
|
data/lib/ruby_pptx/section.rb
CHANGED
|
@@ -57,6 +57,9 @@ module Pptx
|
|
|
57
57
|
#
|
|
58
58
|
# @return [Section]
|
|
59
59
|
def add(name, slides: [])
|
|
60
|
+
# Checked before the list is created: a rejected name must not leave
|
|
61
|
+
# an empty `p14:sectionLst`, which the schema does not allow.
|
|
62
|
+
Oxml.xml_text(name)
|
|
60
63
|
element = @presentation.element.get_or_add_section_list.add_section(name)
|
|
61
64
|
Section.new(element, @presentation).tap do |section|
|
|
62
65
|
slides.each { |slide| section << slide }
|
|
@@ -199,24 +199,12 @@ module Pptx
|
|
|
199
199
|
# centre and going counter-clockwise. That is a convention rather than a
|
|
200
200
|
# rule, so the result is only predictable for rectangular shapes.
|
|
201
201
|
def begin_connect(shape, connection_point)
|
|
202
|
-
|
|
203
|
-
connection.id = shape.shape_id
|
|
204
|
-
connection.idx = connection_point
|
|
205
|
-
x, y = connection_point_of(shape, connection_point)
|
|
206
|
-
self.begin_x = x
|
|
207
|
-
self.begin_y = y
|
|
208
|
-
self
|
|
202
|
+
connect(shape, connection_point, begin_point: true)
|
|
209
203
|
end
|
|
210
204
|
|
|
211
205
|
# As {#begin_connect}, for the far end.
|
|
212
206
|
def end_connect(shape, connection_point)
|
|
213
|
-
|
|
214
|
-
connection.id = shape.shape_id
|
|
215
|
-
connection.idx = connection_point
|
|
216
|
-
x, y = connection_point_of(shape, connection_point)
|
|
217
|
-
self.end_x = x
|
|
218
|
-
self.end_y = y
|
|
219
|
-
self
|
|
207
|
+
connect(shape, connection_point, begin_point: false)
|
|
220
208
|
end
|
|
221
209
|
|
|
222
210
|
def begin_connected?
|
|
@@ -234,6 +222,22 @@ module Pptx
|
|
|
234
222
|
|
|
235
223
|
private
|
|
236
224
|
|
|
225
|
+
# Moves the end first, so a point too far away for Office raises before
|
|
226
|
+
# the connection is recorded; the size is checked for both axes before
|
|
227
|
+
# either moves.
|
|
228
|
+
def connect(shape, connection_point, begin_point:)
|
|
229
|
+
x, y = connection_point_of(shape, connection_point)
|
|
230
|
+
fixed_x, fixed_y = begin_point ? [end_x.emu, end_y.emu] : [begin_x.emu, begin_y.emu]
|
|
231
|
+
Oxml.ext_attrs((x - fixed_x).abs, (y - fixed_y).abs)
|
|
232
|
+
move_x(x, begin_point:)
|
|
233
|
+
move_y(y, begin_point:)
|
|
234
|
+
cxn = @element.nvCxnSpPr.cNvCxnSpPr
|
|
235
|
+
connection = begin_point ? cxn.get_or_add_stCxn : cxn.get_or_add_endCxn
|
|
236
|
+
connection.id = shape.shape_id
|
|
237
|
+
connection.idx = connection_point
|
|
238
|
+
self
|
|
239
|
+
end
|
|
240
|
+
|
|
237
241
|
# The four points PowerPoint puts on a rectangle: top, left, bottom, right.
|
|
238
242
|
def connection_point_of(shape, index)
|
|
239
243
|
x = shape.left.to_i
|
|
@@ -254,17 +258,20 @@ module Pptx
|
|
|
254
258
|
#
|
|
255
259
|
# The box has no notion of direction, so pulling an end past the other one
|
|
256
260
|
# flips the box rather than giving it a negative size.
|
|
261
|
+
#
|
|
262
|
+
# The size is set first: one too large for Office raises before anything
|
|
263
|
+
# has moved.
|
|
257
264
|
def move_x(new_value, begin_point:)
|
|
258
265
|
fixed = begin_point ? end_x.emu : begin_x.emu
|
|
259
|
-
@element.x = [new_value, fixed].min
|
|
260
266
|
@element.cx = (new_value - fixed).abs
|
|
267
|
+
@element.x = [new_value, fixed].min
|
|
261
268
|
@element.flipH = begin_point ? new_value > fixed : new_value < fixed
|
|
262
269
|
end
|
|
263
270
|
|
|
264
271
|
def move_y(new_value, begin_point:)
|
|
265
272
|
fixed = begin_point ? end_y.emu : begin_y.emu
|
|
266
|
-
@element.y = [new_value, fixed].min
|
|
267
273
|
@element.cy = (new_value - fixed).abs
|
|
274
|
+
@element.y = [new_value, fixed].min
|
|
268
275
|
@element.flipV = begin_point ? new_value > fixed : new_value < fixed
|
|
269
276
|
end
|
|
270
277
|
end
|
|
@@ -342,6 +342,7 @@ module Pptx
|
|
|
342
342
|
#
|
|
343
343
|
# @return [GroupShape]
|
|
344
344
|
def add_group_shape(shapes = [])
|
|
345
|
+
check_group_extent(shapes)
|
|
345
346
|
grp_sp = @sp_tree.add_grpSp
|
|
346
347
|
shapes.each { |shape| grp_sp.insert_element_before(shape.element, "p:extLst") }
|
|
347
348
|
grp_sp.recalculate_extents unless shapes.empty?
|
|
@@ -349,6 +350,20 @@ module Pptx
|
|
|
349
350
|
drawn(grp_sp)
|
|
350
351
|
end
|
|
351
352
|
|
|
353
|
+
# A group's size is its members' bounding box, which Office reads as a
|
|
354
|
+
# 32-bit value. Checked before anything moves, so a refused group leaves
|
|
355
|
+
# its would-be members where they were.
|
|
356
|
+
def check_group_extent(shapes)
|
|
357
|
+
return if shapes.empty?
|
|
358
|
+
|
|
359
|
+
lefts = shapes.map { |shape| shape.left.to_i }
|
|
360
|
+
tops = shapes.map { |shape| shape.top.to_i }
|
|
361
|
+
rights = shapes.map { |shape| shape.left.to_i + shape.width.to_i }
|
|
362
|
+
bottoms = shapes.map { |shape| shape.top.to_i + shape.height.to_i }
|
|
363
|
+
Oxml.ext_attrs(rights.max - lefts.min, bottoms.max - tops.min)
|
|
364
|
+
end
|
|
365
|
+
private :check_group_extent
|
|
366
|
+
|
|
352
367
|
private
|
|
353
368
|
|
|
354
369
|
# The proxy for a shape just added. PowerPoint marks shapes drawn on a
|
|
@@ -395,6 +410,7 @@ module Pptx
|
|
|
395
410
|
content_type: Video::UNKNOWN_CONTENT_TYPE)
|
|
396
411
|
left, top = at
|
|
397
412
|
width, height = size
|
|
413
|
+
Oxml.ext_attrs(width, height) # before any part is added for it
|
|
398
414
|
video = Video.from_file(movie_file, content_type)
|
|
399
415
|
media_r_id, video_r_id = part.get_or_add_video_media_part(video)
|
|
400
416
|
_poster_part, poster_r_id = part.get_or_add_image_part(poster_frame || default_poster_frame)
|
|
@@ -413,6 +429,7 @@ module Pptx
|
|
|
413
429
|
def add_chart(chart_type, chart_data, at:, size:)
|
|
414
430
|
left, top = at
|
|
415
431
|
width, height = size
|
|
432
|
+
Oxml.ext_attrs(width, height) # before any part is added for it
|
|
416
433
|
r_id = part.add_chart_part(chart_type, chart_data)
|
|
417
434
|
id = next_shape_id
|
|
418
435
|
frame = @sp_tree.add_graphic_frame_chart(id, "Chart #{id - 1}", r_id,
|
|
@@ -439,6 +456,7 @@ module Pptx
|
|
|
439
456
|
|
|
440
457
|
left, top = at
|
|
441
458
|
width, height = size
|
|
459
|
+
Oxml.ext_attrs(width, height) # before any part is added for it
|
|
442
460
|
r_id = part.add_combo_chart_part(builder)
|
|
443
461
|
id = next_shape_id
|
|
444
462
|
frame = @sp_tree.add_graphic_frame_chart(id, "Chart #{id - 1}", r_id,
|
|
@@ -489,6 +507,7 @@ module Pptx
|
|
|
489
507
|
default_size
|
|
490
508
|
end)
|
|
491
509
|
icon_width, icon_height = icon_size || default_size
|
|
510
|
+
Oxml.ext_attrs(width, height) && Oxml.ext_attrs(icon_width, icon_height) # before any part is added
|
|
492
511
|
ole_r_id = part.add_embedded_ole_object_part(prog_id, object_file)
|
|
493
512
|
_icon_part, icon_r_id = part.get_or_add_image_part(icon_file || default_ole_icon(prog_id))
|
|
494
513
|
id = next_shape_id
|
|
@@ -582,9 +601,23 @@ module Pptx
|
|
|
582
601
|
private
|
|
583
602
|
|
|
584
603
|
# Adding to a group changes where the group sits and how big it is.
|
|
604
|
+
#
|
|
605
|
+
# When the new shape would stretch this group, or one around it, past
|
|
606
|
+
# what Office reads, it is taken out again -- a group it formed gives its
|
|
607
|
+
# members back -- and the extents return to what they were.
|
|
585
608
|
def recalculate_extents
|
|
586
609
|
@sp_tree.recalculate_extents
|
|
587
610
|
nil
|
|
611
|
+
rescue ArgumentError
|
|
612
|
+
newest = @sp_tree.shape_elements.to_a.last
|
|
613
|
+
if newest.nsptag == "p:grpSp"
|
|
614
|
+
newest.shape_elements.each do |member|
|
|
615
|
+
@sp_tree.insert_element_before(member, "p:extLst")
|
|
616
|
+
end
|
|
617
|
+
end
|
|
618
|
+
@sp_tree.remove(newest)
|
|
619
|
+
@sp_tree.recalculate_extents
|
|
620
|
+
raise
|
|
588
621
|
end
|
|
589
622
|
end
|
|
590
623
|
|
data/lib/ruby_pptx/version.rb
CHANGED
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.3.
|
|
4
|
+
version: 0.3.1
|
|
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-
|
|
11
|
+
date: 2026-11-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|