| 1 | package XUL::Image::PPT; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.006001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use File::Spec; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 0 | ▶ | use Win32::OLE; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 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__ | ||