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

bamaer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new 6d0d8ff91d Fix#9444  fit exported SVG diagrams to the drawing (#9489)
6d0d8ff91d is described below

commit 6d0d8ff91d1fc548548465b7b810d2409b1f7f13
Author: Lance <[email protected]>
AuthorDate: Sun Nov 15 14:03:00 2026 +0800

    Fix#9444  fit exported SVG diagrams to the drawing (#9489)
    
    * Fix fit exported SVG diagrams to the drawing
    
    Signed-off-by: leehaut <[email protected]>
    
    * Fix fit exported SVG diagrams to the drawing
    
    Signed-off-by: leehaut <[email protected]>
    
    * Fix fit exported SVG diagrams to the drawing
    
    Signed-off-by: leehaut <[email protected]>
    
    ---------
    
    Signed-off-by: leehaut <[email protected]>
---
 .../java/org/apache/hop/core/gui/BasePainter.java  |  17 ++
 .../org/apache/hop/core/gui/SvgExportCanvas.java   | 122 ++++++++++++++
 .../apache/hop/pipeline/PipelineSvgPainter.java    |  96 +++++++++--
 .../apache/hop/workflow/WorkflowSvgPainter.java    |  45 ++++--
 .../apache/hop/core/gui/SvgExportCanvasTest.java   |  62 ++++++++
 .../apache/hop/pipeline/SvgDiagramExportTest.java  | 176 +++++++++++++++++++++
 .../hop/documentation/PipelineDocDelegate.java     |   2 +-
 .../hop/pipeline/transforms/vcard/VCardMapper.java |   7 +-
 8 files changed, 497 insertions(+), 30 deletions(-)

diff --git a/engine/src/main/java/org/apache/hop/core/gui/BasePainter.java 
b/engine/src/main/java/org/apache/hop/core/gui/BasePainter.java
index 2c474b5893..d0553f604a 100644
--- a/engine/src/main/java/org/apache/hop/core/gui/BasePainter.java
+++ b/engine/src/main/java/org/apache/hop/core/gui/BasePainter.java
@@ -197,6 +197,23 @@ public abstract class BasePainter<H extends 
BaseHopMeta<?>, P extends IBaseMeta>
     return size;
   }
 
