Class: PPTX::Shapes::Shape
- Inherits:
-
Object
- Object
- PPTX::Shapes::Shape
show all
- Defined in:
- lib/pptx/shapes/shape.rb
Instance Method Summary
collapse
Constructor Details
#initialize(transform) ⇒ Shape
4
5
6
|
# File 'lib/pptx/shapes/shape.rb', line 4
def initialize(transform)
@transform = transform
end
|
Instance Method Details
#base_node ⇒ Object
8
9
10
11
12
|
# File 'lib/pptx/shapes/shape.rb', line 8
def base_node
@base_node ||= Nokogiri::XML::DocumentFragment.parse(base_xml).tap do |node|
set_shape_properties(node, *@transform)
end
end
|
#build_solid_fill(rgb_color) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/pptx/shapes/shape.rb', line 33
def build_solid_fill(rgb_color)
fill_xml = """
<a:solidFill xmlns:a='http://schemas.openxmlformats.org/drawingml/2006/main'>
<a:srgbClr val='SETME'/>
</a:solidFill>
"""
Nokogiri::XML::DocumentFragment.parse(fill_xml).tap do |node|
node.xpath('.//a:srgbClr', a: DRAWING_NS).first['val'] = rgb_color
end
end
|
#set_shape_properties(node, x, y, width, height) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/pptx/shapes/shape.rb', line 14
def set_shape_properties(node, x, y, width, height)
xml = """
<p:spPr xmlns:a='http://schemas.openxmlformats.org/drawingml/2006/main'
xmlns:p='http://schemas.openxmlformats.org/presentationml/2006/main'>
<a:xfrm>
<a:off x='#{x.to_i}' y='#{y.to_i}'/>
<a:ext cx='#{width.to_i}' cy='#{height.to_i}'/>
</a:xfrm>
<a:prstGeom prst='rect'>
<a:avLst/>
</a:prstGeom>
</p:spPr>
"""
node.xpath('.//p:spPr', p: Presentation::NS)
.first
.replace(Nokogiri::XML::DocumentFragment.parse(xml))
end
|