You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by ha...@apache.org on 2021/10/13 18:55:52 UTC

[incubator-hop] branch master updated: HOP-3381 : Improve support for SVGs without width or height

This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hop.git


The following commit(s) were added to refs/heads/master by this push:
     new a2c6eca  HOP-3381 : Improve support for SVGs without width or height
     new 35f78ea  Merge pull request #1135 from mattcasters/master
a2c6eca is described below

commit a2c6ecad5395fbbe24924de8ed4d39aa99e384d9
Author: Matt Casters <ma...@gmail.com>
AuthorDate: Wed Oct 13 17:31:08 2021 +0200

    HOP-3381 : Improve support for SVGs without width or height
---
 .../main/java/org/apache/hop/core/svg/SvgCache.java   | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/hop/core/svg/SvgCache.java b/core/src/main/java/org/apache/hop/core/svg/SvgCache.java
index 2fda52d..2f5448f 100644
--- a/core/src/main/java/org/apache/hop/core/svg/SvgCache.java
+++ b/core/src/main/java/org/apache/hop/core/svg/SvgCache.java
@@ -20,7 +20,9 @@ package org.apache.hop.core.svg;
 import org.apache.batik.anim.dom.SAXSVGDocumentFactory;
 import org.apache.batik.bridge.*;
 import org.apache.batik.gvt.GraphicsNode;
+import org.apache.batik.util.SVGConstants;
 import org.apache.batik.util.XMLResourceDescriptor;
+import org.apache.commons.lang.StringUtils;
 import org.apache.hop.core.Const;
 import org.apache.hop.core.exception.HopException;
 import org.apache.hop.core.vfs.HopVfs;
@@ -108,7 +110,7 @@ public class SvgCache {
         GVTBuilder builder = new GVTBuilder();
         GraphicsNode root = builder.build(context, svgDocument);
 
-        // We need to go through the document to figure it out unfortunately.
+        // We need to go through the document to figure it out, unfortunately.
         // It is slower but should always work.
         //
         Rectangle2D primitiveBounds = root.getPrimitiveBounds();
@@ -117,6 +119,21 @@ public class SvgCache {
         height = (float) primitiveBounds.getHeight();
         x = (float) primitiveBounds.getX();
         y = (float) primitiveBounds.getY();
+
+        if (width <= 1 || height <= 1) {
+          // See if we can use a viewbox...
+          //
+          String attributeNS = elSVG.getAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
+          if (StringUtils.isNotEmpty(attributeNS)) {
+            String[] parts = attributeNS.split(" ");
+            if (parts.length == 4) {
+              // Usually this is in the form "0 0 100 200" : x y width height
+              //
+              width = (float) Const.toDouble(parts[2], 0.0);
+              height = (float) Const.toDouble(parts[3], 0.0);
+            }
+          }
+        }
       }
 
       if (width <= 1 || height <= 1) {