Class: PPTX::Slide

Inherits:
OPC::Part show all
Defined in:
lib/pptx/slide.rb

Instance Method Summary collapse

Methods inherited from OPC::Part

#relationship_part_name, #relationships, #relative_part_name

Methods inherited from OPC::BasePart

#doc, #marshal, #part_name, #template

Constructor Details

#initialize(package) ⇒ Slide

Returns a new instance of Slide.



5
6
7
8
9
# File 'lib/pptx/slide.rb', line 5

def initialize(package)
  part_name = package.next_part_with_prefix('ppt/slides/slide', '.xml')
  super(package, part_name)
  relationships.add('../slideLayouts/slideLayout7.xml', RELTYPE_SLIDE_LAYOUT)
end

Instance Method Details

#add_filled_rectangle(transform, color) ⇒ Object

Add rectangle filled with given color. Give color in RGB hex format (e.g. ‘558ed5’)



39
40
41
42
# File 'lib/pptx/slide.rb', line 39

def add_filled_rectangle(transform, color)
  shape = Shapes::FilledRectangle.new(transform, color)
  shape_tree_xml.add_child(shape.build_node)
end

#add_picture(transform, name, image) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/pptx/slide.rb', line 44

def add_picture(transform, name, image)
  # TODO do something with name or remove
  rid = relationships.add(relative_part_name(image.part_name), PPTX::RELTYPE_IMAGE)

  shape = Shapes::Picture.new(transform, rid)
  shape_tree_xml.add_child(shape.build_node)
end

#add_slide_number(transform, number, formatting = {}) ⇒ Object

Add a slide number that is recognized by Powerpoint as such and automatically updated See textbox for formatting.



70
71
72
73
# File 'lib/pptx/slide.rb', line 70

def add_slide_number(transform, number, formatting={})
  shape = Shapes::SlideNumber.new(transform, number, formatting)
  shape_tree_xml.add_child(shape.build_node)
end

#add_textbox(transform, content, formatting = {}) ⇒ Object

Add a text box at the given position with the given dimensions

Pass distance values in EMUs (use PPTX::CM) Formatting values a are mostly raw OOXML Text Run Properties (rPr) element attributes. Examples:

  • sz: font size (use PPTX::POINT)

  • b: 1 for bold

  • i: 1 for italic

There are two custom properties:

  • color: aabbcc (hex RGB color)

  • align: ctr|dist|just|justLow|l|r|thaiDist (ST_TextAlignType (Text Alignment Types))



63
64
65
66
# File 'lib/pptx/slide.rb', line 63

def add_textbox(transform, content, formatting={})
  shape = Shapes::Textbox.new(transform, content, formatting)
  shape_tree_xml.add_child(shape.build_node)
end

#base_xmlObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pptx/slide.rb', line 11

def base_xml
  '''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
           xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"
           xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
        <p:cSld>
            <p:spTree>
                <p:nvGrpSpPr>
                    <p:cNvPr id="1" name=""/>
                    <p:cNvGrpSpPr/>
                    <p:nvPr/>
                </p:nvGrpSpPr>
                <p:grpSpPr/>
            </p:spTree>
        </p:cSld>
        <p:clrMapOvr>
            <a:masterClrMapping/>
        </p:clrMapOvr>
    </p:sld>
    '''
end

#content_typeObject



33
34
35
# File 'lib/pptx/slide.rb', line 33

def content_type
  'application/vnd.openxmlformats-officedocument.presentationml.slide+xml'
end

#shape_tree_xmlObject



75
76
77
# File 'lib/pptx/slide.rb', line 75

def shape_tree_xml
  @shape_tree_xml ||= doc.xpath('/p:sld/p:cSld/p:spTree').first
end