X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FDjVuImage.php;h=80b7408cbeb4dda840db2da76b2a2e516e70d523;hb=2745ecc1e49ca00f991839ce0a023a788e2fe3f9;hp=8e7caf63d064f1740702047fa13bc2633f77a6fe;hpb=087a9f70c5c152b72dc6c539cf64e334a0f2d029;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/DjVuImage.php b/includes/DjVuImage.php index 8e7caf63d0..80b7408cbe 100644 --- a/includes/DjVuImage.php +++ b/includes/DjVuImage.php @@ -1,8 +1,8 @@ + * Copyright © 2006 Brion Vibber * http://www.mediawiki.org/ * * This program is free software; you can redistribute it and/or modify @@ -20,6 +20,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * + * @file */ /** @@ -71,7 +72,7 @@ class DjVuImage { function dump() { $file = fopen( $this->mFilename, 'rb' ); $header = fread( $file, 12 ); - // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. + // @todo FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. extract( unpack( 'a4magic/a4chunk/NchunkLength', $header ) ); echo "$chunk $chunkLength\n"; $this->dumpForm( $file, $chunkLength, 1 ); @@ -87,7 +88,7 @@ class DjVuImage { if( $chunkHeader == '' ) { break; } - // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. + // @todo FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. extract( unpack( 'a4chunk/NchunkLength', $chunkHeader ) ); echo str_repeat( ' ', $indent * 4 ) . "$chunk $chunkLength\n"; @@ -118,7 +119,7 @@ class DjVuImage { if( strlen( $header ) < 16 ) { wfDebug( __METHOD__ . ": too short file header\n" ); } else { - // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. + // @todo FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. extract( unpack( 'a4magic/a4form/NformLength/a4subtype', $header ) ); if( $magic != 'AT&T' ) { @@ -142,7 +143,7 @@ class DjVuImage { if( strlen( $header ) < 8 ) { return array( false, 0 ); } else { - // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. + // @todo FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. extract( unpack( 'a4chunk/Nlength', $header ) ); return array( $chunk, $length ); } @@ -201,7 +202,7 @@ class DjVuImage { return false; } - // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. + // @todo FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. extract( unpack( 'nwidth/' . 'nheight/' . @@ -224,7 +225,9 @@ class DjVuImage { * @return string */ function retrieveMetaData() { - global $wgDjvuToXML, $wgDjvuDump; + global $wgDjvuToXML, $wgDjvuDump, $wgDjvuTxt; + wfProfileIn( __METHOD__ ); + if ( isset( $wgDjvuDump ) ) { # djvudump is faster as of version 3.5 # http://sourceforge.net/tracker/index.php?func=detail&aid=1704049&group_id=32953&atid=406583 @@ -242,9 +245,43 @@ class DjVuImage { } else { $xml = null; } + # Text layer + if ( isset( $wgDjvuTxt ) ) { + wfProfileIn( 'djvutxt' ); + $cmd = wfEscapeShellArg( $wgDjvuTxt ) . ' --detail=page ' . wfEscapeShellArg( $this->mFilename ) ; + wfDebug( __METHOD__.": $cmd\n" ); + $retval = ''; + $txt = wfShellExec( $cmd, $retval ); + wfProfileOut( 'djvutxt' ); + if( $retval == 0) { + # Strip some control characters + $txt = preg_replace( "/[\013\035\037]/", "", $txt ); + $reg = << # Text to match is composed of atoms of either: + \\\\. # - any escaped character + | # - any character different from " and \ + [^"\\\\]+ + )*?) + "\s*\) + | # Or page can be empty ; in this case, djvutxt dumps () + \(\s*()\)/sx +EOR; + $txt = preg_replace_callback( $reg, array( $this, 'pageTextCallback' ), $txt ); + $txt = "\n\n\n" . $txt . "\n\n"; + $xml = preg_replace( "//", "", $xml, 1 ); + $xml = $xml . $txt. '' ; + } + } + wfProfileOut( __METHOD__ ); return $xml; } + function pageTextCallback( $matches ) { + # Get rid of invalid UTF-8, strip control characters + return ''; + } + /** * Hack to temporarily work around djvutoxml bug */