1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-22 13:05:09 +00:00

Rename UGraphic2.writeImageTOBEMOVED() -> UGraphic.writeToStream() & remove UGraphic2 interface.

This commit is contained in:
matthew16550 2021-09-20 16:56:14 +10:00
parent 5ed7094e1f
commit 9791fc3f66
17 changed files with 66 additions and 103 deletions

View File

@ -34,6 +34,8 @@
*/
package net.sourceforge.plantuml.braille;
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.plainPngBuilder;
import java.io.IOException;
import java.io.OutputStream;
@ -45,7 +47,6 @@ import net.sourceforge.plantuml.ugraphic.AbstractUGraphic;
import net.sourceforge.plantuml.ugraphic.ClipContainer;
import net.sourceforge.plantuml.ugraphic.UCenteredCharacter;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic2;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UPath;
@ -55,10 +56,8 @@ import net.sourceforge.plantuml.ugraphic.UText;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.plainPngBuilder;
// https://www.branah.com/braille-translator
public class UGraphicBraille extends AbstractUGraphic<BrailleGrid> implements ClipContainer, UGraphic2 {
public class UGraphicBraille extends AbstractUGraphic<BrailleGrid> implements ClipContainer {
public static final int QUANTA = 4;
private final BrailleGrid grid;
@ -121,7 +120,8 @@ public class UGraphicBraille extends AbstractUGraphic<BrailleGrid> implements Cl
return FileFormat.BRAILLE_PNG.getDefaultStringBounder();
}
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
plainPngBuilder(new BrailleDrawer(getGraphicObject()))
.metadata(metadata)
.write(os);

View File

@ -43,6 +43,9 @@ import net.sourceforge.plantuml.ugraphic.UShape;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import java.io.IOException;
import java.io.OutputStream;
public abstract class UGraphicDelegator implements UGraphic {
final private UGraphic ug;
@ -105,4 +108,8 @@ public abstract class UGraphicDelegator implements UGraphic {
return ug.getDefaultBackground();
}
}
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
ug.writeToStream(os, metadata, dpi);
}
}

View File

@ -93,7 +93,7 @@ public class GraphicsSudoku {
new ColorMapperIdentity(), false, 1.0, null, null, 0, "none", SvgCharSizeHack.NO_HACK,
LengthAdjust.defaultValue());
drawInternal(ug);
ug.createXml(os, null);
ug.writeToStream(os, null, -1); // dpi param is not used
return ImageDataSimple.ok();
}
@ -101,7 +101,7 @@ public class GraphicsSudoku {
final UGraphicTikz ug = new UGraphicTikz(HColorUtils.WHITE, new ColorMapperIdentity(), 1,
fileFormat == FileFormat.LATEX, TikzFontDistortion.getDefault());
drawInternal(ug);
ug.createTikz(os);
ug.writeToStream(os, null, -1); // dpi param is not used
return ImageDataSimple.ok();
}

View File

