1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-26 04:17:39 +00:00
Arnaud Roques 2023-02-04 13:50:16 +01:00
parent 4888ac976d
commit 1c650bb2f9
28 changed files with 515 additions and 80 deletions

View File

@ -0,0 +1,135 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2023, 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 com.plantuml.wasm;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.io.IOException;
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import net.sourceforge.plantuml.BlockUml;
import net.sourceforge.plantuml.BlockUmlBuilder;
import net.sourceforge.plantuml.ErrorUml;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.error.PSystemError;
import net.sourceforge.plantuml.klimt.URectangle;
import net.sourceforge.plantuml.klimt.color.ColorMapper;
import net.sourceforge.plantuml.klimt.color.HColor;
import net.sourceforge.plantuml.klimt.color.HColors;
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d;
public class Canvas {
public static Frame frame;
public static Graphics2D g2d;
private static int frameWidth;
private static int frameHeight;
public static int initCanvas(int width, int height) throws IOException {
WasmLog.start = System.currentTimeMillis();
WasmLog.log("initCanvas");
if (g2d == null) {
frameWidth = width;
frameHeight = height;
frame = new Frame();
frame.setUndecorated(true);
frame.setSize(frameWidth, frameHeight);
frame.setLayout(null);
frame.setVisible(true);
g2d = (Graphics2D) frame.getGraphics();
WasmLog.log("initCanvas done = " + frame);
return 45;
}
WasmLog.log("initCanvas skipped because it has already been done");
return 47;
}
public static int convertCanvas(int width, int height, String text) throws IOException {
WasmLog.start = System.currentTimeMillis();
WasmLog.log("1frame= " + frame);
if (g2d == null) {
frameWidth = width;
frameHeight = height;
frame = new Frame();
frame.setUndecorated(true);
frame.setSize(frameWidth, frameHeight);
frame.setLayout(null);
frame.setVisible(true);
g2d = (Graphics2D) frame.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
WasmLog.log("3frame= " + frame);
return 45;
}
final BlockUmlBuilder builder = new BlockUmlBuilder(Collections.<String>emptyList(), UTF_8,
Defines.createEmpty(), new StringReader(text), null, "string");
List<BlockUml> blocks = builder.getBlockUmls();
WasmLog.log("...loading data...");
final Diagram system = blocks.get(0).getDiagram();
if (system instanceof PSystemError) {
final ErrorUml error = ((PSystemError) system).getFirstError();
WasmLog.log("[" + error.getPosition() + "] " + error.getError());
return -242;
}
WasmLog.log("...processing...");
final HColor back = HColors.simple(Color.WHITE);
final StringBounder stringBounder = new StringBounderCanvas(g2d);
final UGraphicG2d ug = new UGraphicG2d(back, ColorMapper.IDENTITY, stringBounder, g2d, 1.0);
// ug.apply(back).apply(back.bg()).draw(new URectangle(frameWidth,
// frameHeight));
ug.apply(HColors.RED).apply(back.bg()).draw(new URectangle(frameWidth, frameHeight));
WasmLog.log("system= " + system.getClass().getName());
system.exportDiagramGraphic(ug);
return 43;
}
}

View File

@ -47,6 +47,7 @@ public class RunInit {
cheerpjPath = argsArray[0];
System.err.println("RunInit: " + Version.versionString());
System.err.println("cheerpjPath is " + cheerpjPath);
WasmLog.log("Loading completed!");
}
}

View File

@ -0,0 +1,69 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2023, 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 com.plantuml.wasm;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import net.sourceforge.plantuml.awt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.font.StringBounderRaw;
import net.sourceforge.plantuml.klimt.font.UFont;
public class StringBounderCanvas extends StringBounderRaw {
private final Graphics2D g2d;
public StringBounderCanvas(Graphics2D g2d) {
super(g2d.getFontRenderContext());
this.g2d = g2d;
}
@Override
public boolean matchesProperty(String propertyName) {
return false;
}
@Override
protected XDimension2D calculateDimensionInternal(UFont font, String text) {
final Font javaFont = font.getUnderlayingFont();
final FontMetrics fm = g2d.getFontMetrics(javaFont);
final Rectangle2D rect = fm.getStringBounds(text, g2d);
return new XDimension2D(rect.getWidth(), rect.getHeight());
}
}

