File Coverage

blib/lib/XUL/Image/PPT.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package XUL::Image::PPT;
2              
3 1     1   21625 use 5.006001;
  1         3  
  1         29  
4 1     1   397 use Moose;
  0            
  0            
5              
6             use File::Spec;
7             use Win32::OLE;
8             use Win32::OLE::Const;
9              
10             has 'from' => (is => 'rw', isa => 'Int', default => 1);
11             has 'indir' => (is => 'rw', isa => 'Str', default => 'xul_img');
12              
13             sub go {
14             my $self = shift;
15             my $app = Win32::OLE->GetActiveObject("PowerPoint.Application");
16             my $show;
17             if (!$app) {
18             $app = Win32::OLE->new('PowerPoint.Application')
19             or die Win32::OLE->LastError;
20             $app->{Visible} = 1;
21             $show = $app->Presentations->Add;
22             } else {
23             $app->{Visible} = 1;
24             $show = $app->ActivePresentation;
25             }
26             if (!$show) {
27             $show = $app->Presentations->Add;
28             }
29             if (!$show) { die "Can't create a new presentation"; }
30            
31             my $const = Win32::OLE::Const->Load($app);
32             my $slides = $show->Slides();
33              
34             my $listing = File::Spec->catfile($self->indir, 'listing.txt');
35             open my $in, $listing
36             or die "Cannot open $listing for reading: $!\n";
37             my $i = $self->from;
38             my $slide_w = $show->PageSetup->SlideWidth;
39             my $slide_h = $show->PageSetup->SlideHeight;
40             while (<$in>) {
41             chomp;
42             next if /^\s*$/;
43             my $fbase = $_;
44             my $fname = File::Spec->catfile($self->indir, $fbase);
45             my $slide = $slides->Add($i++, $const->{ppLayoutBlank});
46             warn "inserting $fname...\n";
47             my $msoFalse = 0;
48             my $msoTrue = -1;
49             my $pic = $slide->Shapes->AddPicture(
50             File::Spec->rel2abs($fname), # FileName
51             $msoFalse, # LinkToFile
52             $msoTrue, # SaveWithDocument
53             0, 0, # Left and Top
54             ) or die "error: Failed to insert picture $fname.\n";
55             $pic->{Left} = ($slide_w - $pic->Width) / 2;
56             $pic->{Top} = ($slide_h - $pic->Height) / 3;
57              
58             #$pic->Scaleheight(1, $msoTrue);
59             #$pic->Scalewidth (1, $msoTrue);
60             }
61             }
62              
63             1;
64             __END__
65              
66              
67             =head1 NAME
68              
69             XUL::Image::PPT - insert images into a ppt
70              
71             =head1 SYNOPSIS
72              
73             use XUL::Image::PPT;
74              
75             $obj = XUL::Image::PPT->new();
76              
77             $obj->go;
78              
79             This module provides interface to get ppt by inseting it images
80              
81             =head1 METHODS
82              
83             =head2 new(%option)
84              
85             =over
86              
87             =item * from => $from
88              
89             This option gives the index from which the rest images will be inserted into a ppt and 1 is default
90              
91             =item * indir => $indir
92              
93             This option gives the directory, under which images are saved and 'xul_img' is default
94              
95             =back
96              
97             =head2 go()
98              
99             invoke this method to start inserting images to get a ppt
100              
101             =SEE ALSO
102              
103             L<XUL::Image>
104              
105             =head1 AUTHOR
106              
107             Sal Zhong E<lt>zhongxiang721@gmail.comE<gt>
108              
109             =head1 COPYRIGHT
110              
111             Copyright (c) 2006~2007 Sal Zhong. All rights reserved.
112              
113             This library is free software; you can redistribute it
114             and/or modify it under the same terms as perl itself.
115