Changeset 15914
- Timestamp:
- 2008-06-09T13:26:33+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/plugins/PagedImagePlugin.pm
r15911 r15914 229 229 } 230 230 231 sub rotate_image { 232 my $self = shift (@_); 233 my ($filename_full_path) = @_; 234 235 my ($this_filetype) = $filename_full_path =~ /\.([^\.]*)$/; 236 my $result = $self->convert($filename_full_path, $this_filetype, "-rotate 180", "ROTATE"); 237 my ($new_filename) = ($result =~ /=>(.*\.$this_filetype)/); 238 if (-e "$new_filename") { 239 return $new_filename; 240 } 241 # somethings gone wrong 242 return $filename_full_path; 243 244 } 245 246 sub process_image { 247 my $self = shift(@_); 248 my ($filename_full_path, $filename_no_path, $doc_obj, $section, $rotate) = @_; 249 # do rotation 250 if ($rotate eq "r") { 251 # check the filenames 252 return 0 if ($filename_no_path eq "" || !-f $filename_full_path); 253 254 # we get a new temporary file which is rotated 255 $filename_full_path = $self->rotate_image($filename_full_path); 256 } 257 258 # do generate images 259 my $result = $self->generate_images($filename_full_path, $filename_no_path, $doc_obj, $section); 260 #overwrite one set in ImageConverter 261 $doc_obj->set_metadata_element ($section, "FileFormat", "PagedImage"); 262 return $result; 263 } 264 265 sub old_read_stuff_for_xml_version { 266 my ($self, $filename, $file, $gli); 267 268 # this bit same as ReadXMLFile read 269 # $file =~ s/^[\/\\]+//; # $file often begins with / so we'll tidy it up 270 # $self->{'file'} = $file; 271 # $self->{'filename'} = $filename_full_path; 272 # $self->{'processor'} = $processor; 273 # $self->{'metadata'} = $metadata; 274 # 275 eval { 276 $@ = ""; 277 my $xslt = $self->{'xslt'}; 278 if (defined $xslt && ($xslt ne "")) { 279 # perform xslt 280 my $transformed_xml = $self->apply_xslt($xslt,$filename); 281 282 # feed transformed file (now in memory as string) into XML parser 283 $self->{'parser'}->parse($transformed_xml); 284 ###$self->parse_string($transformed_xml); 285 } 286 else { 287 $self->{'parser'}->parsefile($filename); 288 #$self->parse_file($filename); 289 } 290 }; 291 292 293 294 if ($@) { 295 296 # parsefile may either croak somewhere in XML::Parser (e.g. because 297 # the document is not well formed) or die somewhere in XMLPlug or a 298 # derived plugin (e.g. because we're attempting to process a 299 # document whose DOCTYPE is not meant for this plugin). For the 300 # first case we'll print a warning and continue, for the second 301 # we'll just continue quietly 302 303 print STDERR "**** XML Parse Error is: $@\n"; 304 305 my ($msg) = $@ =~ /Carp::croak\(\'(.*?)\'\)/; 306 if (defined $msg) { 307 my $outhandle = $self->{'outhandle'}; 308 my $plugin_name = ref ($self); 309 print $outhandle "$plugin_name failed to process $file ($msg)\n"; 310 } 311 312 # reset ourself for the next document 313 $self->{'section_level'}=0; 314 print STDERR "<ProcessingError n='$file'>\n" if ($gli); 315 return -1; # error during processing 316 } 317 318 } 319 320 321 # The PagedImagePlugin read() function. This function does all the right things 322 # to make general options work for a given plugin. It calls the process() 323 # function which does all the work specific to a plugin (like the old 324 # read functions used to do). Most plugins should define their own 325 # process() function and let this read() function keep control. 326 # 327 # PagedImagePlugin overrides read() because there is no need to read the actual 328 # text of the file in, because the contents of the file is not text... 329 # 330 # Return number of files processed, undef if can't process 331 # Note that $base_dir might be "" and that $file might 332 # include directories 231 # we want to use BasePlugin's read, not ReadXMLFile's 232 sub read 233 { 234 my $self = shift (@_); 235 $self->BasePlugin::read(@_); 236 } 237 333 238 334 239 sub read_into_doc_obj { … … 429 334 430 335 } 431 # de we need this? old read was the same as BasePlug read, not the same as ReadXMLfile read 432 sub read 433 { 434 my $self = shift (@_); 435 $self->BasePlugin::read(@_); 436 } 336 337 sub rotate_image { 338 my $self = shift (@_); 339 my ($filename_full_path) = @_; 340 341 my ($this_filetype) = $filename_full_path =~ /\.([^\.]*)$/; 342 my $result = $self->convert($filename_full_path, $this_filetype, "-rotate 180", "ROTATE"); 343 my ($new_filename) = ($result =~ /=>(.*\.$this_filetype)/); 344 if (-e "$new_filename") { 345 return $new_filename; 346 } 347 # somethings gone wrong 348 return $filename_full_path; 349 350 } 351 352 sub process_image { 353 my $self = shift(@_); 354 my ($filename_full_path, $filename_no_path, $doc_obj, $section, $rotate) = @_; 355 # do rotation 356 if ($rotate eq "r") { 357 # check the filenames 358 return 0 if ($filename_no_path eq "" || !-f $filename_full_path); 359 360 # we get a new temporary file which is rotated 361 $filename_full_path = $self->rotate_image($filename_full_path); 362 } 363 364 # do generate images 365 my $result = $self->generate_images($filename_full_path, $filename_no_path, $doc_obj, $section); 366 #overwrite one set in ImageConverter 367 $doc_obj->set_metadata_element ($section, "FileFormat", "PagedImage"); 368 return $result; 369 } 370 437 371 438 372 sub xml_start_tag { … … 661 595 } 662 596 663 # do plugin specific processing of doc_obj664 sub process_old {665 my $self = shift (@_);666 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;667 my $outhandle = $self->{'outhandle'};668 669 return 1;670 }671 597 672 598 sub clean_up_after_doc_obj_processing {
Note:
See TracChangeset
for help on using the changeset viewer.