View File

@ -35,22 +35,40 @@
*/
package com.plantuml.wasm;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import net.sourceforge.plantuml.BlockUml;
import net.sourceforge.plantuml.BlockUmlBuilder;
import net.sourceforge.plantuml.ErrorUml;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.error.PSystemError;
import net.sourceforge.plantuml.preproc.Defines;
public class Utils {
public static int convertPng(String pathOut, String text) throws IOException {
final FileFormatOption format = new FileFormatOption(FileFormat.PNG);
text = cleanText(text);
return doTheJob(pathOut, text, format);
WasmLog.start = System.currentTimeMillis();
WasmLog.log("Starting processing");
int ret = 42;
try {
final FileFormatOption format = new FileFormatOption(FileFormat.PNG);
text = cleanText(text);
ret = doTheJob(pathOut, text, format);
} catch (Throwable t) {
WasmLog.log("Fatal error " + t);
}
return ret;
}
private static String cleanText(String text) {
@ -62,22 +80,37 @@ public class Utils {
return text;
}
// public static int convertSvg(String pathOut, String text) throws IOException {
// final FileFormatOption format = new FileFormatOption(FileFormat.SVG);
// text = cleanText(text);
// return doTheJob(pathOut, text, format);
// }
private static int doTheJob(String pathOut, String text, final FileFormatOption format)
throws FileNotFoundException, IOException {
final SourceStringReader sr = new SourceStringReader(text);
final BlockUmlBuilder builder = new BlockUmlBuilder(Collections.<String>emptyList(), UTF_8,
Defines.createEmpty(), new StringReader(text), null, "string");
List<BlockUml> blocks = builder.getBlockUmls();
if (blocks.size() == 0)
return 142;
final FileOutputStream fos = new FileOutputStream(new File(pathOut));
DiagramDescription description = sr.outputImage(fos, format);
fos.close();
if (description.getDescription() != null && description.getDescription().contains("error"))
return 1;
WasmLog.log("...loading data...");
return 0;
}
public static int convertSvg(String pathOut, String text) throws IOException {
final FileFormatOption format = new FileFormatOption(FileFormat.SVG);
text = cleanText(text);
return doTheJob(pathOut, text, format);
final Diagram system = blocks.get(0).getDiagram();
if (system instanceof PSystemError) {
final ErrorUml error = ((PSystemError) system).getFirstError();
WasmLog.log("[" + error.getPosition() + "] " + error.getError());
return -242;
} else {
WasmLog.log("...processing...");
final ImageData imageData = system.exportDiagram(fos, 0, format);
WasmLog.log("Done!");
fos.close();
return 0;
}
}
}

View File

@ -0,0 +1,65 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2023, 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 com.plantuml.wasm;
//::uncomment when WASM
//import com.leaningtech.client.Document;
//import com.leaningtech.client.Element;
//import com.leaningtech.client.Global;
//::done
public class WasmLog {
public static long start;
public static void log(String message) {
// ::uncomment when WASM
// if (start > 0) {
// final long duration = System.currentTimeMillis() - start;
// message = "(" + duration + " ms) " + message;
// }
// System.err.print(message);
// final Document document = Global.document;
// if (document == null)
// return;
// final Element messageJava = document.getElementById(Global.JSString("message-java"));
// if (messageJava == null)
// return;
// messageJava.set_textContent(Global.JSString(message));
// ::done
}
}

View File

@ -41,6 +41,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.Objects;
import net.sourceforge.plantuml.api.ImageDataSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.ProtectedCommand;
@ -51,13 +52,18 @@ import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.DisplayPositioned;
import net.sourceforge.plantuml.cucadiagram.DisplayPositionned;
import net.sourceforge.plantuml.graphic.VerticalAlignment;
import net.sourceforge.plantuml.klimt.UText;
import net.sourceforge.plantuml.klimt.UTranslate;
import net.sourceforge.plantuml.klimt.color.ColorMapper;
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.klimt.font.UFont;
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
import net.sourceforge.plantuml.stats.StatsUtilsIncrement;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.text.BackSlash;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.utils.BlocLines;
import net.sourceforge.plantuml.version.License;
import net.sourceforge.plantuml.version.Version;
@ -221,4 +227,13 @@ public abstract class AbstractPSystem implements Diagram {
return null;
}
@Override
public ImageData exportDiagramGraphic(UGraphic ug) {
final UFont font = UFont.monospaced(14);
final FontConfiguration fc = FontConfiguration.blackBlueTrue(font);
final UText text = new UText("Not implemented yet for " + getClass().getName(), fc);
ug.apply(new UTranslate(10, 10)).draw(text);
return new ImageDataSimple(100, 100);
}
}

