Adamw has submitted this change and it was merged.

Change subject: Specify width and height of SVG images to ensure they are 
rasterized properly
......................................................................


Specify width and height of SVG images to ensure they are rasterized properly

Change-Id: Iaa9da5de5928f4f3e440e4d87be6ef27e6a5f1cc
---
M EasyTimeline.pl
M Timeline.php
2 files changed, 33 insertions(+), 20 deletions(-)

Approvals:
  Adamw: Verified; Looks good to me, approved
  Matmarex: Looks good to me, but someone else must approve



diff --git a/EasyTimeline.pl b/EasyTimeline.pl
index 4a970c7..a4dcb00 100644
--- a/EasyTimeline.pl
+++ b/EasyTimeline.pl
@@ -4055,34 +4055,47 @@
     if (-e $file_vector) {
         open my $file_vector_handle, '<', $file_vector
             or Abort("Can't open $file_vector for reading: $OS_ERROR");
-        my @svg = <$file_vector_handle>;
+        my $svg = join("", <$file_vector_handle>);
         close $file_vector_handle
             or Abort("Can't open $file_vector after reading: $OS_ERROR");
 
-        foreach (@svg) {
-            s/\{\{(\d+)\}\}x+/$textsSVG[$1]/gxe;
+        # Ploticus only specifies the viewBox of a SVG image,
+        # we need with and height as well to ensure it scales properly.
+        # Check if the attributes are present already, just in case,
+        # so we don't produce invalid XML if this ever changes.
+        if ( $svg !~ /<svg[^>]+?(width|height)/ ) {
+            $svg =~ /<svg[^>]+?viewBox="0 0 ([\d.]+) ([\d.]+)"/;
 
-            if ($SVG_ONLY) {
-                s{
-                    (
-                        <text
-                        .*?
-                    )
-                    >
-                    \[(\d+)\[
-                    (.*?)
-                    \]\d+\]
-                }
-                {$1 style="fill:blue;">$3}gx;
+            # This unfortunate transformation is necessary to compensate for
+            # the differing default resolutions of Ploticus svg and png images.
+            # Without this adjustment, the htmlmap will not align with the png.
+            my $width = $1 * 100 / 72;
+            my $height = $2 * 100 / 72;
+            $svg =~ s/<svg[^>]+/$& width="$width" height="$height"/;
+        }
+
+        $svg =~ s/\{\{(\d+)\}\}x+/$textsSVG[$1]/gxe;
+
+        if ($SVG_ONLY) {
+            $svg =~ s{
+                (
+                    <text
+                    .*?
+                )
+                >
+                \[(\d+)\[
+                (.*?)
+                \]\d+\]
             }
-            else {
-                s/\[(\d+)\[ (.*?) \]\d+\]/'<a style="fill:blue;" xlink:href="' 
. $linksSVG[$1] . '">' . $2 . '<\/a>'/gxe;
-            }
+            {$1 style="fill:blue;">$3}gx;
+        }
+        else {
+            $svg =~ s/\[(\d+)\[ (.*?) \]\d+\]/'<a style="fill:blue;" 
xlink:href="' . $linksSVG[$1] . '">' . $2 . '<\/a>'/gxe;
         }
 
         open $file_vector_handle, '>', $file_vector
             or Abort("Can't open $file_vector for writing: $OS_ERROR");
-        print {$file_vector_handle} @svg;
+        print {$file_vector_handle} $svg;
         close $file_vector_handle
             or Abort("Can't open $file_vector after writing: $OS_ERROR");
     }
diff --git a/Timeline.php b/Timeline.php
index 7c82562..1cab1ff 100644
--- a/Timeline.php
+++ b/Timeline.php
@@ -145,7 +145,7 @@
                                }
                                while ( !feof( $svgHandle ) ) {
                                        $line = fgets( $svgHandle );
-                                       if ( preg_match( '/viewBox="0 0 
([0-9.]+) ([0-9.]+)"/', $line, $matches ) ) {
+                                       if ( preg_match( '/width="([0-9.]+)" 
height="([0-9.]+)"/', $line, $matches ) ) {
                                                $svgWidth = $matches[1];
                                                $svgHeight = $matches[2];
                                                break;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iaa9da5de5928f4f3e440e4d87be6ef27e6a5f1cc
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/timeline
Gerrit-Branch: master
Gerrit-Owner: Matmarex <[email protected]>
Gerrit-Reviewer: Adamw <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Matmarex <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to