From d6737bb6aa9bccc81c200da9bee0b1bb61a03473 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Fri, 29 Oct 2021 16:42:46 +1100 Subject: [PATCH] Inject StringBounder into UGraphicBraille, UGraphicEps, UGraphicHtml5, UGraphicVdx. Also minor nearby tidying. --- .../plantuml/braille/UGraphicBraille.java | 15 ++++----------- .../plantuml/sudoku/GraphicsSudoku.java | 2 +- .../plantuml/ugraphic/ImageBuilder.java | 10 +++++----- .../plantuml/ugraphic/eps/UGraphicEps.java | 19 ++++++++----------- .../ugraphic/html5/UGraphicHtml5.java | 6 +++--- .../plantuml/ugraphic/visio/UGraphicVdx.java | 12 +++--------- 6 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/net/sourceforge/plantuml/braille/UGraphicBraille.java b/src/net/sourceforge/plantuml/braille/UGraphicBraille.java index cd4a271ba..680da8881 100644 --- a/src/net/sourceforge/plantuml/braille/UGraphicBraille.java +++ b/src/net/sourceforge/plantuml/braille/UGraphicBraille.java @@ -39,7 +39,7 @@ import static net.sourceforge.plantuml.ugraphic.ImageBuilder.plainPngBuilder; 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; @@ -59,20 +59,19 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class UGraphicBraille extends AbstractUGraphic implements ClipContainer { public static final int QUANTA = 4; - private final BrailleGrid grid; @Override protected AbstractCommonUGraphic copyUGraphic() { return new UGraphicBraille(this); } - public UGraphicBraille(HColor defaultBackground, ColorMapper colorMapper) { - this(defaultBackground, colorMapper, new BrailleGrid(QUANTA)); + public UGraphicBraille(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder) { + super(defaultBackground, colorMapper, stringBounder, new BrailleGrid(QUANTA)); + register(); } private UGraphicBraille(UGraphicBraille other) { super(other); - this.grid = other.grid; register(); } @@ -96,12 +95,6 @@ public class UGraphicBraille extends AbstractUGraphic implements Cl // svg.paintBackcolorGradient(mapper, gr); // } - private UGraphicBraille(HColor defaultBackground, ColorMapper colorMapper, BrailleGrid grid) { - super(defaultBackground, colorMapper, FileFormat.BRAILLE_PNG.getDefaultStringBounder(), grid); - this.grid = grid; - register(); - } - private void register() { ignoreShape(URectangle.class); registerDriver(URectangle.class, new DriverRectangleBraille(this)); diff --git a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java index 5c7d0eded..1cc90e9ca 100644 --- a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java +++ b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java @@ -81,7 +81,7 @@ public class GraphicsSudoku { public ImageData writeImageEps(OutputStream os) throws IOException { final UGraphicEps ug = new UGraphicEps(HColorUtils.WHITE, new ColorMapperIdentity(), - EpsStrategy.WITH_MACRO_AND_TEXT); + FileFormat.EPS_TEXT.getDefaultStringBounder(), EpsStrategy.WITH_MACRO_AND_TEXT); drawInternal(ug); os.write(ug.getEPSCode().getBytes()); return ImageDataSimple.ok(); diff --git a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java index 15ed78804..2c2da6772 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java +++ b/src/net/sourceforge/plantuml/ugraphic/ImageBuilder.java @@ -406,19 +406,19 @@ public class ImageBuilder { case SVG: return createUGraphicSVG(scaleFactor, dim); case EPS: - return new UGraphicEps(backcolor, colorMapper, EpsStrategy.getDefault2()); + return new UGraphicEps(backcolor, colorMapper, stringBounder, EpsStrategy.getDefault2()); case EPS_TEXT: - return new UGraphicEps(backcolor, colorMapper, EpsStrategy.WITH_MACRO_AND_TEXT); + return new UGraphicEps(backcolor, colorMapper, stringBounder, EpsStrategy.WITH_MACRO_AND_TEXT); case HTML5: - return new UGraphicHtml5(backcolor, colorMapper); + return new UGraphicHtml5(backcolor, colorMapper, stringBounder); case VDX: - return new UGraphicVdx(backcolor, colorMapper); + return new UGraphicVdx(backcolor, colorMapper, stringBounder); case LATEX: return new UGraphicTikz(backcolor, colorMapper, stringBounder, scaleFactor, true); case LATEX_NO_PREAMBLE: return new UGraphicTikz(backcolor, colorMapper, stringBounder, scaleFactor, false); case BRAILLE_PNG: - return new UGraphicBraille(backcolor, colorMapper); + return new UGraphicBraille(backcolor, colorMapper, stringBounder); case UTXT: case ATXT: return new UGraphicTxt(); diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java index 452974348..7529460af 100644 --- a/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java +++ b/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java @@ -41,6 +41,7 @@ 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; @@ -69,22 +70,18 @@ public class UGraphicEps extends AbstractUGraphic implements ClipCo protected UGraphicEps(UGraphicEps other) { super(other); this.strategyTOBEREMOVED = other.strategyTOBEREMOVED; - register(strategyTOBEREMOVED); + register(); } - public UGraphicEps(HColor defaultBackground, ColorMapper colorMapper, EpsStrategy strategy) { - this(defaultBackground, colorMapper, strategy, strategy.creatEpsGraphics()); - } - - private UGraphicEps(HColor defaultBackground, ColorMapper colorMapper, EpsStrategy strategy, EpsGraphics eps) { - super(defaultBackground, colorMapper, FileFormat.PNG.getDefaultStringBounder(), eps); + public UGraphicEps(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, EpsStrategy strategy) { + super(defaultBackground, colorMapper, stringBounder, strategy.creatEpsGraphics()); this.strategyTOBEREMOVED = strategy; - register(strategy); + register(); } - private void register(EpsStrategy strategy) { + private void register() { registerDriver(URectangle.class, new DriverRectangleEps(this)); - registerDriver(UText.class, new DriverTextEps(this, strategy)); + registerDriver(UText.class, new DriverTextEps(this, strategyTOBEREMOVED)); registerDriver(ULine.class, new DriverLineEps(this)); registerDriver(UPolygon.class, new DriverPolygonEps(this)); registerDriver(UEllipse.class, new DriverEllipseEps(this)); @@ -112,7 +109,7 @@ public class UGraphicEps extends AbstractUGraphic implements ClipCo static public String getEpsString(HColor defaultBackground, ColorMapper colorMapper, EpsStrategy epsStrategy, UDrawable udrawable) throws IOException { - final UGraphicEps ug = new UGraphicEps(defaultBackground, colorMapper, epsStrategy); + final UGraphicEps ug = new UGraphicEps(defaultBackground, colorMapper, FileFormat.EPS_TEXT.getDefaultStringBounder(), epsStrategy); udrawable.drawU(ug); return ug.getEPSCode(); } diff --git a/src/net/sourceforge/plantuml/ugraphic/html5/UGraphicHtml5.java b/src/net/sourceforge/plantuml/ugraphic/html5/UGraphicHtml5.java index ca5bc0a98..ee3c49536 100644 --- a/src/net/sourceforge/plantuml/ugraphic/html5/UGraphicHtml5.java +++ b/src/net/sourceforge/plantuml/ugraphic/html5/UGraphicHtml5.java @@ -37,7 +37,7 @@ package net.sourceforge.plantuml.ugraphic.html5; 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; @@ -55,8 +55,8 @@ public class UGraphicHtml5 extends AbstractUGraphic implements Clip return this; } - public UGraphicHtml5(HColor defaultBackground, ColorMapper colorMapper) { - super(defaultBackground, colorMapper, FileFormat.PNG.getDefaultStringBounder(), new Html5Drawer()); + public UGraphicHtml5(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder) { + super(defaultBackground, colorMapper, stringBounder, new Html5Drawer()); registerDriver(URectangle.class, new DriverRectangleHtml5(this)); // registerDriver(UText.class, new DriverTextEps(imDummy, this, strategy)); ignoreShape(UText.class); diff --git a/src/net/sourceforge/plantuml/ugraphic/visio/UGraphicVdx.java b/src/net/sourceforge/plantuml/ugraphic/visio/UGraphicVdx.java index fdb6605c4..522d13454 100644 --- a/src/net/sourceforge/plantuml/ugraphic/visio/UGraphicVdx.java +++ b/src/net/sourceforge/plantuml/ugraphic/visio/UGraphicVdx.java @@ -37,8 +37,8 @@ package net.sourceforge.plantuml.ugraphic.visio; import java.io.IOException; 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; @@ -61,15 +61,9 @@ public class UGraphicVdx extends AbstractUGraphic implements Clip return 1; } - private UGraphicVdx(HColor defaultBackground, ColorMapper colorMapper, VisioGraphics visio) { - super(defaultBackground, colorMapper, FileFormat.PNG.getDefaultStringBounder(), visio); + public UGraphicVdx(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder) { + super(defaultBackground, colorMapper, stringBounder, new VisioGraphics()); register(); - - } - - public UGraphicVdx(HColor defaultBackground, ColorMapper colorMapper) { - this(defaultBackground, colorMapper, new VisioGraphics()); - } @Override