Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/84925


Change subject: First test to replace png->svg
......................................................................

First test to replace png->svg

Cleanup of the temporary files still fails.

Change-Id: Ifcd8786e35adfa3344f2be7ef3cff0d8df48027e
---
M MathTexvc.php
M math/render.ml
2 files changed, 15 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/25/84925/1

diff --git a/MathTexvc.php b/MathTexvc.php
index 4f4bbd2..7b2b838 100644
--- a/MathTexvc.php
+++ b/MathTexvc.php
@@ -70,7 +70,7 @@
        public function getMathImageUrl() {
                global $wgMathPath;
                $dir = $this->getHashSubPath();
-               return "$wgMathPath/$dir/{$this->getHash()}.png";
+               return "$wgMathPath/$dir/{$this->getHash()}.svg";
        }
 
        /**
@@ -173,7 +173,7 @@
                        }
                }
 
-               $tempFsFile = new TempFSFile( "$tmpDir/{$this->getHash()}.png" 
);
+               $tempFsFile = new TempFSFile( "$tmpDir/{$this->getHash()}.svg" 
);
                $tempFsFile->autocollect(); // destroy file when $tempFsFile 
leaves scope
                $tempFsFile = new TempFSFile( "$tmpDir/{$this->getHash()}.tex" 
);
                $tempFsFile->autocollect(); // destroy file when $tempFsFile 
leaves scope
@@ -225,9 +225,9 @@
                        return $errmsg;
                } elseif ( !preg_match( "/^[a-f0-9]{32}$/", $this->getHash() ) 
) {
                        return $this->getError( 'math_unknown_error' );
-               } elseif ( !file_exists( "$tmpDir/{$this->getHash()}.png" ) ) {
+               } elseif ( !file_exists( "$tmpDir/{$this->getHash()}.svg" ) ) {
                        return $this->getError( 'math_image_error' );
-               } elseif ( filesize( "$tmpDir/{$this->getHash()}.png" ) == 0 ) {
+               } elseif ( filesize( "$tmpDir/{$this->getHash()}.svg" ) == 0 ) {
                        return $this->getError( 'math_image_error' );
                }
 
@@ -240,7 +240,7 @@
                }
                // Store the file at the final storage path...
                if ( !$backend->quickStore( array(
-                       'src' => "$tmpDir/{$this->getHash()}.png", 'dst' => 
"$hashpath/{$this->getHash()}.png"
+                       'src' => "$tmpDir/{$this->getHash()}.svg", 'dst' => 
"$hashpath/{$this->getHash()}.svg"
                ) )->isOK()
                ) {
                        return $this->getError( 'math_output_error' );
@@ -335,7 +335,7 @@
                                // Short-circuit the file existence & migration 
checks
                                return true;
                        }
-                       $filename = $this->getHashPath() . 
"/{$this->getHash()}.png"; // final storage path
+                       $filename = $this->getHashPath() . 
"/{$this->getHash()}.svg"; // final storage path
                        $backend = $this->getBackend();
                        if ( $backend->fileExists( array( 'src' => $filename ) 
) ) {
                                if ( $backend->getFileSize( array( 'src' => 
$filename ) ) == 0 ) {
diff --git a/math/render.ml b/math/render.ml
index 67cb389..2f3050a 100644
--- a/math/render.ml
+++ b/math/render.ml
@@ -1,7 +1,7 @@
 (* vim: set sw=8 ts=8 et: *)
 
-let cmd_dvips tmpprefix = "dvips -q -R -E " ^ tmpprefix ^ ".dvi -f >" ^ 
tmpprefix ^ ".ps"
-let cmd_latex tmpprefix = "latex " ^ tmpprefix ^ ".tex >/dev/null"
+let cmd_dvips tmpprefix = "pdf2svg" ^ tmpprefix ^ ".pdf " ^ tmpprefix ^ ".svg"
+let cmd_latex tmpprefix = "pdflatex " ^ tmpprefix ^ ".tex >/dev/null && 
pdfcrop " ^ tmpprefix ^ ".pdf " ^ tmpprefix ^ ".pdf >/dev/null"
 
 (* Putting -transparent white in converts arguments will sort-of give you 
transperancy *)
 let cmd_convert tmpprefix finalpath = "convert -quality 100 -density 120 " ^ 
tmpprefix ^ ".ps " ^ finalpath ^ " >/dev/null 2>/dev/null"
@@ -9,7 +9,7 @@
 (* Putting -bg Transparent in dvipng's arguments will give full-alpha 
transparency *)
 (* Note that IE have problems with such PNGs and need an additional javascript 
snippet *)
 (* Putting -bg transparent in dvipng's arguments will give binary transparency 
*)
-let cmd_dvipng tmpprefix finalpath backcolor = "dvipng -bg \'" ^ backcolor ^ 
"\' -gamma 1.5 -D 120 -T tight --strict " ^ tmpprefix ^ ".dvi -o " ^ finalpath 
^ " >/dev/null 2>/dev/null"
+let cmd_pdf2svg tmpprefix finalpath backcolor = "pdf2svg " ^ tmpprefix ^ ".pdf 
" ^ finalpath ^ " >/dev/null 2>/dev/null"
 
 exception ExternalCommandFailure of string
 
@@ -19,7 +19,7 @@
     let unlink_all () =
       begin
         (* Commenting this block out will aid in debugging *)
-        Sys.remove (tmpprefix ^ ".dvi");
+        Sys.remove (tmpprefix ^ ".pdf");
         Sys.remove (tmpprefix ^ ".aux");
         Sys.remove (tmpprefix ^ ".log");
         Sys.rename (tmpprefix ^ ".tex") (tmppath^"/"^md5^".tex");
@@ -39,14 +39,14 @@
         if Util.run_in_other_directory tmppath (cmd_latex tmpprefix0) != 0
           then (
             unlink_all (); raise (ExternalCommandFailure "latex")
-        ) else if (Sys.command (cmd_dvipng tmpprefix 
(finalpath^"/"^md5^".png") backcolor) != 0)
+        ) else if (Sys.command (cmd_pdf2svg tmpprefix 
(finalpath^"/"^md5^".svg") backcolor) != 0)
           then (
             if (Sys.command (cmd_dvips tmpprefix) != 0)
               then (
                 unlink_all ();
                 raise (ExternalCommandFailure "dvips")
-            ) else if (Sys.command (cmd_convert tmpprefix 
(finalpath^"/"^md5^".png")) != 0)
-              then ( 
+            ) else if (Sys.command (cmd_convert tmpprefix 
(finalpath^"/"^md5^".svg")) != 0)
+              then (
                 unlink_all ();
                 raise (ExternalCommandFailure "convert")
             ) else (
@@ -54,5 +54,6 @@
             )
         ) else (
             unlink_all ()
-        )
+        );
+      unlink_all ()
       end

-- 
To view, visit https://gerrit.wikimedia.org/r/84925
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifcd8786e35adfa3344f2be7ef3cff0d8df48027e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: dev
Gerrit-Owner: Physikerwelt <w...@physikerwelt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to