[2981] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[15872] | 3 | # PPTPlugin.pm -- plugin for importing Microsoft PowerPoint files.
|
---|
[2981] | 4 | # (currently only versions 95 and 97)
|
---|
| 5 | #
|
---|
| 6 | # A component of the Greenstone digital library software
|
---|
| 7 | # from the New Zealand Digital Library Project at the
|
---|
| 8 | # University of Waikato, New Zealand.
|
---|
| 9 | #
|
---|
| 10 | # Copyright (C) 2002 New Zealand Digital Library Project
|
---|
| 11 | #
|
---|
| 12 | # This program is free software; you can redistribute it and/or modify
|
---|
| 13 | # it under the terms of the GNU General Public License as published by
|
---|
| 14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | # (at your option) any later version.
|
---|
| 16 | #
|
---|
| 17 | # This program is distributed in the hope that it will be useful,
|
---|
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | # GNU General Public License for more details.
|
---|
| 21 | #
|
---|
| 22 | # You should have received a copy of the GNU General Public License
|
---|
| 23 | # along with this program; if not, write to the Free Software
|
---|
| 24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | #
|
---|
| 26 | ###########################################################################
|
---|
| 27 |
|
---|
[15872] | 28 | package PPTPlugin;
|
---|
[2981] | 29 |
|
---|
[15872] | 30 | use ConvertBinaryFile;
|
---|
| 31 | use ReadTextFile; # for read_file in convert_post_process. do we need it?
|
---|
| 32 |
|
---|
[10254] | 33 | use strict;
|
---|
| 34 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
[2981] | 35 |
|
---|
| 36 | sub BEGIN {
|
---|
[15872] | 37 | @PPTPlugin::ISA = ('ConvertBinaryFile', 'ReadTextFile');
|
---|
[2981] | 38 | }
|
---|
| 39 |
|
---|
[10466] | 40 | my $convert_to_list =
|
---|
| 41 | [ { 'name' => "auto",
|
---|
[15872] | 42 | 'desc' => "{ConvertBinaryFile.convert_to.auto}" },
|
---|
[10466] | 43 | { 'name' => "html",
|
---|
[15872] | 44 | 'desc' => "{ConvertBinaryFile.convert_to.html}" },
|
---|
[10466] | 45 | { 'name' => "text",
|
---|
[15872] | 46 | 'desc' => "{ConvertBinaryFile.convert_to.text}" },
|
---|
[10466] | 47 | { 'name' => "pagedimg_jpg",
|
---|
[15872] | 48 | 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_jpg}" },
|
---|
[10466] | 49 | { 'name' => "pagedimg_gif",
|
---|
[15872] | 50 | 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_gif}" },
|
---|
[10466] | 51 | { 'name' => "pagedimg_png",
|
---|
[15872] | 52 | 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_png}" }
|
---|
[10466] | 53 | ];
|
---|
| 54 |
|
---|
[6408] | 55 | my $arguments =
|
---|
| 56 | [ { 'name' => "process_exp",
|
---|
[15872] | 57 | 'desc' => "{BasePlugin.process_exp}",
|
---|
[6408] | 58 | 'type' => "regexp",
|
---|
| 59 | 'reqd' => "no",
|
---|
[10275] | 60 | 'deft' => &get_default_process_exp()}
|
---|
[6408] | 61 | ];
|
---|
| 62 |
|
---|
[15872] | 63 | my $options = { 'name' => "PPTPlugin",
|
---|
| 64 | 'desc' => "{PPTPlugin.desc}",
|
---|
[6408] | 65 | 'abstract' => "no",
|
---|
[11679] | 66 | 'inherits' => "yes",
|
---|
[15114] | 67 | 'srcreplaceable' => "yes", # Source docs in PPT format can be replaced with GS-generated html
|
---|
[6408] | 68 | 'args' => $arguments };
|
---|
[4744] | 69 |
|
---|
[2981] | 70 | sub new {
|
---|
[10218] | 71 | my ($class) = shift (@_);
|
---|
| 72 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 73 | push(@$pluginlist, $class);
|
---|
[2981] | 74 |
|
---|
[10275] | 75 | if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
|
---|
[10466] | 76 | my $ws_arg =[{ 'name' => "convert_to",
|
---|
[15872] | 77 | 'desc' => "{ConvertBinaryFile.convert_to}",
|
---|
[10466] | 78 | 'type' => "enum",
|
---|
| 79 | 'reqd' => "yes",
|
---|
| 80 | 'list' => $convert_to_list,
|
---|
| 81 | 'deft' => "html" },
|
---|
| 82 | { 'name' => "windows_scripting",
|
---|
[15872] | 83 | 'desc' => "{PPTPlugin.windows_scripting}",
|
---|
[10275] | 84 | 'type' => "flag",
|
---|
[10466] | 85 | 'reqd' => "no" }
|
---|
| 86 | ];
|
---|
| 87 | push(@$arguments,@$ws_arg);
|
---|
[10275] | 88 | }
|
---|
| 89 |
|
---|
[15872] | 90 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 91 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[10218] | 92 |
|
---|
[10427] | 93 |
|
---|
[15872] | 94 | my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[10275] | 95 |
|
---|
[10580] | 96 | if ($self->{'info_only'}) {
|
---|
| 97 | # don't worry about any options etc
|
---|
| 98 | return bless $self, $class;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[15872] | 101 | $self->{'filename_extension'} = "ppt";
|
---|
| 102 | $self->{'file_type'} = "PPT";
|
---|
| 103 |
|
---|
[10275] | 104 | # ppthtml outputs utf-8 already.
|
---|
[15872] | 105 | #these are passed through to gsConvert.pl by ConvertBinaryFile.pm
|
---|
[10491] | 106 | $self->{'convert_options'} = "-windows_scripting" if $self->{'windows_scripting'};
|
---|
[10275] | 107 | my $secondary_plugin_options = $self->{'secondary_plugin_options'};
|
---|
[10218] | 108 |
|
---|
[10275] | 109 | if ($self->{'windows_scripting'} && ($self->{'convert_to'} eq "PagedImg")) {
|
---|
[15872] | 110 | $secondary_plugin_options->{'PagedImagePlugin'} = [];
|
---|
[10275] | 111 | } else {
|
---|
[15872] | 112 | $secondary_plugin_options->{'HTMLPlugin'} = [];
|
---|
[10275] | 113 | }
|
---|
[15872] | 114 | my $html_options = $secondary_plugin_options->{'HTMLPlugin'};
|
---|
| 115 | my $pageimg_options = $secondary_plugin_options->{'PagedImagePlugin'};
|
---|
[10275] | 116 |
|
---|
[16021] | 117 | # if ($self->{'input_encoding'} eq "auto") {
|
---|
| 118 | # $self->{'input_encoding'} = "utf8";
|
---|
| 119 | # }
|
---|
| 120 |
|
---|
[15903] | 121 | if (defined $secondary_plugin_options->{'HTMLPlugin'}){
|
---|
| 122 | push(@$html_options,"-input_encoding", "utf8");
|
---|
| 123 | push(@$html_options,"-extract_language") if $self->{'extract_language'};
|
---|
| 124 |
|
---|
| 125 | # Instruct HTMLPlugin (when eventually accessed through read_into_doc_obj)
|
---|
| 126 | # to extract these metadata fields from the HEAD META fields
|
---|
| 127 | push(@$html_options,"-metadata_fields","Title,GENERATOR,date,author<Creator>");
|
---|
| 128 | }
|
---|
| 129 | if (defined $secondary_plugin_options->{'PagedImagePlugin'}){
|
---|
| 130 | push(@$pageimg_options,"-input_encoding", "utf8");
|
---|
| 131 | push(@$pageimg_options,"-extract_language") if $self->{'extract_language'};
|
---|
| 132 | }
|
---|
[2981] | 133 |
|
---|
[10275] | 134 | $self = bless $self, $class;
|
---|
| 135 |
|
---|
[10427] | 136 | $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
|
---|
[10275] | 137 | return $self;
|
---|
[2981] | 138 | }
|
---|
| 139 |
|
---|
| 140 | sub get_default_process_exp {
|
---|
| 141 | my $self = shift (@_);
|
---|
| 142 | return q^(?i)\.ppt$^;
|
---|
| 143 | }
|
---|
[10275] | 144 |
|
---|
[15872] | 145 | # do we need this? above states that ppthtml produces utf8 text...
|
---|
[10275] | 146 | sub convert_post_process
|
---|
| 147 | {
|
---|
| 148 | my $self = shift (@_);
|
---|
| 149 | my ($conv_filename) = @_;
|
---|
[2981] | 150 |
|
---|
[10275] | 151 | my $outhandle=$self->{'outhandle'};
|
---|
| 152 | my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
|
---|
| 153 | # read in file ($text will be in utf8)
|
---|
| 154 | my $text = "";
|
---|
| 155 | $self->read_file ($conv_filename, $encoding, $language, \$text);
|
---|
| 156 |
|
---|
| 157 | # turn any high bytes that aren't valid utf-8 into utf-8.
|
---|
| 158 | unicode::ensure_utf8(\$text);
|
---|
| 159 | # Write it out again!
|
---|
| 160 | $self->utf8_write_file (\$text, $conv_filename);
|
---|
[2981] | 161 | }
|
---|
| 162 |
|
---|
[10275] | 163 |
|
---|
[2981] | 164 | 1;
|
---|
[10275] | 165 |
|
---|