openxml-pptx 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +6 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +92 -0
- data/Guardfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/build_fixtures +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/zipflip +56 -0
- data/lib/openxml/pptx.rb +52 -0
- data/lib/openxml/pptx/elements.rb +12 -0
- data/lib/openxml/pptx/package.rb +33 -0
- data/lib/openxml/pptx/parts.rb +12 -0
- data/lib/openxml/pptx/parts/image.rb +32 -0
- data/lib/openxml/pptx/parts/presentation.rb +142 -0
- data/lib/openxml/pptx/parts/presentation_properties.rb +38 -0
- data/lib/openxml/pptx/parts/slide.rb +87 -0
- data/lib/openxml/pptx/parts/slide_layout.rb +88 -0
- data/lib/openxml/pptx/parts/slide_master.rb +132 -0
- data/lib/openxml/pptx/parts/theme.rb +61 -0
- data/lib/openxml/pptx/properties.rb +21 -0
- data/lib/openxml/pptx/properties/background.rb +19 -0
- data/lib/openxml/pptx/properties/background_properties.rb +30 -0
- data/lib/openxml/pptx/properties/background_reference.rb +23 -0
- data/lib/openxml/pptx/properties/blip_fill.rb +11 -0
- data/lib/openxml/pptx/properties/color_mapping.rb +11 -0
- data/lib/openxml/pptx/properties/color_mapping_override.rb +11 -0
- data/lib/openxml/pptx/properties/common_slide_data.rb +21 -0
- data/lib/openxml/pptx/properties/connection_shape.rb +16 -0
- data/lib/openxml/pptx/properties/content_part.rb +13 -0
- data/lib/openxml/pptx/properties/control.rb +36 -0
- data/lib/openxml/pptx/properties/control_list.rb +14 -0
- data/lib/openxml/pptx/properties/custom_show.rb +18 -0
- data/lib/openxml/pptx/properties/custom_show_list.rb +14 -0
- data/lib/openxml/pptx/properties/customer_data.rb +13 -0
- data/lib/openxml/pptx/properties/customer_data_container.rb +12 -0
- data/lib/openxml/pptx/properties/customer_data_list.rb +14 -0
- data/lib/openxml/pptx/properties/data_tags.rb +13 -0
- data/lib/openxml/pptx/properties/default_text_style.rb +24 -0
- data/lib/openxml/pptx/properties/embedded_font.rb +18 -0
- data/lib/openxml/pptx/properties/embedded_font_list.rb +14 -0
- data/lib/openxml/pptx/properties/extension.rb +14 -0
- data/lib/openxml/pptx/properties/extension_list.rb +14 -0
- data/lib/openxml/pptx/properties/font.rb +32 -0
- data/lib/openxml/pptx/properties/font_reference.rb +12 -0
- data/lib/openxml/pptx/properties/font_reference_bold.rb +13 -0
- data/lib/openxml/pptx/properties/font_reference_bold_italic.rb +13 -0
- data/lib/openxml/pptx/properties/font_reference_italic.rb +13 -0
- data/lib/openxml/pptx/properties/font_reference_regular.rb +13 -0
- data/lib/openxml/pptx/properties/graphic_frame.rb +20 -0
- data/lib/openxml/pptx/properties/group_shape_properties.rb +34 -0
- data/lib/openxml/pptx/properties/handout_master_id.rb +18 -0
- data/lib/openxml/pptx/properties/handout_master_id_list.rb +14 -0
- data/lib/openxml/pptx/properties/non_visual_connection_shape_drawing_properties.rb +18 -0
- data/lib/openxml/pptx/properties/non_visual_connection_shape_properties.rb +16 -0
- data/lib/openxml/pptx/properties/non_visual_drawing_properties.rb +30 -0
- data/lib/openxml/pptx/properties/non_visual_graphic_frame_drawing_properties.rb +15 -0
- data/lib/openxml/pptx/properties/non_visual_graphic_frame_properties.rb +16 -0
- data/lib/openxml/pptx/properties/non_visual_group_shape_drawing_properties.rb +15 -0
- data/lib/openxml/pptx/properties/non_visual_group_shape_properties.rb +16 -0
- data/lib/openxml/pptx/properties/non_visual_picture_properties.rb +16 -0
- data/lib/openxml/pptx/properties/non_visual_picutre_drawing_properties.rb +18 -0
- data/lib/openxml/pptx/properties/non_visual_properties.rb +29 -0
- data/lib/openxml/pptx/properties/non_visual_shape_drawing_properties.rb +18 -0
- data/lib/openxml/pptx/properties/non_visual_shape_properties.rb +16 -0
- data/lib/openxml/pptx/properties/notes_master_id.rb +18 -0
- data/lib/openxml/pptx/properties/notes_master_id_list.rb +14 -0
- data/lib/openxml/pptx/properties/notes_size.rb +14 -0
- data/lib/openxml/pptx/properties/photo_album.rb +19 -0
- data/lib/openxml/pptx/properties/picture.rb +30 -0
- data/lib/openxml/pptx/properties/placeholder.rb +20 -0
- data/lib/openxml/pptx/properties/shape.rb +34 -0
- data/lib/openxml/pptx/properties/shape_group.rb +18 -0
- data/lib/openxml/pptx/properties/shape_properties.rb +11 -0
- data/lib/openxml/pptx/properties/shape_style.rb +11 -0
- data/lib/openxml/pptx/properties/shape_tree.rb +13 -0
- data/lib/openxml/pptx/properties/shapes_container.rb +18 -0
- data/lib/openxml/pptx/properties/simple_boolean_property.rb +16 -0
- data/lib/openxml/pptx/properties/simple_property_container_property.rb +14 -0
- data/lib/openxml/pptx/properties/slide_id.rb +29 -0
- data/lib/openxml/pptx/properties/slide_id_list.rb +14 -0
- data/lib/openxml/pptx/properties/slide_layout_id.rb +26 -0
- data/lib/openxml/pptx/properties/slide_layout_id_list.rb +14 -0
- data/lib/openxml/pptx/properties/slide_list.rb +14 -0
- data/lib/openxml/pptx/properties/slide_master_id.rb +29 -0
- data/lib/openxml/pptx/properties/slide_master_id_list.rb +14 -0
- data/lib/openxml/pptx/properties/slide_reference.rb +15 -0
- data/lib/openxml/pptx/properties/slide_size.rb +16 -0
- data/lib/openxml/pptx/properties/smart_tags.rb +15 -0
- data/lib/openxml/pptx/properties/text_body.rb +11 -0
- data/lib/openxml/pptx/properties/text_style_body.rb +11 -0
- data/lib/openxml/pptx/properties/text_style_other.rb +11 -0
- data/lib/openxml/pptx/properties/text_style_title.rb +11 -0
- data/lib/openxml/pptx/properties/text_styles.rb +17 -0
- data/lib/openxml/pptx/properties/transform.rb +11 -0
- data/lib/openxml/pptx/properties/transparent_container_property.rb +14 -0
- data/lib/openxml/pptx/relatable_part.rb +100 -0
- data/lib/openxml/pptx/version.rb +5 -0
- data/openxml-pptx.gemspec +33 -0
- metadata +258 -0
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literals: true
|
2
|
+
|
3
|
+
module OpenXml
|
4
|
+
module Pptx
|
5
|
+
module Parts
|
6
|
+
class Presentation < OpenXml::Part
|
7
|
+
include OpenXml::RelatablePart
|
8
|
+
include OpenXml::HasAttributes
|
9
|
+
include OpenXml::ContainsProperties
|
10
|
+
attr_reader :slides, :slide_masters, :themes, :presentation_properties
|
11
|
+
|
12
|
+
relationship_type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
|
13
|
+
content_type "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"
|
14
|
+
default_path "ppt/presentation.xml"
|
15
|
+
|
16
|
+
attribute :auto_compress_pictures, displays_as: :autoCompressPict, expects: :boolean
|
17
|
+
attribute :bookmark_id_seed, displays_as: :bookmarkIdSeed, expects: :integer, in_range: (1..2_147_483_648)
|
18
|
+
attribute :compatibility_mode, displays_as: :compatMode, expects: :boolean
|
19
|
+
attribute :conformance, one_of: %i{ strict transitional }
|
20
|
+
attribute :embed_fonts, displays_as: :embedTrueTypeFonts, expects: :boolean
|
21
|
+
attribute :first_slide_number, displays_as: :firstSlideNum, expects: :integer
|
22
|
+
attribute :remove_personal_information_on_save, displays_as: :removePersonalInfoOnSave, expects: :boolean
|
23
|
+
attribute :right_to_left, displays_as: :rtl, expects: :boolean
|
24
|
+
attribute :save_subset_fonts, displays_as: :saveSubsetFonts, expects: :boolean
|
25
|
+
attribute :server_zoom, displays_as: :serverZoom, expects: :percentage
|
26
|
+
attribute :show_special_placeholders_on_title_slide, displays_as: :showSpecialPlsOnTitleSld, expects: :boolean
|
27
|
+
attribute :strict_first_and_last_characters, displays_as: :strictFirstAndLastChars, expects: :boolean
|
28
|
+
|
29
|
+
property :slide_master_id_list
|
30
|
+
property :notes_master_id_list
|
31
|
+
property :handout_master_id_list
|
32
|
+
property :slide_id_list
|
33
|
+
property :slide_size
|
34
|
+
property :notes_size, required: true
|
35
|
+
property :smart_tags
|
36
|
+
property :embedded_font_list
|
37
|
+
property :custom_show_list
|
38
|
+
property :photo_album
|
39
|
+
# property :customer_data_list # tag :custDataLst
|
40
|
+
# property :kinsoku
|
41
|
+
property :default_text_style
|
42
|
+
# property :modification_verifier # tag :modifyVerifier
|
43
|
+
|
44
|
+
property :extension_list
|
45
|
+
|
46
|
+
# For proper interaction with HasAttributes
|
47
|
+
def self.tag
|
48
|
+
:presentation
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.namespace
|
52
|
+
:p
|
53
|
+
end
|
54
|
+
|
55
|
+
def name
|
56
|
+
"presentation"
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize(*_args)
|
60
|
+
super
|
61
|
+
@slides = []
|
62
|
+
@slide_masters = []
|
63
|
+
@themes = []
|
64
|
+
@presentation_properties = OpenXml::Pptx::Parts::PresentationProperties.new
|
65
|
+
add_child_part(presentation_properties)
|
66
|
+
|
67
|
+
# Set defaults
|
68
|
+
slide_size.length = 12_192_000
|
69
|
+
slide_size.width = 6_858_000
|
70
|
+
notes_size.length = 6_858_000
|
71
|
+
notes_size.width = 9_144_000
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_slide(slide)
|
75
|
+
slides.push(slide)
|
76
|
+
add_child_part(slide, with_index: slides.count)
|
77
|
+
slide_id_list << OpenXml::Pptx::Properties::SlideId.new.tap do |slide_id|
|
78
|
+
slide_id.rid = relationships_by_path[slide.path].id
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def build_slide(named: nil, slide_layout: nil)
|
83
|
+
OpenXml::Pptx::Parts::Slide.new.tap do |slide|
|
84
|
+
slide.common_slide_data.slide_name = named unless named.nil?
|
85
|
+
slide.set_slide_layout(slide_layout) unless slide_layout.nil?
|
86
|
+
add_slide(slide)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def add_slide_master(slide_master)
|
91
|
+
slide_masters.push(slide_master)
|
92
|
+
add_child_part(slide_master, with_index: slide_masters.count)
|
93
|
+
slide_master_id_list << OpenXml::Pptx::Properties::SlideMasterId.new.tap do |master_id|
|
94
|
+
master_id.rid = relationships_by_path[slide_master.path].id
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def build_slide_master(named: nil, theme: nil)
|
99
|
+
OpenXml::Pptx::Parts::SlideMaster.new.tap do |slide_master|
|
100
|
+
slide_master.common_slide_data.slide_name = named unless named.nil?
|
101
|
+
slide_master.set_theme(theme) unless theme.nil?
|
102
|
+
add_slide_master(slide_master)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def add_theme(theme)
|
107
|
+
themes.push(theme)
|
108
|
+
add_child_part(theme, with_index: themes.count)
|
109
|
+
end
|
110
|
+
|
111
|
+
def build_theme
|
112
|
+
OpenXml::Pptx::Parts::Theme.new.tap do |theme|
|
113
|
+
add_theme(theme)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def next_image_index
|
118
|
+
@image_index = (@image_index || 0) + 1
|
119
|
+
end
|
120
|
+
|
121
|
+
def to_xml
|
122
|
+
build_standalone_xml do |xml|
|
123
|
+
xml[:p].presentation(namespaces.merge(xml_attributes)) do
|
124
|
+
property_xml(xml)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def namespaces
|
132
|
+
{
|
133
|
+
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
134
|
+
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
135
|
+
"xmlns:p": "http://schemas.openxmlformats.org/presentationml/2006/main"
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literals: true
|
2
|
+
|
3
|
+
module OpenXml
|
4
|
+
module Pptx
|
5
|
+
module Parts
|
6
|
+
class PresentationProperties < OpenXml::Part
|
7
|
+
include OpenXml::RelatablePart
|
8
|
+
include OpenXml::ContainsProperties
|
9
|
+
|
10
|
+
relationship_type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps"
|
11
|
+
content_type "application/vnd.openxmlformats-officedocument.presentationml.presProps+xml"
|
12
|
+
default_path "ppt/presProps.xml"
|
13
|
+
|
14
|
+
# property :print_properties # tag: :prnPr
|
15
|
+
# property :show_properties # tag: :showPr
|
16
|
+
# property :color_mru # tag: :clrMru, DrawingML type, pptx namespace
|
17
|
+
property :extension_list
|
18
|
+
|
19
|
+
def to_xml
|
20
|
+
build_standalone_xml do |xml|
|
21
|
+
xml[:p].presentationPr(namespaces) do
|
22
|
+
property_xml(xml)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def namespaces
|
30
|
+
{
|
31
|
+
"xmlns:p": "http://schemas.openxmlformats.org/presentationml/2006/main"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Pptx
|
3
|
+
module Parts
|
4
|
+
class Slide < OpenXml::Part
|
5
|
+
include OpenXml::RelatablePart
|
6
|
+
include OpenXml::HasAttributes
|
7
|
+
include OpenXml::ContainsProperties
|
8
|
+
attr_reader :images
|
9
|
+
|
10
|
+
relationship_type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide"
|
11
|
+
content_type "application/vnd.openxmlformats-officedocument.presentationml.slide+xml"
|
12
|
+
default_path "ppt/slides/slide.xml"
|
13
|
+
|
14
|
+
attribute :show_master_shapes, displays_as: :showMasterSp, expects: :boolean
|
15
|
+
attribute :show_master_placeholder_animations, displays_as: :showMasterPhAnim, expects: :boolean
|
16
|
+
attribute :show_slide, displays_as: :show, expects: :boolean
|
17
|
+
|
18
|
+
property :common_slide_data, required: true
|
19
|
+
property :color_mapping_override
|
20
|
+
|
21
|
+
# = TODO ================
|
22
|
+
# property :transition
|
23
|
+
# property :timing
|
24
|
+
|
25
|
+
property :extension_list
|
26
|
+
|
27
|
+
LAYOUT_SCHEMA =
|
28
|
+
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout".freeze
|
29
|
+
|
30
|
+
def initialize(*_args)
|
31
|
+
super
|
32
|
+
@images = []
|
33
|
+
end
|
34
|
+
|
35
|
+
# Necessary for HasAttributes
|
36
|
+
def name
|
37
|
+
"slide"
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_image(image_part)
|
41
|
+
images.push(image_part)
|
42
|
+
index = (parent && parent.next_image_index) || images.count
|
43
|
+
add_child_part(image_part, with_index: index)
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_image_part(path)
|
47
|
+
path = Pathname.new(path)
|
48
|
+
OpenXml::Pptx::Parts::Image.new(path.read, extension: path.extname).tap do |image|
|
49
|
+
add_image(image)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_slide_layout(layout)
|
54
|
+
add_relationship layout.relationship_type, layout.path
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_xml
|
58
|
+
build_standalone_xml do |xml|
|
59
|
+
xml[:p].sld(namespaces.merge(xml_attributes)) do
|
60
|
+
property_xml(xml)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Convenience accessors
|
66
|
+
def shapes
|
67
|
+
common_slide_data.shape_tree.shapes
|
68
|
+
end
|
69
|
+
|
70
|
+
def background_properties
|
71
|
+
common_slide_data.background.background_properties
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def namespaces
|
77
|
+
{
|
78
|
+
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
79
|
+
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
80
|
+
"xmlns:p": "http://schemas.openxmlformats.org/presentationml/2006/main"
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literals: true
|
2
|
+
|
3
|
+
module OpenXml
|
4
|
+
module Pptx
|
5
|
+
module Parts
|
6
|
+
class SlideLayout < OpenXml::Part
|
7
|
+
include OpenXml::RelatablePart
|
8
|
+
include OpenXml::HasAttributes
|
9
|
+
include OpenXml::ContainsProperties
|
10
|
+
attr_reader :images
|
11
|
+
|
12
|
+
relationship_type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"
|
13
|
+
content_type "application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"
|
14
|
+
default_path "ppt/slideLayouts/slideLayout.xml"
|
15
|
+
|
16
|
+
attribute :show_master_shapes, displays_as: :showMasterSp, expects: :boolean
|
17
|
+
attribute :show_master_placeholder_animations, displays_as: :showMasterPhAnim, expects: :boolean
|
18
|
+
attribute :matching_name, displays_as: :matchingName, expects: :string
|
19
|
+
attribute :type, one_of: OpenXml::Pptx::ST_SlideLayoutType
|
20
|
+
attribute :preserve, expects: :boolean
|
21
|
+
attribute :drawn_by_user, displays_as: :userDrawn, expects: :boolean
|
22
|
+
|
23
|
+
property :common_slide_data, required: true
|
24
|
+
property :color_mapping_override
|
25
|
+
|
26
|
+
# = TODO ================
|
27
|
+
# property :transition
|
28
|
+
# property :timing
|
29
|
+
# property :header_footer
|
30
|
+
|
31
|
+
property :extension_list
|
32
|
+
|
33
|
+
def initialize(*_args)
|
34
|
+
super
|
35
|
+
@images = []
|
36
|
+
end
|
37
|
+
|
38
|
+
# Necessary for HasAttributes
|
39
|
+
def name
|
40
|
+
"slide_layout"
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_slide_master(master)
|
44
|
+
add_relationship master.relationship_type, master.path
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_image(image_part)
|
48
|
+
images.push(image_part)
|
49
|
+
index = (parent && parent.next_image_index) || images.count
|
50
|
+
add_child_part(image_part, with_index: index)
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_image_part(path)
|
54
|
+
path = Pathname.new(path)
|
55
|
+
OpenXml::Pptx::Parts::Image.new(path.read, extension: path.extname).tap do |image|
|
56
|
+
add_image(image)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_xml
|
61
|
+
build_standalone_xml do |xml|
|
62
|
+
xml[:p].sldLayout(namespaces.merge(xml_attributes)) do
|
63
|
+
property_xml(xml)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Convenience accessors
|
69
|
+
def shapes
|
70
|
+
common_slide_data.shape_tree.shapes
|
71
|
+
end
|
72
|
+
|
73
|
+
def background_properties
|
74
|
+
common_slide_data.background.background_properties
|
75
|
+
end
|
76
|
+
|
77
|
+
private def namespaces
|
78
|
+
{
|
79
|
+
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
80
|
+
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
81
|
+
"xmlns:p": "http://schemas.openxmlformats.org/presentationml/2006/main"
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literals: true
|
2
|
+
|
3
|
+
module OpenXml
|
4
|
+
module Pptx
|
5
|
+
module Parts
|
6
|
+
class SlideMaster < OpenXml::Part
|
7
|
+
include OpenXml::RelatablePart
|
8
|
+
include OpenXml::HasAttributes
|
9
|
+
include OpenXml::ContainsProperties
|
10
|
+
attr_reader :theme, :layouts, :images
|
11
|
+
|
12
|
+
relationship_type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster"
|
13
|
+
content_type "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"
|
14
|
+
default_path "ppt/slideMasters/slideMaster.xml"
|
15
|
+
|
16
|
+
attribute :should_preserve, displays_as: :preserve, expects: :boolean
|
17
|
+
|
18
|
+
property :common_slide_data, required: true
|
19
|
+
property :color_mapping, required: true
|
20
|
+
property :slide_layout_id_list
|
21
|
+
|
22
|
+
# = TODO ================
|
23
|
+
# property :transition
|
24
|
+
# property :timing
|
25
|
+
# property :header_footer
|
26
|
+
|
27
|
+
property :text_styles
|
28
|
+
|
29
|
+
property :extension_list
|
30
|
+
|
31
|
+
def initialize(*_args)
|
32
|
+
super
|
33
|
+
@layouts = []
|
34
|
+
@images = []
|
35
|
+
end
|
36
|
+
|
37
|
+
# Necessary for HasAttributes
|
38
|
+
def name
|
39
|
+
"slide_master"
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_theme(theme)
|
43
|
+
@theme = theme
|
44
|
+
add_relationship theme.relationship_type, theme.path
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_slide_layout(layout)
|
48
|
+
layouts.push(layout)
|
49
|
+
add_child_part(layout, with_index: layouts.count)
|
50
|
+
slide_layout_id_list << OpenXml::Pptx::Properties::SlideLayoutId.new.tap do |layout_id|
|
51
|
+
layout_id.rid = relationships_by_path[layout.path].id
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_slide_layout(named: nil)
|
56
|
+
OpenXml::Pptx::Parts::SlideLayout.new.tap do |layout|
|
57
|
+
layout.set_slide_master(self)
|
58
|
+
layout.common_slide_data.slide_name = named unless named.nil?
|
59
|
+
add_slide_layout(layout)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_image(image_part)
|
64
|
+
images.push(image_part)
|
65
|
+
index = (parent && parent.next_image_index) || images.count
|
66
|
+
add_child_part(image_part, with_index: index)
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_image_part(path)
|
70
|
+
path = Pathname.new(path)
|
71
|
+
OpenXml::Pptx::Parts::Image.new(path.read, extension: path.extname).tap do |image|
|
72
|
+
add_image(image)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def next_image_index
|
77
|
+
@image_index = (parent && parent.next_image_index) || @image_index + 1
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_xml
|
81
|
+
build_standalone_xml do |xml|
|
82
|
+
xml[:p].sldMaster(namespaces.merge(xml_attributes)) do
|
83
|
+
property_xml(xml)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def build_required_properties
|
89
|
+
super
|
90
|
+
DEFAULT_COLOR_MAPPING.each do |key, value|
|
91
|
+
color_mapping.public_send(:"#{key}=", value)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Convenience accessors
|
96
|
+
def shapes
|
97
|
+
common_slide_data.shape_tree.shapes
|
98
|
+
end
|
99
|
+
|
100
|
+
def background_properties
|
101
|
+
common_slide_data.background.background_properties
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def namespaces
|
107
|
+
{
|
108
|
+
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
109
|
+
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
110
|
+
"xmlns:p": "http://schemas.openxmlformats.org/presentationml/2006/main"
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
DEFAULT_COLOR_MAPPING = {
|
115
|
+
bg1: :lt1,
|
116
|
+
tx1: :dk1,
|
117
|
+
bg2: :lt2,
|
118
|
+
tx2: :dk2,
|
119
|
+
accent1: :accent1,
|
120
|
+
accent2: :accent2,
|
121
|
+
accent3: :accent3,
|
122
|
+
accent4: :accent4,
|
123
|
+
accent5: :accent5,
|
124
|
+
accent6: :accent6,
|
125
|
+
hlink: :hlink,
|
126
|
+
folHlink: :folHlink
|
127
|
+
}.freeze
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|