From 16f9d973fa10b5d28b3a3ab93b36b3cf7be5a4a0 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Mon, 20 Sep 2021 22:56:11 +1000 Subject: [PATCH] Add AbstractCommonUGraphic.stringBounder field --- .../plantuml/braille/UGraphicBraille.java | 7 +------ .../plantuml/ugraphic/AbstractCommonUGraphic.java | 11 ++++++++++- .../plantuml/ugraphic/AbstractUGraphic.java | 5 +++-- .../sourceforge/plantuml/ugraphic/UGraphicNull.java | 7 +------ .../plantuml/ugraphic/debug/UGraphicDebug.java | 7 +------ .../plantuml/ugraphic/eps/UGraphicEps.java | 11 +---------- .../plantuml/ugraphic/g2d/UGraphicG2d.java | 10 +--------- .../plantuml/ugraphic/html5/UGraphicHtml5.java | 10 +--------- .../plantuml/ugraphic/svg/UGraphicSvg.java | 10 +--------- .../plantuml/ugraphic/tikz/UGraphicTikz.java | 10 +--------- .../plantuml/ugraphic/txt/UGraphicTxt.java | 7 +------ .../plantuml/ugraphic/visio/UGraphicVdx.java | 13 ++----------- 12 files changed, 24 insertions(+), 84 deletions(-) diff --git a/src/net/sourceforge/plantuml/braille/UGraphicBraille.java b/src/net/sourceforge/plantuml/braille/UGraphicBraille.java index 7b7ab56fc..7eaee354e 100644 --- a/src/net/sourceforge/plantuml/braille/UGraphicBraille.java +++ b/src/net/sourceforge/plantuml/braille/UGraphicBraille.java @@ -40,7 +40,6 @@ import java.io.IOException; import java.io.OutputStream; import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic; import net.sourceforge.plantuml.ugraphic.AbstractUGraphic; @@ -98,7 +97,7 @@ public class UGraphicBraille extends AbstractUGraphic implements Cl // } private UGraphicBraille(HColor defaultBackground, ColorMapper colorMapper, BrailleGrid grid) { - super(defaultBackground, colorMapper, grid); + super(defaultBackground, colorMapper, FileFormat.BRAILLE_PNG.getDefaultStringBounder(), grid); this.grid = grid; register(); } @@ -116,10 +115,6 @@ public class UGraphicBraille extends AbstractUGraphic implements Cl registerDriver(UCenteredCharacter.class, new DriverCenteredCharacterBraille()); } - public StringBounder getStringBounder() { - return FileFormat.BRAILLE_PNG.getDefaultStringBounder(); - } - @Override public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException { plainPngBuilder(new BrailleDrawer(getGraphicObject())) diff --git a/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java b/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java index 9b9e43729..0b10d8498 100644 --- a/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java +++ b/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java @@ -38,6 +38,7 @@ package net.sourceforge.plantuml.ugraphic; import java.util.Objects; import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.color.ColorMapper; import net.sourceforge.plantuml.ugraphic.color.ColorMapperTransparentWrapper; import net.sourceforge.plantuml.ugraphic.color.HColor; @@ -52,6 +53,7 @@ public abstract class AbstractCommonUGraphic implements UGraphic { private HColor color = null; private boolean enlargeClip = false; + private final StringBounder stringBounder; private UTranslate translate = new UTranslate(); private final ColorMapper colorMapper; @@ -107,15 +109,17 @@ public abstract class AbstractCommonUGraphic implements UGraphic { this.enlargeClip = true; } - public AbstractCommonUGraphic(HColor defaultBackground, ColorMapper colorMapper) { + public AbstractCommonUGraphic(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder) { this.colorMapper = colorMapper; this.defaultBackground = defaultBackground; + this.stringBounder = stringBounder; } protected AbstractCommonUGraphic(AbstractCommonUGraphic other) { this.defaultBackground = other.defaultBackground; this.enlargeClip = other.enlargeClip; this.colorMapper = other.colorMapper; + this.stringBounder = other.stringBounder; this.translate = other.translate; this.clip = other.clip; @@ -158,6 +162,11 @@ public abstract class AbstractCommonUGraphic implements UGraphic { }; } + @Override + public StringBounder getStringBounder() { + return stringBounder; + } + final protected double getTranslateX() { return translate.getDx(); } diff --git a/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java b/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java index acfe2b061..6a9b78485 100644 --- a/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java +++ b/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java @@ -40,6 +40,7 @@ import java.util.Map; import java.util.Objects; import net.sourceforge.plantuml.graphic.SpecialText; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.color.ColorMapper; import net.sourceforge.plantuml.ugraphic.color.HColor; @@ -49,8 +50,8 @@ public abstract class AbstractUGraphic extends AbstractCommonUGraphic { private final Map, UDriver> drivers = new HashMap, UDriver>(); - public AbstractUGraphic(HColor defaultBackground, ColorMapper colorMapper, O graphic) { - super(Objects.requireNonNull(defaultBackground), colorMapper); + public AbstractUGraphic(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, O graphic) { + super(Objects.requireNonNull(defaultBackground), colorMapper, stringBounder); this.graphic = graphic; } diff --git a/src/net/sourceforge/plantuml/ugraphic/UGraphicNull.java b/src/net/sourceforge/plantuml/ugraphic/UGraphicNull.java index 4ebb71051..2086b7b3a 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UGraphicNull.java +++ b/src/net/sourceforge/plantuml/ugraphic/UGraphicNull.java @@ -40,7 +40,6 @@ import java.io.OutputStream; import net.sourceforge.plantuml.EnsureVisible; import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity; import net.sourceforge.plantuml.ugraphic.color.HColorUtils; @@ -56,11 +55,7 @@ public class UGraphicNull extends AbstractUGraphic implements EnsureVisi } public UGraphicNull() { - super(HColorUtils.BLACK, new ColorMapperIdentity(), "foo"); - } - - public StringBounder getStringBounder() { - return FileFormat.PNG.getDefaultStringBounder(); + super(HColorUtils.BLACK, new ColorMapperIdentity(), FileFormat.PNG.getDefaultStringBounder(), "foo"); } @Override diff --git a/src/net/sourceforge/plantuml/ugraphic/debug/UGraphicDebug.java b/src/net/sourceforge/plantuml/ugraphic/debug/UGraphicDebug.java index 1630f4c70..e00ff3291 100644 --- a/src/net/sourceforge/plantuml/ugraphic/debug/UGraphicDebug.java +++ b/src/net/sourceforge/plantuml/ugraphic/debug/UGraphicDebug.java @@ -47,7 +47,6 @@ import java.util.Date; import java.util.List; import java.util.Locale; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic; import net.sourceforge.plantuml.ugraphic.ClipContainer; @@ -99,7 +98,7 @@ public class UGraphicDebug extends AbstractCommonUGraphic implements ClipContain public UGraphicDebug(double scaleFactor, Dimension2D dim, String svgLinkTarget, String hoverPathColorRGB, long seed, String preserveAspectRatio) { - super(HColorUtils.WHITE, new ColorMapperIdentity()); + super(HColorUtils.WHITE, new ColorMapperIdentity(), new StringBounderDebug()); this.output = new ArrayList<>(); this.scaleFactor = scaleFactor; this.dim = dim; @@ -109,10 +108,6 @@ public class UGraphicDebug extends AbstractCommonUGraphic implements ClipContain this.preserveAspectRatio = preserveAspectRatio; } - public StringBounder getStringBounder() { - return new StringBounderDebug(); - } - public void draw(UShape shape) { if (shape instanceof ULine) { outLine((ULine) shape); diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java index 011b7206f..452974348 100644 --- a/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java +++ b/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java @@ -41,7 +41,6 @@ import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.Url; import net.sourceforge.plantuml.eps.EpsGraphics; import net.sourceforge.plantuml.eps.EpsStrategy; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.UDrawable; import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic; @@ -60,8 +59,6 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class UGraphicEps extends AbstractUGraphic implements ClipContainer { - private final StringBounder stringBounder; - private final EpsStrategy strategyTOBEREMOVED; @Override @@ -71,7 +68,6 @@ public class UGraphicEps extends AbstractUGraphic implements ClipCo protected UGraphicEps(UGraphicEps other) { super(other); - this.stringBounder = other.stringBounder; this.strategyTOBEREMOVED = other.strategyTOBEREMOVED; register(strategyTOBEREMOVED); } @@ -81,9 +77,8 @@ public class UGraphicEps extends AbstractUGraphic implements ClipCo } private UGraphicEps(HColor defaultBackground, ColorMapper colorMapper, EpsStrategy strategy, EpsGraphics eps) { - super(defaultBackground, colorMapper, eps); + super(defaultBackground, colorMapper, FileFormat.PNG.getDefaultStringBounder(), eps); this.strategyTOBEREMOVED = strategy; - this.stringBounder = FileFormat.PNG.getDefaultStringBounder(); register(strategy); } @@ -111,10 +106,6 @@ public class UGraphicEps extends AbstractUGraphic implements ClipCo return this.getGraphicObject(); } - public StringBounder getStringBounder() { - return stringBounder; - } - public void drawEps(String eps, double x, double y) { this.getGraphicObject().drawEps(eps, x, y); } diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java index ae940f500..bdbda0546 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java @@ -53,7 +53,6 @@ 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; @@ -123,7 +122,7 @@ public class UGraphicG2d extends AbstractUGraphic implements EnsureV public UGraphicG2d(HColor defaultBackground, ColorMapper colorMapper, Graphics2D g2d, double dpiFactor, AffineTransformation affineTransform, double dx, double dy) { - super(defaultBackground, colorMapper, g2d); + super(defaultBackground, colorMapper, FileFormat.PNG.getDefaultStringBounder(), g2d); this.hasAffineTransform = affineTransform != null; this.dpiFactor = dpiFactor; if (dpiFactor != 1.0) { @@ -156,13 +155,6 @@ public class UGraphicG2d extends AbstractUGraphic implements EnsureV registerDriver(UCenteredCharacter.class, new DriverCenteredCharacterG2d()); } - public StringBounder getStringBounder() { - // if (hasAffineTransform) { - // return TextBlockUtils.getDummyStringBounder(); - // } - return FileFormat.PNG.getDefaultStringBounder(); - } - @Override protected void beforeDraw() { super.beforeDraw(); diff --git a/src/net/sourceforge/plantuml/ugraphic/html5/UGraphicHtml5.java b/src/net/sourceforge/plantuml/ugraphic/html5/UGraphicHtml5.java index 059edd4e2..5cd9aa316 100644 --- a/src/net/sourceforge/plantuml/ugraphic/html5/UGraphicHtml5.java +++ b/src/net/sourceforge/plantuml/ugraphic/html5/UGraphicHtml5.java @@ -38,7 +38,6 @@ import java.io.IOException; import java.io.OutputStream; import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic; import net.sourceforge.plantuml.ugraphic.AbstractUGraphic; import net.sourceforge.plantuml.ugraphic.ClipContainer; @@ -51,16 +50,13 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class UGraphicHtml5 extends AbstractUGraphic implements ClipContainer { - private final StringBounder stringBounder; - @Override protected AbstractCommonUGraphic copyUGraphic() { return this; } public UGraphicHtml5(HColor defaultBackground, ColorMapper colorMapper) { - super(defaultBackground, colorMapper, new Html5Drawer()); - stringBounder = FileFormat.PNG.getDefaultStringBounder(); + super(defaultBackground, colorMapper, FileFormat.PNG.getDefaultStringBounder(), new Html5Drawer()); registerDriver(URectangle.class, new DriverRectangleHtml5(this)); // registerDriver(UText.class, new DriverTextEps(imDummy, this, strategy)); registerDriver(UText.class, new DriverNopHtml5()); @@ -73,10 +69,6 @@ public class UGraphicHtml5 extends AbstractUGraphic implements Clip // registerDriver(DotPath.class, new DriverDotPathEps()); } - public StringBounder getStringBounder() { - return stringBounder; - } - // public void close() { // getEpsGraphics().close(); // } diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java index 3a14fed26..9627bfda7 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java @@ -44,7 +44,6 @@ import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.SvgCharSizeHack; import net.sourceforge.plantuml.TikzFontDistortion; 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; @@ -69,7 +68,6 @@ import net.sourceforge.plantuml.ugraphic.color.HColorGradient; public class UGraphicSvg extends AbstractUGraphic implements ClipContainer { - private final StringBounder stringBounder; private final boolean textAsPath2; private final String target; @@ -84,7 +82,6 @@ public class UGraphicSvg extends AbstractUGraphic implements ClipCo private UGraphicSvg(UGraphicSvg other) { super(other); - this.stringBounder = other.stringBounder; this.textAsPath2 = other.textAsPath2; this.target = other.target; register(); @@ -119,8 +116,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, svg); - this.stringBounder = FileFormat.SVG.getDefaultStringBounder(TikzFontDistortion.getDefault(), charSizeHack); + super(defaultBackground, colorMapper, FileFormat.SVG.getDefaultStringBounder(TikzFontDistortion.getDefault(), charSizeHack), svg); this.textAsPath2 = textAsPath; this.target = linkTarget; register(); @@ -148,10 +144,6 @@ public class UGraphicSvg extends AbstractUGraphic implements ClipCo return this.getGraphicObject(); } - public StringBounder getStringBounder() { - return stringBounder; - } - @Override public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException { try { diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java index df2d10e3f..d3c4db2bb 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java @@ -41,7 +41,6 @@ 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; @@ -61,14 +60,12 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class UGraphicTikz extends AbstractUGraphic implements ClipContainer { - private final StringBounder stringBounder; private final TikzFontDistortion tikzFontDistortion; private UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, TikzGraphics tikz, TikzFontDistortion tikzFontDistortion) { - super(defaultBackground, colorMapper, tikz); + super(defaultBackground, colorMapper, FileFormat.LATEX.getDefaultStringBounder(tikzFontDistortion), tikz); this.tikzFontDistortion = tikzFontDistortion; - this.stringBounder = FileFormat.LATEX.getDefaultStringBounder(tikzFontDistortion); register(); } @@ -87,7 +84,6 @@ public class UGraphicTikz extends AbstractUGraphic implements Clip private UGraphicTikz(UGraphicTikz other) { super(other); this.tikzFontDistortion = other.tikzFontDistortion; - this.stringBounder = other.stringBounder; register(); } @@ -106,10 +102,6 @@ public class UGraphicTikz extends AbstractUGraphic implements Clip registerDriver(UCenteredCharacter.class, new DriverCenteredCharacterTikz2()); } - public StringBounder getStringBounder() { - return stringBounder; - } - public void startUrl(Url url) { getGraphicObject().openLink(url.getUrl(), url.getTooltip()); } diff --git a/src/net/sourceforge/plantuml/ugraphic/txt/UGraphicTxt.java b/src/net/sourceforge/plantuml/ugraphic/txt/UGraphicTxt.java index c9d407ba6..a8746ea01 100644 --- a/src/net/sourceforge/plantuml/ugraphic/txt/UGraphicTxt.java +++ b/src/net/sourceforge/plantuml/ugraphic/txt/UGraphicTxt.java @@ -47,7 +47,6 @@ import net.sourceforge.plantuml.asciiart.TranslatedCharArea; import net.sourceforge.plantuml.asciiart.UmlCharArea; import net.sourceforge.plantuml.asciiart.UmlCharAreaImpl; import net.sourceforge.plantuml.graphic.FontStyle; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.security.SecurityUtils; import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic; import net.sourceforge.plantuml.ugraphic.ClipContainer; @@ -72,14 +71,10 @@ public class UGraphicTxt extends AbstractCommonUGraphic implements ClipContainer } public UGraphicTxt() { - super(HColorUtils.BLACK, new ColorMapperIdentity()); + super(HColorUtils.BLACK, new ColorMapperIdentity(), new TextStringBounder()); this.charArea = new UmlCharAreaImpl(); } - public StringBounder getStringBounder() { - return new TextStringBounder(); - } - public void draw(UShape shape) { // final UClip clip = getClip(); if (shape instanceof UText) { diff --git a/src/net/sourceforge/plantuml/ugraphic/visio/UGraphicVdx.java b/src/net/sourceforge/plantuml/ugraphic/visio/UGraphicVdx.java index 27dfafa2f..7355f04c2 100644 --- a/src/net/sourceforge/plantuml/ugraphic/visio/UGraphicVdx.java +++ b/src/net/sourceforge/plantuml/ugraphic/visio/UGraphicVdx.java @@ -39,7 +39,6 @@ import java.io.OutputStream; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.creole.legacy.AtomText; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic; import net.sourceforge.plantuml.ugraphic.AbstractUGraphic; @@ -58,15 +57,12 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class UGraphicVdx extends AbstractUGraphic implements ClipContainer { - private final StringBounder stringBounder; - public double dpiFactor() { return 1; } private UGraphicVdx(HColor defaultBackground, ColorMapper colorMapper, VisioGraphics visio) { - super(defaultBackground, colorMapper, visio); - this.stringBounder = FileFormat.PNG.getDefaultStringBounder(); + super(defaultBackground, colorMapper, FileFormat.PNG.getDefaultStringBounder(), visio); register(); } @@ -83,13 +79,12 @@ public class UGraphicVdx extends AbstractUGraphic implements Clip private UGraphicVdx(UGraphicVdx other) { super(other); - this.stringBounder = other.stringBounder; register(); } private void register() { registerDriver(URectangle.class, new DriverRectangleVdx()); - registerDriver(UText.class, new DriverTextVdx(stringBounder)); + registerDriver(UText.class, new DriverTextVdx(getStringBounder())); registerDriver(AtomText.class, new DriverNoneVdx()); registerDriver(ULine.class, new DriverLineVdx()); registerDriver(UPolygon.class, new DriverPolygonVdx()); @@ -101,10 +96,6 @@ public class UGraphicVdx extends AbstractUGraphic implements Clip registerDriver(UCenteredCharacter.class, new DriverNoneVdx()); } - public StringBounder getStringBounder() { - return stringBounder; - } - @Override public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException { getGraphicObject().createVsd(os);