]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
renderSVG hardening 57/857/1
authorAntti Villberg <antti.villberg@semantum.fi>
Wed, 16 Aug 2017 09:49:09 +0000 (12:49 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Wed, 16 Aug 2017 09:49:09 +0000 (12:49 +0300)
refs #7421

Change-Id: I307f298d8c7c6adfa2627634c3f4d0a6db3e2afb

bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java

index 5f375095fb239db428f53a07040bc58e7b10b21d..3e81b1c5cc620b81f23fa8f1ce0fa40fee67db81 100644 (file)
@@ -632,11 +632,15 @@ public class SCLScenegraph {
                        double trX = -1 * content.getX();
                        double trY = -1 * content.getY();
                        
+                       // NaNs
+                       if(!Double.isFinite(trX)) trX = 0;
+                       if(!Double.isFinite(trY)) trY = 0;
+                       
                        result.append(MAIN_SECTION, "<g transform=\"translate(");
                        result.append(MAIN_SECTION, "" + trX);
-                       result.append(MAIN_SECTION, " ");
+                       result.append(MAIN_SECTION, ", ");
                        result.append(MAIN_SECTION, "" + trY);
-                       result.append(MAIN_SECTION, "\">");
+                       result.append(MAIN_SECTION, ")\">");
 
                        result.append(SELECTION_SECTION, "<g class=\"selections\">");
                        
@@ -785,10 +789,13 @@ public class SCLScenegraph {
                     parentBuilder2.append(SELECTION_SECTION, "\n</g>");
                     parentBuilder2.append(SELECTION_MASK_SECTION, "\n<g class=\"selectionMask\" id=\"" + key + "\">");
                     Rectangle2D rect = n.getRect();
-                    parentBuilder2.append(SELECTION_MASK_SECTION,"<rect style=\"fill:#fff\" opacity=\"0.001\"");
-                    parentBuilder2.append(SELECTION_MASK_SECTION," x=\"" + rect.getX() + "\" y=\"" + rect.getY() + "\"");
-                    parentBuilder2.append(SELECTION_MASK_SECTION," width=\"" + rect.getWidth() + "\" height=\"" + rect.getHeight() + "\"");
-                    parentBuilder2.append(SELECTION_MASK_SECTION,"></rect>");
+                    // NaN
+                    if(rect.getHeight() == rect.getHeight() && rect.getWidth() == rect.getWidth()) {
+                           parentBuilder2.append(SELECTION_MASK_SECTION,"<rect style=\"fill:#fff\" opacity=\"0.001\"");
+                           parentBuilder2.append(SELECTION_MASK_SECTION," x=\"" + rect.getX() + "\" y=\"" + rect.getY() + "\"");
+                           parentBuilder2.append(SELECTION_MASK_SECTION," width=\"" + rect.getWidth() + "\" height=\"" + rect.getHeight() + "\"");
+                           parentBuilder2.append(SELECTION_MASK_SECTION,"></rect>");
+                    }
                     parentBuilder2.append(SELECTION_MASK_SECTION,"\n</g>");
                 }
             } else if (node instanceof SVGNode) {