From 9c865ab58bef7178eeb31212aa1194165e2a74b1 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 18:27:57 +1000 Subject: [PATCH 01/11] Infer svgCharSizeHack instead of storing it in ImageBuilder. --- .../sourceforge/plantuml/ugraphic/ImageBuilder.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index 9591e62a7..51f4c818a 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -127,7 +127,6 @@ public class ImageBuilder { private long seed = 42; private ISkinParam skinParam; private int status = 0; - private SvgCharSizeHack svgCharSizeHack = SvgCharSizeHack.NO_HACK; private boolean svgDimensionStyle = true; private String svgLinkTarget; private TitledDiagram titledDiagram; @@ -209,6 +208,10 @@ public class ImageBuilder { return this; } + private SvgCharSizeHack getSvgCharSizeHack() { + return skinParam == null ? SvgCharSizeHack.NO_HACK : skinParam; + } + public ImageBuilder warningOrError(String warningOrError) { this.warningOrError = warningOrError; return this; @@ -229,7 +232,6 @@ public class ImageBuilder { preserveAspectRatio = calculatePreserveAspectRatio(fileFormatOption, skinParam); scale = diagram.getScale(); seed = diagram.seed(); - svgCharSizeHack = skinParam; svgDimensionStyle = skinParam.svgDimensionStyle(); svgLinkTarget = (fileFormatOption.getSvgLinkTarget() != null) ? fileFormatOption.getSvgLinkTarget() : skinParam.getSvgLinkTarget(); @@ -267,7 +269,7 @@ public class ImageBuilder { private ImageData writeImageInternal(FileFormatOption fileFormatOption, OutputStream os, Animation animationArg) throws IOException { Dimension2D dim = (dimension == null) - ? getFinalDimension(fileFormatOption.getDefaultStringBounder(svgCharSizeHack)) : dimension; + ? getFinalDimension(fileFormatOption.getDefaultStringBounder(getSvgCharSizeHack())) : dimension; double dx = 0; double dy = 0; if (animationArg != null) { @@ -334,7 +336,7 @@ public class ImageBuilder { } private Dimension2D getFinalDimension() { - return getFinalDimension(fileFormatOption.getDefaultStringBounder(svgCharSizeHack)); + return getFinalDimension(fileFormatOption.getDefaultStringBounder(getSvgCharSizeHack())); } private UGraphic handwritten(UGraphic ug) { @@ -443,6 +445,7 @@ public class ImageBuilder { } private UGraphic2 createUGraphicSVG(double scaleFactor, Dimension2D dim) { + final SvgCharSizeHack svgCharSizeHack = getSvgCharSizeHack(); HColor backColor = HColorUtils.WHITE; // TODO simplify backcolor some more in a future PR if (this.backcolor instanceof HColorSimple) { backColor = this.backcolor; From 81abee58fa0ec4e05d84938da4b74003c48f95b6 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 18:38:29 +1000 Subject: [PATCH 02/11] Refactor duplicate scaleFactor calculations. --- src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index 51f4c818a..4e837a95e 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -279,8 +279,8 @@ public class ImageBuilder { dx = -minmax.getMinX(); dy = -minmax.getMinY(); } - - final UGraphic2 ug = createUGraphic(fileFormatOption, dim, animationArg, dx, dy); + final double scaleFactor = (scale == null ? 1 : scale.getScale(dim.getWidth(), dim.getHeight())) * dpi / 96.0; + final UGraphic2 ug = createUGraphic(fileFormatOption, dim, animationArg, dx, dy, scaleFactor); UGraphic ug2 = ug; maybeDrawBorder(ug, dim); if (randomPixel) { @@ -295,7 +295,6 @@ public class ImageBuilder { if (ug instanceof UGraphicG2d) { final Set urls = ((UGraphicG2d) ug).getAllUrlsEncountered(); if (urls.size() > 0) { - final double scaleFactor = (scale == null ? 1 : scale.getScale(dim.getWidth(), dim.getHeight())) * dpi / 96.0; final CMapData cmap = CMapData.cmapString(urls, scaleFactor); return new ImageDataComplex(dim, cmap, warningOrError, status); } @@ -412,8 +411,7 @@ public class ImageBuilder { } private UGraphic2 createUGraphic(FileFormatOption option, final Dimension2D dim, Animation animationArg, - double dx, double dy) { - final double scaleFactor = (scale == null ? 1 : scale.getScale(dim.getWidth(), dim.getHeight())) * dpi / 96.0; + double dx, double dy, double scaleFactor) { switch (option.getFileFormat()) { case PNG: return createUGraphicPNG(scaleFactor, dim, animationArg, dx, dy, From c4fe9f434915c2430284f67d845347c8d98661de Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 18:46:12 +1000 Subject: [PATCH 03/11] Infer dpi instead of storing it in ImageBuilder. --- src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index 4e837a95e..9785cca9a 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -114,7 +114,6 @@ public class ImageBuilder { private HColor backcolor = HColorUtils.WHITE; private ColorMapper colorMapper = new ColorMapperIdentity(); private Dimension2D dimension; - private int dpi = 96; private final FileFormatOption fileFormatOption; private boolean handwritten; private String hoverPathColorRGB; @@ -171,6 +170,10 @@ public class ImageBuilder { return this; } + private int getDpi() { + return skinParam == null ? 96 : skinParam.getDpi(); + } + public ImageBuilder drawable(UDrawable drawable) { this.udrawable = drawable; if (backcolor == null && drawable instanceof TextBlockBackcolored) { @@ -223,7 +226,6 @@ public class ImageBuilder { annotations = true; backcolor = calculateBackColor(diagram); colorMapper = skinParam.getColorMapper(); - dpi = skinParam.getDpi(); handwritten = skinParam.handwritten(); hoverPathColorRGB = calculateHoverPathColor(skinParam); lengthAdjust = skinParam.getlengthAdjust(); @@ -279,7 +281,7 @@ public class ImageBuilder { dx = -minmax.getMinX(); dy = -minmax.getMinY(); } - final double scaleFactor = (scale == null ? 1 : scale.getScale(dim.getWidth(), dim.getHeight())) * dpi / 96.0; + final double scaleFactor = (scale == null ? 1 : scale.getScale(dim.getWidth(), dim.getHeight())) * getDpi() / 96.0; final UGraphic2 ug = createUGraphic(fileFormatOption, dim, animationArg, dx, dy, scaleFactor); UGraphic ug2 = ug; maybeDrawBorder(ug, dim); From 5c8b1dc46ad013d2d99ce0fa8575d963a69fee58 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 18:50:19 +1000 Subject: [PATCH 04/11] Infer handwritten instead of storing it in ImageBuilder. --- src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index 9785cca9a..df0af04fb 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -115,7 +115,6 @@ public class ImageBuilder { private ColorMapper colorMapper = new ColorMapperIdentity(); private Dimension2D dimension; private final FileFormatOption fileFormatOption; - private boolean handwritten; private String hoverPathColorRGB; private LengthAdjust lengthAdjust = LengthAdjust.defaultValue(); private UDrawable udrawable; @@ -226,7 +225,6 @@ public class ImageBuilder { annotations = true; backcolor = calculateBackColor(diagram); colorMapper = skinParam.getColorMapper(); - handwritten = skinParam.handwritten(); hoverPathColorRGB = calculateHoverPathColor(skinParam); lengthAdjust = skinParam.getlengthAdjust(); margin = calculateMargin(diagram); @@ -341,7 +339,7 @@ public class ImageBuilder { } private UGraphic handwritten(UGraphic ug) { - if (handwritten) { + if (skinParam != null && skinParam.handwritten()) { return new UGraphicHandwritten(ug); } // if (OptionFlags.OMEGA_CROSSING) { From 2b712e44c09c86621bf2f87aafd5e62061e5f46e Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 19:11:44 +1000 Subject: [PATCH 05/11] Infer lengthAdjust instead of storing it in ImageBuilder. --- src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index df0af04fb..dc590db59 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -116,7 +116,6 @@ public class ImageBuilder { private Dimension2D dimension; private final FileFormatOption fileFormatOption; private String hoverPathColorRGB; - private LengthAdjust lengthAdjust = LengthAdjust.defaultValue(); private UDrawable udrawable; private ClockwiseTopRightBottomLeft margin = ClockwiseTopRightBottomLeft.none(); private String metadata; @@ -226,7 +225,6 @@ public class ImageBuilder { backcolor = calculateBackColor(diagram); colorMapper = skinParam.getColorMapper(); hoverPathColorRGB = calculateHoverPathColor(skinParam); - lengthAdjust = skinParam.getlengthAdjust(); margin = calculateMargin(diagram); metadata = fileFormatOption.isWithMetadata() ? diagram.getMetadata() : null; preserveAspectRatio = calculatePreserveAspectRatio(fileFormatOption, skinParam); @@ -443,6 +441,7 @@ public class ImageBuilder { } private UGraphic2 createUGraphicSVG(double scaleFactor, Dimension2D dim) { + final LengthAdjust lengthAdjust = skinParam == null ? LengthAdjust.defaultValue() : skinParam.getlengthAdjust(); final SvgCharSizeHack svgCharSizeHack = getSvgCharSizeHack(); HColor backColor = HColorUtils.WHITE; // TODO simplify backcolor some more in a future PR if (this.backcolor instanceof HColorSimple) { From f47a2a14fc71ea0e42606bef908a81617456273b Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 19:16:17 +1000 Subject: [PATCH 06/11] Infer scale instead of storing it in ImageBuilder. --- src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index dc590db59..7d2603bb4 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -120,7 +120,6 @@ public class ImageBuilder { private ClockwiseTopRightBottomLeft margin = ClockwiseTopRightBottomLeft.none(); private String metadata; private String preserveAspectRatio; - private Scale scale; private long seed = 42; private ISkinParam skinParam; private int status = 0; @@ -228,7 +227,6 @@ public class ImageBuilder { margin = calculateMargin(diagram); metadata = fileFormatOption.isWithMetadata() ? diagram.getMetadata() : null; preserveAspectRatio = calculatePreserveAspectRatio(fileFormatOption, skinParam); - scale = diagram.getScale(); seed = diagram.seed(); svgDimensionStyle = skinParam.svgDimensionStyle(); svgLinkTarget = (fileFormatOption.getSvgLinkTarget() != null) @@ -277,6 +275,7 @@ public class ImageBuilder { dx = -minmax.getMinX(); dy = -minmax.getMinY(); } + final Scale scale = titledDiagram == null ? null : titledDiagram.getScale(); final double scaleFactor = (scale == null ? 1 : scale.getScale(dim.getWidth(), dim.getHeight())) * getDpi() / 96.0; final UGraphic2 ug = createUGraphic(fileFormatOption, dim, animationArg, dx, dy, scaleFactor); UGraphic ug2 = ug; From 5c2634cf4e86e45f511cf9209d46a625ef391794 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 19:25:27 +1000 Subject: [PATCH 07/11] Simplify ImageBuilder.getFinalDimension() and cache calculated result. --- .../plantuml/ugraphic/ImageBuilder.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index 7d2603bb4..8eb222f81 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -264,8 +264,7 @@ public class ImageBuilder { private ImageData writeImageInternal(FileFormatOption fileFormatOption, OutputStream os, Animation animationArg) throws IOException { - Dimension2D dim = (dimension == null) - ? getFinalDimension(fileFormatOption.getDefaultStringBounder(getSvgCharSizeHack())) : dimension; + Dimension2D dim = getFinalDimension(); double dx = 0; double dy = 0; if (animationArg != null) { @@ -324,15 +323,14 @@ public class ImageBuilder { ug2.apply(color).apply(color.bg()).draw(new URectangle(1, 1)); } - private Dimension2D getFinalDimension(StringBounder stringBounder) { - final LimitFinder limitFinder = new LimitFinder(stringBounder, true); - udrawable.drawU(limitFinder); - return new Dimension2DDouble(limitFinder.getMaxX() + 1 + margin.getLeft() + margin.getRight(), - limitFinder.getMaxY() + 1 + margin.getTop() + margin.getBottom()); - } - private Dimension2D getFinalDimension() { - return getFinalDimension(fileFormatOption.getDefaultStringBounder(getSvgCharSizeHack())); + if (dimension == null) { + final LimitFinder limitFinder = new LimitFinder(fileFormatOption.getDefaultStringBounder(getSvgCharSizeHack()), true); + udrawable.drawU(limitFinder); + dimension = new Dimension2DDouble(limitFinder.getMaxX() + 1 + margin.getLeft() + margin.getRight(), + limitFinder.getMaxY() + 1 + margin.getTop() + margin.getBottom()); + } + return dimension; } private UGraphic handwritten(UGraphic ug) { From 5b970db545bf72fe94be3a61df0005bb4c35cab8 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 19:32:14 +1000 Subject: [PATCH 08/11] Infer hoverPathColorRGB instead of storing it in ImageBuilder. --- .../plantuml/ugraphic/ImageBuilder.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index 8eb222f81..e07d6b4ee 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -115,7 +115,6 @@ public class ImageBuilder { private ColorMapper colorMapper = new ColorMapperIdentity(); private Dimension2D dimension; private final FileFormatOption fileFormatOption; - private String hoverPathColorRGB; private UDrawable udrawable; private ClockwiseTopRightBottomLeft margin = ClockwiseTopRightBottomLeft.none(); private String metadata; @@ -223,7 +222,6 @@ public class ImageBuilder { annotations = true; backcolor = calculateBackColor(diagram); colorMapper = skinParam.getColorMapper(); - hoverPathColorRGB = calculateHoverPathColor(skinParam); margin = calculateMargin(diagram); metadata = fileFormatOption.isWithMetadata() ? diagram.getMetadata() : null; preserveAspectRatio = calculatePreserveAspectRatio(fileFormatOption, skinParam); @@ -431,13 +429,14 @@ public class ImageBuilder { case ATXT: return new UGraphicTxt(); case DEBUG: - return new UGraphicDebug(scaleFactor, dim, svgLinkTarget, hoverPathColorRGB, seed, preserveAspectRatio); + return new UGraphicDebug(scaleFactor, dim, svgLinkTarget, getHoverPathColorRGB(), seed, preserveAspectRatio); default: throw new UnsupportedOperationException(option.getFileFormat().toString()); } } private UGraphic2 createUGraphicSVG(double scaleFactor, Dimension2D dim) { + final String hoverPathColorRGB = getHoverPathColorRGB(); final LengthAdjust lengthAdjust = skinParam == null ? LengthAdjust.defaultValue() : skinParam.getlengthAdjust(); final SvgCharSizeHack svgCharSizeHack = getSvgCharSizeHack(); HColor backColor = HColorUtils.WHITE; // TODO simplify backcolor some more in a future PR @@ -501,12 +500,16 @@ public class ImageBuilder { return diagram.getSkinParam().getBackgroundColor(false); } - private String calculateHoverPathColor(ISkinParam skinParam) { + private String getHoverPathColorRGB() { if (fileFormatOption.getHoverColor() != null) { return fileFormatOption.getHoverColor(); + } else if (skinParam != null) { + final HColor color = skinParam.hoverPathColor(); + if (color != null) { + return colorMapper.toRGB(color); + } } - final HColor color = skinParam.hoverPathColor(); - return color == null ? null : colorMapper.toRGB(color); + return null; } private static ClockwiseTopRightBottomLeft calculateMargin(TitledDiagram diagram) { From 8fc84d437a1d223063c6e3d22013c4f8f4bcb894 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 19:38:03 +1000 Subject: [PATCH 09/11] Infer preserveAspectRatio instead of storing it in ImageBuilder. --- .../sourceforge/plantuml/ugraphic/ImageBuilder.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index e07d6b4ee..c7fcb174a 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -118,7 +118,6 @@ public class ImageBuilder { private UDrawable udrawable; private ClockwiseTopRightBottomLeft margin = ClockwiseTopRightBottomLeft.none(); private String metadata; - private String preserveAspectRatio; private long seed = 42; private ISkinParam skinParam; private int status = 0; @@ -144,7 +143,6 @@ public class ImageBuilder { private ImageBuilder(FileFormatOption fileFormatOption) { this.fileFormatOption = fileFormatOption; - this.preserveAspectRatio = calculatePreserveAspectRatio(fileFormatOption, null); } public ImageBuilder annotations(boolean annotations) { @@ -188,10 +186,6 @@ public class ImageBuilder { return this; } - public String getPreserveAspectRatio() { - return preserveAspectRatio; - } - public ImageBuilder randomPixel() { this.randomPixel = true; return this; @@ -224,7 +218,6 @@ public class ImageBuilder { colorMapper = skinParam.getColorMapper(); margin = calculateMargin(diagram); metadata = fileFormatOption.isWithMetadata() ? diagram.getMetadata() : null; - preserveAspectRatio = calculatePreserveAspectRatio(fileFormatOption, skinParam); seed = diagram.seed(); svgDimensionStyle = skinParam.svgDimensionStyle(); svgLinkTarget = (fileFormatOption.getSvgLinkTarget() != null) @@ -429,7 +422,7 @@ public class ImageBuilder { case ATXT: return new UGraphicTxt(); case DEBUG: - return new UGraphicDebug(scaleFactor, dim, svgLinkTarget, getHoverPathColorRGB(), seed, preserveAspectRatio); + return new UGraphicDebug(scaleFactor, dim, svgLinkTarget, getHoverPathColorRGB(), seed, getPreserveAspectRatio()); default: throw new UnsupportedOperationException(option.getFileFormat().toString()); } @@ -438,6 +431,7 @@ public class ImageBuilder { private UGraphic2 createUGraphicSVG(double scaleFactor, Dimension2D dim) { final String hoverPathColorRGB = getHoverPathColorRGB(); final LengthAdjust lengthAdjust = skinParam == null ? LengthAdjust.defaultValue() : skinParam.getlengthAdjust(); + final String preserveAspectRatio = getPreserveAspectRatio(); final SvgCharSizeHack svgCharSizeHack = getSvgCharSizeHack(); HColor backColor = HColorUtils.WHITE; // TODO simplify backcolor some more in a future PR if (this.backcolor instanceof HColorSimple) { @@ -523,7 +517,7 @@ public class ImageBuilder { return diagram.getDefaultMargins(); } - private static String calculatePreserveAspectRatio(FileFormatOption fileFormatOption, ISkinParam skinParam) { + public String getPreserveAspectRatio() { if (fileFormatOption.getPreserveAspectRatio() != null) { return fileFormatOption.getPreserveAspectRatio(); } else if (skinParam != null) { From f1b5a4c8270664ea65e399e2dc8e8b5243b50d68 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 19:41:13 +1000 Subject: [PATCH 10/11] Infer svgDimensionStyle instead of storing it in ImageBuilder. --- src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index c7fcb174a..d16fd1706 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -121,7 +121,6 @@ public class ImageBuilder { private long seed = 42; private ISkinParam skinParam; private int status = 0; - private boolean svgDimensionStyle = true; private String svgLinkTarget; private TitledDiagram titledDiagram; private boolean randomPixel; @@ -219,7 +218,6 @@ public class ImageBuilder { margin = calculateMargin(diagram); metadata = fileFormatOption.isWithMetadata() ? diagram.getMetadata() : null; seed = diagram.seed(); - svgDimensionStyle = skinParam.svgDimensionStyle(); svgLinkTarget = (fileFormatOption.getSvgLinkTarget() != null) ? fileFormatOption.getSvgLinkTarget() : skinParam.getSvgLinkTarget(); titledDiagram = diagram; @@ -433,6 +431,7 @@ public class ImageBuilder { final LengthAdjust lengthAdjust = skinParam == null ? LengthAdjust.defaultValue() : skinParam.getlengthAdjust(); final String preserveAspectRatio = getPreserveAspectRatio(); final SvgCharSizeHack svgCharSizeHack = getSvgCharSizeHack(); + final boolean svgDimensionStyle = skinParam == null || skinParam.svgDimensionStyle(); HColor backColor = HColorUtils.WHITE; // TODO simplify backcolor some more in a future PR if (this.backcolor instanceof HColorSimple) { backColor = this.backcolor; From 7863aae1af4a177c963fbab264c6cbb1f7e5ae68 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 7 Apr 2021 19:47:24 +1000 Subject: [PATCH 11/11] Infer svgLinkTarget instead of storing it in ImageBuilder. --- .../plantuml/ugraphic/ImageBuilder.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index d16fd1706..937c89f78 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -121,7 +121,6 @@ public class ImageBuilder { private long seed = 42; private ISkinParam skinParam; private int status = 0; - private String svgLinkTarget; private TitledDiagram titledDiagram; private boolean randomPixel; private String warningOrError; @@ -204,6 +203,16 @@ public class ImageBuilder { return skinParam == null ? SvgCharSizeHack.NO_HACK : skinParam; } + private String getSvgLinkTarget() { + if (fileFormatOption.getSvgLinkTarget() != null) { + return fileFormatOption.getSvgLinkTarget(); + } else if (skinParam != null) { + return skinParam.getSvgLinkTarget(); + } else { + return null; + } + } + public ImageBuilder warningOrError(String warningOrError) { this.warningOrError = warningOrError; return this; @@ -218,8 +227,6 @@ public class ImageBuilder { margin = calculateMargin(diagram); metadata = fileFormatOption.isWithMetadata() ? diagram.getMetadata() : null; seed = diagram.seed(); - svgLinkTarget = (fileFormatOption.getSvgLinkTarget() != null) - ? fileFormatOption.getSvgLinkTarget() : skinParam.getSvgLinkTarget(); titledDiagram = diagram; warningOrError = diagram.getWarningOrError(); return this; @@ -420,7 +427,7 @@ public class ImageBuilder { case ATXT: return new UGraphicTxt(); case DEBUG: - return new UGraphicDebug(scaleFactor, dim, svgLinkTarget, getHoverPathColorRGB(), seed, getPreserveAspectRatio()); + return new UGraphicDebug(scaleFactor, dim, getSvgLinkTarget(), getHoverPathColorRGB(), seed, getPreserveAspectRatio()); default: throw new UnsupportedOperationException(option.getFileFormat().toString()); } @@ -432,6 +439,7 @@ public class ImageBuilder { final String preserveAspectRatio = getPreserveAspectRatio(); final SvgCharSizeHack svgCharSizeHack = getSvgCharSizeHack(); final boolean svgDimensionStyle = skinParam == null || skinParam.svgDimensionStyle(); + final String svgLinkTarget = getSvgLinkTarget(); HColor backColor = HColorUtils.WHITE; // TODO simplify backcolor some more in a future PR if (this.backcolor instanceof HColorSimple) { backColor = this.backcolor;