diff --git a/src/net/sourceforge/plantuml/PSystemUtils.java b/src/net/sourceforge/plantuml/PSystemUtils.java index 3244c3ac9..81f56539f 100644 --- a/src/net/sourceforge/plantuml/PSystemUtils.java +++ b/src/net/sourceforge/plantuml/PSystemUtils.java @@ -65,13 +65,8 @@ public class PSystemUtils { FileFormatOption fileFormatOption, boolean checkMetadata) throws IOException { final SFile existingFile = suggestedFile.getFile(0); - if (checkMetadata && fileFormatOption.getFileFormat().doesSupportMetadata() && existingFile.exists() - && system.getNbImages() == 1) { - // final String version = Version.versionString(); - // System.out.println(system.getMetadata()); - // System.out.println(data); - // System.out.println(version); - // System.out.println(data.contains(version)); + if (checkMetadata && fileFormatOption.getFileFormat().doesSupportMetadata() && existingFile.exists()) { + // && system.getNbImages() == 1) { final boolean sameMetadata = fileFormatOption.getFileFormat().equalsMetadata(system.getMetadata(), existingFile); if (sameMetadata) { @@ -80,15 +75,14 @@ public class PSystemUtils { } } - if (system instanceof NewpagedDiagram) { + if (system instanceof NewpagedDiagram) return exportDiagramsNewpaged((NewpagedDiagram) system, suggestedFile, fileFormatOption); - } - if (system instanceof SequenceDiagram) { + + if (system instanceof SequenceDiagram) return exportDiagramsSequence((SequenceDiagram) system, suggestedFile, fileFormatOption); - } - if (system instanceof CucaDiagram && fileFormatOption.getFileFormat() == FileFormat.HTML) { + + if (system instanceof CucaDiagram && fileFormatOption.getFileFormat() == FileFormat.HTML) return createFilesHtml((CucaDiagram) system, suggestedFile); - } return exportDiagramsDefault(system, suggestedFile, fileFormatOption); } @@ -100,9 +94,9 @@ public class PSystemUtils { for (int i = 0; i < nbImages; i++) { final SFile f = suggestedFile.getFile(i); - if (canFileBeWritten(f) == false) { + if (canFileBeWritten(f) == false) return result; - } + final OutputStream fos = f.createBufferedOutputStream(); ImageData cmap = null; try { @@ -141,9 +135,9 @@ public class PSystemUtils { for (int i = 0; i < nbImages; i++) { final SFile f = suggestedFile.getFile(i); - if (PSystemUtils.canFileBeWritten(suggestedFile.getFile(i)) == false) { + if (PSystemUtils.canFileBeWritten(suggestedFile.getFile(i)) == false) return result; - } + final OutputStream fos = f.createBufferedOutputStream(); ImageData cmap = null; try { @@ -151,9 +145,9 @@ public class PSystemUtils { } finally { fos.close(); } - if (cmap != null && cmap.containsCMapData()) { + if (cmap != null && cmap.containsCMapData()) system.exportCmap(suggestedFile, i, cmap); - } + Log.info("File size : " + f.length()); result.add(new FileImageData(f, cmap)); } @@ -179,9 +173,9 @@ public class PSystemUtils { : diagram.getSkinParam().getSplitParam()).getFiles(); final List result = new ArrayList<>(); - for (SFile f : files) { + for (SFile f : files) result.add(new FileImageData(f, imageData)); - } + return result; } @@ -190,13 +184,11 @@ public class PSystemUtils { final SFile outputFile = suggestedFile.getFile(0); - if (outputFile.isDirectory()) { + if (outputFile.isDirectory()) throw new IllegalArgumentException("File is a directory " + suggestedFile); - } - if (!canFileBeWritten(outputFile)) { + if (!canFileBeWritten(outputFile)) return emptyList(); - } final ImageData imageData; @@ -204,17 +196,14 @@ public class PSystemUtils { imageData = system.exportDiagram(os, 0, fileFormatOption); } - if (imageData == null) { + if (imageData == null) return emptyList(); - } - if (imageData.containsCMapData() && system instanceof UmlDiagram) { + if (imageData.containsCMapData() && system instanceof UmlDiagram) ((UmlDiagram) system).exportCmap(suggestedFile, 0, imageData); - } - if (system instanceof TitledDiagram && fileFormatOption.getFileFormat() == FileFormat.PNG) { + if (system instanceof TitledDiagram && fileFormatOption.getFileFormat() == FileFormat.PNG) return splitPng((TitledDiagram) system, suggestedFile, imageData, fileFormatOption); - } return singletonList(new FileImageData(outputFile, imageData)); } diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java index 0fc74323e..123efbc8f 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java @@ -65,23 +65,22 @@ public class ComponentTextNote extends AbstractComponentText { final int height = (int) dimensionToUse.getHeight(); charArea.fillRect(' ', 2, 1, width - 3, height - 2); if (type == ComponentType.NOTE) { - if (fileFormat == FileFormat.UTXT) { + if (fileFormat == FileFormat.UTXT) charArea.drawNoteSimpleUnicode(2, 0, width - 2, height); - } else { + else charArea.drawNoteSimple(2, 0, width - 2, height); - } - } else if (type == ComponentType.NOTE_BOX) { - if (fileFormat == FileFormat.UTXT) { + } else if (type == ComponentType.NOTE_BOX || type == ComponentType.NOTE_HEXAGONAL) { + if (fileFormat == FileFormat.UTXT) charArea.drawBoxSimpleUnicode(2, 0, width - 2, height); - } else { + else charArea.drawBoxSimple(2, 0, width - 2, height); - } } - if (fileFormat == FileFormat.UTXT) { + + if (fileFormat == FileFormat.UTXT) charArea.drawStringsLRUnicode(stringsToDisplay.asList(), 3, 1); - } else { + else charArea.drawStringsLRSimple(stringsToDisplay.asList(), 3, 1); - } + } public double getPreferredHeight(StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/asciiart/TextSkin.java b/src/net/sourceforge/plantuml/asciiart/TextSkin.java index c4c0e6189..e1bb54655 100644 --- a/src/net/sourceforge/plantuml/asciiart/TextSkin.java +++ b/src/net/sourceforge/plantuml/asciiart/TextSkin.java @@ -75,7 +75,7 @@ public class TextSkin extends Rose { @Override public Component createComponentNote(Style[] styles, ComponentType type, ISkinParam param, Display stringsToDisplay, Colors colors, NotePosition notePosition) { - if (type == ComponentType.NOTE || type == ComponentType.NOTE_BOX) + if (type == ComponentType.NOTE || type == ComponentType.NOTE_BOX || type == ComponentType.NOTE_HEXAGONAL) return new ComponentTextNote(type, stringsToDisplay, fileFormat); throw new UnsupportedOperationException(type.toString()); diff --git a/src/net/sourceforge/plantuml/awt/geom/XLine2D.java b/src/net/sourceforge/plantuml/awt/geom/XLine2D.java index f8f46d1f0..2815a113e 100644 --- a/src/net/sourceforge/plantuml/awt/geom/XLine2D.java +++ b/src/net/sourceforge/plantuml/awt/geom/XLine2D.java @@ -1,8 +1,12 @@ package net.sourceforge.plantuml.awt.geom; import net.sourceforge.plantuml.awt.XShape; +import net.sourceforge.plantuml.graphic.UDrawable; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UTranslate; -public class XLine2D implements XShape { +public class XLine2D implements XShape, UDrawable { final public double x1; final public double y1; @@ -18,7 +22,10 @@ public class XLine2D implements XShape { this.y1 = y1; this.x2 = x2; this.y2 = y2; + } + public XLine2D(XPoint2D p1, XPoint2D p2) { + this(p1.getX(), p1.getY(), p2.getX(), p2.getY()); } public XPoint2D getMiddle() { @@ -27,10 +34,6 @@ public class XLine2D implements XShape { return new XPoint2D(mx, my); } - public XLine2D(XPoint2D p1, XPoint2D p2) { - this(p1.getX(), p1.getY(), p2.getX(), p2.getY()); - } - public final double getX1() { return x1; } @@ -129,4 +132,31 @@ public class XLine2D implements XShape { } return lenSq; } + + public XPoint2D intersect(XLine2D line2) { + + final double s1x = this.x2 - this.x1; + final double s1y = this.y2 - this.y1; + + final double s2x = line2.x2 - line2.x1; + final double s2y = line2.y2 - line2.y1; + + final double s = (-s1y * (this.x1 - line2.x1) + s1x * (this.y1 - line2.y1)) / (-s2x * s1y + s1x * s2y); + final double t = (s2x * (this.y1 - line2.y1) - s2y * (this.x1 - line2.x1)) / (-s2x * s1y + s1x * s2y); + + if (s >= 0 && s <= 1 && t >= 0 && t <= 1) + return new XPoint2D(this.x1 + (t * s1x), this.y1 + (t * s1y)); + + return null; + } + + public void drawU(UGraphic ug) { + ug = ug.apply(new UTranslate(x1, y1)); + final ULine line = new ULine(x2 - x1, y2 - y1); + ug.draw(line); + } + + public double getAngle() { + return Math.atan2(y2 - y1, x2 - x1); + } } diff --git a/src/net/sourceforge/plantuml/awt/geom/XRectangle2D.java b/src/net/sourceforge/plantuml/awt/geom/XRectangle2D.java index 0a7379847..8c1d38ec9 100644 --- a/src/net/sourceforge/plantuml/awt/geom/XRectangle2D.java +++ b/src/net/sourceforge/plantuml/awt/geom/XRectangle2D.java @@ -76,4 +76,30 @@ public class XRectangle2D implements XShape { return xp >= getMinX() && xp < getMaxX() && yp >= getMinY() && yp < getMaxY(); } + public XPoint2D intersect(XLine2D line) { + final XPoint2D a = new XPoint2D(x, y); + final XPoint2D b = new XPoint2D(x + width, y); + final XPoint2D c = new XPoint2D(x + width, y + height); + final XPoint2D d = new XPoint2D(x, y + height); + final XLine2D line1 = new XLine2D(a, b); + final XLine2D line2 = new XLine2D(b, c); + final XLine2D line3 = new XLine2D(c, d); + final XLine2D line4 = new XLine2D(d, a); + + XPoint2D result = line.intersect(line1); + if (result != null) + return result; + result = line.intersect(line2); + if (result != null) + return result; + result = line.intersect(line3); + if (result != null) + return result; + result = line.intersect(line4); + if (result != null) + return result; + + return null; + } + } diff --git a/src/net/sourceforge/plantuml/ebnf/ETileBox.java b/src/net/sourceforge/plantuml/ebnf/ETileBox.java index 20c96031c..c2f425004 100644 --- a/src/net/sourceforge/plantuml/ebnf/ETileBox.java +++ b/src/net/sourceforge/plantuml/ebnf/ETileBox.java @@ -154,10 +154,12 @@ public class ETileBox extends ETile { final URectangle rect = new URectangle(dimBox); ug.apply(new UTranslate(posxBox, posy)).apply(lineColor).apply(new UStroke(0.5)).draw(rect); } else if (symbol == Symbol.SPECIAL_SEQUENCE) { - final URectangle rect1 = new URectangle(dimBox.delta(2)).rounded(12); - final URectangle rect2 = new URectangle(dimBox.delta(-2)).rounded(8); - ug.apply(new UTranslate(posxBox - 1, posy - 1)).apply(lineColor).apply(new UStroke(1.0, 1.0, 1.0)).draw(rect1); - ug.apply(new UTranslate(posxBox + 1, posy + 1)).apply(lineColor).apply(new UStroke(0.5)).draw(rect2); + final URectangle rect = new URectangle(dimBox); + ug.apply(new UTranslate(posxBox, posy)).apply(lineColor).apply(new UStroke(5, 5, 1)).draw(rect); +// final URectangle rect1 = new URectangle(dimBox.delta(2)).rounded(12); +// final URectangle rect2 = new URectangle(dimBox.delta(-2)).rounded(8); +// ug.apply(new UTranslate(posxBox - 1, posy - 1)).apply(lineColor).apply(new UStroke(5.0, 5.0, 1.0)).draw(rect1); +// ug.apply(new UTranslate(posxBox + 1, posy + 1)).apply(lineColor).apply(new UStroke(0.5)).draw(rect2); } else { final URectangle rect = new URectangle(dimBox).rounded(10); ug.apply(new UTranslate(posxBox, posy)).apply(lineColor).apply(backgroundColor.bg()).apply(new UStroke(1.5)) diff --git a/src/net/sourceforge/plantuml/fun/IconLoader.java b/src/net/sourceforge/plantuml/fun/IconLoader.java index b6bc08732..27de929f5 100644 --- a/src/net/sourceforge/plantuml/fun/IconLoader.java +++ b/src/net/sourceforge/plantuml/fun/IconLoader.java @@ -48,7 +48,7 @@ import net.sourceforge.plantuml.security.SImageIO; public class IconLoader { - private static final int NUMBER_OF_ICONS = 30; + private static final int NUMBER_OF_ICONS = 31; private final static Map all = new ConcurrentHashMap(); static private final List tmp = new ArrayList<>(); @@ -61,9 +61,9 @@ public class IconLoader { private static String getSomeQuote() { synchronized (tmp) { if (tmp.size() == 0) { - for (int i = 0; i < NUMBER_OF_ICONS; i++) { + for (int i = 0; i < NUMBER_OF_ICONS; i++) tmp.add("sprite" + String.format("%03d", i) + ".png"); - } + Collections.shuffle(tmp); } final int size = tmp.size(); @@ -77,9 +77,9 @@ public class IconLoader { BufferedImage result = all.get(name); if (result == null) { result = getIconSlow(name); - if (result != null) { + if (result != null) all.put(name, result); - } + } return result; } @@ -87,9 +87,9 @@ public class IconLoader { private static BufferedImage getIconSlow(String name) { try { final InputStream is = IconLoader.class.getResourceAsStream(name); - if (is == null) { + if (is == null) return null; - } + final BufferedImage image = SImageIO.read(is); is.close(); return image; @@ -100,19 +100,18 @@ public class IconLoader { } private static BufferedImage addTransparent(BufferedImage ico) { - if (ico == null) { + if (ico == null) return null; - } + final BufferedImage transparentIcon = new BufferedImage(ico.getWidth(), ico.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE); - for (int i = 0; i < ico.getWidth(); i++) { + for (int i = 0; i < ico.getWidth(); i++) for (int j = 0; j < ico.getHeight(); j++) { final int col = ico.getRGB(i, j); - if (col != ico.getRGB(0, 0)) { + if (col != ico.getRGB(0, 0)) transparentIcon.setRGB(i, j, col); - } } - } + return transparentIcon; } diff --git a/src/net/sourceforge/plantuml/fun/sprite030.png b/src/net/sourceforge/plantuml/fun/sprite030.png new file mode 100644 index 000000000..748c7cd7c Binary files /dev/null and b/src/net/sourceforge/plantuml/fun/sprite030.png differ diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandLinkAnchor.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandLinkAnchor.java index 6c1012470..4eb92444f 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandLinkAnchor.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandLinkAnchor.java @@ -57,7 +57,8 @@ public class CommandLinkAnchor extends SingleLineCommand2 { new RegexLeaf("LINK", "\\<-\\>"), // RegexLeaf.spaceZeroOrMore(), // new RegexLeaf("ANCHOR2", "\\{([%pLN_]+)\\}"), // - RegexLeaf.spaceZeroOrMore(), new RegexLeaf("MESSAGE", "(?::[%s]*(.*))?"), RegexLeaf.end()); + RegexLeaf.spaceZeroOrMore(), // + new RegexLeaf("MESSAGE", "(?::[%s]*(.*))?"), RegexLeaf.end()); } @Override diff --git a/src/net/sourceforge/plantuml/svek/extremity/Extremity.java b/src/net/sourceforge/plantuml/svek/extremity/Extremity.java index 470ab514c..c2ddbdeff 100644 --- a/src/net/sourceforge/plantuml/svek/extremity/Extremity.java +++ b/src/net/sourceforge/plantuml/svek/extremity/Extremity.java @@ -43,28 +43,28 @@ public abstract class Extremity implements UDrawable { protected double manageround(double angle) { final double deg = angle * 180.0 / Math.PI; - if (isCloseTo(0, deg)) { + if (isCloseTo(0, deg)) return 0; - } - if (isCloseTo(90, deg)) { + + if (isCloseTo(90, deg)) return 90.0 * Math.PI / 180.0; - } - if (isCloseTo(180, deg)) { + + if (isCloseTo(180, deg)) return 180.0 * Math.PI / 180.0; - } - if (isCloseTo(270, deg)) { + + if (isCloseTo(270, deg)) return 270.0 * Math.PI / 180.0; - } - if (isCloseTo(360, deg)) { + + if (isCloseTo(360, deg)) return 0; - } + return angle; } private boolean isCloseTo(double value, double variable) { - if (Math.abs(value - variable) < 0.05) { + if (Math.abs(value - variable) < 0.05) return true; - } + return false; } diff --git a/src/net/sourceforge/plantuml/svek/extremity/ExtremityArrow.java b/src/net/sourceforge/plantuml/svek/extremity/ExtremityArrow.java index 49f48f727..088c49937 100644 --- a/src/net/sourceforge/plantuml/svek/extremity/ExtremityArrow.java +++ b/src/net/sourceforge/plantuml/svek/extremity/ExtremityArrow.java @@ -36,7 +36,6 @@ package net.sourceforge.plantuml.svek.extremity; import net.sourceforge.plantuml.awt.geom.XPoint2D; -import net.sourceforge.plantuml.graphic.UDrawable; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; diff --git a/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java b/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java index 83fee8516..944d75e8e 100644 --- a/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java +++ b/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java @@ -196,4 +196,8 @@ public abstract class AbstractCommonUGraphic implements UGraphic { return false; } + public final UTranslate getTranslate() { + return translate; + } + } diff --git a/src/net/sourceforge/plantuml/ugraphic/UFont.java b/src/net/sourceforge/plantuml/ugraphic/UFont.java index 78e391930..357a23762 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UFont.java +++ b/src/net/sourceforge/plantuml/ugraphic/UFont.java @@ -50,9 +50,9 @@ public class UFont { private static final Set names = new HashSet<>(); static { - for (String name : GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()) { + for (String name : GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()) names.add(name.toLowerCase()); - } + } public String toStringDebug() { @@ -71,9 +71,9 @@ public class UFont { if (fontFamily.contains(",")) { for (String name : fontFamily.split(",")) { name = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(name).trim(); - if (doesFamilyExists(name)) { + if (doesFamilyExists(name)) return new Font(fontFamily, fontStyle, fontSize); - } + } } return new Font(fontFamily, fontStyle, fontSize); @@ -154,21 +154,22 @@ public class UFont { public String getFamily(UFontContext context) { if (context == UFontContext.EPS) { - if (family == null) { + if (family == null) return "Times-Roman"; - } + return font.getPSName(); } if (context == UFontContext.SVG) { - if (family.equalsIgnoreCase("sansserif")) { + if (family.equalsIgnoreCase("sansserif")) return "sans-serif"; - } + return family; } return family; } - // Kludge for testing because font names on some machines (only macOS?) do not end with