Browse Source

Fixed resizing

Krzysztof Krysiński 4 months ago
parent
commit
c1f61b7432
1 changed files with 13 additions and 9 deletions
  1. 13 9
      src/PixiEditor/Models/IO/CustomDocumentFormats/SvgDocumentBuilder.cs

+ 13 - 9
src/PixiEditor/Models/IO/CustomDocumentFormats/SvgDocumentBuilder.cs

@@ -193,21 +193,25 @@ internal class SvgDocumentBuilder : IDocumentBuilder
         Surface? imgSurface = bytes is { Length: > 0 } ? Surface.Load(bytes) : null;
         Surface? finalSurface = null;
 
-        if (style.ViewboxSize.ShortestAxis > 0)
+        if (imgSurface != null)
+        {
+            if (imgSurface.Size.X != (int)image.Width.Unit?.PixelsValue ||
+                imgSurface.Size.Y != (int)image.Height.Unit?.PixelsValue)
+            {
+                var resized = imgSurface.ResizeNearestNeighbor(
+                    new VecI((int)image.Width.Unit?.PixelsValue, (int)image.Height.Unit?.PixelsValue));
+                imgSurface.Dispose();
+                imgSurface = resized;
+            }
+        }
+
+        if (style.ViewboxSize.ShortestAxis > 0 && imgSurface != null)
         {
             finalSurface = new Surface((VecI)style.ViewboxSize);
             double x = image.X.Unit?.PixelsValue ?? 0;
             double y = image.Y.Unit?.PixelsValue ?? 0;
             finalSurface.DrawingSurface.Canvas.DrawSurface(imgSurface.DrawingSurface, (int)x, (int)y);
             imgSurface.Dispose();
-
-            if (finalSurface.Size.X != (int)image.Width.Unit?.PixelsValue || finalSurface.Size.Y != (int)image.Height.Unit?.PixelsValue)
-            {
-                var resized = finalSurface.ResizeNearestNeighbor((VecI)style.ViewboxSize);
-                finalSurface.Dispose();
-                finalSurface = resized;
-            }
-
         }
 
         var graphBuilder = graph.WithImageLayerNode(