From ecf54172c465d78566a821d11ea674e5f49946df Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Sep 2021 01:03:02 +0000 Subject: [PATCH 01/47] Bump junit-bom from 5.8.0 to 5.8.1 Bumps [junit-bom](https://github.com/junit-team/junit5) from 5.8.0 to 5.8.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.0...r5.8.1) --- updated-dependencies: - dependency-name: org.junit:junit-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2615dd94f..abef39f8e 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ org.junit junit-bom - 5.8.0 + 5.8.1 pom import From 1ebd727d9f10d2b57f64e505cc5d7ec37c6783d4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Sep 2021 01:13:05 +0000 Subject: [PATCH 02/47] Bump actions/setup-java from 2.3.0 to 2.3.1 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.3.0 to 2.3.1. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v2.3.0...v2.3.1) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa966d1c4..5f6173b4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: uses: actions/checkout@v2 - name: Set up java - uses: actions/setup-java@v2.3.0 + uses: actions/setup-java@v2.3.1 with: java-version: 8 distribution: temurin From 3c5769cc5fe6e140d5cc4ec21a7598fdb5da92d3 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 04:02:00 +1100 Subject: [PATCH 03/47] Remove unused stringBounder field --- src/net/sourceforge/plantuml/ugraphic/eps/DriverTextEps.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/DriverTextEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/DriverTextEps.java index 6a538e9d9..bd62af601 100644 --- a/src/net/sourceforge/plantuml/ugraphic/eps/DriverTextEps.java +++ b/src/net/sourceforge/plantuml/ugraphic/eps/DriverTextEps.java @@ -43,13 +43,11 @@ import java.awt.geom.PathIterator; import java.util.ArrayList; import java.util.List; -import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.eps.EpsGraphics; import net.sourceforge.plantuml.eps.EpsGraphicsMacroAndText; import net.sourceforge.plantuml.eps.EpsStrategy; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.FontStyle; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.ClipContainer; import net.sourceforge.plantuml.ugraphic.MinMax; import net.sourceforge.plantuml.ugraphic.UClip; @@ -63,12 +61,10 @@ import net.sourceforge.plantuml.ugraphic.color.HColorUtils; public class DriverTextEps implements UDriver { - private final StringBounder stringBounder; private final ClipContainer clipContainer; private final EpsStrategy strategy; public DriverTextEps(ClipContainer clipContainer, EpsStrategy strategy) { - this.stringBounder = FileFormat.PNG.getDefaultStringBounder(); this.clipContainer = clipContainer; this.strategy = strategy; } From 4c3b0bd9898404c6ca1a74cc4b1d8cf903b4545c Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 04:04:23 +1100 Subject: [PATCH 04/47] Remove unused tikzFontDistortion field --- src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java index d3c4db2bb..c9f2367d7 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java @@ -60,12 +60,9 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class UGraphicTikz extends AbstractUGraphic implements ClipContainer { - private final TikzFontDistortion tikzFontDistortion; - private UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, TikzGraphics tikz, TikzFontDistortion tikzFontDistortion) { super(defaultBackground, colorMapper, FileFormat.LATEX.getDefaultStringBounder(tikzFontDistortion), tikz); - this.tikzFontDistortion = tikzFontDistortion; register(); } @@ -83,7 +80,6 @@ public class UGraphicTikz extends AbstractUGraphic implements Clip private UGraphicTikz(UGraphicTikz other) { super(other); - this.tikzFontDistortion = other.tikzFontDistortion; register(); } From ff53f679ef03dc3ed98cb44c4bbe24ee3f8f29a6 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 04:31:42 +1100 Subject: [PATCH 05/47] Pass a StringBounder into UGraphicTikz --- .../sourceforge/plantuml/sudoku/GraphicsSudoku.java | 2 +- .../sourceforge/plantuml/ugraphic/ImageBuilder.java | 4 ++-- .../plantuml/ugraphic/tikz/UGraphicTikz.java | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java index 6b4d9961e..144fd54a1 100644 --- a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java +++ b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java @@ -98,7 +98,7 @@ public class GraphicsSudoku { } public ImageData writeImageLatex(OutputStream os, FileFormat fileFormat) throws IOException { - final UGraphicTikz ug = new UGraphicTikz(HColorUtils.WHITE, new ColorMapperIdentity(), 1, + final UGraphicTikz ug = new UGraphicTikz(HColorUtils.WHITE, new ColorMapperIdentity(), FileFormat.LATEX.getDefaultStringBounder(), 1, fileFormat == FileFormat.LATEX, TikzFontDistortion.getDefault()); drawInternal(ug); ug.writeToStream(os, null, -1); // dpi param is not used diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index 9a983e645..8a64da0a4 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -418,9 +418,9 @@ public class ImageBuilder { case VDX: return new UGraphicVdx(backcolor, colorMapper); case LATEX: - return new UGraphicTikz(backcolor, colorMapper, scaleFactor, true, option.getTikzFontDistortion()); + return new UGraphicTikz(backcolor, colorMapper, FileFormat.LATEX.getDefaultStringBounder(option.getTikzFontDistortion()), scaleFactor, true, option.getTikzFontDistortion()); case LATEX_NO_PREAMBLE: - return new UGraphicTikz(backcolor, colorMapper, scaleFactor, false, option.getTikzFontDistortion()); + return new UGraphicTikz(backcolor, colorMapper, FileFormat.LATEX.getDefaultStringBounder(option.getTikzFontDistortion()), scaleFactor, false, option.getTikzFontDistortion()); case BRAILLE_PNG: return new UGraphicBraille(backcolor, colorMapper); case UTXT: diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java index c9f2367d7..e55d6ac84 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java @@ -37,10 +37,10 @@ package net.sourceforge.plantuml.ugraphic.tikz; import java.io.IOException; import java.io.OutputStream; -import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.TikzFontDistortion; import net.sourceforge.plantuml.Url; import net.sourceforge.plantuml.creole.legacy.AtomText; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.tikz.TikzGraphics; import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic; @@ -60,16 +60,16 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class UGraphicTikz extends AbstractUGraphic implements ClipContainer { - private UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, TikzGraphics tikz, + private UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, TikzGraphics tikz, TikzFontDistortion tikzFontDistortion) { - super(defaultBackground, colorMapper, FileFormat.LATEX.getDefaultStringBounder(tikzFontDistortion), tikz); + super(defaultBackground, colorMapper, stringBounder, tikz); register(); } - public UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, double scale, boolean withPreamble, + public UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, double scale, boolean withPreamble, TikzFontDistortion tikzFontDistortion) { - this(defaultBackground, colorMapper, new TikzGraphics(scale, withPreamble), tikzFontDistortion); + this(defaultBackground, colorMapper, stringBounder, new TikzGraphics(scale, withPreamble), tikzFontDistortion); } From eecb097640c402ef05cf7d507ea7dc6ba807d0e8 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 04:34:41 +1100 Subject: [PATCH 06/47] Remove redundant UGraphicTikz constructor param --- src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java | 3 +-- src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java | 4 ++-- .../sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java | 9 +++------ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java index 144fd54a1..7ad553451 100644 --- a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java +++ b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java @@ -48,7 +48,6 @@ import net.sourceforge.plantuml.EmptyImageBuilder; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.SpriteContainerEmpty; import net.sourceforge.plantuml.SvgCharSizeHack; -import net.sourceforge.plantuml.TikzFontDistortion; import net.sourceforge.plantuml.api.ImageDataSimple; import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.cucadiagram.Display; @@ -99,7 +98,7 @@ public class GraphicsSudoku { public ImageData writeImageLatex(OutputStream os, FileFormat fileFormat) throws IOException { final UGraphicTikz ug = new UGraphicTikz(HColorUtils.WHITE, new ColorMapperIdentity(), FileFormat.LATEX.getDefaultStringBounder(), 1, - fileFormat == FileFormat.LATEX, TikzFontDistortion.getDefault()); + fileFormat == FileFormat.LATEX); drawInternal(ug); ug.writeToStream(os, null, -1); // dpi param is not used return ImageDataSimple.ok(); diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index 8a64da0a4..dc3ac2299 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -418,9 +418,9 @@ public class ImageBuilder { case VDX: return new UGraphicVdx(backcolor, colorMapper); case LATEX: - return new UGraphicTikz(backcolor, colorMapper, FileFormat.LATEX.getDefaultStringBounder(option.getTikzFontDistortion()), scaleFactor, true, option.getTikzFontDistortion()); + return new UGraphicTikz(backcolor, colorMapper, FileFormat.LATEX.getDefaultStringBounder(option.getTikzFontDistortion()), scaleFactor, true); case LATEX_NO_PREAMBLE: - return new UGraphicTikz(backcolor, colorMapper, FileFormat.LATEX.getDefaultStringBounder(option.getTikzFontDistortion()), scaleFactor, false, option.getTikzFontDistortion()); + return new UGraphicTikz(backcolor, colorMapper, FileFormat.LATEX.getDefaultStringBounder(option.getTikzFontDistortion()), scaleFactor, false); case BRAILLE_PNG: return new UGraphicBraille(backcolor, colorMapper); case UTXT: diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java index e55d6ac84..b7bdf5e1e 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java @@ -37,7 +37,6 @@ package net.sourceforge.plantuml.ugraphic.tikz; import java.io.IOException; import java.io.OutputStream; -import net.sourceforge.plantuml.TikzFontDistortion; import net.sourceforge.plantuml.Url; import net.sourceforge.plantuml.creole.legacy.AtomText; import net.sourceforge.plantuml.graphic.StringBounder; @@ -60,16 +59,14 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class UGraphicTikz extends AbstractUGraphic implements ClipContainer { - private UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, TikzGraphics tikz, - TikzFontDistortion tikzFontDistortion) { + private UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, TikzGraphics tikz) { super(defaultBackground, colorMapper, stringBounder, tikz); register(); } - public UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, double scale, boolean withPreamble, - TikzFontDistortion tikzFontDistortion) { - this(defaultBackground, colorMapper, stringBounder, new TikzGraphics(scale, withPreamble), tikzFontDistortion); + public UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, double scale, boolean withPreamble) { + this(defaultBackground, colorMapper, stringBounder, new TikzGraphics(scale, withPreamble)); } From f1bff6dde657441cd557592e914f47c3ffd2568d Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 04:36:02 +1100 Subject: [PATCH 07/47] Simplify UGraphicTikz constructors --- .../plantuml/ugraphic/tikz/UGraphicTikz.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java index b7bdf5e1e..57a3b2b68 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java @@ -59,15 +59,9 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class UGraphicTikz extends AbstractUGraphic implements ClipContainer { - private UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, TikzGraphics tikz) { - super(defaultBackground, colorMapper, stringBounder, tikz); - register(); - - } - public UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, double scale, boolean withPreamble) { - this(defaultBackground, colorMapper, stringBounder, new TikzGraphics(scale, withPreamble)); - + super(defaultBackground, colorMapper, stringBounder, new TikzGraphics(scale, withPreamble)); + register(); } @Override From 2b2a47b9f09a6b28d807af404d077b0b24b8b0aa Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 04:50:13 +1100 Subject: [PATCH 08/47] Add FileFormat.getDefaultStringBounder(SvgCharSizeHack) --- src/net/sourceforge/plantuml/FileFormat.java | 4 ++++ src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/net/sourceforge/plantuml/FileFormat.java b/src/net/sourceforge/plantuml/FileFormat.java index f31a3ff4c..52ed6d6ae 100644 --- a/src/net/sourceforge/plantuml/FileFormat.java +++ b/src/net/sourceforge/plantuml/FileFormat.java @@ -132,6 +132,10 @@ public enum FileFormat { return getDefaultStringBounder(TikzFontDistortion.getDefault(), SvgCharSizeHack.NO_HACK); } + public StringBounder getDefaultStringBounder(SvgCharSizeHack charSizeHack) { + return getDefaultStringBounder(TikzFontDistortion.getDefault(), charSizeHack); + } + public StringBounder getDefaultStringBounder(TikzFontDistortion tikzFontDistortion) { return getDefaultStringBounder(tikzFontDistortion, SvgCharSizeHack.NO_HACK); } diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java index 9627bfda7..8d7f94fcd 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java @@ -42,7 +42,6 @@ import javax.xml.transform.TransformerException; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.SvgCharSizeHack; -import net.sourceforge.plantuml.TikzFontDistortion; import net.sourceforge.plantuml.Url; import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.svg.LengthAdjust; @@ -116,7 +115,7 @@ public class UGraphicSvg extends AbstractUGraphic implements ClipCo private UGraphicSvg(HColor defaultBackground, Dimension2D minDim, ColorMapper colorMapper, SvgGraphics svg, boolean textAsPath, String linkTarget, SvgCharSizeHack charSizeHack) { - super(defaultBackground, colorMapper, FileFormat.SVG.getDefaultStringBounder(TikzFontDistortion.getDefault(), charSizeHack), svg); + super(defaultBackground, colorMapper, FileFormat.SVG.getDefaultStringBounder(charSizeHack), svg); this.textAsPath2 = textAsPath; this.target = linkTarget; register(); From d3a4fc6fe0eee5b5ed215496551355f506d7bd29 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 04:54:37 +1100 Subject: [PATCH 09/47] Pass a StringBounder into UGraphicSvg --- .../sourceforge/plantuml/sudoku/GraphicsSudoku.java | 3 +-- .../sourceforge/plantuml/ugraphic/ImageBuilder.java | 3 +-- .../plantuml/ugraphic/svg/UGraphicSvg.java | 11 +++++------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java index 7ad553451..316368363 100644 --- a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java +++ b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java @@ -47,7 +47,6 @@ import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmptyImageBuilder; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.SpriteContainerEmpty; -import net.sourceforge.plantuml.SvgCharSizeHack; import net.sourceforge.plantuml.api.ImageDataSimple; import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.cucadiagram.Display; @@ -89,7 +88,7 @@ public class GraphicsSudoku { public ImageData writeImageSvg(OutputStream os) throws IOException { final UGraphicSvg ug = new UGraphicSvg(HColorUtils.WHITE, true, new Dimension2DDouble(0, 0), - new ColorMapperIdentity(), false, 1.0, null, null, 0, "none", SvgCharSizeHack.NO_HACK, + new ColorMapperIdentity(), false, 1.0, null, null, 0, "none", FileFormat.SVG.getDefaultStringBounder(), LengthAdjust.defaultValue()); drawInternal(ug); ug.writeToStream(os, null, -1); // dpi param is not used diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index dc3ac2299..bfd163ccc 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -438,11 +438,10 @@ public class ImageBuilder { final String hoverPathColorRGB = getHoverPathColorRGB(); final LengthAdjust lengthAdjust = skinParam == null ? LengthAdjust.defaultValue() : skinParam.getlengthAdjust(); final String preserveAspectRatio = getPreserveAspectRatio(); - final SvgCharSizeHack svgCharSizeHack = getSvgCharSizeHack(); final boolean svgDimensionStyle = skinParam == null || skinParam.svgDimensionStyle(); final String svgLinkTarget = getSvgLinkTarget(); final UGraphicSvg ug = new UGraphicSvg(backcolor, svgDimensionStyle, dim, colorMapper, false, scaleFactor, - svgLinkTarget, hoverPathColorRGB, seed, preserveAspectRatio, svgCharSizeHack, lengthAdjust); + svgLinkTarget, hoverPathColorRGB, seed, preserveAspectRatio, FileFormat.SVG.getDefaultStringBounder(getSvgCharSizeHack()), lengthAdjust); return ug; } diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java index 8d7f94fcd..6ebdc53c2 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java @@ -40,9 +40,8 @@ import java.io.OutputStream; import javax.xml.transform.TransformerException; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.SvgCharSizeHack; import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.svg.LengthAdjust; import net.sourceforge.plantuml.svg.SvgGraphics; @@ -88,10 +87,10 @@ public class UGraphicSvg extends AbstractUGraphic implements ClipCo public UGraphicSvg(HColor defaultBackground, boolean svgDimensionStyle, Dimension2D minDim, ColorMapper colorMapper, boolean textAsPath, double scale, String linkTarget, String hover, long seed, String preserveAspectRatio, - SvgCharSizeHack charSizeHack, LengthAdjust lengthAdjust) { + StringBounder stringBounder, LengthAdjust lengthAdjust) { this(defaultBackground, minDim, colorMapper, new SvgGraphics(colorMapper.toSvg(defaultBackground), svgDimensionStyle, minDim, scale, hover, seed, preserveAspectRatio, lengthAdjust), textAsPath, - linkTarget, charSizeHack); + linkTarget, stringBounder); if (defaultBackground instanceof HColorGradient) { final SvgGraphics svg = getGraphicObject(); svg.paintBackcolorGradient(colorMapper, (HColorGradient) defaultBackground); @@ -114,8 +113,8 @@ public class UGraphicSvg extends AbstractUGraphic implements ClipCo } private UGraphicSvg(HColor defaultBackground, Dimension2D minDim, ColorMapper colorMapper, SvgGraphics svg, - boolean textAsPath, String linkTarget, SvgCharSizeHack charSizeHack) { - super(defaultBackground, colorMapper, FileFormat.SVG.getDefaultStringBounder(charSizeHack), svg); + boolean textAsPath, String linkTarget, StringBounder stringBounder) { + super(defaultBackground, colorMapper, stringBounder, svg); this.textAsPath2 = textAsPath; this.target = linkTarget; register(); From 102a7ccf64e0f34d4796549db0456e2aea84dde2 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 05:12:56 +1100 Subject: [PATCH 10/47] Pass a StringBounder into UGraphicG2d & EmptyImageBuilder --- .../sourceforge/plantuml/EmptyImageBuilder.java | 15 +++++++++------ .../sourceforge/plantuml/eggs/GraphicsPath.java | 7 +++++-- .../sourceforge/plantuml/logo/PSystemLogo.java | 7 +++++-- .../plantuml/sudoku/GraphicsSudoku.java | 6 ++++-- .../plantuml/ugraphic/ImageBuilder.java | 5 +++-- .../plantuml/ugraphic/g2d/UGraphicG2d.java | 10 +++++----- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/net/sourceforge/plantuml/EmptyImageBuilder.java b/src/net/sourceforge/plantuml/EmptyImageBuilder.java index f3fd01cfe..70b60e731 100644 --- a/src/net/sourceforge/plantuml/EmptyImageBuilder.java +++ b/src/net/sourceforge/plantuml/EmptyImageBuilder.java @@ -46,6 +46,7 @@ import java.util.ArrayList; import java.util.List; import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.UAntiAliasing; import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity; import net.sourceforge.plantuml.ugraphic.color.HColor; @@ -57,12 +58,13 @@ public class EmptyImageBuilder { private final BufferedImage im; private final Graphics2D g2d; private final Color background; + private final StringBounder stringBounder; - public EmptyImageBuilder(String watermark, double width, double height, Color background) { - this(watermark, (int) width, (int) height, background); + public EmptyImageBuilder(String watermark, double width, double height, Color background, StringBounder stringBounder) { + this(watermark, (int) width, (int) height, background, stringBounder); } - public EmptyImageBuilder(String watermark, int width, int height, Color background) { + public EmptyImageBuilder(String watermark, int width, int height, Color background, StringBounder stringBounder) { if (width > GraphvizUtils.getenvImageLimit()) { Log.info("Width too large " + width + ". You should set PLANTUML_LIMIT_SIZE"); width = GraphvizUtils.getenvImageLimit(); @@ -72,6 +74,7 @@ public class EmptyImageBuilder { height = GraphvizUtils.getenvImageLimit(); } this.background = background; + this.stringBounder = stringBounder; Log.info("Creating image " + width + "x" + height); im = new BufferedImage(width, height, getType(background)); g2d = im.createGraphics(); @@ -149,8 +152,8 @@ public class EmptyImageBuilder { return result; } - public EmptyImageBuilder(String watermark, int width, int height, Color background, double dpiFactor) { - this(watermark, width * dpiFactor, height * dpiFactor, background); + public EmptyImageBuilder(String watermark, int width, int height, Color background, StringBounder stringBounder, double dpiFactor) { + this(watermark, width * dpiFactor, height * dpiFactor, background, stringBounder); if (dpiFactor != 1.0) { g2d.setTransform(AffineTransform.getScaleInstance(dpiFactor, dpiFactor)); } @@ -166,7 +169,7 @@ public class EmptyImageBuilder { public UGraphicG2d getUGraphicG2d() { final HColor back = new HColorSimple(background, false); - final UGraphicG2d result = new UGraphicG2d(back, new ColorMapperIdentity(), g2d, 1.0); + final UGraphicG2d result = new UGraphicG2d(back, new ColorMapperIdentity(), stringBounder, g2d, 1.0); result.setBufferedImage(im); return result; } diff --git a/src/net/sourceforge/plantuml/eggs/GraphicsPath.java b/src/net/sourceforge/plantuml/eggs/GraphicsPath.java index 7e812f16e..ea68db158 100644 --- a/src/net/sourceforge/plantuml/eggs/GraphicsPath.java +++ b/src/net/sourceforge/plantuml/eggs/GraphicsPath.java @@ -42,8 +42,10 @@ import java.io.IOException; import java.io.OutputStream; import net.sourceforge.plantuml.EmptyImageBuilder; +import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.api.ImageDataSimple; import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.png.PngIO; import net.sourceforge.plantuml.ugraphic.UChange; import net.sourceforge.plantuml.ugraphic.UMotif; @@ -68,11 +70,12 @@ public class GraphicsPath { } private BufferedImage createImage() { - final EmptyImageBuilder builder = new EmptyImageBuilder(null, 50, 50, Color.WHITE); + final StringBounder stringBounder = FileFormat.PNG.getDefaultStringBounder(); + final EmptyImageBuilder builder = new EmptyImageBuilder(null, 50, 50, Color.WHITE, stringBounder); final BufferedImage im = builder.getBufferedImage(); final Graphics2D g2d = builder.getGraphics2D(); - final UGraphicG2d ug = new UGraphicG2d(HColorUtils.WHITE, colorMapper, g2d, 1.0); + final UGraphicG2d ug = new UGraphicG2d(HColorUtils.WHITE, colorMapper, stringBounder, g2d, 1.0); ug.setBufferedImage(im); final UMotif motif = new UMotif(path); motif.drawHorizontal(ug.apply((UChange) HColorUtils.BLACK), 20, 20, 1); diff --git a/src/net/sourceforge/plantuml/logo/PSystemLogo.java b/src/net/sourceforge/plantuml/logo/PSystemLogo.java index 1c0afed03..1626f3ef7 100644 --- a/src/net/sourceforge/plantuml/logo/PSystemLogo.java +++ b/src/net/sourceforge/plantuml/logo/PSystemLogo.java @@ -44,11 +44,13 @@ import java.util.List; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.EmptyImageBuilder; +import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.api.ImageDataSimple; import net.sourceforge.plantuml.core.DiagramDescription; import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.core.UmlSource; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.png.PngIO; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity; @@ -68,9 +70,10 @@ public class PSystemLogo extends AbstractPSystem { throws IOException { final int width = 640; final int height = 480; - final EmptyImageBuilder builder = new EmptyImageBuilder(fileFormat.getWatermark(), width, height, Color.WHITE); + final StringBounder stringBounder = FileFormat.PNG.getDefaultStringBounder(); + final EmptyImageBuilder builder = new EmptyImageBuilder(fileFormat.getWatermark(), width, height, Color.WHITE, stringBounder); final BufferedImage im = builder.getBufferedImage(); - final UGraphic ug = new UGraphicG2d(HColorUtils.WHITE, new ColorMapperIdentity(), builder.getGraphics2D(), 1.0); + final UGraphic ug = new UGraphicG2d(HColorUtils.WHITE, new ColorMapperIdentity(), stringBounder, builder.getGraphics2D(), 1.0); ((UGraphicG2d) ug).setBufferedImage(im); final TurtleGraphicsPane turtleGraphicsPane = new TurtleGraphicsPane(width, height); diff --git a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java index 316368363..5c7d0eded 100644 --- a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java +++ b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java @@ -53,6 +53,7 @@ import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.eps.EpsStrategy; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.png.PngIO; import net.sourceforge.plantuml.svg.LengthAdjust; @@ -104,12 +105,13 @@ public class GraphicsSudoku { } public ImageData writeImagePng(OutputStream os) throws IOException { + final StringBounder stringBounder = FileFormat.PNG.getDefaultStringBounder(); final EmptyImageBuilder builder = new EmptyImageBuilder(null, sudoWidth, sudoHeight + textTotalHeight, - Color.WHITE); + Color.WHITE, stringBounder); final BufferedImage im = builder.getBufferedImage(); final Graphics2D g3d = builder.getGraphics2D(); - final UGraphic ug = new UGraphicG2d(HColorUtils.WHITE, new ColorMapperIdentity(), g3d, 1.0); + final UGraphic ug = new UGraphicG2d(HColorUtils.WHITE, new ColorMapperIdentity(), stringBounder, g3d, 1.0); drawInternal(ug); g3d.dispose(); diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index bfd163ccc..2bbcc5239 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -461,11 +461,12 @@ public class ImageBuilder { backColor = new Color(0, 0, 0, 0); } + final StringBounder stringBounder = FileFormat.PNG.getDefaultStringBounder(); final EmptyImageBuilder builder = new EmptyImageBuilder(watermark, (int) (dim.getWidth() * scaleFactor), - (int) (dim.getHeight() * scaleFactor), backColor); + (int) (dim.getHeight() * scaleFactor), backColor, stringBounder); final Graphics2D graphics2D = builder.getGraphics2D(); - final UGraphicG2d ug = new UGraphicG2d(backcolor, colorMapper, graphics2D, scaleFactor, + final UGraphicG2d ug = new UGraphicG2d(backcolor, colorMapper, stringBounder, graphics2D, scaleFactor, affineTransforms == null ? null : affineTransforms.getFirst(), dx, dy); ug.setBufferedImage(builder.getBufferedImage()); final BufferedImage im = ug.getBufferedImage(); diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java index bdbda0546..c8c086691 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java @@ -50,9 +50,9 @@ import java.util.Objects; import java.util.Set; import net.sourceforge.plantuml.EnsureVisible; -import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.Url; import net.sourceforge.plantuml.anim.AffineTransformation; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.png.PngIO; import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic; @@ -116,13 +116,13 @@ public class UGraphicG2d extends AbstractUGraphic implements EnsureV register(dpiFactor); } - public UGraphicG2d(HColor defaultBackground, ColorMapper colorMapper, Graphics2D g2d, double dpiFactor) { - this(defaultBackground, colorMapper, g2d, dpiFactor, null, 0, 0); + public UGraphicG2d(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, Graphics2D g2d, double dpiFactor) { + this(defaultBackground, colorMapper, stringBounder, g2d, dpiFactor, null, 0, 0); } - public UGraphicG2d(HColor defaultBackground, ColorMapper colorMapper, Graphics2D g2d, double dpiFactor, + public UGraphicG2d(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, Graphics2D g2d, double dpiFactor, AffineTransformation affineTransform, double dx, double dy) { - super(defaultBackground, colorMapper, FileFormat.PNG.getDefaultStringBounder(), g2d); + super(defaultBackground, colorMapper, stringBounder, g2d); this.hasAffineTransform = affineTransform != null; this.dpiFactor = dpiFactor; if (dpiFactor != 1.0) { From 102d67271c5608275ad0241599c066815dc26a5d Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 05:39:53 +1100 Subject: [PATCH 11/47] Pass a StringBounder into DriverTextG2d & DriverTextAsPathG2d --- .../ugraphic/g2d/DriverTextAsPathG2d.java | 15 ++++++++------- .../plantuml/ugraphic/g2d/DriverTextG2d.java | 18 +++++++++--------- .../plantuml/ugraphic/g2d/UGraphicG2d.java | 4 ++-- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextAsPathG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextAsPathG2d.java index d9aacf87c..5c5dd3cb5 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextAsPathG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextAsPathG2d.java @@ -48,7 +48,6 @@ import java.awt.geom.Rectangle2D; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EnsureVisible; -import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.Log; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.FontStyle; @@ -64,9 +63,11 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class DriverTextAsPathG2d implements UDriver { private final EnsureVisible visible; + private final StringBounder stringBounder; - public DriverTextAsPathG2d(EnsureVisible visible) { + public DriverTextAsPathG2d(EnsureVisible visible, StringBounder stringBounder) { this.visible = visible; + this.stringBounder = stringBounder; } private static void printFont() { @@ -83,7 +84,7 @@ public class DriverTextAsPathG2d implements UDriver { final FontConfiguration fontConfiguration = shape.getFontConfiguration(); final UFont font = fontConfiguration.getFont().scaled(param.getScale()); - final Dimension2D dimBack = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, shape.getText()); + final Dimension2D dimBack = calculateDimension(font, shape.getText()); if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) { final Color extended = mapper.toColor(fontConfiguration.getExtendedColor()); if (extended != null) { @@ -108,14 +109,14 @@ public class DriverTextAsPathG2d implements UDriver { if (extended != null) { g2d.setColor(mapper.toColor(extended)); } - final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, shape.getText()); + final Dimension2D dim = calculateDimension(font, shape.getText()); final int ypos = (int) (y + 2.5); g2d.setStroke(new BasicStroke((float) 1)); g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); g2d.setStroke(new BasicStroke()); } if (fontConfiguration.containsStyle(FontStyle.WAVE)) { - final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, shape.getText()); + final Dimension2D dim = calculateDimension(font, shape.getText()); final int ypos = (int) (y + 2.5) - 1; final HColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { @@ -127,7 +128,7 @@ public class DriverTextAsPathG2d implements UDriver { } } if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { - final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, shape.getText()); + final Dimension2D dim = calculateDimension(font, shape.getText()); final FontMetrics fm = g2d.getFontMetrics(font.getUnderlayingFont()); final int ypos = (int) (y - fm.getDescent() - 0.5); final HColor extended = fontConfiguration.getExtendedColor(); @@ -140,7 +141,7 @@ public class DriverTextAsPathG2d implements UDriver { } } - static public Dimension2D calculateDimension(StringBounder stringBounder, UFont font, String text) { + public Dimension2D calculateDimension(UFont font, String text) { final Dimension2D rect = stringBounder.calculateDimension(font, text); double h = rect.getHeight(); if (h < 10) { diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java index 11f49133d..a45c1ed47 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java @@ -48,7 +48,6 @@ import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EnsureVisible; -import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.FontStyle; import net.sourceforge.plantuml.graphic.StringBounder; @@ -66,9 +65,11 @@ import net.sourceforge.plantuml.ugraphic.color.HColorUtils; public class DriverTextG2d implements UDriver { private final EnsureVisible visible; + private final StringBounder stringBounder; - public DriverTextG2d(EnsureVisible visible) { + public DriverTextG2d(EnsureVisible visible, StringBounder stringBounder) { this.visible = visible; + this.stringBounder = stringBounder; } public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) { @@ -87,8 +88,7 @@ public class DriverTextG2d implements UDriver { for (StyledString styledString : strings) { final FontConfiguration fc = styledString.getStyle() == FontStyle.BOLD ? fontConfiguration.bold() : fontConfiguration; - final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), fc.getFont(), - styledString.getText()); + final Dimension2D dim = calculateDimension(fc.getFont(), styledString.getText()); printSingleText(g2d, fc, styledString.getText(), x, y, mapper, param); x += dim.getWidth(); } @@ -113,7 +113,7 @@ public class DriverTextG2d implements UDriver { } else if (orientation == 0) { - final Dimension2D dimBack = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, text); + final Dimension2D dimBack = calculateDimension(font, text); if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) { final Rectangle2D.Double area = new Rectangle2D.Double(x, y - dimBack.getHeight() + 1.5, dimBack.getWidth(), dimBack.getHeight()); @@ -143,14 +143,14 @@ public class DriverTextG2d implements UDriver { if (extended != null) { g2d.setColor(mapper.toColor(extended)); } - final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, text); + final Dimension2D dim = calculateDimension(font, text); final int ypos = (int) (y + 2.5); g2d.setStroke(new BasicStroke((float) 1)); g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); g2d.setStroke(new BasicStroke()); } if (fontConfiguration.containsStyle(FontStyle.WAVE)) { - final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, text); + final Dimension2D dim = calculateDimension(font, text); final int ypos = (int) (y + 2.5) - 1; if (extended != null) { g2d.setColor(mapper.toColor(extended)); @@ -161,7 +161,7 @@ public class DriverTextG2d implements UDriver { } } if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { - final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, text); + final Dimension2D dim = calculateDimension(font, text); final FontMetrics fm = g2d.getFontMetrics(font.getUnderlayingFont()); final int ypos = (int) (y - fm.getDescent() - 0.5); if (extended != null) { @@ -174,7 +174,7 @@ public class DriverTextG2d implements UDriver { } } - static public Dimension2D calculateDimension(StringBounder stringBounder, UFont font, String text) { + public Dimension2D calculateDimension(UFont font, String text) { final Dimension2D rect = stringBounder.calculateDimension(font, text); double h = rect.getHeight(); if (h < 10) { diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java index c8c086691..1322261f9 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java @@ -140,9 +140,9 @@ public class UGraphicG2d extends AbstractUGraphic implements EnsureV private void register(double dpiFactor) { registerDriver(URectangle.class, new DriverRectangleG2d(dpiFactor, this)); if (this.hasAffineTransform || dpiFactor != 1.0) { - registerDriver(UText.class, new DriverTextAsPathG2d(this)); + registerDriver(UText.class, new DriverTextAsPathG2d(this, getStringBounder())); } else { - registerDriver(UText.class, new DriverTextG2d(this)); + registerDriver(UText.class, new DriverTextG2d(this, getStringBounder())); } registerDriver(ULine.class, new DriverLineG2d(dpiFactor)); registerDriver(UPixel.class, new DriverPixelG2d()); From c38b269089a4272bc124354ef6c50a87485a6440 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 06:11:03 +1100 Subject: [PATCH 12/47] Simplify StringBounder code in ImageBuilder --- .../plantuml/ugraphic/ImageBuilder.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index 2bbcc5239..887a53818 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -121,6 +121,7 @@ public class ImageBuilder { private String metadata; private long seed = 42; private ISkinParam skinParam; + private StringBounder stringBounder; private int status = 0; private TitledDiagram titledDiagram; private boolean randomPixel; @@ -140,6 +141,7 @@ public class ImageBuilder { private ImageBuilder(FileFormatOption fileFormatOption) { this.fileFormatOption = fileFormatOption; + this.stringBounder = fileFormatOption.getDefaultStringBounder(SvgCharSizeHack.NO_HACK); } public ImageBuilder annotations(boolean annotations) { @@ -198,10 +200,6 @@ public class ImageBuilder { return this; } - private SvgCharSizeHack getSvgCharSizeHack() { - return skinParam == null ? SvgCharSizeHack.NO_HACK : skinParam; - } - private String getSvgLinkTarget() { if (fileFormatOption.getSvgLinkTarget() != null) { return fileFormatOption.getSvgLinkTarget(); @@ -219,6 +217,7 @@ public class ImageBuilder { public ImageBuilder styled(TitledDiagram diagram) { skinParam = diagram.getSkinParam(); + stringBounder = fileFormatOption.getDefaultStringBounder(skinParam); animation = diagram.getAnimation(); annotations = true; backcolor = diagram.calculateBackColor(); @@ -235,8 +234,6 @@ public class ImageBuilder { if (annotations && titledDiagram != null) { if (!(udrawable instanceof TextBlock)) throw new IllegalStateException("udrawable is not a TextBlock"); - final ISkinParam skinParam = titledDiagram.getSkinParam(); - final StringBounder stringBounder = fileFormatOption.getDefaultStringBounder(skinParam); final AnnotatedWorker annotatedWorker = new AnnotatedWorker(titledDiagram, skinParam, stringBounder); udrawable = annotatedWorker.addAdd((TextBlock) udrawable); } @@ -325,8 +322,7 @@ public class ImageBuilder { private Dimension2D getFinalDimension() { if (dimension == null) { - final LimitFinder limitFinder = new LimitFinder( - fileFormatOption.getDefaultStringBounder(getSvgCharSizeHack()), true); + final LimitFinder limitFinder = new LimitFinder(stringBounder, true); udrawable.drawU(limitFinder); dimension = new Dimension2DDouble(limitFinder.getMaxX() + 1 + margin.getLeft() + margin.getRight(), limitFinder.getMaxY() + 1 + margin.getTop() + margin.getBottom()); @@ -418,9 +414,9 @@ public class ImageBuilder { case VDX: return new UGraphicVdx(backcolor, colorMapper); case LATEX: - return new UGraphicTikz(backcolor, colorMapper, FileFormat.LATEX.getDefaultStringBounder(option.getTikzFontDistortion()), scaleFactor, true); + return new UGraphicTikz(backcolor, colorMapper, stringBounder, scaleFactor, true); case LATEX_NO_PREAMBLE: - return new UGraphicTikz(backcolor, colorMapper, FileFormat.LATEX.getDefaultStringBounder(option.getTikzFontDistortion()), scaleFactor, false); + return new UGraphicTikz(backcolor, colorMapper, stringBounder, scaleFactor, false); case BRAILLE_PNG: return new UGraphicBraille(backcolor, colorMapper); case UTXT: @@ -441,7 +437,7 @@ public class ImageBuilder { final boolean svgDimensionStyle = skinParam == null || skinParam.svgDimensionStyle(); final String svgLinkTarget = getSvgLinkTarget(); final UGraphicSvg ug = new UGraphicSvg(backcolor, svgDimensionStyle, dim, colorMapper, false, scaleFactor, - svgLinkTarget, hoverPathColorRGB, seed, preserveAspectRatio, FileFormat.SVG.getDefaultStringBounder(getSvgCharSizeHack()), lengthAdjust); + svgLinkTarget, hoverPathColorRGB, seed, preserveAspectRatio, stringBounder, lengthAdjust); return ug; } @@ -461,7 +457,6 @@ public class ImageBuilder { backColor = new Color(0, 0, 0, 0); } - final StringBounder stringBounder = FileFormat.PNG.getDefaultStringBounder(); final EmptyImageBuilder builder = new EmptyImageBuilder(watermark, (int) (dim.getWidth() * scaleFactor), (int) (dim.getHeight() * scaleFactor), backColor, stringBounder); final Graphics2D graphics2D = builder.getGraphics2D(); From ead2698f010a4bb9d705a25fee41c5bc12c07c20 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Sun, 3 Oct 2021 06:12:31 +1100 Subject: [PATCH 13/47] Remove redundant getDefaultStringBounder() methods --- src/net/sourceforge/plantuml/FileFormat.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/net/sourceforge/plantuml/FileFormat.java b/src/net/sourceforge/plantuml/FileFormat.java index 52ed6d6ae..9ea941f7b 100644 --- a/src/net/sourceforge/plantuml/FileFormat.java +++ b/src/net/sourceforge/plantuml/FileFormat.java @@ -132,14 +132,6 @@ public enum FileFormat { return getDefaultStringBounder(TikzFontDistortion.getDefault(), SvgCharSizeHack.NO_HACK); } - public StringBounder getDefaultStringBounder(SvgCharSizeHack charSizeHack) { - return getDefaultStringBounder(TikzFontDistortion.getDefault(), charSizeHack); - } - - public StringBounder getDefaultStringBounder(TikzFontDistortion tikzFontDistortion) { - return getDefaultStringBounder(tikzFontDistortion, SvgCharSizeHack.NO_HACK); - } - public StringBounder getDefaultStringBounder(TikzFontDistortion tikzFontDistortion, SvgCharSizeHack charSizeHack) { if (this == LATEX || this == LATEX_NO_PREAMBLE) { return getTikzStringBounder(tikzFontDistortion); From d8ad68d9c20082805fda3d670fba41302967f8d1 Mon Sep 17 00:00:00 2001 From: The-Lum <86879521+The-Lum@users.noreply.github.com> Date: Sun, 3 Oct 2021 17:38:04 +0200 Subject: [PATCH 14/47] Create puml-theme-_none_.puml A no theme named `_none_` (intentionally empty) Especially to have a `no theme` (first or last in alphabetical order) to compare with all the others. --- themes/puml-theme-_none_.puml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 themes/puml-theme-_none_.puml diff --git a/themes/puml-theme-_none_.puml b/themes/puml-theme-_none_.puml new file mode 100644 index 000000000..b6d5f619e --- /dev/null +++ b/themes/puml-theme-_none_.puml @@ -0,0 +1,6 @@ +'' +'' A no theme named `_none_` (intentionally empty) +'' Especially to have a `no theme` (first or last in alphabetical order) to compare with all the others +'' +'' Original Author: The-Lum +'' From 11de152d92688a1824f51e7d27077573ebe4677f Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Sun, 3 Oct 2021 23:01:18 +0200 Subject: [PATCH 15/47] Import version 1.2021.11 --- .../activitydiagram3/InstructionRepeat.java | 4 +- .../vcompact/ConnectionVerticalDown.java | 7 +- .../vcompact/FtileFactoryDelegatorRepeat.java | 2 +- .../ftile/vcompact/FtileIfDown.java | 5 +- .../ftile/vcompact/FtileIfLongHorizontal.java | 1 + .../ftile/vcompact/FtileRepeat.java | 99 ++++++++-------- .../ftile/vcompact/FtileWhile.java | 2 + .../ftile/vcompact/ParallelBuilderFork.java | 2 + .../ftile/vcompact/ParallelBuilderMerge.java | 1 + .../ftile/vcompact/ParallelBuilderSplit.java | 2 + .../ftile/vcompact/cond/FtileIfWithLinks.java | 10 +- .../plantuml/donors/PSystemDonors.java | 46 +++---- .../plantuml/graphic/QuoteUtils.java | 4 +- .../plantuml/nwdiag/CommandEndSomething.java | 2 +- .../plantuml/nwdiag/NwDiagram.java | 112 ++++++++++-------- .../plantuml/nwdiag/core/NServer.java | 23 +++- .../plantuml/nwdiag/core/NStackable.java | 45 +++++++ .../plantuml/nwdiag/core/Network.java | 4 +- .../plantuml/nwdiag/core/NwGroup.java | 6 +- .../plantuml/timingdiagram/PlayerAnalog.java | 3 - .../plantuml/timingdiagram/PlayerBinary.java | 3 - .../plantuml/timingdiagram/PlayerClock.java | 64 ++++++++-- .../plantuml/timingdiagram/TimingDiagram.java | 6 +- .../timingdiagram/command/CommandClock.java | 32 +++-- .../sourceforge/plantuml/version/Version.java | 6 +- 25 files changed, 315 insertions(+), 176 deletions(-) create mode 100644 src/net/sourceforge/plantuml/nwdiag/core/NStackable.java diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java index 19d356e4d..5504fadf5 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java @@ -131,9 +131,9 @@ public class InstructionRepeat implements Instruction { if (Display.isNull(backward)) { return null; } - Ftile result = factory.activity(backward, swimlane, boxStyle, Colors.empty(), null); + Ftile result = factory.activity(backward, swimlaneOut, boxStyle, Colors.empty(), null); if (backwardNotes.size() > 0) { - result = factory.addNote(result, swimlane, backwardNotes); + result = factory.addNote(result, swimlaneOut, backwardNotes); } return result; } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ConnectionVerticalDown.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ConnectionVerticalDown.java index d125ae253..300dbfdd9 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ConnectionVerticalDown.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ConnectionVerticalDown.java @@ -76,16 +76,15 @@ public class ConnectionVerticalDown extends AbstractConnection implements Connec } private Snake getSimpleSnake() { - final Snake snake = Snake.create(color, Arrows.asToDown()).withLabel(textBlock, - arrowHorizontalAlignment()); + final Snake snake = Snake.create(color, Arrows.asToDown()).withLabel(textBlock, arrowHorizontalAlignment()); snake.addPoint(p1); snake.addPoint(p2); return snake; } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { - final Snake snake = Snake.create(color, Arrows.asToDown()).withLabel(textBlock, - arrowHorizontalAlignment()); + final Snake snake = Snake.create(color, Arrows.asToDown()).withLabel(textBlock, arrowHorizontalAlignment()); final Point2D mp1a = translate1.getTranslated(p1); final Point2D mp2b = translate2.getTranslated(p2); final double middle = (mp1a.getY() + mp2b.getY()) / 2.0; diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorRepeat.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorRepeat.java index 68a64d106..0b8ce2049 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorRepeat.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorRepeat.java @@ -114,7 +114,7 @@ public class FtileFactoryDelegatorRepeat extends FtileFactoryDelegator { final LinkRendering endRepeatLinkRendering = repeat.getOutLinkRendering(); final Rainbow endRepeatLinkColor = endRepeatLinkRendering == null ? null : endRepeatLinkRendering.getRainbow(); - final Ftile entry = getEntry(swimlane, startLabel, colors, boxStyleIn); + final Ftile entry = getEntry(repeat.getSwimlaneIn(), startLabel, colors, boxStyleIn); Ftile result = FtileRepeat.create(swimlane, swimlaneOut, entry, repeat, test, yes, out, borderColor, diamondColor, arrowColor, endRepeatLinkColor, conditionStyle, this.skinParam(), fcDiamond, fcArrow, diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfDown.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfDown.java index 4f29cd953..9cd9fe916 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfDown.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfDown.java @@ -205,6 +205,7 @@ public class FtileIfDown extends AbstractFtile { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { final StringBounder stringBounder = ug.getStringBounder(); final Point2D p1 = getP1(stringBounder); @@ -266,6 +267,7 @@ public class FtileIfDown extends AbstractFtile { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { if (getFtile1().calculateDimension(ug.getStringBounder()).hasPointOut() == false) { @@ -329,8 +331,7 @@ public class FtileIfDown extends AbstractFtile { final double xmax = Math.max(x1 + Diamond.diamondHalfSize, getTranslateForThen(stringBounder).getDx() + thenGeom.getWidth()); - final Snake snake = Snake.create(endInlinkColor, Arrows.asToLeft()) - .emphasizeDirection(Direction.DOWN); + final Snake snake = Snake.create(endInlinkColor, Arrows.asToLeft()).emphasizeDirection(Direction.DOWN); snake.addPoint(x1, y1); snake.addPoint(xmax, y1); snake.addPoint(xmax, y2); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfLongHorizontal.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfLongHorizontal.java index 23b79357b..9960e36eb 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfLongHorizontal.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfLongHorizontal.java @@ -402,6 +402,7 @@ class FtileIfLongHorizontal extends AbstractFtile { return getTranslate1(getFtile2(), stringBounder).getTranslated(p); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { final Point2D p1 = getP1(ug.getStringBounder()); final Point2D p2 = getP2(ug.getStringBounder()); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java index 1e4c9d734..c2dcc1885 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java @@ -121,7 +121,8 @@ class FtileRepeat extends AbstractFtile { FontConfiguration fcDiamond, FontConfiguration fcArrow, Ftile backward, boolean noOut, LinkRendering incoming1, LinkRendering incoming2) { - final FontConfiguration fontConfiguration1 = conditionStyle == ConditionStyle.INSIDE_HEXAGON ? fcDiamond : fcArrow; + final FontConfiguration fontConfiguration1 = conditionStyle == ConditionStyle.INSIDE_HEXAGON ? fcDiamond + : fcArrow; final TextBlock tbTest = (Display.isNull(test) || test.isWhite()) ? TextBlockUtils.empty(0, 0) : test.create(fontConfiguration1, repeat.skinParam().getDefaultTextAlignment(HorizontalAlignment.LEFT), @@ -168,22 +169,17 @@ class FtileRepeat extends AbstractFtile { : incoming1.getDisplay().create7(fcArrow, HorizontalAlignment.LEFT, spriteContainer, CreoleMode.SIMPLE_LINE); - if (repeat.getSwimlaneIn() == null || repeat.getSwimlaneIn() == swimlaneOut) { - if (backward == null) { - conns.add(result.new ConnectionBackSimple(incoming1.getRainbow(arrowColor), incomingText)); - } else { - final Rainbow rainbow1 = incoming1.getRainbow(arrowColor); - conns.add(result.new ConnectionBackBackward1(rainbow1, incomingText)); - final TextBlock backArrowLabel = incoming2 == null || incoming2.getDisplay() == null ? null - : incoming2.getDisplay().create(fcArrow, HorizontalAlignment.LEFT, spriteContainer); - final Rainbow rainbow2 = incoming2.getRainbow(arrowColor); - conns.add(result.new ConnectionBackBackward2(rainbow2, backArrowLabel)); - } + if (backward != null) { + final Rainbow rainbow1 = incoming1.getRainbow(arrowColor); + conns.add(result.new ConnectionBackBackward1(rainbow1, incomingText)); + final TextBlock backArrowLabel = incoming2 == null || incoming2.getDisplay() == null ? null + : incoming2.getDisplay().create(fcArrow, HorizontalAlignment.LEFT, spriteContainer); + final Rainbow rainbow2 = incoming2.getRainbow(arrowColor); + conns.add(result.new ConnectionBackBackward2(rainbow2, backArrowLabel)); + } else if (repeat.getSwimlaneIn() == null || repeat.getSwimlaneIn() == swimlaneOut) { + conns.add(result.new ConnectionBackSimple(incoming1.getRainbow(arrowColor), incomingText)); } else { conns.add(result.new ConnectionBackComplex1(incoming1.getRainbow(arrowColor))); - // conns.add(result.new - // ConnectionBackComplexHorizontalOnly(incoming1.getRainbow(arrowColor), - // incomingText)); } final Display out1 = repeat.getOutLinkRendering().getDisplay(); @@ -260,6 +256,7 @@ class FtileRepeat extends AbstractFtile { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { final StringBounder stringBounder = ug.getStringBounder(); if (getFtile1().calculateDimension(stringBounder).hasPointOut() == false) { @@ -304,6 +301,7 @@ class FtileRepeat extends AbstractFtile { // throw new UnsupportedOperationException(); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { final StringBounder stringBounder = ug.getStringBounder(); final Dimension2D dimRepeat = repeat.calculateDimension(stringBounder); @@ -345,39 +343,6 @@ class FtileRepeat extends AbstractFtile { } -// class ConnectionBackComplexHorizontalOnly extends AbstractConnection { -// private final Rainbow arrowColor; -// private final TextBlock tbback; -// -// public ConnectionBackComplexHorizontalOnly(Rainbow arrowColor, TextBlock tbback) { -// super(diamond2, diamond2); -// this.arrowColor = arrowColor; -// this.tbback = tbback; -// } -// -// private Point2D getP1(final StringBounder stringBounder) { -// return getTranslateDiamond2(stringBounder).getTranslated(new Point2D.Double(0, 0)); -// } -// -// public void drawU(UGraphic ug) { -// final StringBounder stringBounder = ug.getStringBounder(); -// -// final Snake snake = Snake.create(arrowColor, null).withLabel(tbback, arrowHorizontalAlignment()); -// final Dimension2D dimRepeat = repeat.calculateDimension(stringBounder); -// final Point2D p1 = getP1(stringBounder); -// final Dimension2D dimDiamond2 = diamond2.calculateDimension(stringBounder); -// final double x1 = p1.getX() + dimDiamond2.getWidth(); -// final double y1 = p1.getY() + dimDiamond2.getHeight() / 2; -// -// snake.addPoint(x1, y1); -// final double xmax = p1.getX() + dimDiamond2.getWidth() / 2 + dimRepeat.getWidth() / 2 -// + Diamond.diamondHalfSize; -// snake.addPoint(xmax, y1); -// ug.draw(snake); -// } -// -// } - class ConnectionBackBackward1 extends AbstractConnection { private final Rainbow arrowColor; private final TextBlock tbback; @@ -400,7 +365,6 @@ class FtileRepeat extends AbstractFtile { public void drawU(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); - final Snake snake = Snake.create(arrowColor, Arrows.asToUp()).withLabel(tbback, arrowHorizontalAlignment()); final Point2D p1 = getP1(stringBounder); final Point2D p2 = getP2(stringBounder); final Dimension2D dimDiamond2 = diamond2.calculateDimension(stringBounder); @@ -409,6 +373,8 @@ class FtileRepeat extends AbstractFtile { final double x2 = p2.getX(); final double y2 = p2.getY(); + final Snake snake = Snake.create(arrowColor, Arrows.asToUp()).withLabel(tbback, arrowHorizontalAlignment()); + snake.addPoint(x1, y1); snake.addPoint(x2, y1); snake.addPoint(x2, y2); @@ -418,7 +384,7 @@ class FtileRepeat extends AbstractFtile { } - class ConnectionBackBackward2 extends AbstractConnection { + class ConnectionBackBackward2 extends AbstractConnection implements ConnectionTranslatable { private final Rainbow arrowColor; private final TextBlock label; @@ -437,11 +403,41 @@ class FtileRepeat extends AbstractFtile { return getTranslateDiamond1(stringBounder).getTranslated(new Point2D.Double(0, 0)); } + @Override + public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { + final StringBounder stringBounder = ug.getStringBounder(); + + Point2D p1 = getP1(stringBounder); + Point2D p2 = getP2(stringBounder); + p1 = translate1.getTranslated(p1); + p2 = translate2.getTranslated(p2); + + final Dimension2D dimDiamond1 = diamond1.calculateDimension(stringBounder); + + final double x1 = p1.getX(); + final double y1 = p1.getY(); + double x2 = p2.getX(); + if (x2 < x1) + x2 += dimDiamond1.getWidth(); + final double y2 = p2.getY() + dimDiamond1.getHeight() / 2; + + Snake snake = Snake.create(arrowColor, x2 < x1 ? Arrows.asToLeft() : Arrows.asToRight()); + if (label != null) { + snake = snake.withLabel(label, arrowHorizontalAlignment()); + } + + snake.addPoint(x1, y1); + snake.addPoint(x1, y2); + snake.addPoint(x2, y2); + + ug.draw(snake); + + } + public void drawU(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); Snake snake = Snake.create(arrowColor, Arrows.asToLeft()); - // .emphasizeDirection(Direction.UP); if (label != null) { snake = snake.withLabel(label, arrowHorizontalAlignment()); } @@ -504,6 +500,7 @@ class FtileRepeat extends AbstractFtile { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { final StringBounder stringBounder = ug.getStringBounder(); final Snake snake = Snake.create(arrowColor, Arrows.asToLeft()).emphasizeDirection(Direction.UP) diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWhile.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWhile.java index ae02c0ecf..104fb80e0 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWhile.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWhile.java @@ -196,6 +196,7 @@ class FtileWhile extends AbstractFtile { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { final StringBounder stringBounder = ug.getStringBounder(); final Point2D p1 = getP1(stringBounder); @@ -271,6 +272,7 @@ class FtileWhile extends AbstractFtile { } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { final StringBounder stringBounder = ug.getStringBounder(); final Snake snake = Snake.create(endInlinkColor, Arrows.asToLeft()).withMerge(MergeStrategy.LIMITED); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderFork.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderFork.java index 597bcbf3b..7c4a5b4e7 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderFork.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderFork.java @@ -244,6 +244,7 @@ public class ParallelBuilderFork extends AbstractParallelFtilesBuilder { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { ug = ug.apply(UTranslate.dx(x)); final FtileGeometry geo2 = getFtile2().calculateDimension(getStringBounder()); @@ -297,6 +298,7 @@ public class ParallelBuilderFork extends AbstractParallelFtilesBuilder { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { ug = ug.apply(UTranslate.dx(x)); final FtileGeometry geo = getFtile1().calculateDimension(getStringBounder()); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderMerge.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderMerge.java index 230710e90..68c087466 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderMerge.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderMerge.java @@ -225,6 +225,7 @@ public class ParallelBuilderMerge extends AbstractParallelFtilesBuilder { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { ug = ug.apply(UTranslate.dx(x)); final FtileGeometry geo = getFtile2().calculateDimension(getStringBounder()); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderSplit.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderSplit.java index 4578c1cd2..2f3c0794e 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderSplit.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderSplit.java @@ -236,6 +236,7 @@ public class ParallelBuilderSplit extends AbstractParallelFtilesBuilder { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { ug = ug.apply(UTranslate.dx(x)); final FtileGeometry geo = getFtile2().calculateDimension(getStringBounder()); @@ -292,6 +293,7 @@ public class ParallelBuilderSplit extends AbstractParallelFtilesBuilder { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { ug = ug.apply(UTranslate.dx(x)); final FtileGeometry geo = getFtile1().calculateDimension(getStringBounder()); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java index 74bec1163..e1240a8c1 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java @@ -135,6 +135,7 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { throw new IllegalStateException(); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { final StringBounder stringBounder = ug.getStringBounder(); Point2D p1 = getP1(stringBounder); @@ -223,6 +224,7 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { throw new IllegalStateException(); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { final StringBounder stringBounder = ug.getStringBounder(); final FtileGeometry geo = getFtile1().calculateDimension(stringBounder); @@ -313,6 +315,7 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { ug.draw(snake); } + @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { final StringBounder stringBounder = ug.getStringBounder(); final FtileGeometry dimTotal = calculateDimensionInternal(stringBounder); @@ -416,7 +419,7 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { super(null, null); this.arrowColor = arrowColor; } - + public void drawU(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); final Dimension2D totalDim = calculateDimensionInternal(stringBounder); @@ -446,7 +449,7 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { s.addPoint(maxX, totalDim.getHeight()); ug.draw(s); } - + private double[] getMinmax(StringBounder stringBounder, double width, List allTiles, Swimlane intoSw, List allSwimlanes) { final int current = allSwimlanes.indexOf(intoSw); @@ -499,7 +502,7 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { } return new double[] { minX, maxX }; } - + private int getFirstSwimlane(StringBounder stringBounder, List allTiles, List allSwimlanes) { for (int i = 0; i < allSwimlanes.size(); i++) { if (atLeastOne(stringBounder, allSwimlanes.get(i), allTiles)) { @@ -529,7 +532,6 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { return ftile.getSwimlaneOut() == swimlane && ftile.getSwimlanes().contains(swimlane); } - } public Ftile addLinks(Branch branch1, Branch branch2, StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/donors/PSystemDonors.java b/src/net/sourceforge/plantuml/donors/PSystemDonors.java index f608f8986..0db4f213a 100644 --- a/src/net/sourceforge/plantuml/donors/PSystemDonors.java +++ b/src/net/sourceforge/plantuml/donors/PSystemDonors.java @@ -70,29 +70,29 @@ public class PSystemDonors extends PlainDiagram { private static final int COLS = 6; private static final int FREE_LINES = 6; - public static final String DONORS = "6zeD0AmFjCllA6nYeh4EstErPvQF9MScYM1vdb2SMCJfBY3-0FTEZ_kDz1VHbUvzqunHwxL9EOEeFWXw" - + "mBlRGljG-byVX3bBNWHtfWGNa0AYEBf4VgGRsKwVL1bIWcUfwEzlcRYztJekL2Q9lX7AWU9-EMJWRVfi" - + "dft6XqOlK0t-zf1sN_tVfRDrULKLfWNThS08Z3gDSAJiDVwFQb575Em4DUpqOpgLgreErQh4PjkR8bf9" - + "SyUiqD3EHvqc5yLaf4ZnraOANZ6OeIadiq-HN_f5uu-w2HrQgsk8vGuWpfdIe-kstgx7WrX-iSG7mHLy" - + "GHQ1EP1o95v4otFJZOQB1muDkwZ6bfNSyyGAGIgqa3V_A9AItaCykmnk6curGE3rDWf8ng0cJJZRTpUW" - + "qXviqQM1gwxr5-RMTLYUoisauGd4mis2Ma0DGUA3Nj0PVUMMoJqFXIqXJqayfwr6_Pbu9srpGT_uKX8m" - + "NpjFpSp-Y56s7j8uSf_phyuEUDUGbQlVZ3d2EOEwlCm5CTzQe7u4UcnEM1BVK-uif23KH-gc3vrhJseL" - + "uPHSKYhMwKjiUItt3rrfams9vEbWoNotV5rhYWTRw2ga6dX3gpJDEb_0f8Rw-qiUBPtlWcjAnUuDYpOY" - + "kuRelvzRcXcA0tHeYjdGJG26iKghpc834UmMEZRW9e4SXF9fSicVbb-Yj_m4m5jA15rXGz8CVlzIyf23" - + "2p6GgUjIN00idbBgHSFZ0GkLEWJTZYgXz3Pt_GoJbctBni8oQHVFEmt6o8_fbEB2V9bBU8HXgLeqvpwi" - + "7S0kmRFvECshxZFDLO1BXVUOZMl_ae4ymvmHaQBJ5Oz7sXRpK8TX5cFEIrrqJxUJWuTkFN0sY-OneqmU" - + "iXmO74v6JRr5w4E3uMyAsHnxhKNr2RQ7w_JWPaOUl9wQt5AJ8neksrcEdIq2aip5AtPHuVo2jImZcQDh" - + "2P4ZLaz2XlnEzKbOgiI5fWaxbxi6psHw5EJXl2TMFUh757GkeAgO9WX92sRE49I7hGKoi5RHCzS6iVkb" - + "7GlwDZyvSPP3yMKJxJHkoC8Kc1uYlU4W4ZC7iXAzr2GHm7T_tArUPgr37D_TqufnaBIGn40LcTFfFoWp" - + "zTOZD8tr5ltVrjhBilFdNsjaarEplVOUWcWT90KWmWjqb0j214-1hpSR9WDEM255Jp9SkMxfUI1XmLRw" - + "u2RgT9jHl-F5SXDoqThpGvN-DBKeEEiRKbo4WlBPboXfxQKULDJshMySRd8m_5rKcPJ9lRsCfib8-0Ig" - + "E7V7RZCLzTYi0IAO0vK9ZDtzMPd6KyRShr2g3Cy4ylqM6PAC7bfOKzFAk11OAvtRUolR4C_e_u8H_QZM" - + "kUTUFJITvEe6YeZ2jod8k22Ik5oa7GYmcsjEFEZc6p_oGRLG1fPspR1p1YlaD_GZl95mp3O-KEGn5ytJ" - + "NiXXMyZUDGly2S1x20zaOR5Aho8MIZaUI94Kp5ajarcadRG5f_GEe5CKZF_VEn0kDz7yYimky-gDP2xJ" - + "t8yhY7ouFul4fYLR8t9WFoDpsVOLkLrpaGuxzJ_m7UUx7r6tBoB82iIC97Zj9gIx6tjKczZCU6xGu3Wk" - + "y-DWyelO5Uq2oS3ML6n1Lh8PAF4a1BL39XLclP9VtHzSSowHV-_TIs6W2Sypjz2Dv_fW5TbQYwUa0JKt" - + "MNpNlZzm9uiJ2YSU2rnO9cxqCALRotogNJTjDf169NALYl4UPdRJ4YK_qVMakXmokVM2cYMXTTsPeZCu" - + "jWLpwTgvvuKPNEetKtqcfCT0m_Mb1W00"; + public static final String DONORS = "6mOE03mSRygAqa-2sUB1zgHs3y67oAViE8BbUK9nOX6dku3u0zmxFUutqbz4LtRlcsP4hTScvGoY-Y3e" + + "0Uzk2-r3wNzz4EOiUH7ScH9SG0g8ukWI-P5kP3jzKcL82RxyZVJFg8c_kaepeSDd0_UtWMiJ21dDARPx" + + "cJAlLqYb59-_yX7w138rLbrJbICmjvO2rb-oUYLzo_zDdQtBGo7CqjqAZC2eQ8JBFFOO_vygg70ATWur" + + "xFHZEfLKBOTgLMApxKqHhQIvOrQeR_9Hg-QY62r5YdyqKl2BP8R6dCm-ILxqcyOVTHCwN9yAoN9FG6TR" + + "FJgVz7QkAx7y8j67W2VuWcm6Hi1of2wY-RdfHiF30mxrkwZ6bfRSyoG9Wane8H_-KPYINf9dLy1Dmwi6" + + "8FpUXWAI7DIeXhELkm6LbDYYqy9L5_k5kMKTbgTod3GyXLXucQW5L0aI7tH1PzGyRqtkxWPRfAT4Ozeg" + + "bCy2EsYR2_h6bXB1V6qVcYNuAqQvbDGupdlltxKNWDtIygg7CKSuPw0kMoZ4U6k1-X7eiJbXYRwct5d8" + + "WgYFqvi-TAuvgLM4Kt9BMQpJbx3bjPmVkgJ91YLv2YpwU-ANOWjui4bNKwe1NsYLf5dd2vYqpD-N7Yt_" + + "VI-ufaJith1e8rmXwQ_V4PiP2W4wE8NPq4q136MLLXt51YBOBNHiW7O4qWdbo779H_oIFl8J06yk8Rh2" + + "HaWJ-FFBaeSEBc8WKzUcS06m-PIYBXe-3x1GeIdeLbG9fRVny9qvMlOvRMnQ9ktcURl16FandQLOcAzG" + + "uH669Nf6SyxRsaVO9NWM7wTvrNkMSnNWKk4zQkFQBpBWvmmP4IawNV5UpsoPXmd3BFQSbodTyyZWuA5R" + + "3jpDeZdCA9E7B1i6XnDHhO-4_hOO_fOXcvtN6bIVOEjqdH7SpCY2rrkJMwevek6noI9EDWb8CnUlE2KB" + + "5n2iPTd971Kb8j-nUX8ov7UgJy9IfIuqZTXOxYeyetiKvE6y9rOzvayVw5n0bMeJXAG5Crj2-SpyW0oi" + + "LVJCjYHs__U51MFhsnCJX-BB9jf-SWF159WUmddW81B9G5gYbpKn0lZkZxlLqsiTvl6tBwSO1qaBIGHK" + + "GQOptb1cwgazmiPwY_wVj6MB2t_-jKURd9hisdi8edKG5u08Bz1HBWWXdW9V7pPC1vnWYOiECbovPkbP" + + "8B9W2trm4tLvcz6uunVBZSj5QyyFLVBTt0uNyy4tfBW85ULzJIcPjfb1DT8ltdMuoK7nTr5bM2INlJcP" + + "Z8HDe8fpT-pMDjHZoG0pc0EL2UpT_LbPQ6ZC_Ggaod02vFijaaf6XHPMQreH2u4rSk7stfQJyepwJ4Rq" + + "axNE6Nlrq3Z8rVKN8GhV3WbvGPYuNIHE1EZDDISMTFDD0FcYMYY9fHqTTkvWXVmF_WZUI3Xc6nzOv0cb" + + "UPODENIJx8EpG7qWxo4ia8d5Ibr5B9HoF90YAPYpMiQpIDjf2yxe7K2dA1Z_tziGBYVH_8fcbrxLIEPo" + + "pBsuWiY6-xj8R56oDI0T-rhcigqpSZld8Xrswd_WEyvtFg9kNKH00b5BWjUMWtHtOvzQ6ZQrvteLnt6P" + + "fuF9BsHNjFELWQtnOWkodCr0YIS1X1q85P9NuLVx1wuvvyYlzwbI6AZXUUOMTEEvDp0MAvR4KzA0waqM" + + "vTht1-xanGc54ui5BYmLRlGmgLihd6h7JPlrf569NALYl8Snkxcav9yg1fNIDRcze6P9Q5rtbj4Pd6nX" + + "Bi_xl7jX1fNw9UfJmHu33TU7RvmXlRAiOXyX50RLk31POW00"; /* * Special thanks to our sponsors and donors: diff --git a/src/net/sourceforge/plantuml/graphic/QuoteUtils.java b/src/net/sourceforge/plantuml/graphic/QuoteUtils.java index ccc95a697..e9943859b 100644 --- a/src/net/sourceforge/plantuml/graphic/QuoteUtils.java +++ b/src/net/sourceforge/plantuml/graphic/QuoteUtils.java @@ -304,8 +304,8 @@ public class QuoteUtils { "Lbh jnag gb tb ubzr naq erguvax lbhe yvsr", "V'z trggva gbb byq sbe guvf fuvg", "Vg'f n jryy xabja snpg gung n tybony pbafcvenpl jbhyq or ng gur bevtva bs znal snxr pbafcvenpl gurbevrf", "Gh nhenvf ienvzrag qh pubvfve ha nhger zrgvre.", - "...rg qrf srfgvaf qr ebv fhe yr mvap q'ha ohssrg qr tner", - "Obevf, V guvax lbh'er tbaan arrq n ovttre ohf"); + "...rg qrf srfgvaf qr ebv fhe yr mvap q'ha ohssrg qr tner", "Obevf, V guvax lbh'er tbaan arrq n ovttre ohf", + "Cebtenzzvat vf na neg sbez gung svtugf onpx", "Jr ernyyl fubhyq trg fbzr cncrejrvtugf"); private QuoteUtils() { } diff --git a/src/net/sourceforge/plantuml/nwdiag/CommandEndSomething.java b/src/net/sourceforge/plantuml/nwdiag/CommandEndSomething.java index 4de68ceff..759724510 100644 --- a/src/net/sourceforge/plantuml/nwdiag/CommandEndSomething.java +++ b/src/net/sourceforge/plantuml/nwdiag/CommandEndSomething.java @@ -58,7 +58,7 @@ public class CommandEndSomething extends SingleLineCommand2 { @Override protected CommandExecutionResult executeArg(NwDiagram diagram, LineLocation location, RegexResult arg) { - return diagram.endSomething(); + return diagram.closeSomething(); } } diff --git a/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java b/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java index c808fd6ed..f6ac17a2c 100644 --- a/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java +++ b/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java @@ -63,6 +63,7 @@ import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.graphic.UDrawable; import net.sourceforge.plantuml.nwdiag.core.NServer; +import net.sourceforge.plantuml.nwdiag.core.NStackable; import net.sourceforge.plantuml.nwdiag.core.Network; import net.sourceforge.plantuml.nwdiag.core.NwGroup; import net.sourceforge.plantuml.nwdiag.next.GridTextBlockDecorated; @@ -103,19 +104,41 @@ public class NwDiagram extends UmlDiagram { initDone = true; } - private Network currentNetwork() { + private Network lastNetwork() { if (networks.size() == 0) { return null; } return networks.get(networks.size() - 1); } + private Network stackedNetwork() { + for (NStackable element : stack) + if (element instanceof Network) + return (Network) element; + return null; + } + + private NwGroup stakedGroup() { + for (NStackable element : stack) + if (element instanceof NwGroup) + return (NwGroup) element; + return null; + } + + private final List stack = new ArrayList(); + public CommandExecutionResult openGroup(String name) { if (initDone == false) { return errorNoInit(); } - currentGroup = new NwGroup(name, currentNetwork()); - groups.add(currentGroup); + for (NStackable element : stack) + if (element instanceof NwGroup) + return CommandExecutionResult.error("Cannot nest group"); + + final NwGroup newGroup = new NwGroup(name); + stack.add(0, newGroup); + groups.add(newGroup); + currentGroup = newGroup; return CommandExecutionResult.ok(); } @@ -123,7 +146,21 @@ public class NwDiagram extends UmlDiagram { if (initDone == false) { return errorNoInit(); } - createNetwork(name); + for (NStackable element : stack) + if (element instanceof Network) + return CommandExecutionResult.error("Cannot nest network"); + final Network network = createNetwork(name); + stack.add(0, network); + return CommandExecutionResult.ok(); + } + + public CommandExecutionResult closeSomething() { + if (initDone == false) { + return errorNoInit(); + } + if (stack.size() > 0) + stack.remove(0); + this.currentGroup = null; return CommandExecutionResult.ok(); } @@ -137,41 +174,25 @@ public class NwDiagram extends UmlDiagram { if (initDone == false) { return errorNoInit(); } - final NServer element; - if (currentNetwork() == null) { + final NServer server2; + if (lastNetwork() == null) { createNetwork(name1); - element = new NServer(name2); + server2 = new NServer(name2); } else { - final NServer already = servers.get(name1); + final NServer server1 = servers.get(name1); final Network network1 = createNetwork(""); network1.goInvisible(); - if (already != null) { - connect(already, toSet(null)); + if (server1 != null) { + server1.connectTo(lastNetwork()); } - element = new NServer(name2, already.getBar()); + server2 = new NServer(name2, server1.getBar()); } - servers.put(name2, element); - addInternal(element, toSet(null)); + servers.put(name2, server2); + server2.connectTo(lastNetwork()); + playField.addInPlayfield(server2.getBar()); return CommandExecutionResult.ok(); } - private void addInternal(NServer server, Map props) { - connect(server, props); - final String description = props.get("description"); - if (description != null) { - server.setDescription(description); - } - final String shape = props.get("shape"); - if (shape != null) { - server.setShape(shape); - } - playField.addInPlayfield(server.getBar()); - } - - private void connect(NServer server, final Map props) { - server.connect(currentNetwork(), props); - } - public CommandExecutionResult addElement(String name, String definition) { if (initDone == false) { return errorNoInit(); @@ -180,7 +201,7 @@ public class NwDiagram extends UmlDiagram { currentGroup.addName(name); } NServer server = null; - if (currentNetwork() == null) { + if (lastNetwork() == null) { if (currentGroup != null) { return CommandExecutionResult.ok(); } @@ -197,15 +218,10 @@ public class NwDiagram extends UmlDiagram { servers.put(name, server); } } - addInternal(server, toSet(definition)); - return CommandExecutionResult.ok(); - } - - public CommandExecutionResult endSomething() { - if (initDone == false) { - return errorNoInit(); - } - this.currentGroup = null; + final Map props = toSet(definition); + server.connectTo(lastNetwork(), props.get("address")); + server.updateProperties(props); + playField.addInPlayfield(server.getBar()); return CommandExecutionResult.ok(); } @@ -357,7 +373,7 @@ public class NwDiagram extends UmlDiagram { NwGroup group = getGroupOf(server); if (group != null) topMargin += group.getTopHeaderHeight(stringBounder, getSkinParam()); - grid.add(i, col, server.asTextBlock(topMargin, conns, networks, getSkinParam())); + grid.add(i, col, server.getLinkedElement(topMargin, conns, networks, getSkinParam())); } } } @@ -378,24 +394,24 @@ public class NwDiagram extends UmlDiagram { if (initDone == false) { return errorNoInit(); } - if ("address".equalsIgnoreCase(property) && currentNetwork() != null) { - currentNetwork().setOwnAdress(value); + if ("address".equalsIgnoreCase(property) && lastNetwork() != null) { + lastNetwork().setOwnAdress(value); } - if ("width".equalsIgnoreCase(property) && currentNetwork() != null) { - currentNetwork().setFullWidth("full".equalsIgnoreCase(value)); + if ("width".equalsIgnoreCase(property) && lastNetwork() != null) { + lastNetwork().setFullWidth("full".equalsIgnoreCase(value)); } if ("color".equalsIgnoreCase(property)) { final HColor color = value == null ? null : getSkinParam().getIHtmlColorSet().getColorOrWhite(getSkinParam().getThemeStyle(), value); if (currentGroup != null) { currentGroup.setColor(color); - } else if (currentNetwork() != null) { - currentNetwork().setColor(color); + } else if (lastNetwork() != null) { + lastNetwork().setColor(color); } } if ("description".equalsIgnoreCase(property)) { if (currentGroup == null) { - currentNetwork().setDescription(value); + lastNetwork().setDescription(value); } else { currentGroup.setDescription(value); } diff --git a/src/net/sourceforge/plantuml/nwdiag/core/NServer.java b/src/net/sourceforge/plantuml/nwdiag/core/NServer.java index 5c92a590d..800587efa 100644 --- a/src/net/sourceforge/plantuml/nwdiag/core/NServer.java +++ b/src/net/sourceforge/plantuml/nwdiag/core/NServer.java @@ -106,7 +106,7 @@ public class NServer { return style.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); } - public LinkedElement asTextBlock(double topMargin, Map conns, List networks, + public LinkedElement getLinkedElement(double topMargin, Map conns, List networks, ISkinParam skinParam) { final StyleBuilder styleBuilder = skinParam.getCurrentStyleBuilder(); final SymbolContext symbolContext = getStyleDefinition(SName.server).getMergedStyle(styleBuilder) @@ -123,11 +123,13 @@ public class NServer { return new LinkedElement(topMargin, this, box, conns2, networks); } - public void connect(Network network, Map props) { - String address = props.get("address"); - if (address == null) { + public void connectTo(Network network) { + connectTo(network, ""); + } + + public void connectTo(Network network, String address) { + if (address == null) address = ""; - } if (address.length() == 0 && connections.containsKey(network)) { return; } @@ -138,6 +140,17 @@ public class NServer { bar.addStage(network.getUp()); } + public void updateProperties(Map props) { + final String description = props.get("description"); + if (description != null) { + this.setDescription(description); + } + final String shape = props.get("shape"); + if (shape != null) { + this.setShape(shape); + } + } + @Override public final String toString() { return name; diff --git a/src/net/sourceforge/plantuml/nwdiag/core/NStackable.java b/src/net/sourceforge/plantuml/nwdiag/core/NStackable.java new file mode 100644 index 000000000..9b6a86aed --- /dev/null +++ b/src/net/sourceforge/plantuml/nwdiag/core/NStackable.java @@ -0,0 +1,45 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * http://plantuml.com/patreon (only 1$ per month!) + * http://plantuml.com/paypal + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * + * Original Author: Arnaud Roques + * + */ +package net.sourceforge.plantuml.nwdiag.core; + +import net.sourceforge.plantuml.ugraphic.color.HColor; + +public interface NStackable { + + public void setDescription(String description); + + public void setColor(HColor color); + +} diff --git a/src/net/sourceforge/plantuml/nwdiag/core/Network.java b/src/net/sourceforge/plantuml/nwdiag/core/Network.java index b7bf8915d..d3facae88 100644 --- a/src/net/sourceforge/plantuml/nwdiag/core/Network.java +++ b/src/net/sourceforge/plantuml/nwdiag/core/Network.java @@ -37,7 +37,7 @@ package net.sourceforge.plantuml.nwdiag.core; import net.sourceforge.plantuml.nwdiag.next.NStage; import net.sourceforge.plantuml.ugraphic.color.HColor; -public class Network { +public class Network implements NStackable { private final String name; private String description; @@ -93,6 +93,7 @@ public class Network { return this.description; } + @Override public void setDescription(String description) { this.description = description; } @@ -101,6 +102,7 @@ public class Network { return color; } + @Override public final void setColor(HColor color) { this.color = color; } diff --git a/src/net/sourceforge/plantuml/nwdiag/core/NwGroup.java b/src/net/sourceforge/plantuml/nwdiag/core/NwGroup.java index e8ace9aec..bd42d566e 100644 --- a/src/net/sourceforge/plantuml/nwdiag/core/NwGroup.java +++ b/src/net/sourceforge/plantuml/nwdiag/core/NwGroup.java @@ -57,7 +57,7 @@ import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; -public class NwGroup { +public class NwGroup implements NStackable { private final Set names = new HashSet<>(); @@ -94,7 +94,7 @@ public class NwGroup { return "NwGroup:" + name + " " + names + " " + nbox; } - public NwGroup(String name, Object... unused) { + public NwGroup(String name) { this.name = name; } @@ -106,10 +106,12 @@ public class NwGroup { return color; } + @Override public final void setColor(HColor color) { this.color = color; } + @Override public final void setDescription(String value) { this.description = value; } diff --git a/src/net/sourceforge/plantuml/timingdiagram/PlayerAnalog.java b/src/net/sourceforge/plantuml/timingdiagram/PlayerAnalog.java index 15e807c4c..988c9cbec 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/PlayerAnalog.java +++ b/src/net/sourceforge/plantuml/timingdiagram/PlayerAnalog.java @@ -98,9 +98,6 @@ public class PlayerAnalog extends Player { return suggestedHeight; } - public void drawFrameTitle(UGraphic ug) { - } - private SymbolContext getContext() { return new SymbolContext(HColorUtils.COL_D7E0F2, HColorUtils.COL_038048).withStroke(new UStroke(1.5)); } diff --git a/src/net/sourceforge/plantuml/timingdiagram/PlayerBinary.java b/src/net/sourceforge/plantuml/timingdiagram/PlayerBinary.java index 25734f85a..549592288 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/PlayerBinary.java +++ b/src/net/sourceforge/plantuml/timingdiagram/PlayerBinary.java @@ -78,9 +78,6 @@ public class PlayerBinary extends Player { return getHeightForConstraints(stringBounder) + suggestedHeight; } - public void drawFrameTitle(UGraphic ug) { - } - private SymbolContext getContext() { return new SymbolContext(HColorUtils.COL_D7E0F2, HColorUtils.COL_038048).withStroke(new UStroke(1.5)); } diff --git a/src/net/sourceforge/plantuml/timingdiagram/PlayerClock.java b/src/net/sourceforge/plantuml/timingdiagram/PlayerClock.java index 63fd4c769..addf95d47 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/PlayerClock.java +++ b/src/net/sourceforge/plantuml/timingdiagram/PlayerClock.java @@ -34,11 +34,13 @@ */ package net.sourceforge.plantuml.timingdiagram; +import java.awt.geom.Dimension2D; import java.math.BigDecimal; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.command.Position; import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.AbstractTextBlock; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.SymbolContext; import net.sourceforge.plantuml.graphic.TextBlock; @@ -46,6 +48,7 @@ import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.graphic.UDrawable; import net.sourceforge.plantuml.graphic.color.Colors; import net.sourceforge.plantuml.timingdiagram.graphic.IntricatedPoint; +import net.sourceforge.plantuml.timingdiagram.graphic.PlayerFrame; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UStroke; @@ -56,20 +59,32 @@ public class PlayerClock extends Player { private final int period; private final int pulse; + private final int offset; private final double ymargin = 8; + private final boolean displayTitle; - public PlayerClock(ISkinParam skinParam, TimingRuler ruler, int period, int pulse, boolean compact) { - super("", skinParam, ruler, compact); + public PlayerClock(String title, ISkinParam skinParam, TimingRuler ruler, int period, int pulse, int offset, + boolean compact) { + super(title, skinParam, ruler, compact); + this.displayTitle = title.length() > 0; this.period = period; this.pulse = pulse; + this.offset = offset; this.suggestedHeight = 30; } - public double getFullHeight(StringBounder striWngBounder) { - return suggestedHeight; + public double getFullHeight(StringBounder stringBounder) { + return suggestedHeight + getTitleHeight(stringBounder); } - public void drawFrameTitle(UGraphic ug) { + private double getLineHeight(StringBounder stringBounder) { + return suggestedHeight - 2 * ymargin; + } + + private double getTitleHeight(StringBounder stringBounder) { + if (displayTitle) + return getTitle().calculateDimension(stringBounder).getHeight(); + return 0; } private SymbolContext getContext() { @@ -103,11 +118,26 @@ public class PlayerClock extends Player { return 1.0 * pulse / period; } + private double getOffsetCoef() { + return 1.0 * offset / period; + } + public final int getPeriod() { return period; } public TextBlock getPart1(double fullAvailableWidth, double specialVSpace) { + if (displayTitle) + return new AbstractTextBlock() { + + public void drawU(UGraphic ug) { + new PlayerFrame(getTitle()).drawFrameTitle(ug); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return getTitle().calculateDimension(stringBounder); + } + }; return TextBlockUtils.empty(0, 0); } @@ -115,7 +145,8 @@ public class PlayerClock extends Player { return new UDrawable() { public void drawU(UGraphic ug) { ug = getContext().apply(ug); - final ULine vline = ULine.vline(getFullHeight(ug.getStringBounder()) - 2 * ymargin); + ug = ug.apply(UTranslate.dy(getTitleHeight(ug.getStringBounder()))); + final ULine vline = ULine.vline(getLineHeight(ug.getStringBounder())); int i = 0; double lastx = -Double.MAX_VALUE; while (i < 1000) { @@ -127,13 +158,22 @@ public class PlayerClock extends Player { i++; if (x > lastx) { final double dx = x - lastx; - final ULine hline1 = ULine.hline(dx * getPulseCoef()); - final ULine hline2 = ULine.hline(dx * (1 - getPulseCoef())); - ug.apply(new UTranslate(lastx, ymargin)).draw(vline); - ug.apply(new UTranslate(lastx, ymargin)).draw(hline1); - final double x2 = lastx + dx * getPulseCoef(); + + final ULine hline1 = ULine.hline(dx * getOffsetCoef()); + final ULine hline2 = ULine.hline(dx * getPulseCoef()); + final ULine hline3 = ULine.hline(dx * (1 - getPulseCoef() - getOffsetCoef())); + + final double x2 = lastx + dx * getOffsetCoef(); + final double x3 = lastx + dx * (getOffsetCoef() + getPulseCoef()); + + if (offset > 0) + ug.apply(new UTranslate(lastx, ymargin + vline.getDY())).draw(hline1); + ug.apply(new UTranslate(x2, ymargin)).draw(hline2); + ug.apply(new UTranslate(x3, ymargin + vline.getDY())).draw(hline3); + ug.apply(new UTranslate(x2, ymargin)).draw(vline); - ug.apply(new UTranslate(x2, ymargin + vline.getDY())).draw(hline2); + ug.apply(new UTranslate(x3, ymargin)).draw(vline); + } lastx = x; } diff --git a/src/net/sourceforge/plantuml/timingdiagram/TimingDiagram.java b/src/net/sourceforge/plantuml/timingdiagram/TimingDiagram.java index 26d0c90cf..1bd098b17 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/TimingDiagram.java +++ b/src/net/sourceforge/plantuml/timingdiagram/TimingDiagram.java @@ -286,8 +286,10 @@ public class TimingDiagram extends UmlDiagram implements Clocks { return CommandExecutionResult.ok(); } - public CommandExecutionResult createClock(String code, String full, int period, int pulse, boolean compact) { - final PlayerClock player = new PlayerClock(getSkinParam(), ruler, period, pulse, compactByDefault); + public CommandExecutionResult createClock(String code, String full, int period, int pulse, int offset, + boolean compact) { + final PlayerClock player = new PlayerClock(full, getSkinParam(), ruler, period, pulse, offset, + compactByDefault); players.put(code, player); clocks.put(code, player); final TimeTick tick = new TimeTick(new BigDecimal(period), TimingFormat.DECIMAL); diff --git a/src/net/sourceforge/plantuml/timingdiagram/command/CommandClock.java b/src/net/sourceforge/plantuml/timingdiagram/command/CommandClock.java index 20a879f33..6ee7be642 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/command/CommandClock.java +++ b/src/net/sourceforge/plantuml/timingdiagram/command/CommandClock.java @@ -59,6 +59,11 @@ public class CommandClock extends SingleLineCommand2 { RegexLeaf.spaceOneOrMore())), // new RegexLeaf("TYPE", "clock"), // RegexLeaf.spaceOneOrMore(), // + new RegexOptional(new RegexConcat( // + new RegexLeaf("FULL", "[%g]([^%g]+)[%g]"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("as"), // + RegexLeaf.spaceOneOrMore())), // new RegexLeaf("CODE", "([%pLN_.@]+)"), // RegexLeaf.spaceOneOrMore(), // new RegexLeaf("with"), // @@ -71,7 +76,14 @@ public class CommandClock extends SingleLineCommand2 { new RegexLeaf("pulse"), // RegexLeaf.spaceOneOrMore(), // new RegexLeaf("PULSE", "([0-9]+)") // - )), RegexLeaf.end()); + )), // + new RegexOptional(new RegexConcat( // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("offset"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("OFFSET", "([0-9]+)") // + )), // + RegexLeaf.end()); } @Override @@ -79,12 +91,18 @@ public class CommandClock extends SingleLineCommand2 { final String compact = arg.get("COMPACT", 0); final String code = arg.get("CODE", 0); final int period = Integer.parseInt(arg.get("PERIOD", 0)); - final String pulseString = arg.get("PULSE", 0); - int pulse = 0; - if (pulseString != null) { - pulse = Integer.parseInt(pulseString); - } - return diagram.createClock(code, code, period, pulse, compact != null); + final int pulse = getInt(arg.get("PULSE", 0)); + final int offset = getInt(arg.get("OFFSET", 0)); + String full = arg.get("FULL", 0); + if (full == null) + full = ""; + return diagram.createClock(code, full, period, pulse, offset, compact != null); + } + + private int getInt(String value) { + if (value == null) + return 0; + return Integer.parseInt(value); } } diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 57e1e69e5..e77af740b 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -44,7 +44,7 @@ public class Version { private static final int MAJOR_SEPARATOR = 1000000; public static int version() { - return 1202110; + return 1202111; } public static int versionPatched() { @@ -80,7 +80,7 @@ public class Version { } public static int beta() { - final int beta = 6; + final int beta = 0; return beta; } @@ -93,7 +93,7 @@ public class Version { } public static long compileTime() { - return 1630331028954L; + return 1633181171844L; } public static String compileTimeString() { From a02ff86cbdc71b712be9dc5ac4215a5e5b330780 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Mon, 4 Oct 2021 22:00:11 +1100 Subject: [PATCH 16/47] Delete UScale and related code as it is now unused. --- .../ugraphic/AbstractCommonUGraphic.java | 11 +--- .../plantuml/ugraphic/AbstractUGraphic.java | 8 +-- .../plantuml/ugraphic/LimitFinder.java | 1 - .../plantuml/ugraphic/Scalable.java | 41 ------------ .../plantuml/ugraphic/UEllipse.java | 11 +--- .../sourceforge/plantuml/ugraphic/UFont.java | 8 --- .../sourceforge/plantuml/ugraphic/ULine.java | 11 +--- .../sourceforge/plantuml/ugraphic/UParam.java | 2 - .../plantuml/ugraphic/UParamNull.java | 6 -- .../plantuml/ugraphic/URectangle.java | 12 +--- .../sourceforge/plantuml/ugraphic/UScale.java | 63 ------------------- .../plantuml/ugraphic/g2d/DriverLineG2d.java | 2 +- .../ugraphic/g2d/DriverTextAsPathG2d.java | 2 +- .../plantuml/ugraphic/g2d/DriverTextG2d.java | 8 +-- 14 files changed, 10 insertions(+), 176 deletions(-) delete mode 100644 src/net/sourceforge/plantuml/ugraphic/Scalable.java delete mode 100644 src/net/sourceforge/plantuml/ugraphic/UScale.java diff --git a/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java b/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java index 0b10d8498..244c6441e 100644 --- a/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java +++ b/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java @@ -58,7 +58,6 @@ public abstract class AbstractCommonUGraphic implements UGraphic { private final ColorMapper colorMapper; private UClip clip; - private double scale = 1; private final HColor defaultBackground; @@ -75,7 +74,7 @@ public abstract class AbstractCommonUGraphic implements UGraphic { Objects.requireNonNull(change); final AbstractCommonUGraphic copy = copyUGraphic(); if (change instanceof UTranslate) { - copy.translate = ((UTranslate) change).scaled(scale).compose(copy.translate); + copy.translate = ((UTranslate) change).compose(copy.translate); } else if (change instanceof UClip) { copy.clip = (UClip) change; copy.clip = copy.clip.translate(getTranslateX(), getTranslateY()); @@ -91,9 +90,6 @@ public abstract class AbstractCommonUGraphic implements UGraphic { copy.color = null; } else if (change instanceof HColor) { copy.color = (HColor) change; - } else if (change instanceof UScale) { - final double factor = ((UScale) change).getScale(); - copy.scale = scale * factor; } return copy; } @@ -128,7 +124,6 @@ public abstract class AbstractCommonUGraphic implements UGraphic { this.hidden = other.hidden; this.color = other.color; this.backColor = other.backColor; - this.scale = other.scale; } protected abstract AbstractCommonUGraphic copyUGraphic(); @@ -155,10 +150,6 @@ public abstract class AbstractCommonUGraphic implements UGraphic { public UPattern getPattern() { return pattern; } - - public double getScale() { - return scale; - } }; } diff --git a/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java b/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java index 6a9b78485..c2704705c 100644 --- a/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java +++ b/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java @@ -93,13 +93,7 @@ public abstract class AbstractUGraphic extends AbstractCommonUGraphic { return; } beforeDraw(); - if (shape instanceof Scalable) { - final double scale = getParam().getScale(); - shape = ((Scalable) shape).getScaled(scale); - driver.draw(shape, getTranslateX(), getTranslateY(), getColorMapper(), getParam(), graphic); - } else { - driver.draw(shape, getTranslateX(), getTranslateY(), getColorMapper(), getParam(), graphic); - } + driver.draw(shape, getTranslateX(), getTranslateY(), getColorMapper(), getParam(), graphic); afterDraw(); } diff --git a/src/net/sourceforge/plantuml/ugraphic/LimitFinder.java b/src/net/sourceforge/plantuml/ugraphic/LimitFinder.java index f073c3650..fc29b3098 100644 --- a/src/net/sourceforge/plantuml/ugraphic/LimitFinder.java +++ b/src/net/sourceforge/plantuml/ugraphic/LimitFinder.java @@ -72,7 +72,6 @@ public class LimitFinder extends UGraphicNo { UClip.class, HColor.class, UHidden.class, - UScale.class, UStroke.class, UTranslate.class )) { diff --git a/src/net/sourceforge/plantuml/ugraphic/Scalable.java b/src/net/sourceforge/plantuml/ugraphic/Scalable.java deleted file mode 100644 index f4b4ea011..000000000 --- a/src/net/sourceforge/plantuml/ugraphic/Scalable.java +++ /dev/null @@ -1,41 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009-2020, Arnaud Roques - * - * Project Info: http://plantuml.com - * - * If you like this project or if you find it useful, you can support us at: - * - * http://plantuml.com/patreon (only 1$ per month!) - * http://plantuml.com/paypal - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * - * Original Author: Arnaud Roques - * - * - */ -package net.sourceforge.plantuml.ugraphic; - -public interface Scalable { - - public UShape getScaled(double scale); -} diff --git a/src/net/sourceforge/plantuml/ugraphic/UEllipse.java b/src/net/sourceforge/plantuml/ugraphic/UEllipse.java index b8faca214..f18bb3bea 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UEllipse.java +++ b/src/net/sourceforge/plantuml/ugraphic/UEllipse.java @@ -40,22 +40,13 @@ import java.awt.geom.Point2D; import net.sourceforge.plantuml.Dimension2DDouble; -public class UEllipse extends AbstractShadowable implements Scalable, UShapeSized { +public class UEllipse extends AbstractShadowable implements UShapeSized { private final double width; private final double height; private final double start; private final double extend; - public UShape getScaled(double scale) { - if (scale == 1) { - return this; - } - final AbstractShadowable result = new UEllipse(width * scale, height * scale, start, extend); - result.setDeltaShadow(this.getDeltaShadow()); - return result; - } - public UEllipse(double width, double height) { this(width, height, 0, 0); } diff --git a/src/net/sourceforge/plantuml/ugraphic/UFont.java b/src/net/sourceforge/plantuml/ugraphic/UFont.java index 0e78914e0..6a4d86797 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UFont.java +++ b/src/net/sourceforge/plantuml/ugraphic/UFont.java @@ -116,14 +116,6 @@ public class UFont { return font; } - public UFont scaled(double scale) { - if (scale == 1) { - return this; - } - final float current = font.getSize2D(); - return withSize((float) (current * scale)); - } - public UFont withSize(float size) { return new UFont(font.deriveFont(size), family); } diff --git a/src/net/sourceforge/plantuml/ugraphic/ULine.java b/src/net/sourceforge/plantuml/ugraphic/ULine.java index a8affa1f6..0fe095ab7 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ULine.java +++ b/src/net/sourceforge/plantuml/ugraphic/ULine.java @@ -37,20 +37,11 @@ package net.sourceforge.plantuml.ugraphic; import java.awt.geom.Point2D; -public class ULine extends AbstractShadowable implements Scalable, UShapeSized { +public class ULine extends AbstractShadowable implements UShapeSized { private final double dx; private final double dy; - public UShape getScaled(double scale) { - if (scale == 1) { - return this; - } - final AbstractShadowable result = new ULine(dx * scale, dy * scale); - result.setDeltaShadow(this.getDeltaShadow()); - return result; - } - public ULine(Point2D p1, Point2D p2) { this(p2.getX() - p1.getX(), p2.getY() - p1.getY()); } diff --git a/src/net/sourceforge/plantuml/ugraphic/UParam.java b/src/net/sourceforge/plantuml/ugraphic/UParam.java index 2a9f0cf92..10a7340d4 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UParam.java +++ b/src/net/sourceforge/plantuml/ugraphic/UParam.java @@ -48,6 +48,4 @@ public interface UParam { public boolean isHidden(); public UPattern getPattern(); - - public double getScale(); } diff --git a/src/net/sourceforge/plantuml/ugraphic/UParamNull.java b/src/net/sourceforge/plantuml/ugraphic/UParamNull.java index b17d4dbbd..c55264e57 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UParamNull.java +++ b/src/net/sourceforge/plantuml/ugraphic/UParamNull.java @@ -58,10 +58,4 @@ public class UParamNull implements UParam { public UPattern getPattern() { return UPattern.FULL; } - - public double getScale() { - return 1; - } - - } diff --git a/src/net/sourceforge/plantuml/ugraphic/URectangle.java b/src/net/sourceforge/plantuml/ugraphic/URectangle.java index b21462847..07e0bf8b2 100644 --- a/src/net/sourceforge/plantuml/ugraphic/URectangle.java +++ b/src/net/sourceforge/plantuml/ugraphic/URectangle.java @@ -39,7 +39,7 @@ import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.ugraphic.comp.CompressionMode; -public class URectangle extends AbstractShadowable implements Scalable, UShapeSized, UShapeIgnorableForCompression { +public class URectangle extends AbstractShadowable implements UShapeSized, UShapeIgnorableForCompression { private final double width; private final double height; @@ -102,16 +102,6 @@ public class URectangle extends AbstractShadowable implements Scalable, UShapeSi return new URectangle(width, height, rx, ry, comment, ignoreForCompressionOnX, true, codeLine); } - public UShape getScaled(double scale) { - if (scale == 1) { - return this; - } - final AbstractShadowable result = new URectangle(width * scale, height * scale, rx * scale, ry * scale, comment, - ignoreForCompressionOnX, ignoreForCompressionOnY, codeLine); - result.setDeltaShadow(this.getDeltaShadow()); - return result; - } - public URectangle(double width, double height) { this(width, height, 0, 0, null, false, false, null); } diff --git a/src/net/sourceforge/plantuml/ugraphic/UScale.java b/src/net/sourceforge/plantuml/ugraphic/UScale.java deleted file mode 100644 index 937994080..000000000 --- a/src/net/sourceforge/plantuml/ugraphic/UScale.java +++ /dev/null @@ -1,63 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009-2020, Arnaud Roques - * - * Project Info: http://plantuml.com - * - * If you like this project or if you find it useful, you can support us at: - * - * http://plantuml.com/patreon (only 1$ per month!) - * http://plantuml.com/paypal - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * - * Original Author: Arnaud Roques - * - * - */ -package net.sourceforge.plantuml.ugraphic; - - -public class UScale implements UChange { - - private final double scale; - - @Override - public String toString() { - return "scale scale=" + scale; - } - - public UScale(double scale) { - this.scale = scale; - } - - public double getScale() { - return scale; - } - -// public Point2D getTranslated(Point2D p) { -// if (p == null) { -// return null; -// } -// return new Point2D.Double(p.getX() + dx, p.getY() + dy); -// } - -} diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverLineG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverLineG2d.java index f844a9a03..30084854b 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverLineG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverLineG2d.java @@ -73,7 +73,7 @@ public class DriverLineG2d extends DriverShadowedG2d implements UDriver { final UText shape = (UText) ushape; final FontConfiguration fontConfiguration = shape.getFontConfiguration(); - final UFont font = fontConfiguration.getFont().scaled(param.getScale()); + final UFont font = fontConfiguration.getFont(); final Dimension2D dimBack = calculateDimension(font, shape.getText()); if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) { final Color extended = mapper.toColor(fontConfiguration.getExtendedColor()); diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java index a45c1ed47..e5e8259d8 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java @@ -83,20 +83,18 @@ public class DriverTextG2d implements UDriver { final List strings = StyledString.build(text); - final UFont font = fontConfiguration.getFont().scaled(param.getScale()); - for (StyledString styledString : strings) { final FontConfiguration fc = styledString.getStyle() == FontStyle.BOLD ? fontConfiguration.bold() : fontConfiguration; final Dimension2D dim = calculateDimension(fc.getFont(), styledString.getText()); - printSingleText(g2d, fc, styledString.getText(), x, y, mapper, param); + printSingleText(g2d, fc, styledString.getText(), x, y, mapper); x += dim.getWidth(); } } private void printSingleText(Graphics2D g2d, final FontConfiguration fontConfiguration, final String text, double x, - double y, ColorMapper mapper, UParam param) { - final UFont font = fontConfiguration.getFont().scaled(param.getScale()); + double y, ColorMapper mapper) { + final UFont font = fontConfiguration.getFont(); final HColor extended = fontConfiguration.getExtendedColor(); final int orientation = 0; From abc3ca620f149bf7123c14b64ec780b0c57eb700 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Mon, 4 Oct 2021 23:56:35 +1100 Subject: [PATCH 17/47] Remove some redundant calls to StringBounder.calculateDimension() --- .../ugraphic/g2d/DriverTextAsPathG2d.java | 33 +++++--------- .../plantuml/ugraphic/g2d/DriverTextG2d.java | 43 +++++++------------ 2 files changed, 27 insertions(+), 49 deletions(-) diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextAsPathG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextAsPathG2d.java index 0dec81911..8428d20f2 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextAsPathG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextAsPathG2d.java @@ -35,6 +35,7 @@ */ package net.sourceforge.plantuml.ugraphic.g2d; +import static java.lang.Math.max; import static net.sourceforge.plantuml.graphic.TextBlockUtils.createTextLayout; import java.awt.BasicStroke; @@ -46,7 +47,6 @@ import java.awt.font.TextLayout; import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; -import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EnsureVisible; import net.sourceforge.plantuml.Log; import net.sourceforge.plantuml.graphic.FontConfiguration; @@ -84,18 +84,20 @@ public class DriverTextAsPathG2d implements UDriver { final FontConfiguration fontConfiguration = shape.getFontConfiguration(); final UFont font = fontConfiguration.getFont(); - final Dimension2D dimBack = calculateDimension(font, shape.getText()); + final Dimension2D dim = stringBounder.calculateDimension(font, shape.getText()); + final double height = max(10, dim.getHeight()); + final double width = dim.getWidth(); + if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) { final Color extended = mapper.toColor(fontConfiguration.getExtendedColor()); if (extended != null) { g2d.setColor(extended); g2d.setBackground(extended); - g2d.fill(new Rectangle2D.Double(x, y - dimBack.getHeight() + 1.5, dimBack.getWidth(), dimBack - .getHeight())); + g2d.fill(new Rectangle2D.Double(x, y - height + 1.5, width, height)); } } - visible.ensureVisible(x, y - dimBack.getHeight() + 1.5); - visible.ensureVisible(x + dimBack.getWidth(), y + 1.5); + visible.ensureVisible(x, y - height + 1.5); + visible.ensureVisible(x + width, y + 1.5); g2d.setFont(font.getUnderlayingFont()); g2d.setColor(mapper.toColor(fontConfiguration.getColor())); @@ -109,26 +111,23 @@ public class DriverTextAsPathG2d implements UDriver { if (extended != null) { g2d.setColor(mapper.toColor(extended)); } - final Dimension2D dim = calculateDimension(font, shape.getText()); final int ypos = (int) (y + 2.5); g2d.setStroke(new BasicStroke((float) 1)); - g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); + g2d.drawLine((int) x, ypos, (int) (x + width), ypos); g2d.setStroke(new BasicStroke()); } if (fontConfiguration.containsStyle(FontStyle.WAVE)) { - final Dimension2D dim = calculateDimension(font, shape.getText()); final int ypos = (int) (y + 2.5) - 1; final HColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { g2d.setColor(mapper.toColor(extended)); } - for (int i = (int) x; i < x + dim.getWidth() - 5; i += 6) { + for (int i = (int) x; i < x + width - 5; i += 6) { g2d.drawLine(i, ypos - 0, i + 3, ypos + 1); g2d.drawLine(i + 3, ypos + 1, i + 6, ypos - 0); } } if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { - final Dimension2D dim = calculateDimension(font, shape.getText()); final FontMetrics fm = g2d.getFontMetrics(font.getUnderlayingFont()); final int ypos = (int) (y - fm.getDescent() - 0.5); final HColor extended = fontConfiguration.getExtendedColor(); @@ -136,18 +135,8 @@ public class DriverTextAsPathG2d implements UDriver { g2d.setColor(mapper.toColor(extended)); } g2d.setStroke(new BasicStroke((float) 1.5)); - g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); + g2d.drawLine((int) x, ypos, (int) (x + width), ypos); g2d.setStroke(new BasicStroke()); } } - - public Dimension2D calculateDimension(UFont font, String text) { - final Dimension2D rect = stringBounder.calculateDimension(font, text); - double h = rect.getHeight(); - if (h < 10) { - h = 10; - } - return new Dimension2DDouble(rect.getWidth(), h); - } - } diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java index e5e8259d8..b862b917b 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java @@ -35,6 +35,8 @@ */ package net.sourceforge.plantuml.ugraphic.g2d; +import static java.lang.Math.max; + import java.awt.BasicStroke; import java.awt.Color; import java.awt.FontMetrics; @@ -46,7 +48,6 @@ import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; import java.util.List; -import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EnsureVisible; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.FontStyle; @@ -86,16 +87,18 @@ public class DriverTextG2d implements UDriver { for (StyledString styledString : strings) { final FontConfiguration fc = styledString.getStyle() == FontStyle.BOLD ? fontConfiguration.bold() : fontConfiguration; - final Dimension2D dim = calculateDimension(fc.getFont(), styledString.getText()); - printSingleText(g2d, fc, styledString.getText(), x, y, mapper); - x += dim.getWidth(); + x += printSingleText(g2d, fc, styledString.getText(), x, y, mapper); } } - private void printSingleText(Graphics2D g2d, final FontConfiguration fontConfiguration, final String text, double x, + private double printSingleText(Graphics2D g2d, final FontConfiguration fontConfiguration, final String text, double x, double y, ColorMapper mapper) { final UFont font = fontConfiguration.getFont(); final HColor extended = fontConfiguration.getExtendedColor(); + + final Dimension2D dim = stringBounder.calculateDimension(font, text); + final double height = max(10, dim.getHeight()); + final double width = dim.getWidth(); final int orientation = 0; @@ -111,13 +114,10 @@ public class DriverTextG2d implements UDriver { } else if (orientation == 0) { - final Dimension2D dimBack = calculateDimension(font, text); if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) { - final Rectangle2D.Double area = new Rectangle2D.Double(x, y - dimBack.getHeight() + 1.5, - dimBack.getWidth(), dimBack.getHeight()); + final Rectangle2D.Double area = new Rectangle2D.Double(x, y - height + 1.5, width, height); if (extended instanceof HColorGradient) { - final GradientPaint paint = DriverRectangleG2d.getPaintGradient(x, y, mapper, dimBack.getWidth(), - dimBack.getHeight(), extended); + final GradientPaint paint = DriverRectangleG2d.getPaintGradient(x, y, mapper, width, height, extended); g2d.setPaint(paint); g2d.fill(area); } else { @@ -129,8 +129,8 @@ public class DriverTextG2d implements UDriver { } } } - visible.ensureVisible(x, y - dimBack.getHeight() + 1.5); - visible.ensureVisible(x + dimBack.getWidth(), y + 1.5); + visible.ensureVisible(x, y - height + 1.5); + visible.ensureVisible(x + width, y + 1.5); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2d.setFont(font.getUnderlayingFont()); @@ -141,44 +141,33 @@ public class DriverTextG2d implements UDriver { if (extended != null) { g2d.setColor(mapper.toColor(extended)); } - final Dimension2D dim = calculateDimension(font, text); final int ypos = (int) (y + 2.5); g2d.setStroke(new BasicStroke((float) 1)); - g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); + g2d.drawLine((int) x, ypos, (int) (x + width), ypos); g2d.setStroke(new BasicStroke()); } if (fontConfiguration.containsStyle(FontStyle.WAVE)) { - final Dimension2D dim = calculateDimension(font, text); final int ypos = (int) (y + 2.5) - 1; if (extended != null) { g2d.setColor(mapper.toColor(extended)); } - for (int i = (int) x; i < x + dim.getWidth() - 5; i += 6) { + for (int i = (int) x; i < x + width - 5; i += 6) { g2d.drawLine(i, ypos - 0, i + 3, ypos + 1); g2d.drawLine(i + 3, ypos + 1, i + 6, ypos - 0); } } if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { - final Dimension2D dim = calculateDimension(font, text); final FontMetrics fm = g2d.getFontMetrics(font.getUnderlayingFont()); final int ypos = (int) (y - fm.getDescent() - 0.5); if (extended != null) { g2d.setColor(mapper.toColor(extended)); } g2d.setStroke(new BasicStroke((float) 1.5)); - g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); + g2d.drawLine((int) x, ypos, (int) (x + width), ypos); g2d.setStroke(new BasicStroke()); } } - } - - public Dimension2D calculateDimension(UFont font, String text) { - final Dimension2D rect = stringBounder.calculateDimension(font, text); - double h = rect.getHeight(); - if (h < 10) { - h = 10; - } - return new Dimension2DDouble(rect.getWidth(), h); + return width; } } From 5fb770cb5784af4fd0576aafedbe4e4978f95930 Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Mon, 4 Oct 2021 23:01:59 +0200 Subject: [PATCH 18/47] Fix arrow constraint position --- .../timingdiagram/TimeConstraint.java | 4 ++++ .../timingdiagram/graphic/Histogram.java | 24 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/net/sourceforge/plantuml/timingdiagram/TimeConstraint.java b/src/net/sourceforge/plantuml/timingdiagram/TimeConstraint.java index f44927e53..3cbdd1a93 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/TimeConstraint.java +++ b/src/net/sourceforge/plantuml/timingdiagram/TimeConstraint.java @@ -76,6 +76,10 @@ public class TimeConstraint { this.styleBuilder = skinParam.getCurrentStyleBuilder(); } + public final boolean containsStrict(TimeTick other) { + return tick1.compareTo(other) < 0 && tick2.compareTo(other) > 0; + } + public final TimeTick getTick1() { return tick1; } diff --git a/src/net/sourceforge/plantuml/timingdiagram/graphic/Histogram.java b/src/net/sourceforge/plantuml/timingdiagram/graphic/Histogram.java index 7b0a26283..d0e3ae801 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/graphic/Histogram.java +++ b/src/net/sourceforge/plantuml/timingdiagram/graphic/Histogram.java @@ -347,18 +347,16 @@ public class Histogram implements PDrawing { private void drawConstraints(UGraphic ug) { for (TimeConstraint constraint : constraints) { - final String state1 = last(getStatesAt(constraint.getTick1())); - final String state2 = getStatesAt(constraint.getTick2()).get(0); - final double y1 = yOfState(state1); - final double y2 = yOfState(state2); - constraint.drawU(ug.apply(UTranslate.dy(y1)), ruler); + double y = yOfState(constraint.getTick1()); + for (ChangeState change : changes) { + if (constraint.containsStrict(change.getWhen())) { + y = Math.min(y, yOfState(change.getWhen())); + } + } + constraint.drawU(ug.apply(UTranslate.dy(y)), ruler); } } - private static String last(List list) { - return list.get(list.size() - 1); - } - private Point2D.Double getInitialPoint() { return new Point2D.Double(-getInitialWidth(), yOfState(initialState)); } @@ -380,6 +378,14 @@ public class Histogram implements PDrawing { return stepHeight() * nb; } + private double yOfState(TimeTick when) { + return yOfState(last(getStatesAt(when))); + } + + private static String last(List list) { + return list.get(list.size() - 1); + } + private double stepHeight() { if (suggestedHeight == 0 || allStates.size() <= 1) { return 20; From c8748421584d3c0edb734c271721ed0a0b8e79a0 Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Tue, 5 Oct 2021 18:52:46 +0200 Subject: [PATCH 19/47] Import version 1.2021.12 --- pom.xml | 4 +- .../activitydiagram3/ftile/Snake.java | 6 ++- .../plantuml/activitydiagram3/ftile/Worm.java | 9 +++- .../vcompact/FtileFactoryDelegatorSwitch.java | 42 ++++++++++++----- .../cond/FtileSwitchWithDiamonds.java | 45 +++++++++++++------ .../cond/FtileSwitchWithManyLinks.java | 9 +++- .../sourceforge/plantuml/version/Version.java | 4 +- 7 files changed, 87 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index abef39f8e..7acda68b2 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ net.sourceforge.plantuml plantuml - 1.2021.11-SNAPSHOT + 1.2021.13-SNAPSHOT jar PlantUML @@ -179,7 +179,7 @@ maven-javadoc-plugin - 3.3.1 + 3.2.0 attach-javadocs diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Snake.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Snake.java index 70517c9f8..2cd09cc4c 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Snake.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Snake.java @@ -137,7 +137,7 @@ public class Snake implements UShape { if (textBlock != null) { this.texts.add(new Text(textBlock, verticalAlignment, null)); } - if (verticalAlignment != VerticalAlignment.BOTTOM) { + if (verticalAlignment != VerticalAlignment.CENTER) { throw new UnsupportedOperationException(); } return this; @@ -254,6 +254,10 @@ public class Snake implements UShape { double y = (pt1.getY() + pt2.getY()) / 2 - dim.getHeight() / 2; if (text.verticalAlignment == VerticalAlignment.BOTTOM) { x = worm.getLast().getX(); + throw new AssertionError(); + } else if (text.verticalAlignment == VerticalAlignment.CENTER) { + x = worm.getMinX(); + y = (worm.getFirst().getY() + worm.getLast().getY() - 10) / 2 - dim.getHeight() / 2; } else if (text.horizontalAlignment == HorizontalAlignment.CENTER && zigzag) { final Point2D pt3 = worm.get(2); x = (pt2.getX() + pt3.getX()) / 2 - dim.getWidth() / 2; diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Worm.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Worm.java index e8553c216..3f09e58c8 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Worm.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Worm.java @@ -309,7 +309,7 @@ public class Worm implements Iterable { this.points.add(i, pt); } - private Point2D getFirst() { + public Point2D getFirst() { return points.get(0); } @@ -317,6 +317,13 @@ public class Worm implements Iterable { return points.get(points.size() - 1); } + public double getMinX() { + double result = points.get(0).getX(); + for (Point2D.Double pt : points) + result = Math.min(result, pt.getX()); + return result; + } + public Worm merge(Worm other, MergeStrategy merge) { if (Snake.same(this.getLast(), other.getFirst()) == false) { throw new IllegalArgumentException(); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorSwitch.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorSwitch.java index 66580a104..4a0d33343 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorSwitch.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorSwitch.java @@ -40,6 +40,7 @@ import java.util.List; import net.sourceforge.plantuml.ColorParam; import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.LineBreakStrategy; import net.sourceforge.plantuml.UseStyle; import net.sourceforge.plantuml.activitydiagram3.Branch; import net.sourceforge.plantuml.activitydiagram3.LinkRendering; @@ -53,12 +54,14 @@ import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.cond.FtileSwitch import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.cond.FtileSwitchWithManyLinks; import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.cond.FtileSwitchWithOneLink; import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondInside; +import net.sourceforge.plantuml.creole.CreoleMode; import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.Rainbow; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.style.PName; import net.sourceforge.plantuml.style.Style; import net.sourceforge.plantuml.ugraphic.color.HColor; @@ -121,16 +124,33 @@ public class FtileFactoryDelegatorSwitch extends FtileFactoryDelegator { } private Ftile getDiamond1(Swimlane swimlane, Branch branch0, Display test) { - final HColor borderColor = getRose().getHtmlColor(skinParam(), ColorParam.activityDiamondBorder); - final HColor backColor = branch0.getColor() == null - ? getRose().getHtmlColor(skinParam(), ColorParam.activityDiamondBackground) - : branch0.getColor(); - final FontConfiguration fcDiamond = new FontConfiguration(skinParam(), FontParam.ACTIVITY_DIAMOND, null); + LineBreakStrategy lineBreak = LineBreakStrategy.NONE; + final FontConfiguration fcDiamond; + final HColor borderColor; + final HColor backColor; + if (UseStyle.useBetaStyle()) { + final Style style = getDefaultStyleDefinitionDiamond().getMergedStyle(skinParam().getCurrentStyleBuilder()); + lineBreak = style.wrapWidth(); + fcDiamond = style.getFontConfiguration(skinParam().getThemeStyle(), skinParam().getIHtmlColorSet()); + borderColor = style.value(PName.LineColor).asColor(skinParam().getThemeStyle(), + skinParam().getIHtmlColorSet()); + backColor = branch0.getColor() == null ? style.value(PName.BackGroundColor) + .asColor(skinParam().getThemeStyle(), skinParam().getIHtmlColorSet()) : branch0.getColor(); + } else { + fcDiamond = new FontConfiguration(skinParam(), FontParam.ACTIVITY_DIAMOND, null); + borderColor = getRose().getHtmlColor(skinParam(), ColorParam.activityDiamondBorder); + backColor = branch0.getColor() == null + ? getRose().getHtmlColor(skinParam(), ColorParam.activityDiamondBackground) + : branch0.getColor(); + } - final TextBlock tbTest = (Display.isNull(test) || test.isWhite()) ? TextBlockUtils.empty(0, 0) - : test.create(fcDiamond, branch0.skinParam().getDefaultTextAlignment(HorizontalAlignment.LEFT), - branch0.skinParam()); + final TextBlock tbTest; + if (Display.isNull(test) || test.isWhite()) + tbTest = TextBlockUtils.empty(0, 0); + else + tbTest = test.create0(fcDiamond, branch0.skinParam().getDefaultTextAlignment(HorizontalAlignment.LEFT), + branch0.skinParam(), lineBreak, CreoleMode.FULL, null, null); return new FtileDiamondInside(branch0.skinParam(), backColor, borderColor, swimlane, tbTest); } @@ -145,8 +165,8 @@ public class FtileFactoryDelegatorSwitch extends FtileFactoryDelegator { TextBlockUtils.empty(0, 0)); } - private HColor fontColor(FontParam param) { - return skinParam().getFontHtmlColor(null, param); - } +// private HColor fontColor(FontParam param) { +// return skinParam().getFontHtmlColor(null, param); +// } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchWithDiamonds.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchWithDiamonds.java index 49ceb1854..c6dd355a1 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchWithDiamonds.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchWithDiamonds.java @@ -41,6 +41,8 @@ import java.util.Collections; import java.util.List; import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.LineBreakStrategy; +import net.sourceforge.plantuml.UseStyle; import net.sourceforge.plantuml.activitydiagram3.Branch; import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileGeometry; @@ -50,6 +52,10 @@ import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.style.PName; +import net.sourceforge.plantuml.style.SName; +import net.sourceforge.plantuml.style.Style; +import net.sourceforge.plantuml.style.StyleSignature; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; @@ -64,7 +70,7 @@ public class FtileSwitchWithDiamonds extends FtileSwitchNude { protected final Ftile diamond1; protected final Ftile diamond2; protected final List branches; - private Mode mode; + protected final Mode mode; private final double w13; private final double w9; @@ -95,18 +101,18 @@ public class FtileSwitchWithDiamonds extends FtileSwitchNude { } @Override - public Collection getMyChildren() { + final public Collection getMyChildren() { final Collection result = new ArrayList<>(super.getMyChildren()); result.add(diamond1); result.add(diamond2); return Collections.unmodifiableCollection(result); } - public double getYdelta1a(StringBounder stringBounder) { + protected double getYdelta1a(StringBounder stringBounder) { return 20; } - public double getYdelta1b(StringBounder stringBounder) { + final protected double getYdelta1b(StringBounder stringBounder) { return 10; } @@ -134,7 +140,7 @@ public class FtileSwitchWithDiamonds extends FtileSwitchNude { } @Override - public void drawU(UGraphic ug) { + final public void drawU(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); ug.apply(getTranslateDiamond1(stringBounder)).draw(diamond1); @@ -151,7 +157,7 @@ public class FtileSwitchWithDiamonds extends FtileSwitchNude { } } - protected UTranslate getTranslateOf(Ftile tile, StringBounder stringBounder) { + final protected UTranslate getTranslateOf(Ftile tile, StringBounder stringBounder) { final UTranslate main = getTranslateMain(stringBounder); if (mode == Mode.BIG_DIAMOND) { double dx = 0; @@ -173,13 +179,13 @@ public class FtileSwitchWithDiamonds extends FtileSwitchNude { return getTranslateNude(tile, stringBounder).compose(main); } - protected UTranslate getTranslateMain(StringBounder stringBounder) { + final protected UTranslate getTranslateMain(StringBounder stringBounder) { final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); final double dy1 = dimDiamond1.getHeight() + getYdelta1a(stringBounder); return UTranslate.dy(dy1); } - protected UTranslate getTranslateDiamond1(StringBounder stringBounder) { + final protected UTranslate getTranslateDiamond1(StringBounder stringBounder) { final double y1 = 0; final FtileGeometry dimTotal = calculateDimensionInternal(stringBounder); final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); @@ -187,7 +193,7 @@ public class FtileSwitchWithDiamonds extends FtileSwitchNude { return new UTranslate(x1, y1); } - protected UTranslate getTranslateDiamond2(StringBounder stringBounder) { + final protected UTranslate getTranslateDiamond2(StringBounder stringBounder) { final FtileGeometry dimTotal = calculateDimensionInternal(stringBounder); final FtileGeometry dimDiamond2 = diamond2.calculateDimension(stringBounder); final double y2 = dimTotal.getHeight() - dimDiamond2.getHeight(); @@ -195,10 +201,23 @@ public class FtileSwitchWithDiamonds extends FtileSwitchNude { return new UTranslate(x2, y2); } - protected TextBlock getLabelPositive(Branch branch) { - final FontConfiguration fcArrow = new FontConfiguration(skinParam(), FontParam.ARROW, null); - return branch.getLabelPositive().create7(fcArrow, HorizontalAlignment.LEFT, skinParam(), - CreoleMode.SIMPLE_LINE); + final public StyleSignature getDefaultStyleDefinitionArrow() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.activity, SName.arrow); + } + + final protected TextBlock getLabelPositive(Branch branch) { + LineBreakStrategy lineBreak = LineBreakStrategy.NONE; + final FontConfiguration fcArrow; + if (UseStyle.useBetaStyle()) { + final Style style = getDefaultStyleDefinitionArrow().getMergedStyle(skinParam().getCurrentStyleBuilder()); + lineBreak = style.wrapWidth(); + fcArrow = style.getFontConfiguration(skinParam().getThemeStyle(), getIHtmlColorSet()); + } else { + fcArrow = new FontConfiguration(skinParam(), FontParam.ARROW, null); + } + + return branch.getLabelPositive().create0(fcArrow, HorizontalAlignment.LEFT, skinParam(), lineBreak, + CreoleMode.SIMPLE_LINE, null, null); } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchWithManyLinks.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchWithManyLinks.java index 9b475149a..027891b9c 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchWithManyLinks.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchWithManyLinks.java @@ -196,7 +196,7 @@ public class FtileSwitchWithManyLinks extends FtileSwitchWithDiamonds { final double y2 = p2.getY(); final Snake snake = Snake.create(null, arrowColor, Arrows.asToDown()).withLabel(getLabelPositive(branch), - VerticalAlignment.BOTTOM); + VerticalAlignment.CENTER); if (x2 < p1d.getX() - margin || x2 > p1b.getX() + margin) { snake.addPoint(x2, p1d.getY()); snake.addPoint(x2, y2); @@ -270,11 +270,16 @@ public class FtileSwitchWithManyLinks extends FtileSwitchWithDiamonds { } - public double getYdelta1a(StringBounder stringBounder) { + @Override + protected double getYdelta1a(StringBounder stringBounder) { double max = 10; for (Branch branch : branches) { max = Math.max(max, getLabelPositive(branch).calculateDimension(stringBounder).getHeight()); } + if (mode == Mode.BIG_DIAMOND) { + final double diamondHeight = diamond1.calculateDimension(stringBounder).getHeight(); + max += diamondHeight / 2; + } return max + 10; } diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index e77af740b..af994b4a6 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -44,7 +44,7 @@ public class Version { private static final int MAJOR_SEPARATOR = 1000000; public static int version() { - return 1202111; + return 1202112; } public static int versionPatched() { @@ -93,7 +93,7 @@ public class Version { } public static long compileTime() { - return 1633181171844L; + return 1633449718349L; } public static String compileTimeString() { From cd6f988eac89e834ff15c0a11ce210576d4296b2 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Thu, 7 Oct 2021 02:59:13 +1100 Subject: [PATCH 20/47] Reuse long-lived XML DocumentBuilderFactory & TransformerFactory instances. --- .../plantuml/stats/XmlConverter.java | 9 ++--- .../sourceforge/plantuml/svg/SvgGraphics.java | 21 ++---------- .../plantuml/xmi/XmiClassDiagramAbstract.java | 9 ++--- .../plantuml/xmi/XmiDescriptionDiagram.java | 9 ++--- .../plantuml/xmi/XmiStateDiagram.java | 9 ++--- .../plantuml/xml/XmlFactories.java | 34 +++++++++++++++++++ .../xmlsc/ScxmlStateDiagramStandard.java | 9 ++--- 7 files changed, 52 insertions(+), 48 deletions(-) create mode 100644 src/net/sourceforge/plantuml/xml/XmlFactories.java diff --git a/src/net/sourceforge/plantuml/stats/XmlConverter.java b/src/net/sourceforge/plantuml/stats/XmlConverter.java index 3422ef1d6..7a30be5d7 100644 --- a/src/net/sourceforge/plantuml/stats/XmlConverter.java +++ b/src/net/sourceforge/plantuml/stats/XmlConverter.java @@ -42,12 +42,10 @@ import java.util.Date; import java.util.List; import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -59,6 +57,7 @@ import net.sourceforge.plantuml.stats.api.Stats; import net.sourceforge.plantuml.stats.api.StatsColumn; import net.sourceforge.plantuml.stats.api.StatsLine; import net.sourceforge.plantuml.stats.api.StatsTable; +import net.sourceforge.plantuml.xml.XmlFactories; public class XmlConverter { @@ -71,8 +70,7 @@ public class XmlConverter { } private Document getDocument() throws ParserConfigurationException { - final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - final DocumentBuilder builder = factory.newDocumentBuilder(); + final DocumentBuilder builder = XmlFactories.newDocumentBuilder(); final Document document = builder.newDocument(); document.setXmlStandalone(true); @@ -124,8 +122,7 @@ public class XmlConverter { } private Transformer getTransformer() throws TransformerException { - final TransformerFactory xformFactory = TransformerFactory.newInstance(); - final Transformer transformer = xformFactory.newTransformer(); + final Transformer transformer = XmlFactories.newTransformer(); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); return transformer; } diff --git a/src/net/sourceforge/plantuml/svg/SvgGraphics.java b/src/net/sourceforge/plantuml/svg/SvgGraphics.java index d9e724915..129a162f3 100644 --- a/src/net/sourceforge/plantuml/svg/SvgGraphics.java +++ b/src/net/sourceforge/plantuml/svg/SvgGraphics.java @@ -53,12 +53,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -81,6 +79,7 @@ import net.sourceforge.plantuml.ugraphic.USegment; import net.sourceforge.plantuml.ugraphic.USegmentType; import net.sourceforge.plantuml.ugraphic.color.ColorMapper; import net.sourceforge.plantuml.ugraphic.color.HColorGradient; +import net.sourceforge.plantuml.xml.XmlFactories; public class SvgGraphics { @@ -240,9 +239,7 @@ public class SvgGraphics { } private Document getDocument() throws ParserConfigurationException { - final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - - final DocumentBuilder builder = factory.newDocumentBuilder(); + final DocumentBuilder builder = XmlFactories.newDocumentBuilder(); final Document document = builder.newDocument(); document.setXmlStandalone(true); return document; @@ -569,19 +566,7 @@ public class SvgGraphics { } private Transformer getTransformer() throws TransformerException { - // Get a TransformerFactory object. - TransformerFactory xformFactory = null; -// try { -// final Class factoryClass = Class -// .forName("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); -// xformFactory = (TransformerFactory) factoryClass.newInstance(); -// } catch (Exception e) { - xformFactory = TransformerFactory.newInstance(); -// } - Log.info("TransformerFactory=" + xformFactory.getClass()); - - // Get an XSL Transformer object. - final Transformer transformer = xformFactory.newTransformer(); + final Transformer transformer = XmlFactories.newTransformer(); Log.info("Transformer=" + transformer.getClass()); // // Sets the standalone property in the first line of diff --git a/src/net/sourceforge/plantuml/xmi/XmiClassDiagramAbstract.java b/src/net/sourceforge/plantuml/xmi/XmiClassDiagramAbstract.java index 2fb4b2243..484866c3e 100644 --- a/src/net/sourceforge/plantuml/xmi/XmiClassDiagramAbstract.java +++ b/src/net/sourceforge/plantuml/xmi/XmiClassDiagramAbstract.java @@ -42,14 +42,12 @@ import java.util.HashSet; import java.util.Set; import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -64,6 +62,7 @@ import net.sourceforge.plantuml.cucadiagram.Member; import net.sourceforge.plantuml.cucadiagram.Stereotype; import net.sourceforge.plantuml.skin.VisibilityModifier; import net.sourceforge.plantuml.utils.UniqueSequence; +import net.sourceforge.plantuml.xml.XmlFactories; abstract class XmiClassDiagramAbstract implements IXmiClassDiagram { @@ -78,9 +77,8 @@ abstract class XmiClassDiagramAbstract implements IXmiClassDiagram { public XmiClassDiagramAbstract(ClassDiagram classDiagram) throws ParserConfigurationException { this.classDiagram = classDiagram; - final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - final DocumentBuilder builder = factory.newDocumentBuilder(); + final DocumentBuilder builder = XmlFactories.newDocumentBuilder(); this.document = builder.newDocument(); document.setXmlVersion("1.0"); document.setXmlStandalone(true); @@ -131,8 +129,7 @@ abstract class XmiClassDiagramAbstract implements IXmiClassDiagram { final Result resultat = new StreamResult(os); - final TransformerFactory fabrique = TransformerFactory.newInstance(); - final Transformer transformer = fabrique.newTransformer(); + final Transformer transformer = XmlFactories.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); transformer.setOutputProperty(OutputKeys.ENCODING, UTF_8.name()); diff --git a/src/net/sourceforge/plantuml/xmi/XmiDescriptionDiagram.java b/src/net/sourceforge/plantuml/xmi/XmiDescriptionDiagram.java index 8810b5ef0..fdd7b1fab 100644 --- a/src/net/sourceforge/plantuml/xmi/XmiDescriptionDiagram.java +++ b/src/net/sourceforge/plantuml/xmi/XmiDescriptionDiagram.java @@ -40,14 +40,12 @@ import static java.nio.charset.StandardCharsets.UTF_8; import java.io.OutputStream; import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -63,6 +61,7 @@ import net.sourceforge.plantuml.cucadiagram.LinkDecor; import net.sourceforge.plantuml.descdiagram.DescriptionDiagram; import net.sourceforge.plantuml.utils.UniqueSequence; import net.sourceforge.plantuml.version.Version; +import net.sourceforge.plantuml.xml.XmlFactories; public class XmiDescriptionDiagram implements IXmiClassDiagram { @@ -72,9 +71,8 @@ public class XmiDescriptionDiagram implements IXmiClassDiagram { public XmiDescriptionDiagram(DescriptionDiagram diagram) throws ParserConfigurationException { this.diagram = diagram; - final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - final DocumentBuilder builder = factory.newDocumentBuilder(); + final DocumentBuilder builder = XmlFactories.newDocumentBuilder(); this.document = builder.newDocument(); document.setXmlVersion("1.0"); document.setXmlStandalone(true); @@ -232,8 +230,7 @@ public class XmiDescriptionDiagram implements IXmiClassDiagram { final Result resultat = new StreamResult(os); - final TransformerFactory fabrique = TransformerFactory.newInstance(); - final Transformer transformer = fabrique.newTransformer(); + final Transformer transformer = XmlFactories.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); transformer.setOutputProperty(OutputKeys.ENCODING, UTF_8.name()); diff --git a/src/net/sourceforge/plantuml/xmi/XmiStateDiagram.java b/src/net/sourceforge/plantuml/xmi/XmiStateDiagram.java index 709176b82..c9041497c 100644 --- a/src/net/sourceforge/plantuml/xmi/XmiStateDiagram.java +++ b/src/net/sourceforge/plantuml/xmi/XmiStateDiagram.java @@ -40,14 +40,12 @@ import static java.nio.charset.StandardCharsets.UTF_8; import java.io.OutputStream; import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -63,6 +61,7 @@ import net.sourceforge.plantuml.cucadiagram.LinkDecor; import net.sourceforge.plantuml.statediagram.StateDiagram; import net.sourceforge.plantuml.utils.UniqueSequence; import net.sourceforge.plantuml.version.Version; +import net.sourceforge.plantuml.xml.XmlFactories; public class XmiStateDiagram implements IXmiClassDiagram { @@ -72,9 +71,8 @@ public class XmiStateDiagram implements IXmiClassDiagram { public XmiStateDiagram(StateDiagram diagram) throws ParserConfigurationException { this.diagram = diagram; - final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - final DocumentBuilder builder = factory.newDocumentBuilder(); + final DocumentBuilder builder = XmlFactories.newDocumentBuilder(); this.document = builder.newDocument(); document.setXmlVersion("1.0"); document.setXmlStandalone(true); @@ -246,8 +244,7 @@ public class XmiStateDiagram implements IXmiClassDiagram { final Result resultat = new StreamResult(os); - final TransformerFactory fabrique = TransformerFactory.newInstance(); - final Transformer transformer = fabrique.newTransformer(); + final Transformer transformer = XmlFactories.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); transformer.setOutputProperty(OutputKeys.ENCODING, UTF_8.name()); diff --git a/src/net/sourceforge/plantuml/xml/XmlFactories.java b/src/net/sourceforge/plantuml/xml/XmlFactories.java new file mode 100644 index 000000000..d37f999d1 --- /dev/null +++ b/src/net/sourceforge/plantuml/xml/XmlFactories.java @@ -0,0 +1,34 @@ +package net.sourceforge.plantuml.xml; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactory; + +public class XmlFactories { + + private XmlFactories() { + } + + // This class uses the "initialization-on-demand holder" idiom to provide thread-safe + // lazy initialization of expensive factories. + // (see https://stackoverflow.com/a/8297830/1848731) + + private static class DocumentBuilderFactoryHolder { + static final DocumentBuilderFactory INSTANCE = DocumentBuilderFactory.newInstance(); + } + + private static class TransformerFactoryHolder { + static final TransformerFactory INSTANCE = TransformerFactory.newInstance(); + } + + public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { + return DocumentBuilderFactoryHolder.INSTANCE.newDocumentBuilder(); + } + + public static Transformer newTransformer() throws TransformerConfigurationException { + return TransformerFactoryHolder.INSTANCE.newTransformer(); + } +} diff --git a/src/net/sourceforge/plantuml/xmlsc/ScxmlStateDiagramStandard.java b/src/net/sourceforge/plantuml/xmlsc/ScxmlStateDiagramStandard.java index 9f3da6116..3460f79a3 100644 --- a/src/net/sourceforge/plantuml/xmlsc/ScxmlStateDiagramStandard.java +++ b/src/net/sourceforge/plantuml/xmlsc/ScxmlStateDiagramStandard.java @@ -40,14 +40,12 @@ import static java.nio.charset.StandardCharsets.UTF_8; import java.io.OutputStream; import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -59,6 +57,7 @@ import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.LeafType; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.statediagram.StateDiagram; +import net.sourceforge.plantuml.xml.XmlFactories; public class ScxmlStateDiagramStandard { @@ -67,9 +66,8 @@ public class ScxmlStateDiagramStandard { public ScxmlStateDiagramStandard(StateDiagram diagram) throws ParserConfigurationException { this.diagram = diagram; - final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - final DocumentBuilder builder = factory.newDocumentBuilder(); + final DocumentBuilder builder = XmlFactories.newDocumentBuilder(); this.document = builder.newDocument(); document.setXmlVersion("1.0"); document.setXmlStandalone(true); @@ -132,8 +130,7 @@ public class ScxmlStateDiagramStandard { final Result resultat = new StreamResult(os); - final TransformerFactory fabrique = TransformerFactory.newInstance(); - final Transformer transformer = fabrique.newTransformer(); + final Transformer transformer = XmlFactories.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, UTF_8.name()); transformer.transform(source, resultat); From 637adfa6cb32adc52d073c404145941d70f1489c Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Thu, 7 Oct 2021 18:51:26 +0200 Subject: [PATCH 21/47] Stereotype refactoring --- .../command/CommandLinkActivity.java | 4 +- .../command/CommandLinkLongActivity.java | 4 +- .../command/CommandPartition.java | 2 +- .../command/CommandActivity3.java | 2 +- .../command/CommandPartition3.java | 2 +- .../command/CommandRepeat3.java | 2 +- .../ftile/vcompact/FtileRepeat.java | 11 +- .../vcompact/cond/ConditionalBuilder.java | 12 +- .../vcompact/cond/FtileIfWithDiamonds.java | 15 +- .../command/CommandCreateClass.java | 2 +- .../command/CommandCreateClassMultilines.java | 2 +- .../command/CommandCreateElementFull2.java | 2 +- .../command/CommandStereotype.java | 2 +- .../plantuml/command/CommandNamespace.java | 2 +- .../plantuml/command/CommandNamespace2.java | 2 +- .../command/CommandNamespaceEmpty.java | 2 +- .../plantuml/command/CommandPackage.java | 2 +- .../note/CommandFactoryNoteOnEntity.java | 2 +- .../FactorySequenceNoteAcrossCommand.java | 2 +- .../sequence/FactorySequenceNoteCommand.java | 2 +- .../FactorySequenceNoteOnArrowCommand.java | 2 +- ...FactorySequenceNoteOverSeveralCommand.java | 2 +- .../plantuml/cucadiagram/Stereotype.java | 209 +++++------------- .../cucadiagram/StereotypeDecoration.java | 175 +++++++++++++++ .../descdiagram/CommandCreateDomain.java | 2 +- .../descdiagram/command/CommandArchimate.java | 2 +- .../command/CommandArchimateMultilines.java | 2 +- .../command/CommandCreateElementFull.java | 2 +- .../CommandCreateElementMultilines.java | 2 +- .../CommandCreateElementParenthesis.java | 2 +- .../command/CommandLinkElement.java | 2 +- .../command/CommandPackageWithUSymbol.java | 2 +- .../command/CommandCreateEntityObject.java | 2 +- .../CommandCreateEntityObjectMultilines.java | 2 +- .../command/CommandCreateMap.java | 2 +- .../command/CommandBoxStart.java | 2 +- .../command/CommandParticipant.java | 2 +- .../command/CommandCreatePackageState.java | 2 +- .../command/CommandCreateState.java | 2 +- .../command/CommandLinkState.java | 4 +- .../plantuml/timingdiagram/PlayerClock.java | 81 +++---- 41 files changed, 330 insertions(+), 249 deletions(-) create mode 100644 src/net/sourceforge/plantuml/cucadiagram/StereotypeDecoration.java diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java index 0ec71fd60..dbcbd1904 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java @@ -129,7 +129,7 @@ public class CommandLinkActivity extends SingleLineCommand2 { return CommandExecutionResult.error("No such activity"); } if (arg.get("STEREOTYPE", 0) != null) { - entity1.setStereotype(new Stereotype(arg.get("STEREOTYPE", 0))); + entity1.setStereotype(Stereotype.build(arg.get("STEREOTYPE", 0))); } if (arg.get("BACKCOLOR", 0) != null) { String s = arg.get("BACKCOLOR", 0); @@ -147,7 +147,7 @@ public class CommandLinkActivity extends SingleLineCommand2 { diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), s)); } if (arg.get("STEREOTYPE2", 0) != null) { - entity2.setStereotype(new Stereotype(arg.get("STEREOTYPE2", 0))); + entity2.setStereotype(Stereotype.build(arg.get("STEREOTYPE2", 0))); } final Display linkLabel = Display.getWithNewlines(arg.get("BRACKET", 0)); diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java index 335eb8cf6..9372d9ff8 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java @@ -126,7 +126,7 @@ public class CommandLinkLongActivity extends CommandMultilines2 } if (line0.get("STEREOTYPE", 0) != null) { - entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE", 0))); + entity1.setStereotype(Stereotype.build(line0.get("STEREOTYPE", 0))); } final String stringColor = line0.get("BACKCOLOR", 0); if (stringColor != null) { @@ -196,7 +196,7 @@ public class CommandLinkLongActivity extends CommandMultilines2 } if (lineLast.get(2) != null) { - entity2.setStereotype(new Stereotype(lineLast.get(2))); + entity2.setStereotype(Stereotype.build(lineLast.get(2))); } if (lineLast.get(4) != null) { String s = lineLast.get(4); diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java index 66630899c..d8918b920 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java @@ -101,7 +101,7 @@ public class CommandPartition extends SingleLineCommand2 { p.setColors(colors); } if (arg.get("STEREOTYPE", 0) != null) { - p.setStereotype(new Stereotype(arg.get("STEREOTYPE", 0))); + p.setStereotype(Stereotype.build(arg.get("STEREOTYPE", 0))); } return CommandExecutionResult.ok(); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java index 1974bcc4e..833086306 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java @@ -118,7 +118,7 @@ public class CommandActivity3 extends SingleLineCommand2 { final String stereo = arg.get("STEREO", 0); Stereotype stereotype = null; if (stereo != null) { - stereotype = new Stereotype(stereo); + stereotype = Stereotype.build(stereo); colors = colors.applyStereotype(stereotype, diagram.getSkinParam(), ColorParam.activityBackground); } final BoxStyle style = BoxStyle.fromChar(arg.get("STYLE", 0).charAt(0)); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandPartition3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandPartition3.java index 48b462c85..03e1a628e 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandPartition3.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandPartition3.java @@ -129,7 +129,7 @@ public class CommandPartition3 extends SingleLineCommand2 { final USymbol symbol = getUSymbol(arg.get("TYPE", 0)); final String stereo = arg.get("STEREO", 0); - final Stereotype stereotype = stereo == null ? null : new Stereotype(stereo); + final Stereotype stereotype = stereo == null ? null : Stereotype.build(stereo); final HColor backColorInSkinparam = diagram.getSkinParam().getHtmlColor(getColorParamBack(symbol), stereotype, false); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java index 349ce431d..dfae89a2a 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java @@ -94,7 +94,7 @@ public class CommandRepeat3 extends SingleLineCommand2 { diagram.getSkinParam().getIHtmlColorSet()); final String stereo = arg.get("STEREO", 0); if (stereo != null) { - final Stereotype stereotype = new Stereotype(stereo); + final Stereotype stereotype = Stereotype.build(stereo); colors = colors.applyStereotype(stereotype, diagram.getSkinParam(), ColorParam.activityBackground); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java index c2dcc1885..86359f7c0 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java @@ -215,8 +215,15 @@ class FtileRepeat extends AbstractFtile { final StringBounder stringBounder = ug.getStringBounder(); final Snake snake = Snake.create(arrowColor, Arrows.asToDown()).withLabel(tbin, arrowHorizontalAlignment()); - snake.addPoint(getP1(stringBounder)); - snake.addPoint(getP2(stringBounder)); + final Point2D p1 = getP1(stringBounder); + final Point2D p2 = getP2(stringBounder); + snake.addPoint(p1); + if (p1.getX() != p2.getX()) { + final double my = (p1.getY() + p2.getY()) / 2; + snake.addPoint(new Point2D.Double(p1.getX(), my)); + snake.addPoint(new Point2D.Double(p2.getX(), my)); + } + snake.addPoint(p2); ug.draw(snake); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java index e830a976c..7654deb0a 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java @@ -78,6 +78,8 @@ public class ConditionalBuilder { private final Swimlane swimlane; private final HColor borderColor; private final HColor backColor; + private final LineBreakStrategy diamondLineBreak; + private final LineBreakStrategy labelLineBreak; private final Rainbow arrowColor; private final FtileFactory ftileFactory; private final ConditionStyle conditionStyle; @@ -110,6 +112,8 @@ public class ConditionalBuilder { .getMergedStyle(skinParam.getCurrentStyleBuilder()); final Style styleDiamond = getDefaultStyleDefinitionDiamond() .getMergedStyle(skinParam.getCurrentStyleBuilder()); + this.diamondLineBreak = styleDiamond.wrapWidth(); + this.labelLineBreak = styleArrow.wrapWidth(); this.borderColor = styleDiamond.value(PName.LineColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); this.backColor = styleDiamond.value(PName.BackGroundColor).asColor(skinParam.getThemeStyle(), @@ -120,6 +124,8 @@ public class ConditionalBuilder { this.fontTest = styleDiamond.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); this.fontArrow = styleArrow.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); } else { + this.diamondLineBreak = LineBreakStrategy.NONE; + this.labelLineBreak = LineBreakStrategy.NONE; this.borderColor = borderColor; this.backColor = backColor; this.arrowColor = arrowColor; @@ -242,7 +248,7 @@ public class ConditionalBuilder { final Sheet sheet = Parser.build(fontTest, skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), skinParam, CreoleMode.FULL).createSheet(labelTest); - final SheetBlock1 sheetBlock1 = new SheetBlock1(sheet, LineBreakStrategy.NONE, skinParam.getPadding()); + final SheetBlock1 sheetBlock1 = new SheetBlock1(sheet, diamondLineBreak, skinParam.getPadding()); final TextBlock tbTest = new SheetBlock2(sheetBlock1, Diamond.asStencil(sheetBlock1), tile1.getThickness()); final Ftile diamond1; @@ -277,8 +283,8 @@ public class ConditionalBuilder { } private TextBlock getLabelPositive(Branch branch) { - return branch.getLabelPositive().create7(fontArrow, HorizontalAlignment.LEFT, ftileFactory.skinParam(), - CreoleMode.SIMPLE_LINE); + return branch.getLabelPositive().create0(fontArrow, HorizontalAlignment.LEFT, ftileFactory.skinParam(), + labelLineBreak, CreoleMode.SIMPLE_LINE, null, null); } private Ftile getDiamond2(Branch branch1, Branch branch2, boolean useNorth) { diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java index 8b277349b..73da00734 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java @@ -65,16 +65,13 @@ public class FtileIfWithDiamonds extends FtileIfNude { } public int getYdelta1a(StringBounder stringBounder) { - // if (getSwimlanes().size() > 1 && hasTwoBranches(stringBounder)) { if (getSwimlanes().size() > 1) { return 20; } return 10; - // return hasTwoBranches(stringBounder) ? 6 : 6; } public int getYdelta1b(StringBounder stringBounder) { - // if (getSwimlanes().size() > 1 && hasTwoBranches(stringBounder)) { if (getSwimlanes().size() > 1) { return 10; } @@ -98,9 +95,6 @@ public class FtileIfWithDiamonds extends FtileIfNude { return all.addDim(0, getYdelta1a(stringBounder) + getYdelta1b(stringBounder)); - // final double height = dimNude.getHeight() + dim1.getHeight() + dim2.getHeight() + getYdelta1a(stringBounder) - // + getYdelta1b(stringBounder); - // return new Dimension2DDouble(width, height); } @Override @@ -115,22 +109,21 @@ public class FtileIfWithDiamonds extends FtileIfNude { @Override protected UTranslate getTranslate1(StringBounder stringBounder) { final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); - return super.getTranslate1(stringBounder).compose( - UTranslate.dy(dimDiamond1.getHeight() + getYdelta1a(stringBounder))); + return super.getTranslate1(stringBounder) + .compose(UTranslate.dy(dimDiamond1.getHeight() + getYdelta1a(stringBounder))); } @Override protected UTranslate getTranslate2(StringBounder stringBounder) { final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); - return super.getTranslate2(stringBounder).compose( - UTranslate.dy(dimDiamond1.getHeight() + getYdelta1a(stringBounder))); + return super.getTranslate2(stringBounder) + .compose(UTranslate.dy(dimDiamond1.getHeight() + getYdelta1a(stringBounder))); } protected UTranslate getTranslateDiamond1(StringBounder stringBounder) { final double y1 = 0; final FtileGeometry dimTotal = calculateDimensionInternal(stringBounder); final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); - // final double x1 = getLeft(stringBounder) - dimDiamond1.getWidth() / 2; final double x1 = dimTotal.getLeft() - dimDiamond1.getLeft(); return new UTranslate(x1, y1); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java index e95e912fa..31f8a7c8d 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java @@ -157,7 +157,7 @@ public class CommandCreateClass extends SingleLineCommand2 { } } if (stereotype != null) { - entity.setStereotype(new Stereotype(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), + entity.setStereotype(Stereotype.build(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram.getSkinParam().getFont(null, false, FontParam.CIRCLED_CHARACTER), diagram.getSkinParam().getIHtmlColorSet())); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java index 44177fc1d..a844f65f1 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java @@ -264,7 +264,7 @@ public class CommandCreateClassMultilines extends CommandMultilines2 entity.setDisplay(Display.getWithNewlines(display)); entity.setUSymbol(usymbol); if (stereotype != null) { - entity.setStereotype(new Stereotype(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), + entity.setStereotype(Stereotype.build(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram.getSkinParam().getFont(null, false, FontParam.CIRCLED_CHARACTER), diagram.getSkinParam().getIHtmlColorSet())); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java index 458c54a67..f9c1ed2bd 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java @@ -71,7 +71,7 @@ public class CommandStereotype extends SingleLineCommand2 { final Code code = diagram.V1972() ? ident : diagram.buildCode(name); final String stereotype = arg.get("STEREO", 0); final IEntity entity = diagram.getOrCreateLeaf(ident, code, null, null); - entity.setStereotype(new Stereotype(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram + entity.setStereotype(Stereotype.build(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram .getSkinParam().getFont(null, false, FontParam.CIRCLED_CHARACTER), diagram.getSkinParam() .getIHtmlColorSet())); return CommandExecutionResult.ok(); diff --git a/src/net/sourceforge/plantuml/command/CommandNamespace.java b/src/net/sourceforge/plantuml/command/CommandNamespace.java index f83d9963f..e84f6cc47 100644 --- a/src/net/sourceforge/plantuml/command/CommandNamespace.java +++ b/src/net/sourceforge/plantuml/command/CommandNamespace.java @@ -98,7 +98,7 @@ public class CommandNamespace extends SingleLineCommand2 { final IEntity p = diagram.getCurrentGroup(); final String stereotype = arg.get("STEREOTYPE", 0); if (stereotype != null) { - p.setStereotype(new Stereotype(stereotype)); + p.setStereotype(Stereotype.build(stereotype)); } final String urlString = arg.get("URL", 0); diff --git a/src/net/sourceforge/plantuml/command/CommandNamespace2.java b/src/net/sourceforge/plantuml/command/CommandNamespace2.java index 83393d62f..c1fb4e84b 100644 --- a/src/net/sourceforge/plantuml/command/CommandNamespace2.java +++ b/src/net/sourceforge/plantuml/command/CommandNamespace2.java @@ -98,7 +98,7 @@ public class CommandNamespace2 extends SingleLineCommand2 { final IEntity p = diagram.getCurrentGroup(); final String stereotype = arg.get("STEREOTYPE", 0); if (stereotype != null) { - p.setStereotype(new Stereotype(stereotype)); + p.setStereotype(Stereotype.build(stereotype)); } final String urlString = arg.get("URL", 0); diff --git a/src/net/sourceforge/plantuml/command/CommandNamespaceEmpty.java b/src/net/sourceforge/plantuml/command/CommandNamespaceEmpty.java index 168c80672..8262332b9 100644 --- a/src/net/sourceforge/plantuml/command/CommandNamespaceEmpty.java +++ b/src/net/sourceforge/plantuml/command/CommandNamespaceEmpty.java @@ -92,7 +92,7 @@ public class CommandNamespaceEmpty extends SingleLineCommand2 { final IEntity p = diagram.getCurrentGroup(); final String stereotype = arg.get("STEREOTYPE", 0); if (stereotype != null) { - p.setStereotype(new Stereotype(stereotype)); + p.setStereotype(Stereotype.build(stereotype)); } final String urlString = arg.get("URL", 0); diff --git a/src/net/sourceforge/plantuml/command/CommandPackage.java b/src/net/sourceforge/plantuml/command/CommandPackage.java index d7fd97d6a..e051d0d9d 100644 --- a/src/net/sourceforge/plantuml/command/CommandPackage.java +++ b/src/net/sourceforge/plantuml/command/CommandPackage.java @@ -141,7 +141,7 @@ public class CommandPackage extends SingleLineCommand2 { final USymbol usymbol = USymbol.fromString(stereotype, diagram.getSkinParam().actorStyle(), diagram.getSkinParam().componentStyle(), diagram.getSkinParam().packageStyle()); if (usymbol == null) { - p.setStereotype(new Stereotype(stereotype)); + p.setStereotype(Stereotype.build(stereotype)); } else { p.setUSymbol(usymbol); } diff --git a/src/net/sourceforge/plantuml/command/note/CommandFactoryNoteOnEntity.java b/src/net/sourceforge/plantuml/command/note/CommandFactoryNoteOnEntity.java index 47ab4fe40..b1d28437c 100644 --- a/src/net/sourceforge/plantuml/command/note/CommandFactoryNoteOnEntity.java +++ b/src/net/sourceforge/plantuml/command/note/CommandFactoryNoteOnEntity.java @@ -242,7 +242,7 @@ public final class CommandFactoryNoteOnEntity implements SingleMultiFactoryComma final String stereotypeString = line0.get("STEREO", 0); if (stereotypeString != null) { - final Stereotype stereotype = new Stereotype(stereotypeString); + final Stereotype stereotype = Stereotype.build(stereotypeString); colors = colors.applyStereotypeForNote(stereotype, diagram.getSkinParam(), FontParam.NOTE, ColorParam.noteBackground, ColorParam.noteBorder); note.setStereotype(stereotype); diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteAcrossCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteAcrossCommand.java index bcfb3baf9..e9f25f3f1 100644 --- a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteAcrossCommand.java +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteAcrossCommand.java @@ -159,7 +159,7 @@ public final class FactorySequenceNoteAcrossCommand implements SingleMultiFactor diagram.getSkinParam().getIHtmlColorSet()); final String stereotypeString = line0.get("STEREO", 0); if (stereotypeString != null) { - final Stereotype stereotype = new Stereotype(stereotypeString); + final Stereotype stereotype = Stereotype.build(stereotypeString); colors = colors.applyStereotypeForNote(stereotype, diagram.getSkinParam(), FontParam.NOTE, ColorParam.noteBackground, ColorParam.noteBorder); note.setStereotype(stereotype); diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java index a5928fdf7..5b89d37f6 100644 --- a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java @@ -158,7 +158,7 @@ public final class FactorySequenceNoteCommand implements SingleMultiFactoryComma diagram.getSkinParam().getIHtmlColorSet()); final String stereotypeString = arg.get("STEREO", 0); if (stereotypeString != null) { - final Stereotype stereotype = new Stereotype(stereotypeString); + final Stereotype stereotype = Stereotype.build(stereotypeString); colors = colors.applyStereotypeForNote(stereotype, diagram.getSkinParam(), FontParam.NOTE, ColorParam.noteBackground, ColorParam.noteBorder); note.setStereotype(stereotype); diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java index 91520773d..9f0ebffac 100644 --- a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java @@ -153,7 +153,7 @@ public final class FactorySequenceNoteOnArrowCommand implements SingleMultiFacto final Note note = new Note(display, position, style, diagram.getSkinParam().getCurrentStyleBuilder()); final String stereotypeString = line0.get("STEREO", 0); if (stereotypeString != null) { - final Stereotype stereotype = new Stereotype(stereotypeString); + final Stereotype stereotype = Stereotype.build(stereotypeString); colors = colors.applyStereotypeForNote(stereotype, diagram.getSkinParam(), FontParam.NOTE, ColorParam.noteBackground, ColorParam.noteBorder); note.setStereotype(stereotype); diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java index b8928fce3..4f852cbcb 100644 --- a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java @@ -169,7 +169,7 @@ public final class FactorySequenceNoteOverSeveralCommand implements SingleMultiF diagram.getSkinParam().getIHtmlColorSet()); final String stereotypeString = line0.get("STEREO", 0); if (stereotypeString != null) { - final Stereotype stereotype = new Stereotype(stereotypeString); + final Stereotype stereotype = Stereotype.build(stereotypeString); colors = colors.applyStereotypeForNote(stereotype, diagram.getSkinParam(), FontParam.NOTE, ColorParam.noteBackground, ColorParam.noteBorder); note.setStereotype(stereotype); diff --git a/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java b/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java index 14a39fbd1..8b8d1f17e 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java @@ -45,191 +45,100 @@ import java.util.regex.Pattern; import net.sourceforge.plantuml.Guillemet; import net.sourceforge.plantuml.SpriteContainer; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.command.regex.Matcher2; -import net.sourceforge.plantuml.command.regex.MyPattern; -import net.sourceforge.plantuml.command.regex.Pattern2; -import net.sourceforge.plantuml.command.regex.RegexComposed; -import net.sourceforge.plantuml.command.regex.RegexConcat; -import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexOptional; -import net.sourceforge.plantuml.command.regex.RegexResult; -import net.sourceforge.plantuml.creole.Parser; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.sprite.Sprite; -import net.sourceforge.plantuml.sprite.SpriteUtils; import net.sourceforge.plantuml.style.Style; import net.sourceforge.plantuml.style.StyleBuilder; import net.sourceforge.plantuml.svek.PackageStyle; import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColorSet; -import net.sourceforge.plantuml.ugraphic.color.HColorUtils; import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException; public class Stereotype implements CharSequence { - private final static RegexComposed circleChar = new RegexConcat( // - new RegexLeaf("\\<\\<"), // - RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf("\\(?"), // - new RegexLeaf("CHAR", "(\\S)"), // - RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf(","), // - RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf("COLOR", "(#[0-9a-fA-F]{6}|\\w+)"), // - RegexLeaf.spaceZeroOrMore(), // - new RegexOptional(new RegexLeaf("LABEL", "[),](.*?)")), // - new RegexLeaf("\\>\\>") // - ); - - private final static RegexComposed circleSprite = new RegexConcat( // - new RegexLeaf("\\<\\<"), // - RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf("\\(?\\$"), // - new RegexLeaf("NAME", "(" + SpriteUtils.SPRITE_NAME + ")"), // - new RegexLeaf("SCALE", "((?:\\{scale=|\\*)([0-9.]+)\\}?)?"), // - RegexLeaf.spaceZeroOrMore(), // - new RegexOptional( // - new RegexConcat( // - new RegexLeaf(","), // - RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf("COLOR", "(#[0-9a-fA-F]{6}|\\w+)") // - )), // - RegexLeaf.spaceZeroOrMore(), // - new RegexOptional(new RegexLeaf("LABEL", "[),](.*?)")), // - new RegexLeaf("\\>\\>") // - ); private final double radius; private final UFont circledFont; private final boolean automaticPackageStyle; + private final StereotypeDecoration decoration; - private String label; - private HColor htmlColor; - private char character; - private String spriteName; - private double spriteScale; - - public Stereotype(String label, double radius, UFont circledFont, HColorSet htmlColorSet) throws NoSuchColorException { - this(label, radius, circledFont, true, htmlColorSet); - } - - public Stereotype(String label, boolean automaticPackageStyle) { - this.automaticPackageStyle = automaticPackageStyle; - this.label = label; - this.htmlColor = null; - this.character = '\0'; - this.radius = 0; - this.circledFont = null; - if (label.startsWith("<<$") && label.endsWith(">>")) { - final RegexResult mCircleSprite = circleSprite.matcher(label); - this.spriteName = mCircleSprite.get("NAME", 0); - this.spriteScale = Parser.getScale(mCircleSprite.get("SCALE", 0), 1); - } else { - this.spriteName = null; - } - } - - public Stereotype(String label, double radius, UFont circledFont, boolean automaticPackageStyle, - HColorSet htmlColorSet) throws NoSuchColorException { - Objects.requireNonNull(label); - if (label.startsWith("<<") == false || label.endsWith(">>") == false) { - throw new IllegalArgumentException(label); - } + private Stereotype(boolean automaticPackageStyle, String label, StereotypeDecoration decoration, double radius, + UFont circledFont) { this.automaticPackageStyle = automaticPackageStyle; this.radius = radius; this.circledFont = circledFont; + this.decoration = decoration; - final StringBuilder tmpLabel = new StringBuilder(); + } - final List list = cutLabels(label, Guillemet.DOUBLE_COMPARATOR); - for (String local : list) { - final RegexResult mCircleChar = circleChar.matcher(local); - final RegexResult mCircleSprite = circleSprite.matcher(local); - if (mCircleSprite != null) { - if (StringUtils.isNotEmpty(mCircleSprite.get("LABEL", 0))) { - local = "<<" + mCircleSprite.get("LABEL", 0) + ">>"; - } else { - local = null; - } - final String colName = mCircleSprite.get("COLOR", 0); - final HColor col = colName == null ? null : htmlColorSet.getColorLEGACY(colName); - this.htmlColor = col == null ? HColorUtils.BLACK : col; - this.spriteName = mCircleSprite.get("NAME", 0); - this.character = '\0'; - this.spriteScale = Parser.getScale(mCircleSprite.get("SCALE", 0), 1); - } else if (mCircleChar != null) { - if (StringUtils.isNotEmpty(mCircleChar.get("LABEL", 0))) { - local = "<<" + mCircleChar.get("LABEL", 0) + ">>"; - } else { - local = null; - } - final String colName = mCircleChar.get("COLOR", 0); - this.htmlColor = colName == null ? null : htmlColorSet.getColorLEGACY(colName); - this.character = mCircleChar.get("CHAR", 0).charAt(0); - this.spriteName = null; - } - if (local != null) { - tmpLabel.append(local); - } - } - if (tmpLabel.length() > 0) { - this.label = tmpLabel.toString(); + private static void checkLabel(String label) { + if (label.startsWith("<<") == false || label.endsWith(">>") == false) { + throw new IllegalArgumentException(label); } } - public Stereotype(String label) { - this(label, true); + public static Stereotype build(String label) { + return build(label, true); + } + + public static Stereotype build(String label, boolean automaticPackageStyle) { + checkLabel(label); + final StereotypeDecoration decoration = StereotypeDecoration.buildSimple(label); + return new Stereotype(automaticPackageStyle, label, decoration, 0, null); + } + + public static Stereotype build(String label, double radius, UFont circledFont, HColorSet htmlColorSet) + throws NoSuchColorException { + checkLabel(label); + final StereotypeDecoration decoration = StereotypeDecoration.buildComplex(label, htmlColorSet); + return new Stereotype(true, label, decoration, radius, circledFont); } public HColor getHtmlColor() { - return htmlColor; + return decoration.htmlColor; } public char getCharacter() { - return character; + return decoration.character; } public final TextBlock getSprite(SpriteContainer container) { - if (spriteName == null || container == null) { + if (decoration.spriteName == null || container == null) { return null; } - final Sprite tmp = container.getSprite(spriteName); + final Sprite tmp = container.getSprite(decoration.spriteName); if (tmp == null) { return null; } - return tmp.asTextBlock(getHtmlColor(), spriteScale); + return tmp.asTextBlock(getHtmlColor(), decoration.spriteScale); } public boolean isWithOOSymbol() { - return "<>".equalsIgnoreCase(label); + return "<>".equalsIgnoreCase(decoration.label); } public List getMultipleLabels() { final List result = new ArrayList<>(); - if (label != null) { - final Pattern p = Pattern.compile("\\<\\<\\s?((?:\\<&\\w+\\>|[^<>])+?)\\s?\\>\\>"); - final Matcher m = p.matcher(label); - while (m.find()) { - result.add(m.group(1)); - } + + final Pattern p = Pattern.compile("\\<\\<\\s?((?:\\<&\\w+\\>|[^<>])+?)\\s?\\>\\>"); + final Matcher m = p.matcher(decoration.label); + while (m.find()) { + result.add(m.group(1)); } + return Collections.unmodifiableList(result); } public boolean isSpotted() { - return character != 0; + return decoration.character != 0; } @Override public String toString() { - if (label == null) { - return "" + character; + if (decoration.character == 0) { + return decoration.label; } - if (character == 0) { - return label; - } - return character + " " + label; + return decoration.character + " " + decoration.label; } public char charAt(int arg0) { @@ -253,14 +162,13 @@ public class Stereotype implements CharSequence { } public String getLabel(Guillemet guillemet) { - assert label == null || label.length() > 0; if (isWithOOSymbol()) { return null; } - if (spriteName != null && spriteName.startsWith("archimate/")) { - return guillemet.manageGuillemet("<<" + spriteName.substring("archimate/".length()) + ">>"); + if (decoration.spriteName != null && decoration.spriteName.startsWith("archimate/")) { + return guillemet.manageGuillemet("<<" + decoration.spriteName.substring("archimate/".length()) + ">>"); } - return guillemet.manageGuillemet(label); + return guillemet.manageGuillemet(decoration.label); } public List getLabels(Guillemet guillemet) { @@ -268,7 +176,7 @@ public class Stereotype implements CharSequence { if (labelLocal == null) { return Collections.emptyList(); } - return cutLabels(labelLocal, guillemet); + return StereotypeDecoration.cutLabels(labelLocal, guillemet); } public List