+  /**
+   * Size the note is painted at. Stored width and height are a lower bound; 
{@link #drawNote} uses
+   * the larger of that and the size the text needs.
+   */
+  public Point getNoteDrawnSize(NotePadMeta note) {
+    Point minimum = calculateMinimumSize(note);
+    int width = note.getWidth();
+    int height = note.getHeight();
+    if (minimum.x > width) {
+      width = minimum.x;
+    }
+    if (minimum.y > height) {
+      height = minimum.y;
+    }
+    return new Point(Math.max(width, 0), Math.max(height, 0));
+  }
+
   /**
    * Base font size for Markdown notes on the canvas. Reads the actual point 
size of {@link
    * EFont#GRAPH} (transform/action name font) so body text matches graph 
labels exactly under the
diff --git a/engine/src/main/java/org/apache/hop/core/gui/SvgExportCanvas.java 
b/engine/src/main/java/org/apache/hop/core/gui/SvgExportCanvas.java
new file mode 100644
index 0000000000..925294e8aa
--- /dev/null
+++ b/engine/src/main/java/org/apache/hop/core/gui/SvgExportCanvas.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.core.gui;
+
+import lombok.Getter;
+
+/**
+ * Canvas size for an exported SVG diagram. The rectangle is the area that is 
actually painted
+ * (icons, labels, and the size notes are drawn at), shifted so a margin of 
the same width sits on
+ * every side. Stored locations are not enough: a pipeline placed away from 
the origin would keep
+ * the empty band, and a note is often painted wider than the width stored on 
it.
+ */
+public final class SvgExportCanvas {
+
+  /** Icon size used by the SVG painters. */
+  public static final int ICON_SIZE = 32;
+
+  /** Gap between an icon and the label under it. Matches the painters. */
+  public static final int LABEL_GAP = 5;
+
+  /** Even margin, in output pixels, around the painted diagram. */
+  public static final int MARGIN = 16;
+
+  private SvgExportCanvas() {}
+
+  /** Inclusive minimum and exclusive maximum of painted graph coordinates. */
+  @Getter
+  public static final class Bounds {
+    private int minX = Integer.MAX_VALUE;
+    private int minY = Integer.MAX_VALUE;
+    private int maxX = Integer.MIN_VALUE;
+    private int maxY = Integer.MIN_VALUE;
+
+    public void include(int x, int y, int width, int height) {
+      if (width < 0) {
+        width = 0;
+      }
+      if (height < 0) {
+        height = 0;
+      }
+      minX = Math.min(minX, x);
+      minY = Math.min(minY, y);
+      maxX = Math.max(maxX, x + width);
+      maxY = Math.max(maxY, y + height);
+    }
+
+    public boolean isEmpty() {
+      return minX == Integer.MAX_VALUE;
+    }
+  }
+
+  /**
+   * Include an icon and the label centered under it. {@code infoIcon} is the 
description badge
+   * drawn just outside the top-left corner.
+   */
+  public static void includeNode(
+      Bounds bounds, IGc gc, Point location, String name, boolean infoIcon, 
int iconSize) {
+    Point loc = location == null ? new Point(50, 50) : location;
+    int padLeft = 1;
+    int padTop = 1;
+    if (infoIcon) {
+      int overhang = iconSize / 4 + 1;
+      padLeft = overhang;
+      padTop = overhang;
+    }
+    bounds.include(loc.x - padLeft, loc.y - padTop, iconSize + padLeft + 1, 
iconSize + padTop + 1);
+
+    gc.setFont(IGc.EFont.GRAPH);
+    Point text = gc.textExtent(name == null ? "" : name);
+    int nameX = loc.x + iconSize / 2 - text.x / 2;
+    int nameY = loc.y + iconSize + LABEL_GAP;
+    bounds.include(nameX, nameY, text.x, text.y);
+  }
+
+  /** Include a note at the size it is painted, plus the border stroke. */
+  public static void includeNote(Bounds bounds, Point location, Point 
drawnSize) {
+    if (location == null || drawnSize == null) {
+      return;
+    }
+    int width = Math.max(0, drawnSize.x);
+    int height = Math.max(0, drawnSize.y);
+    bounds.include(location.x - 1, location.y - 1, width + 2, height + 2);
+  }
+
+  /** Painter offset that places the top-left of {@code bounds} at {@code 
margin}. */
+  public static DPoint offsetFor(Bounds bounds, float magnification, int 
margin) {
+    if (bounds.isEmpty()) {
+      return new DPoint(0, 0);
+    }
+    float mag = magnification > 0f ? magnification : 1f;
+    double pad = Math.max(0, margin);
+    return new DPoint(pad / mag - bounds.minX, pad / mag - bounds.minY);
+  }
+
+  /** Output size of the SVG, in pixels. */
+  public static Point canvasSize(Bounds bounds, float magnification, int 
margin) {
+    int pad = Math.max(0, margin);
+    if (bounds.isEmpty()) {
+      int side = Math.max(1, 2 * pad);
+      return new Point(side, side);
+    }
+    float mag = magnification > 0f ? magnification : 1f;
+    int width = (int) Math.ceil((bounds.maxX - bounds.minX) * (double) mag) + 
2 * pad;
+    int height = (int) Math.ceil((bounds.maxY - bounds.minY) * (double) mag) + 
2 * pad;
+    return new Point(Math.max(1, width), Math.max(1, height));
+  }
+}
diff --git 
a/engine/src/main/java/org/apache/hop/pipeline/PipelineSvgPainter.java 
b/engine/src/main/java/org/apache/hop/pipeline/PipelineSvgPainter.java
index 02df63137b..dbedde57a3 100644
--- a/engine/src/main/java/org/apache/hop/pipeline/PipelineSvgPainter.java
+++ b/engine/src/main/java/org/apache/hop/pipeline/PipelineSvgPainter.java
@@ -17,33 +17,42 @@
 
 package org.apache.hop.pipeline;
 
+import java.awt.Dimension;
 import java.util.ArrayList;
 import java.util.HashMap;
+import org.apache.hop.core.Const;
+import org.apache.hop.core.NotePadMeta;
 import org.apache.hop.core.exception.HopException;
 import org.apache.hop.core.gui.DPoint;
+import org.apache.hop.core.gui.IGc;
 import org.apache.hop.core.gui.Point;