View File

@ -47,6 +47,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.plantuml.wasm.WasmLog;
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.preproc.FileWithSuffix;
import net.sourceforge.plantuml.preproc.ImportedFiles;
@ -136,6 +138,7 @@ public final class BlockUmlBuilder implements DefinitionsContainer {
if (paused)
current.add(s);
WasmLog.log("...text loaded...");
final BlockUml uml = new BlockUml(current, defines.cloneMe(), null, this, charset);
usedFiles.addAll(uml.getIncluded());
blocks.add(uml);

View File

@ -129,7 +129,7 @@ public enum FileFormat {
return "." + StringUtils.goLowerCase(name());
}
final static private BufferedImage imDummy = new BufferedImage(800, 100, BufferedImage.TYPE_INT_RGB);
final static private BufferedImage imDummy = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
final static public Graphics2D gg = imDummy.createGraphics();
static {
// KEY_FRACTIONALMETRICS
@ -159,7 +159,7 @@ public enum FileFormat {
}
private StringBounder getSvgStringBounder(final SvgCharSizeHack charSizeHack) {
return new StringBounderRaw() {
return new StringBounderRaw(FileFormat.gg.getFontRenderContext()) {
public String toString() {
return "FileFormat::getSvgStringBounder";
}
@ -177,7 +177,7 @@ public enum FileFormat {
}
private StringBounder getNormalStringBounder() {
return new StringBounderRaw() {
return new StringBounderRaw(FileFormat.gg.getFontRenderContext()) {
public String toString() {
return "FileFormat::getNormalStringBounder";
}
@ -202,7 +202,7 @@ public enum FileFormat {
// ::comment when WASM
private StringBounder getBrailleStringBounder() {
return new StringBounderRaw() {
return new StringBounderRaw(FileFormat.gg.getFontRenderContext()) {
public String toString() {
return "FileFormat::getBrailleStringBounder";
}
@ -228,7 +228,7 @@ public enum FileFormat {
}
private StringBounder getTikzStringBounder(final TikzFontDistortion tikzFontDistortion) {
return new StringBounderRaw() {
return new StringBounderRaw(FileFormat.gg.getFontRenderContext()) {
public String toString() {
return "FileFormat::getTikzStringBounder";
}

View File

@ -40,6 +40,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.plantuml.wasm.WasmLog;
import net.sourceforge.plantuml.acearth.PSystemXearthFactory;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory;
import net.sourceforge.plantuml.activitydiagram3.ActivityDiagramFactory3;
@ -113,6 +115,8 @@ public class PSystemBuilder {
final public Diagram createPSystem(List<StringLocated> source, List<StringLocated> rawSource,
Map<String, String> skinParam) {
WasmLog.log("..compiling diagram...");
final long now = System.currentTimeMillis();
Diagram result = null;
@ -137,6 +141,7 @@ public class PSystemBuilder {
if (diagramType != systemFactory.getDiagramType())
continue;
WasmLog.log("...trying " + systemFactory.getClass().getName() + " ...");
final Diagram sys = systemFactory.createSystem(umlSource, skinParam);
if (isOk(sys)) {
result = sys;
@ -173,7 +178,7 @@ public class PSystemBuilder {
// ::comment when WASM
factories.add(new BpmDiagramFactory(DiagramType.BPM));
// ::done
// factories.add(new PostIdDiagramFactory());
factories.add(new PSystemLicenseFactory());
factories.add(new PSystemVersionFactory());

View File

@ -35,12 +35,17 @@
*/
package net.sourceforge.plantuml.asciiart;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.awt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.font.StringBounderRaw;
import net.sourceforge.plantuml.klimt.font.UFont;
public class TextStringBounder extends StringBounderRaw {
public TextStringBounder() {
super(FileFormat.gg.getFontRenderContext());
}
protected XDimension2D calculateDimensionInternal(UFont font, String text) {
final int length1 = text.codePointCount(0, text.length());
final int length2 = text.length();

View File

@ -83,6 +83,7 @@ import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.svek.CucaDiagramFileMaker;
import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek;
import net.sourceforge.plantuml.text.BackSlash;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker;
import net.sourceforge.plantuml.xmlsc.StateDiagramScxmlMaker;
@ -422,6 +423,13 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
}
// ::done
@Override
final public ImageData exportDiagramGraphic(UGraphic ug) {
final CucaDiagramFileMaker maker = new CucaDiagramFileMakerSmetana(this, ug.getStringBounder());
return maker.createOneGraphic(ug);
}
@Override
protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption)
throws IOException {

View File

@ -169,18 +169,18 @@ public class CommandCreateClassMultilines extends CommandMultilines2<ClassDiagra
final Quark quark = diagram.quarkInContext(idShort, true);
Display display = Display.getWithNewlines(displayString);
if (Display.isNull(display))
display = Display.getWithNewlines(quark.getName()).withCreoleMode(CreoleMode.SIMPLE_LINE);
EntityImp entity = (EntityImp) quark.getData();
Display display = Display.getWithNewlines(displayString);
if (entity == null) {
if (Display.isNull(display))
display = Display.getWithNewlines(quark.getName()).withCreoleMode(CreoleMode.SIMPLE_LINE);
entity = diagram.reallyCreateLeaf(quark, display, type, null);
} else {
if (entity.muteToType(type, null) == false)
return CommandExecutionResult.error("Cannot create " + idShort + " because it already exists");
entity.setDisplay(display);
if (Display.isNull(display) == false)
entity.setDisplay(display);
}
diagram.setLastEntity(entity);

View File

@ -37,6 +37,8 @@ package net.sourceforge.plantuml.command;
import java.util.Objects;
import com.plantuml.wasm.WasmLog;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.log.Logme;
import net.sourceforge.plantuml.utils.BlocLines;
@ -53,6 +55,7 @@ public class ProtectedCommand<S extends Diagram> implements Command<S> {
public CommandExecutionResult execute(S system, BlocLines lines) {
try {
WasmLog.log("...running " + cmd.getClass().getName() + " ...");
final CommandExecutionResult result = cmd.execute(system, lines);
// if (result.isOk()) {
// // TRACECOMMAND

View File

@ -41,6 +41,7 @@ import java.io.OutputStream;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.api.ApiStable;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.ugraphic.UGraphic;
/**
* Represents a single diagram. A Diagram could be a UML (sequence diagram,
@ -67,6 +68,8 @@ public interface Diagram {
*/
ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException;
ImageData exportDiagramGraphic(UGraphic ug);
/**
* Number of images in this diagram (usually, 1)
*

View File

@ -558,4 +558,9 @@ public class CucaDiagramFileMakerElk implements CucaDiagramFileMaker {
return ent.getSvekImage();
}
@Override
public ImageData createOneGraphic(UGraphic ug) {
throw new UnsupportedOperationException();
}
}

View File

@ -38,13 +38,18 @@ package net.sourceforge.plantuml.klimt.font;
import java.awt.font.FontRenderContext;
import java.awt.font.LineMetrics;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.awt.geom.XDimension2D;
import net.sourceforge.plantuml.text.RichText;
import net.sourceforge.plantuml.text.StyledString;
public abstract class StringBounderRaw implements StringBounder {
private final FontRenderContext frc;
protected StringBounderRaw(FontRenderContext frc) {
this.frc = frc;
}
public final XDimension2D calculateDimension(UFont font, String text) {
if (RichText.isRich(text)) {
double width = 0;
@ -63,7 +68,6 @@ public abstract class StringBounderRaw implements StringBounder {
protected abstract XDimension2D calculateDimensionInternal(UFont font, String text);
public double getDescent(UFont font, String text) {
final FontRenderContext frc = FileFormat.gg.getFontRenderContext();
final LineMetrics lineMetrics = font.getUnderlayingFont().getLineMetrics(text, frc);
final double descent = lineMetrics.getDescent();
return descent;

View File

@ -338,6 +338,25 @@ public class CucaDiagramFileMakerSmetana implements CucaDiagramFileMaker {
}
}
@Override
public ImageData createOneGraphic(UGraphic ug) {
for (EntityImp leaf : diagram.getLeafsvalues())
printEntityNew(leaf);
Z.open();
try {
final TextBlock textBlock = getTextBlock();
textBlock.drawU(ug);
final XDimension2D dim = textBlock.calculateDimension(ug.getStringBounder());
return new ImageDataSimple(dim);
} catch (Throwable e) {
SmetanaDebug.printMe();
return ImageDataSimple.error();
} finally {
Z.close();
}
}
private ImageData createFileLocked(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException {
@ -346,48 +365,7 @@ public class CucaDiagramFileMakerSmetana implements CucaDiagramFileMaker {
Z.open();
try {
final ST_Agraph_s g = agopen(new CString("g"), Z.z().Agdirected, null);
// printCluster(g, root);
exportEntities(g, getUnpackagedEntities());
exportGroups(g, diagram.getEntityFactory().getRootGroup());
// for (ILeaf leaf : diagram.getLeafsvalues()) {
// final Shape shape = bibliotekon.getShape(leaf);
// final Agnode_s node = agnode(g, new CString(shape.getUid()), true);
// agsafeset(node, new CString("shape"), new CString("box"), new CString(""));
// final String width = "" + (shape.getWidth() / 72);
// final String height = "" + (shape.getHeight() / 72);
// agsafeset(node, new CString("width"), new CString(width), new CString(""));
// agsafeset(node, new CString("height"), new CString(height), new CString(""));
// nodes.put(leaf, node);
// // System.err
// // .println("NODE " + leaf.getUid() + " [shape=box, width=" + width + ",
// height=" + height + "]");
// }
//
for (Link link : diagram.getLinks()) {
// System.err.println("link=" + link);
final ST_Agedge_s e = createEdge(g, link);
// System.err.println("Agedge_s=" + e);
if (e != null)
edges.put(link, e);
}
final ST_GVC_s gvc = gvContext();
SmetanaDebug.reset();
gvLayoutJobs(gvc, g);
SmetanaDebug.printMe();
// for (Agedge_s e : edges.values()) {
// DebugUtils.printDebugEdge(e);
// }
final MinMax minMax = TextBlockUtils.getMinMax(new Drawing(null, null), stringBounder, false);
// imageBuilder.setUDrawable(new Drawing(new YMirror(dim.getHeight())));
final TextBlock drawable = new Drawing(new YMirror(minMax.getMaxY()), minMax);
final TextBlock drawable = getTextBlock();
return diagram.createImageBuilder(fileFormatOption).drawable(drawable).write(os);
} catch (Throwable e) {
SmetanaDebug.printMe();
@ -399,6 +377,52 @@ public class CucaDiagramFileMakerSmetana implements CucaDiagramFileMaker {
}
}
private TextBlock getTextBlock() {
final ST_Agraph_s g = agopen(new CString("g"), Z.z().Agdirected, null);
// printCluster(g, root);
exportEntities(g, getUnpackagedEntities());
exportGroups(g, diagram.getEntityFactory().getRootGroup());
// for (ILeaf leaf : diagram.getLeafsvalues()) {
// final Shape shape = bibliotekon.getShape(leaf);
// final Agnode_s node = agnode(g, new CString(shape.getUid()), true);
// agsafeset(node, new CString("shape"), new CString("box"), new CString(""));
// final String width = "" + (shape.getWidth() / 72);
// final String height = "" + (shape.getHeight() / 72);
// agsafeset(node, new CString("width"), new CString(width), new CString(""));
// agsafeset(node, new CString("height"), new CString(height), new CString(""));
// nodes.put(leaf, node);
// // System.err
// // .println("NODE " + leaf.getUid() + " [shape=box, width=" + width + ",
// height=" + height + "]");
// }
//
for (Link link : diagram.getLinks()) {
// System.err.println("link=" + link);
final ST_Agedge_s e = createEdge(g, link);
// System.err.println("Agedge_s=" + e);
if (e != null)
edges.put(link, e);
}
final ST_GVC_s gvc = gvContext();
SmetanaDebug.reset();
gvLayoutJobs(gvc, g);
SmetanaDebug.printMe();
// for (Agedge_s e : edges.values()) {
// DebugUtils.printDebugEdge(e);
// }
final MinMax minMax = TextBlockUtils.getMinMax(new Drawing(null, null), stringBounder, false);
// imageBuilder.setUDrawable(new Drawing(new YMirror(dim.getHeight())));
final TextBlock drawable = new Drawing(new YMirror(minMax.getMaxY()), minMax);
return drawable;
}
private void exportGroups(ST_Agraph_s graph, EntityImp parent) {
for (EntityImp g : diagram.getChildrenGroups(parent)) {
if (g.isRemoved())

View File

@ -71,6 +71,7 @@ import net.sourceforge.plantuml.sequencediagram.teoz.SequenceDiagramFileMakerTeo
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.xmi.SequenceDiagramXmiMaker;
public class SequenceDiagram extends UmlDiagram {
@ -283,6 +284,12 @@ public class SequenceDiagram extends UmlDiagram {
return sequenceDiagramPngMaker.createOne(os, index, fileFormat.isWithMetadata());
}
@Override
final public ImageData exportDiagramGraphic(UGraphic ug) {
final FileMaker sequenceDiagramPngMaker = getSequenceDiagramPngMaker(0, new FileFormatOption(FileFormat.PNG));
return sequenceDiagramPngMaker.createOneGraphic(ug);
}
// support for CommandReturn
private final Stack<AbstractMessage> activationState = new Stack<>();

View File

@ -39,10 +39,13 @@ import java.io.IOException;
import java.io.OutputStream;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.ugraphic.UGraphic;
public interface FileMaker {
ImageData createOne(OutputStream os, int index, boolean isWithMetadata) throws IOException;
ImageData createOneGraphic(UGraphic ug);
public int getNbPages();
}

View File

@ -45,6 +45,7 @@ import java.util.Map;
import net.sourceforge.plantuml.AnnotatedBuilder;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.api.ImageDataSimple;
import net.sourceforge.plantuml.awt.geom.XDimension2D;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.cucadiagram.Display;
@ -133,8 +134,21 @@ public class SequenceDiagramFileMakerPuma2 implements FileMaker {
newpageHeight, title);
}
public ImageData createOne(OutputStream os, final int index, boolean isWithMetadata) throws IOException {
@Override
public ImageData createOneGraphic(UGraphic ug) {
final UDrawable drawable = createUDrawable(0);
drawable.drawU(ug);
return new ImageDataSimple(100, 100);
}
@Override
public ImageData createOne(OutputStream os, final int index, boolean isWithMetadata) throws IOException {
final UDrawable drawable = createUDrawable(index);
return diagram.createImageBuilder(fileFormatOption).drawable(drawable).write(os);
}
private UDrawable createUDrawable(final int index) {
final Page page = pages.get(index);
final AnnotatedBuilder builder = new AnnotatedBuilder(diagram, diagram.getSkinParam(), stringBounder);
double pageHeight = page.getHeight();
@ -206,7 +220,7 @@ public class SequenceDiagramFileMakerPuma2 implements FileMaker {
}
};
return diagram.createImageBuilder(fileFormatOption).drawable(drawable).write(os);
return drawable;
}
private void drawFooter(SequenceDiagramArea area, UGraphic ug, int page) {

View File

@ -56,6 +56,7 @@ import net.sourceforge.plantuml.security.SecurityUtils;
import net.sourceforge.plantuml.sequencediagram.Event;
import net.sourceforge.plantuml.sequencediagram.Participant;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagram;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class SequenceDiagramTxtMaker implements FileMaker {
@ -141,4 +142,10 @@ public class SequenceDiagramTxtMaker implements FileMaker {
public int getNbPages() {
return 1;
}
@Override
public ImageData createOneGraphic(UGraphic ug) {
throw new UnsupportedOperationException();
}
}

View File

@ -285,4 +285,9 @@ public class SequenceDiagramFileMakerTeoz implements FileMaker {
printAligned(ug, diagram.getFooterOrHeaderTeoz(FontParam.FOOTER).getHorizontalAlignment(), footer);
}
@Override
public ImageData createOneGraphic(UGraphic ug) {
throw new UnsupportedOperationException();
}
}

View File

@ -41,9 +41,12 @@ import java.util.List;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.ugraphic.UGraphic;
public interface CucaDiagramFileMaker {
public ImageData createFile(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException;
public ImageData createOneGraphic(UGraphic ug);
}

View File

@ -54,6 +54,7 @@ import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramSimplifierState;
import net.sourceforge.plantuml.cucadiagram.dot.DotData;
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.log.Logme;
import net.sourceforge.plantuml.ugraphic.UGraphic;
public final class CucaDiagramFileMakerSvek implements CucaDiagramFileMaker {
// ::remove file when WASM
@ -74,6 +75,11 @@ public final class CucaDiagramFileMakerSvek implements CucaDiagramFileMaker {
}
}
@Override
public ImageData createOneGraphic(UGraphic ug) {
throw new UnsupportedOperationException();
}
private GeneralImageBuilder createDotDataImageBuilder(DotMode dotMode, StringBounder stringBounder) {
final DotData dotData = new DotData(diagram.getEntityFactory().getRootGroup(), getOrderedLinks(),
diagram.getLeafsvalues(), diagram.getUmlDiagramType(), diagram.getSkinParam(), diagram, diagram,

View File

@ -50,6 +50,8 @@ import java.util.Set;
import javax.swing.ImageIcon;
import com.plantuml.wasm.WasmLog;
import net.sourceforge.plantuml.AnimatedGifEncoder;
import net.sourceforge.plantuml.AnnotatedBuilder;
import net.sourceforge.plantuml.AnnotatedWorker;
@ -291,7 +293,7 @@ public class ImageBuilder {
/ 96.0;
if (scaleFactor <= 0)
throw new IllegalStateException("Bad scaleFactor");
WasmLog.log("...image drawing...");
// ::comment when WASM
UGraphic ug = createUGraphic(dim, animationArg, dx, dy, scaleFactor,
titledDiagram == null ? new Pragma() : titledDiagram.getPragma());

View File

@ -36,6 +36,7 @@ package net.sourceforge.plantuml.ugraphic.debug;
import java.util.Random;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.awt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.font.StringBounderRaw;
@ -44,6 +45,10 @@ import net.sourceforge.plantuml.klimt.font.UFont;
public class StringBounderDebug extends StringBounderRaw {
// ::remove folder when WASM
public StringBounderDebug() {
super(FileFormat.gg.getFontRenderContext());
}
@Override
protected XDimension2D calculateDimensionInternal(UFont font, String text) {
final Random rnd = new Random(StringUtils.seed(text));

View File

@ -81,7 +81,7 @@ public class Version {
}
public static int beta() {
final int beta = 1;
final int beta = 2;
return beta;
}

View File

@ -23,6 +23,7 @@ import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.log.Logme;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagram;
import net.sourceforge.plantuml.sequencediagram.graphic.FileMaker;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.xml.XmlFactories;
public final class SequenceDiagramXmiMaker implements FileMaker {
@ -54,9 +55,9 @@ public final class SequenceDiagramXmiMaker implements FileMaker {
xmi = new XmiSequenceDiagramArgo(diagram, document);
else
xmi = new XmiSequenceDiagramStandard(diagram, document);
xmi.build();
try {
writeDocument(document, os);
} catch (TransformerException | ParserConfigurationException e) {
@ -64,8 +65,7 @@ public final class SequenceDiagramXmiMaker implements FileMaker {
}
return imageData;
}
@Override
public int getNbPages() {
return 1;
@ -83,4 +83,9 @@ public final class SequenceDiagramXmiMaker implements FileMaker {
transformer.transform(source, resultat);
}
@Override
public ImageData createOneGraphic(UGraphic ug) {
throw new UnsupportedOperationException();
}
}