@ -175,8 +175,8 @@ public class FontChecker {
public void drawU(UGraphic ug) {
ug = ug.apply(HColorUtils.BLACK);
ug.draw(new URectangle(dim - 1, dim - 1));
if (ug instanceof UGraphic2) {
ug = (UGraphic2) ug.apply(new UTranslate(dim / 3, 2 * dim / 3));
if (!(ug instanceof LimitFinder)) {
ug = ug.apply(new UTranslate(dim / 3, 2 * dim / 3));
final UText text = new UText("" + c, FontConfiguration.blackBlueTrue(font));
ug.draw(text);
}

View File

@ -273,16 +273,15 @@ public class ImageBuilder {
final Scale scale = titledDiagram == null ? null : titledDiagram.getScale();
final double scaleFactor = (scale == null ? 1 : scale.getScale(dim.getWidth(), dim.getHeight())) * getDpi()
/ 96.0;
final UGraphic2 ug = createUGraphic(fileFormatOption, dim, animationArg, dx, dy, scaleFactor);
UGraphic ug2 = ug;
UGraphic ug = createUGraphic(fileFormatOption, dim, animationArg, dx, dy, scaleFactor);
maybeDrawBorder(ug, dim);
if (randomPixel) {
drawRandomPoint(ug2);
drawRandomPoint(ug);
}
ug2 = handwritten(ug2.apply(new UTranslate(margin.getLeft(), margin.getTop())));
udrawable.drawU(ug2);
ug2.flushUg();
ug.writeImageTOBEMOVED(os, metadata, 96);
ug = handwritten(ug.apply(new UTranslate(margin.getLeft(), margin.getTop())));
udrawable.drawU(ug);
ug.flushUg();
ug.writeToStream(os, metadata, 96);
os.flush();
if (ug instanceof UGraphicG2d) {
@ -403,7 +402,7 @@ public class ImageBuilder {
return ImageIO.read(baos.toByteArray());
}
private UGraphic2 createUGraphic(FileFormatOption option, final Dimension2D dim, Animation animationArg, double dx,
private UGraphic createUGraphic(FileFormatOption option, final Dimension2D dim, Animation animationArg, double dx,
double dy, double scaleFactor) {
switch (option.getFileFormat()) {
case PNG:
@ -435,7 +434,7 @@ public class ImageBuilder {
}
}
private UGraphic2 createUGraphicSVG(double scaleFactor, Dimension2D dim) {
private UGraphic createUGraphicSVG(double scaleFactor, Dimension2D dim) {
final String hoverPathColorRGB = getHoverPathColorRGB();
final LengthAdjust lengthAdjust = skinParam == null ? LengthAdjust.defaultValue() : skinParam.getlengthAdjust();
final String preserveAspectRatio = getPreserveAspectRatio();
@ -448,7 +447,7 @@ public class ImageBuilder {
}
private UGraphic2 createUGraphicPNG(double scaleFactor, final Dimension2D dim, Animation affineTransforms,
private UGraphic createUGraphicPNG(double scaleFactor, final Dimension2D dim, Animation affineTransforms,
double dx, double dy, String watermark) {
Color backColor = getDefaultBackColor();

View File

@ -40,6 +40,9 @@ import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import java.io.IOException;
import java.io.OutputStream;
public interface UGraphic {
public StringBounder getStringBounder();
@ -66,4 +69,5 @@ public interface UGraphic {
public HColor getDefaultBackground();
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException;
}

View File

@ -1,44 +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;
import java.io.IOException;
import java.io.OutputStream;
public interface UGraphic2 extends UGraphic {
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException;
}

View File

@ -41,6 +41,9 @@ import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
import java.io.IOException;
import java.io.OutputStream;
public abstract class UGraphicNo implements UGraphic {
private final StringBounder stringBounder;
@ -104,7 +107,12 @@ public abstract class UGraphicNo implements UGraphic {
public boolean matchesProperty(String propertyName) {
return false;
}
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
throw new UnsupportedOperationException();
}
//
// Internal things
//

View File

@ -44,7 +44,7 @@ import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class UGraphicNull extends AbstractUGraphic<String> implements EnsureVisible, UGraphic2 {
public class UGraphicNull extends AbstractUGraphic<String> implements EnsureVisible {
@Override
protected AbstractCommonUGraphic copyUGraphic() {
@ -63,7 +63,8 @@ public class UGraphicNull extends AbstractUGraphic<String> implements EnsureVisi
return FileFormat.PNG.getDefaultStringBounder();
}
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
}
public void ensureVisible(double x, double y) {

View File

@ -55,7 +55,6 @@ import net.sourceforge.plantuml.ugraphic.UCenteredCharacter;
import net.sourceforge.plantuml.ugraphic.UComment;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UEmpty;
import net.sourceforge.plantuml.ugraphic.UGraphic2;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UPath;
import net.sourceforge.plantuml.ugraphic.UPolygon;
@ -70,7 +69,7 @@ import net.sourceforge.plantuml.ugraphic.color.HColorMiddle;
import net.sourceforge.plantuml.ugraphic.color.HColorSimple;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class UGraphicDebug extends AbstractCommonUGraphic implements ClipContainer, UGraphic2 {
public class UGraphicDebug extends AbstractCommonUGraphic implements ClipContainer {
private final List<String> output;
private final double scaleFactor;
@ -280,7 +279,8 @@ public class UGraphicDebug extends AbstractCommonUGraphic implements ClipContain
return color.getClass().getSimpleName() + " " + new Date();
}
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
print(os, "DPI: " + dpi);
print(os, "dimension: " + pointd(dim.getWidth(), dim.getHeight()));
print(os, "scaleFactor: " + String.format(Locale.US, "%.4f", scaleFactor));

View File

@ -49,7 +49,6 @@ import net.sourceforge.plantuml.ugraphic.AbstractUGraphic;
import net.sourceforge.plantuml.ugraphic.ClipContainer;
import net.sourceforge.plantuml.ugraphic.UCenteredCharacter;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic2;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UPath;
@ -59,7 +58,7 @@ import net.sourceforge.plantuml.ugraphic.UText;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class UGraphicEps extends AbstractUGraphic<EpsGraphics> implements ClipContainer, UGraphic2 {
public class UGraphicEps extends AbstractUGraphic<EpsGraphics> implements ClipContainer {
private final StringBounder stringBounder;
@ -135,7 +134,8 @@ public class UGraphicEps extends AbstractUGraphic<EpsGraphics> implements ClipCo
getGraphicObject().closeLink();
}
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
os.write(getEPSCode().getBytes());
}

View File

@ -64,7 +64,6 @@ import net.sourceforge.plantuml.ugraphic.UChange;
import net.sourceforge.plantuml.ugraphic.UClip;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UGraphic2;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.UImageSvg;
import net.sourceforge.plantuml.ugraphic.ULine;
@ -76,7 +75,7 @@ import net.sourceforge.plantuml.ugraphic.UText;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class UGraphicG2d extends AbstractUGraphic<Graphics2D> implements EnsureVisible, UGraphic2 {
public class UGraphicG2d extends AbstractUGraphic<Graphics2D> implements EnsureVisible {
private BufferedImage bufferedImage;
@ -214,7 +213,8 @@ public class UGraphicG2d extends AbstractUGraphic<Graphics2D> implements EnsureV
return getGraphicObject();
}
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
final BufferedImage im = getBufferedImage();
PngIO.write(im, os, metadata, dpi);
}

View File

@ -42,7 +42,6 @@ import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic;
import net.sourceforge.plantuml.ugraphic.AbstractUGraphic;
import net.sourceforge.plantuml.ugraphic.ClipContainer;
import net.sourceforge.plantuml.ugraphic.UGraphic2;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UPolygon;
import net.sourceforge.plantuml.ugraphic.URectangle;
@ -50,7 +49,7 @@ import net.sourceforge.plantuml.ugraphic.UText;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class UGraphicHtml5 extends AbstractUGraphic<Html5Drawer> implements ClipContainer, UGraphic2 {
public class UGraphicHtml5 extends AbstractUGraphic<Html5Drawer> implements ClipContainer {
private final StringBounder stringBounder;
@ -86,7 +85,8 @@ public class UGraphicHtml5 extends AbstractUGraphic<Html5Drawer> implements Clip
return getGraphicObject().generateHtmlCode();
}
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
os.write(generateHtmlCode().getBytes());
}

View File

@ -54,7 +54,6 @@ import net.sourceforge.plantuml.ugraphic.ClipContainer;
import net.sourceforge.plantuml.ugraphic.UCenteredCharacter;
import net.sourceforge.plantuml.ugraphic.UComment;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic2;
import net.sourceforge.plantuml.ugraphic.UGroupType;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.UImageSvg;
@ -68,7 +67,7 @@ import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorGradient;
public class UGraphicSvg extends AbstractUGraphic<SvgGraphics> implements ClipContainer, UGraphic2 {
public class UGraphicSvg extends AbstractUGraphic<SvgGraphics> implements ClipContainer {
private final StringBounder stringBounder;
private final boolean textAsPath2;
@ -153,7 +152,8 @@ public class UGraphicSvg extends AbstractUGraphic<SvgGraphics> implements ClipCo
return stringBounder;
}
public void createXml(OutputStream os, String metadata) throws IOException {
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
try {
if (metadata != null) {
getGraphicObject().addComment(metadata);
@ -184,10 +184,6 @@ public class UGraphicSvg extends AbstractUGraphic<SvgGraphics> implements ClipCo
getGraphicObject().closeLink();
}
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
createXml(os, metadata);
}
@Override
protected void drawComment(UComment comment) {
getGraphicObject().addComment(comment.getComment());

View File

@ -49,7 +49,6 @@ import net.sourceforge.plantuml.ugraphic.AbstractUGraphic;
import net.sourceforge.plantuml.ugraphic.ClipContainer;
import net.sourceforge.plantuml.ugraphic.UCenteredCharacter;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic2;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.UImageSvg;
import net.sourceforge.plantuml.ugraphic.ULine;
@ -60,7 +59,7 @@ import net.sourceforge.plantuml.ugraphic.UText;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class UGraphicTikz extends AbstractUGraphic<TikzGraphics> implements ClipContainer, UGraphic2 {
public class UGraphicTikz extends AbstractUGraphic<TikzGraphics> implements ClipContainer {
private final StringBounder stringBounder;
private final TikzFontDistortion tikzFontDistortion;
@ -119,11 +118,8 @@ public class UGraphicTikz extends AbstractUGraphic<TikzGraphics> implements Clip
getGraphicObject().closeLink();
}
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
createTikz(os);
}
public void createTikz(OutputStream os) throws IOException {
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
getGraphicObject().createData(os);
}

View File

@ -51,14 +51,13 @@ import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.security.SecurityUtils;
import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic;
import net.sourceforge.plantuml.ugraphic.ClipContainer;
import net.sourceforge.plantuml.ugraphic.UGraphic2;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.UShape;
import net.sourceforge.plantuml.ugraphic.UText;
import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class UGraphicTxt extends AbstractCommonUGraphic implements ClipContainer, UGraphic2 {
public class UGraphicTxt extends AbstractCommonUGraphic implements ClipContainer {
private final UmlCharArea charArea;
@ -116,7 +115,8 @@ public class UGraphicTxt extends AbstractCommonUGraphic implements ClipContainer
return new Dimension2DDouble(0, 0);
}
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
final PrintStream ps = SecurityUtils.createPrintStream(os, true, UTF_8);
getCharArea().print(ps);
}

View File

@ -46,7 +46,6 @@ import net.sourceforge.plantuml.ugraphic.AbstractUGraphic;
import net.sourceforge.plantuml.ugraphic.ClipContainer;
import net.sourceforge.plantuml.ugraphic.UCenteredCharacter;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic2;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.UImageSvg;
import net.sourceforge.plantuml.ugraphic.ULine;
@ -57,7 +56,7 @@ import net.sourceforge.plantuml.ugraphic.UText;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class UGraphicVdx extends AbstractUGraphic<VisioGraphics> implements ClipContainer, UGraphic2 {
public class UGraphicVdx extends AbstractUGraphic<VisioGraphics> implements ClipContainer {
private final StringBounder stringBounder;
@ -106,11 +105,8 @@ public class UGraphicVdx extends AbstractUGraphic<VisioGraphics> implements Clip
return stringBounder;
}
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
createVsd(os);
}
public void createVsd(OutputStream os) throws IOException {
@Override
public void writeToStream(OutputStream os, String metadata, int dpi) throws IOException {
getGraphicObject().createVsd(os);
}