+import org.apache.hop.core.gui.SvgExportCanvas;
 import org.apache.hop.core.gui.SvgGc;
 import org.apache.hop.core.svg.HopSvgGraphics2D;
+import org.apache.hop.core.util.Utils;
 import org.apache.hop.core.variables.IVariables;
+import org.apache.hop.partition.PartitionSchema;
+import org.apache.hop.pipeline.transform.TransformMeta;
 
 public class PipelineSvgPainter {
 
-  public static final String generatePipelineSvg(
+  public static String generatePipelineSvg(
       PipelineMeta pipelineMeta, float magnification, IVariables variables) 
throws HopException {
     return generatePipelineSvg(pipelineMeta, magnification, variables, new 
DPoint(0, 0), 1.0f);
   }
 
-  public static final String generatePipelineSvg(
+  public static String generatePipelineSvg(
       PipelineMeta pipelineMeta,
       float magnification,
       IVariables variables,
       DPoint offset,
       float zoomFactor)
       throws HopException {
-    return generatePipelineSvg(pipelineMeta, magnification, variables, offset, 
zoomFactor, 100);
+    return generatePipelineSvg(
+        pipelineMeta, magnification, variables, offset, zoomFactor, 
SvgExportCanvas.MARGIN);
   }
 
-  public static final String generatePipelineSvg(
+  public static String generatePipelineSvg(
       PipelineMeta pipelineMeta,
       float magnification,
       IVariables variables,
@@ -52,24 +61,23 @@ public class PipelineSvgPainter {
       int extraSize)
       throws HopException {
     try {
-      Point maximum = pipelineMeta.getMaximum();
-      maximum.multiply(magnification);
+      float mag = magnification > 0f ? magnification : 1f;
+      int margin = Math.max(0, extraSize);
 
       HopSvgGraphics2D graphics2D = HopSvgGraphics2D.newDocument();
-
-      SvgGc gc =
-          new SvgGc(graphics2D, new Point(maximum.x + extraSize, maximum.y + 
extraSize), 32, 0, 0);
+      Point area = new Point(1, 1);
+      SvgGc gc = new SvgGc(graphics2D, area, SvgExportCanvas.ICON_SIZE, 0, 0);
       PipelinePainter pipelinePainter =
           new PipelinePainter(
               gc,
               variables,
               pipelineMeta,
-              maximum,
-              offset,
+              area,
+              new DPoint(0, 0),
               null,
               null,
               new ArrayList<>(),
-              32,
+              SvgExportCanvas.ICON_SIZE,
               1,
               0,
               "Arial",
@@ -78,14 +86,72 @@ public class PipelineSvgPainter {
               false,
               null,
               new HashMap<>());
-      pipelinePainter.setMagnification(magnification);
+      pipelinePainter.setMagnification(mag);
+
+      SvgExportCanvas.Bounds bounds = new SvgExportCanvas.Bounds();
+      for (TransformMeta transform : pipelineMeta.getTransforms()) {
+        SvgExportCanvas.includeNode(
+            bounds,
+            gc,
+            transform.getLocation(),
+            transform.getName(),
+            !Utils.isEmpty(transform.getDescription()),
+            SvgExportCanvas.ICON_SIZE);
+        includeTransformDecorations(bounds, gc, transform);
+      }
+      for (NotePadMeta note : pipelineMeta.getNotes()) {
+        SvgExportCanvas.includeNote(
+            bounds, note.getLocation(), 
pipelinePainter.getNoteDrawnSize(note));
+      }
+
+      Point canvas = SvgExportCanvas.canvasSize(bounds, mag, margin);
+      area.x = canvas.x;
+      area.y = canvas.y;
+      graphics2D.setSVGCanvasSize(new Dimension(canvas.x, canvas.y));
+
+      DPoint fit = SvgExportCanvas.offsetFor(bounds, mag, margin);
+      if (offset != null) {
+        fit.x += offset.x;
+        fit.y += offset.y;
+      }
+      pipelinePainter.setOffset(fit);
       pipelinePainter.drawPipelineImage();
 
-      // convert to SVG XML
-      //
       return graphics2D.toXml();
     } catch (Exception e) {
       throw new HopException("Unable to generate SVG for pipeline " + 
pipelineMeta.getName(), e);
     }
   }
+
+  /**
+   * Partition schema box and the {@code xN} copies label are painted outside 
the icon. {@link
+   * PipelinePainter} draws the box 1.5 icons left and 2 icons above, and the 
copies label just
+   * above the icon's top-left.
+   */
+  private static void includeTransformDecorations(
+      SvgExportCanvas.Bounds bounds, IGc gc, TransformMeta transform) {
+    Point loc = transform.getLocation() == null ? new Point(50, 50) : 
transform.getLocation();
+    int icon = SvgExportCanvas.ICON_SIZE;
+    gc.setFont(IGc.EFont.GRAPH);
+    PartitionSchema schema =
+        transform.isPartitioned()
+            ? transform.getTransformPartitioningMeta().getPartitionSchema()
+            : null;
+    if (schema != null) {
+      String count =
+          schema.isDynamicallyDefined()
+              ? Const.NVL(schema.getNumberOfPartitions(), "?")
+              : String.valueOf(schema.getPartitionIDs().size());
+      Point box = gc.textExtent("Px" + count);
+      Point name = gc.textExtent(Const.NVL(schema.getName(), "<no partition 
name>"));
+      bounds.include(
+          loc.x - icon - icon / 2,
+          loc.y - 2 * icon,
+          Math.max(box.x + 2, name.x),
+          box.y + 5 + name.y);
+    } else if (!"1".equals(transform.getCopiesString())) {
+      Point copies = gc.textExtent("x" + transform.getCopiesString());
+      bounds.include(loc.x - copies.x + 1, loc.y - copies.y - 4, copies.x, 
copies.y);
+    }
+  }
 }
diff --git 
a/engine/src/main/java/org/apache/hop/workflow/WorkflowSvgPainter.java 
b/engine/src/main/java/org/apache/hop/workflow/WorkflowSvgPainter.java
index 5339cd40c3..9237209faa 100644
--- a/engine/src/main/java/org/apache/hop/workflow/WorkflowSvgPainter.java
+++ b/engine/src/main/java/org/apache/hop/workflow/WorkflowSvgPainter.java
@@ -17,36 +17,41 @@
 
 package org.apache.hop.workflow;
 
+import java.awt.Dimension;
 import java.util.ArrayList;
+import org.apache.hop.core.NotePadMeta;
 import org.apache.hop.core.exception.HopException;
 import org.apache.hop.core.gui.DPoint;
 import org.apache.hop.core.gui.Point;
+import org.apache.hop.core.gui.SvgExportCanvas;
 import org.apache.hop.core.gui.SvgGc;
 import org.apache.hop.core.svg.HopSvgGraphics2D;
+import org.apache.hop.core.util.Utils;
 import org.apache.hop.core.variables.IVariables;
+import org.apache.hop.workflow.action.ActionMeta;
 
 public class WorkflowSvgPainter {
 
-  public static final String generateWorkflowSvg(
+  public static String generateWorkflowSvg(
       WorkflowMeta workflowMeta, float magnification, IVariables variables) 
throws HopException {
     try {
-      Point maximum = workflowMeta.getMaximum();
-      maximum.multiply(magnification);
+      float mag = magnification > 0f ? magnification : 1f;
+      int margin = SvgExportCanvas.MARGIN;
 
       HopSvgGraphics2D graphics2D = HopSvgGraphics2D.newDocument();
-
-      SvgGc gc = new SvgGc(graphics2D, new Point(maximum.x, maximum.y), 32, 0, 
0);
+      Point area = new Point(1, 1);
+      SvgGc gc = new SvgGc(graphics2D, area, SvgExportCanvas.ICON_SIZE, 0, 0);
       WorkflowPainter workflowPainter =
           new WorkflowPainter(
               gc,
               variables,
               workflowMeta,
-              maximum,
+              area,
               new DPoint(0, 0),
               null,
               null,
               new ArrayList<>(),
-              32,
+              SvgExportCanvas.ICON_SIZE,
               1,
               0,
               "Arial",
@@ -54,13 +59,31 @@ public class WorkflowSvgPainter {
               1.0d,
               false,
               null);
-      workflowPainter.setMagnification(magnification);
+      workflowPainter.setMagnification(mag);
+
+      SvgExportCanvas.Bounds bounds = new SvgExportCanvas.Bounds();
+      for (ActionMeta action : workflowMeta.getActions()) {
+        SvgExportCanvas.includeNode(
+            bounds,
+            gc,
+            action.getLocation(),
+            action.getName(),
+            action.getAction() != null && 
!Utils.isEmpty(action.getDescription()),
+            SvgExportCanvas.ICON_SIZE);
+      }
+      for (NotePadMeta note : workflowMeta.getNotes()) {
+        SvgExportCanvas.includeNote(
+            bounds, note.getLocation(), 
workflowPainter.getNoteDrawnSize(note));
+      }
+
+      Point canvas = SvgExportCanvas.canvasSize(bounds, mag, margin);
+      area.x = canvas.x;
+      area.y = canvas.y;
+      graphics2D.setSVGCanvasSize(new Dimension(canvas.x, canvas.y));
+      workflowPainter.setOffset(SvgExportCanvas.offsetFor(bounds, mag, 
margin));
       workflowPainter.drawWorkflow();
 
-      // convert to SVG XML
-      //
       return graphics2D.toXml();
-
     } catch (Exception e) {
       throw new HopException("Unable to generate SVG for workflow " + 
workflowMeta.getName(), e);
     }
diff --git 
a/engine/src/test/java/org/apache/hop/core/gui/SvgExportCanvasTest.java 
b/engine/src/test/java/org/apache/hop/core/gui/SvgExportCanvasTest.java
new file mode 100644
index 0000000000..4c16f742df
--- /dev/null
+++ b/engine/src/test/java/org/apache/hop/core/gui/SvgExportCanvasTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.core.gui;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+/** Unit test for {@link SvgExportCanvas} canvas. */
+class SvgExportCanvasTest {
+
+  @Test
+  void canvasFitsBoundsWithEvenMargin() {
+    SvgExportCanvas.Bounds bounds = new SvgExportCanvas.Bounds();
+    bounds.include(800, 400, 40, 50);
+
+    Point size = SvgExportCanvas.canvasSize(bounds, 1f, 16);
+    DPoint offset = SvgExportCanvas.offsetFor(bounds, 1f, 16);
+
+    assertEquals(72, size.x);
+    assertEquals(82, size.y);
+    assertEquals(-784d, offset.x, 0.001);
+    assertEquals(-384d, offset.y, 0.001);
+  }
+
+  @Test
+  void magnificationScalesContentAndNotTheMargin() {
+    SvgExportCanvas.Bounds bounds = new SvgExportCanvas.Bounds();
+    bounds.include(0, 0, 100, 40);
+
+    Point size = SvgExportCanvas.canvasSize(bounds, 2f, 16);
+    DPoint offset = SvgExportCanvas.offsetFor(bounds, 2f, 16);
+
+    assertEquals(232, size.x);
+    assertEquals(112, size.y);
+    assertEquals(8d, offset.x, 0.001);
+    assertEquals(8d, offset.y, 0.001);
+  }
+
+  @Test
+  void emptyDiagramIsTheMargin() {
+    Point size = SvgExportCanvas.canvasSize(new SvgExportCanvas.Bounds(), 1f, 
16);
+
+    assertEquals(32, size.x);
+    assertEquals(32, size.y);
+  }
+}
diff --git 
a/engine/src/test/java/org/apache/hop/pipeline/SvgDiagramExportTest.java 
b/engine/src/test/java/org/apache/hop/pipeline/SvgDiagramExportTest.java
new file mode 100644
index 0000000000..720c66c00d
--- /dev/null
+++ b/engine/src/test/java/org/apache/hop/pipeline/SvgDiagramExportTest.java
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.pipeline;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.NotePadMeta;
+import org.apache.hop.core.gui.SvgExportCanvas;
+import org.apache.hop.core.variables.Variables;
+import org.apache.hop.partition.PartitionSchema;
+import org.apache.hop.pipeline.transform.TransformMeta;
+import org.apache.hop.pipeline.transform.TransformPartitioningMeta;
+import org.apache.hop.pipeline.transforms.dummy.DummyMeta;
+import org.apache.hop.workflow.WorkflowMeta;
+import org.apache.hop.workflow.WorkflowSvgPainter;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+/** Unit test for {@link PipelineSvgPainter} {@link WorkflowSvgPainter} svg. */
+class SvgDiagramExportTest {
+
+  @BeforeAll
+  static void initHop() throws Exception {
+    HopClientEnvironment.init();
+  }
+
+  @Test
+  void pipelineCanvasStartsAtTheDrawing() throws Exception {
+    PipelineMeta pipeline = new PipelineMeta();
+    pipeline.setName("grey-border");
+    TransformMeta transform = new TransformMeta("Dummy", "Far away", new 
DummyMeta());
+    transform.setLocation(800, 400);
+    pipeline.addTransform(transform);
+
+    Variables variables = new Variables();
+    String svg = PipelineSvgPainter.generatePipelineSvg(pipeline, 1f, 
variables);
+    String doubled = PipelineSvgPainter.generatePipelineSvg(pipeline, 2f, 
variables);
+
+    int width = svgLength(svg, "width");
+    int height = svgLength(svg, "height");
+    int margin = SvgExportCanvas.MARGIN;
+
+    assertTrue(width < 200, "width " + width);
+    assertTrue(height < 160, "height " + height);
+    assertTrue(textX(svg, "Far away") < 40, svg);
+
+    int wide = svgLength(doubled, "width");
+    int high = svgLength(doubled, "height");
+    assertEquals(2 * width - 2 * margin, wide, "width " + width);
+    assertEquals(2 * height - 2 * margin, high, "height " + height);
+  }
+
+  @Test
+  void partitionedTransformStaysInsideTheCanvas() throws Exception {
+    PipelineMeta pipeline = new PipelineMeta();
+    pipeline.setName("partitioned");
+    TransformMeta transform = new TransformMeta("Dummy", "Top row", new 
DummyMeta());
+    transform.setLocation(800, 400);
+
+    PartitionSchema schema = new PartitionSchema();
+    schema.setName("SCHEMA_BOX");
+    schema.setDynamicallyDefined(false);
+    schema.setPartitionIDs(List.of("p0", "p1"));
+    TransformPartitioningMeta partitioning = new TransformPartitioningMeta();
+    partitioning.setMethod("Mirror");
+    partitioning.setPartitionSchema(schema);
+    transform.setTransformPartitioningMeta(partitioning);
+    pipeline.addTransform(transform);
+
+    String svg = PipelineSvgPainter.generatePipelineSvg(pipeline, 1f, new 
Variables());
+    int schemaX = textX(svg, "SCHEMA_BOX");
+    int schemaY = textY(svg, "SCHEMA_BOX");
+    int countX = textX(svg, "Px2");
+
+    assertTrue(schemaX >= 0 && schemaX < 40, "schema x " + schemaX);
+    assertTrue(schemaY >= 0, "schema y " + schemaY);
+    assertTrue(countX >= 0 && countX < 40, "count x " + countX);
+    assertTrue(svgLength(svg, "width") < 400, svg);
+  }
+
+  @Test
+  void copiesLabelStaysInsideTheCanvas() throws Exception {
+    PipelineMeta pipeline = new PipelineMeta();
+    pipeline.setName("copies");
+    TransformMeta transform = new TransformMeta("Dummy", "Many", new 
DummyMeta());
+    transform.setLocation(800, 400);
+    transform.setCopiesString("12");
+    pipeline.addTransform(transform);
+
+    String svg = PipelineSvgPainter.generatePipelineSvg(pipeline, 1f, new 
Variables());
+    int labelX = textX(svg, "x12");
+    int labelY = textY(svg, "x12");
+
+    assertTrue(labelX >= 0 && labelX < 40, "x " + labelX);
+    assertTrue(labelY >= 0, "y " + labelY);
+  }
+
+  @Test
+  void workflowNoteIsNotClipped() throws Exception {
+    WorkflowMeta workflow = new WorkflowMeta();
+    workflow.setName("note-clipped");
+    NotePadMeta note =
+        new NotePadMeta(
+            "This note is stored only 160 pixels wide. The painter measures 
the whole line and"
+                + " draws past the canvas. The last word must stay visible: 
END_MARKER",
+            48,
+            16,
+            160,
+            48);
+    note.setMarkdown(false);
+    note.setFontName("Arial");
+    note.setFontSize(11);
+    workflow.addNote(note);
+
+    String svg = WorkflowSvgPainter.generateWorkflowSvg(workflow, 1f, new 
Variables());
+    int width = svgLength(svg, "width");
+    int x = textX(svg, "END_MARKER");
+    int textLength = textLength(svg);
+
+    assertTrue(width > 500, "width " + width);
+    assertTrue(x < 40, "x " + x);
+    assertTrue(x + textLength <= width - SvgExportCanvas.MARGIN + 2, "end " + 
(x + textLength));
+  }
+
+  private static int svgLength(String svg, String attribute) {
+    Matcher matcher = Pattern.compile("\\b" + attribute + 
"=\"(\\d+)\"").matcher(svg);
+    assertTrue(matcher.find(), attribute);
+    return Integer.parseInt(matcher.group(1));
+  }
+
+  private static int textX(String svg, String text) {
+    return textAttribute(svg, text, "x=\"");
+  }
+
+  private static int textY(String svg, String text) {
+    return textAttribute(svg, text, "y=\"");
+  }
+
+  private static int textAttribute(String svg, String text, String attribute) {
+    int at = svg.indexOf(text);
+    assertTrue(at > 0, text);
+    int attrAt = svg.lastIndexOf(attribute, at);
+    assertTrue(attrAt >= 0);
+    int end = svg.indexOf('"', attrAt + attribute.length());
+    return Math.round(Float.parseFloat(svg.substring(attrAt + 
attribute.length(), end)));
+  }
+
+  private static int textLength(String svg) {
+    int at = svg.indexOf("END_MARKER");
+    assertTrue(at > 0, "END_MARKER");
+    int lengthAt = svg.lastIndexOf("textLength=\"", at);
+    assertTrue(lengthAt >= 0);
+    int end = svg.indexOf('"', lengthAt + "textLength=\"".length());
+    return Math.round(Float.parseFloat(svg.substring(lengthAt + 
"textLength=\"".length(), end)));
+  }
+}
diff --git 
a/plugins/misc/documentation/src/main/java/org/apache/hop/documentation/PipelineDocDelegate.java
 
b/plugins/misc/documentation/src/main/java/org/apache/hop/documentation/PipelineDocDelegate.java
index 94a0bdaab9..871d318dac 100644
--- 
a/plugins/misc/documentation/src/main/java/org/apache/hop/documentation/PipelineDocDelegate.java
+++ 
b/plugins/misc/documentation/src/main/java/org/apache/hop/documentation/PipelineDocDelegate.java
@@ -79,7 +79,7 @@ public class PipelineDocDelegate extends DocDelegate {
     //
     String pipelineSvg =
         PipelineSvgPainter.generatePipelineSvg(
-            pipelineMeta, 1.0f, builder.getVariables(), new DPoint(0, 0), 
1.0f, 0);
+            pipelineMeta, 1.0f, builder.getVariables(), new DPoint(0, 0), 
1.0f);
     String relativeSvgFilename = calculateTargetImageFile(pipelineName, 
DocBuilder.STRING_PIPELINE);
     String svgFilename =
         targetRootFolder.getName().getPath() + "/" + DocBuilder.ASSETS_IMAGES 
+ relativeSvgFilename;
diff --git 
a/plugins/transforms/vcard/src/main/java/org/apache/hop/pipeline/transforms/vcard/VCardMapper.java
 
b/plugins/transforms/vcard/src/main/java/org/apache/hop/pipeline/transforms/vcard/VCardMapper.java
index 33f858fdf8..64f8a9001f 100644
--- 
a/plugins/transforms/vcard/src/main/java/org/apache/hop/pipeline/transforms/vcard/VCardMapper.java
+++ 
b/plugins/transforms/vcard/src/main/java/org/apache/hop/pipeline/transforms/vcard/VCardMapper.java
@@ -428,9 +428,10 @@ public final class VCardMapper {
     if (tokens == null) {
       tokens =
           Collections.unmodifiableSet(
-              splitList(parameterTypes).stream()
-                  .map(s -> s.toUpperCase(Locale.ROOT))
-                  .collect(Collectors.toCollection(LinkedHashSet::new)));
+              (Set<? extends String>)
+                  splitList(parameterTypes).stream()
+                      .map(s -> s.toUpperCase(Locale.ROOT))
+                      .collect(Collectors.toCollection(LinkedHashSet::new)));
       if (TYPE_TOKENS.size() < MAX_CACHED_TYPE_TOKENS) {
         TYPE_TOKENS.put(parameterTypes, tokens);
       }

Reply via email to