1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-07 10:50:53 +00:00
This commit is contained in:
Arnaud Roques 2022-03-09 20:15:12 +01:00
parent a1a599b633
commit 57b1cde03a
4 changed files with 63 additions and 48 deletions

View File

@ -76,11 +76,11 @@ public class GraphvizUtils {
return new GraphvizJs(dotString);
}
final AbstractGraphviz result;
if (isWindows()) {
if (isWindows())
result = new GraphvizWindowsOld(skinParam, dotString, type);
} else {
else
result = new GraphvizLinux(skinParam, dotString, type);
}
if (result.getExeState() != ExeState.OK && VizJsEngine.isOk()) {
Log.info("Error with file " + result.getDotExe() + ": " + result.getExeState().getTextMessage());
Log.info("Using " + VIZJS);
@ -95,11 +95,11 @@ public class GraphvizUtils {
return new GraphvizJs(dotString);
}
final AbstractGraphviz result;
if (isWindows()) {
if (isWindows())
result = new GraphvizWindowsLite(skinParam, dotString, type);
} else {
else
result = new GraphvizLinux(skinParam, dotString, type);
}
if (result.getExeState() != ExeState.OK && VizJsEngine.isOk()) {
Log.info("Error with file " + result.getDotExe() + ": " + result.getExeState().getTextMessage());
Log.info("Using " + VIZJS);
@ -109,12 +109,12 @@ public class GraphvizUtils {
}
private static boolean useVizJs(ISkinParam skinParam) {
if (skinParam != null && skinParam.isUseVizJs() && VizJsEngine.isOk()) {
if (skinParam != null && skinParam.isUseVizJs() && VizJsEngine.isOk())
return true;
}
if (VIZJS.equalsIgnoreCase(getenvGraphvizDot()) && VizJsEngine.isOk()) {
if (VIZJS.equalsIgnoreCase(getenvGraphvizDot()) && VizJsEngine.isOk())
return true;
}
return false;
}
@ -123,17 +123,17 @@ public class GraphvizUtils {
}
public static String getenvGraphvizDot() {
if (StringUtils.isNotEmpty(dotExecutable)) {
if (StringUtils.isNotEmpty(dotExecutable))
return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(dotExecutable);
}
final String env = System.getProperty("GRAPHVIZ_DOT");
if (StringUtils.isNotEmpty(env)) {
if (StringUtils.isNotEmpty(env))
return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(env);
}
final String getenv = System.getenv("GRAPHVIZ_DOT");
if (StringUtils.isNotEmpty(getenv)) {
if (StringUtils.isNotEmpty(getenv))
return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(getenv);
}
return null;
}
@ -149,13 +149,13 @@ public class GraphvizUtils {
public static int getenvImageLimit() {
final Integer local = limitSize.get();
if (local != null) {
if (local != null)
return local;
}
final String env = SecurityUtils.getenv("PLANTUML_LIMIT_SIZE");
if (StringUtils.isNotEmpty(env) && env.matches("\\d+")) {
if (StringUtils.isNotEmpty(env) && env.matches("\\d+"))
return Integer.parseInt(env);
}
return 4096;
}
@ -173,11 +173,11 @@ public class GraphvizUtils {
if (dotVersion == null) {
final File dotExe = GraphvizUtils.getDotExe();
final ExeState exeState = ExeState.checkFile(dotExe);
if (exeState == ExeState.OK) {
if (exeState == ExeState.OK)
dotVersion = create(null, "png").dotVersion();
} else {
else
dotVersion = "Error:" + exeState.getTextMessage(dotExe);
}
}
return dotVersion;
}
@ -192,15 +192,15 @@ public class GraphvizUtils {
}
public static int retrieveVersion(String s) {
if (s == null) {
if (s == null)
return -1;
}
final Pattern p = Pattern.compile("\\s([12].\\d\\d)\\D");
final Pattern p = Pattern.compile("\\s([23])\\.(\\d\\d?)\\D");
final Matcher m = p.matcher(s);
if (m.find() == false) {
if (m.find() == false)
return -1;
}
return Integer.parseInt(m.group(1).replaceAll("\\.", ""));
return 100 * Integer.parseInt(m.group(1)) + Integer.parseInt(m.group(2));
}
public static int getDotVersion() throws IOException, InterruptedException {
@ -221,11 +221,11 @@ public class GraphvizUtils {
result.add("VizJs library is used!");
try {
final String err = getTestCreateSimpleFile();
if (err == null) {
if (err == null)
result.add(bold + "Installation seems OK. File generation OK");
} else {
else
result.add(red + err);
}
} catch (Exception e) {
result.add(red + e.toString());
e.printStackTrace();
@ -237,11 +237,11 @@ public class GraphvizUtils {
final File dotExe = GraphvizUtils.getDotExe();
if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE) {
final String ent = GraphvizUtils.getenvGraphvizDot();
if (ent == null) {
if (ent == null)
result.add("The environment variable GRAPHVIZ_DOT has not been set");
} else {
else
result.add("The environment variable GRAPHVIZ_DOT has been set to " + ent);
}
result.add("Dot executable is " + dotExe);
}
final ExeState exeState = ExeState.checkFile(dotExe);
@ -285,19 +285,18 @@ public class GraphvizUtils {
final Graphviz graphviz2 = GraphvizUtils.create(null, "digraph foo { test; }", "svg");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ProcessState state = graphviz2.createFile3(baos);
if (state.differs(ProcessState.TERMINATED_OK())) {
if (state.differs(ProcessState.TERMINATED_OK()))
return "Error: timeout " + state;
}
final byte data[] = baos.toByteArray();
if (data.length == 0) {
if (data.length == 0)
return "Error: dot generates empty file. Check you dot installation.";
}
final String s = new String(data);
if (s.indexOf("<svg") == -1) {
if (s.indexOf("<svg") == -1)
return "Error: dot generates unreadable SVG file. Check you dot installation.";
}
return null;
}

View File

@ -36,6 +36,8 @@
package net.sourceforge.plantuml.svek.image;
import net.sourceforge.plantuml.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.util.EnumMap;
import java.util.Map;
@ -51,6 +53,7 @@ import net.sourceforge.plantuml.SkinParamUtils;
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.UseStyle;
import net.sourceforge.plantuml.creole.Stencil;
import net.sourceforge.plantuml.cucadiagram.Bodier;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
import net.sourceforge.plantuml.cucadiagram.ILeaf;
@ -58,6 +61,7 @@ import net.sourceforge.plantuml.cucadiagram.PortionShower;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.InnerStrategy;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockEmpty;
@ -203,11 +207,7 @@ public class EntityImageObject extends AbstractEntityImage implements Stencil, W
ug.startGroup(typeIDent);
ug.apply(stroke).draw(rect);
final ULayoutGroup header = new ULayoutGroup(new PlacementStrategyY1Y2(ug.getStringBounder()));
if (stereo != null)
header.add(stereo);
header.add(name);
final ULayoutGroup header = getLayout(stringBounder);
header.drawU(ug, dimTotal.getWidth(), dimTitle.getHeight());
final UGraphic ug2 = UGraphicStencil.create(ug, this, stroke);
@ -219,6 +219,15 @@ public class EntityImageObject extends AbstractEntityImage implements Stencil, W
ug.closeGroup();
}
private ULayoutGroup getLayout(final StringBounder stringBounder) {
final ULayoutGroup header = new ULayoutGroup(new PlacementStrategyY1Y2(stringBounder));
if (stereo != null)
header.add(stereo);
header.add(name);
return header;
}
private UStroke getStroke() {
UStroke stroke = lineConfig.getColors().getSpecificLineStroke();
if (stroke == null)
@ -276,4 +285,11 @@ public class EntityImageObject extends AbstractEntityImage implements Stencil, W
return new Ports();
}
@Override
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
final Dimension2D dimTitle = getTitleDimension(stringBounder);
final UTranslate translate = UTranslate.dy(dimTitle.getHeight());
return translate.apply(fields.getInnerPosition(member, stringBounder, strategy));
}
}

View File

@ -108,7 +108,7 @@ public class MainWindow extends JFrame {
}
private String getDefaultFileExtensions() {
return "txt, tex, java, htm, html, c, h, cpp, apt, pu, puml, hpp, hh";
return "txt, tex, java, htm, html, c, h, cpp, apt, pu, puml, hpp, hh, md";
}
private void changeExtensions(String ext) {

View File

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