diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java b/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java index b08e91b27..ae5efd596 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java @@ -202,8 +202,6 @@ public class ActivityDiagram3 extends UmlDiagram { @Override protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption) throws IOException { - // BUG42 - // COMPRESSION final StringBounder stringBounder = fileFormatOption.getDefaultStringBounder(getSkinParam()); TextBlock result = getTextBlock(stringBounder); return createImageBuilder(fileFormatOption).drawable(result).write(os); @@ -220,6 +218,8 @@ public class ActivityDiagram3 extends UmlDiagram { swinlanes.computeSize(stringBounder); TextBlock result = swinlanes; + // BUG42 + // COMMENT TO DISABLE COMPRESS result = CompressionXorYBuilder.build(CompressionMode.ON_X, result, stringBounder); result = CompressionXorYBuilder.build(CompressionMode.ON_Y, result, stringBounder); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/AbstractFtile.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/AbstractFtile.java index eb44f5764..5ef9f84ad 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/AbstractFtile.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/AbstractFtile.java @@ -53,10 +53,15 @@ import net.sourceforge.plantuml.style.Style; public abstract class AbstractFtile extends AbstractTextBlock implements Ftile { + protected final boolean TRACE = false; + private final ISkinParam skinParam; public AbstractFtile(ISkinParam skinParam) { this.skinParam = skinParam; + + if (TRACE) + System.err.println("TRACE Building " + this); } final public ISkinParam skinParam() { @@ -105,9 +110,9 @@ public abstract class AbstractFtile extends AbstractTextBlock implements Ftile { private FtileGeometry cachedGeometry; final public FtileGeometry calculateDimension(StringBounder stringBounder) { - if (cachedGeometry == null) { + if (cachedGeometry == null) cachedGeometry = calculateDimensionFtile(stringBounder); - } + return cachedGeometry; } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileHeightFixedCentered.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileHeightFixedCentered.java index f437b1679..f91efa63b 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileHeightFixedCentered.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileHeightFixedCentered.java @@ -91,9 +91,9 @@ public class FtileHeightFixedCentered extends AbstractFtile { private UTranslate getTranslate(StringBounder stringBounder) { final XDimension2D dim = tile.calculateDimension(stringBounder); - if (dim.getHeight() > fixedHeight) { + if (dim.getHeight() > fixedHeight) throw new IllegalStateException(); - } + return UTranslate.dy((fixedHeight - dim.getHeight()) / 2); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMarged.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMarged.java index a5c8df31c..cf0dfb0c8 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMarged.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMarged.java @@ -55,6 +55,10 @@ public class FtileMarged extends AbstractFtile { this.tile = tile; this.margin1 = margin1; this.margin2 = margin2; + + if (TRACE) + System.err.println("TRACE FtileMarged for " + tile); + } @Override diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMinWidthCentered.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMinWidthCentered.java index 09f4123f5..ce5099fbf 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMinWidthCentered.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMinWidthCentered.java @@ -59,26 +59,26 @@ public class FtileMinWidthCentered extends FtileDecorate { @Override public FtileGeometry calculateDimension(StringBounder stringBounder) { - if (calculateDimensionInternal == null) { + if (calculateDimensionInternal == null) calculateDimensionInternal = calculateDimensionSlow(stringBounder); - } + return calculateDimensionInternal; } private FtileGeometry calculateDimensionSlow(StringBounder stringBounder) { final FtileGeometry geo = super.calculateDimension(stringBounder); final double left = getPoint2(geo.getLeft(), stringBounder); - if (geo.hasPointOut() == false) { + if (geo.hasPointOut() == false) return new FtileGeometry(getDimensionInternal(stringBounder), left, geo.getInY()); - } + return new FtileGeometry(getDimensionInternal(stringBounder), left, geo.getInY(), geo.getOutY()); } private XDimension2D getDimensionInternal(StringBounder stringBounder) { final XDimension2D dim = getFtileDelegated().calculateDimension(stringBounder); - if (dim.getWidth() < minWidth) { + if (dim.getWidth() < minWidth) return new XDimension2D(minWidth, dim.getHeight()); - } + return dim; } @@ -90,9 +90,9 @@ public class FtileMinWidthCentered extends FtileDecorate { } public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) { - if (child == getFtileDelegated()) { + if (child == getFtileDelegated()) return getUTranslateInternal(stringBounder); - } + return null; } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/AbstractParallelFtilesBuilder.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/AbstractParallelFtilesBuilder.java index 8e83b47bf..785e83e85 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/AbstractParallelFtilesBuilder.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/AbstractParallelFtilesBuilder.java @@ -40,7 +40,9 @@ import java.util.List; import net.sourceforge.plantuml.activitydiagram3.LinkRendering; import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileGeometry; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileHeightFixedCentered; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileHeightFixedMarged; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; import net.sourceforge.plantuml.klimt.creole.CreoleMode; @@ -48,6 +50,7 @@ import net.sourceforge.plantuml.klimt.creole.Display; import net.sourceforge.plantuml.klimt.font.FontConfiguration; import net.sourceforge.plantuml.klimt.font.StringBounder; import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment; +import net.sourceforge.plantuml.klimt.geom.XDimension2D; import net.sourceforge.plantuml.klimt.shape.TextBlock; import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.style.ISkinParam; @@ -76,28 +79,79 @@ public abstract class AbstractParallelFtilesBuilder { public AbstractParallelFtilesBuilder(ISkinParam skinParam, StringBounder stringBounder, List all) { this.skinParam = skinParam; this.stringBounder = stringBounder; - this.list99.addAll(getFoo2(all)); + this.list99.addAll(decorateAllTiles(all)); } - protected List getFoo2(List all) { + private List decorateAllTiles(List all) { final double maxHeight = computeMaxHeight(all); + final double ymargin1 = getSuppSpace1(all, getStringBounder()); + final double ymargin2 = getSuppSpace2(all, getStringBounder()); final List result = new ArrayList<>(); for (Ftile ftile : all) { - final Ftile newFtile = computeNewFtile(ftile, maxHeight); + final Ftile newFtile = computeNewFtile(ftile, maxHeight, ymargin1, ymargin2); result.add(newFtile); } return result; } - private Ftile computeNewFtile(Ftile ftile, double maxHeight) { + private double getSuppSpace1(List all, StringBounder stringBounder) { + double result = 0; + for (Ftile child : all) { + final TextBlock text = getTextBlock(child.getInLinkRendering().getDisplay()); + if (text == null) + continue; + + final XDimension2D dim = text.calculateDimension(stringBounder); + result = Math.max(result, dim.getHeight()); + + } + return result; + } + + private double getSuppSpace2(List all, StringBounder stringBounder) { + double result = 0; + for (Ftile child : all) { + final TextBlock text = getTextBlock(child.getOutLinkRendering().getDisplay()); + if (text == null) + continue; + + final XDimension2D dim = text.calculateDimension(stringBounder); + result = Math.max(result, dim.getHeight()); + } + return result; + } + + + private Ftile computeNewFtile(Ftile ftile, double maxHeight, double ymargin1, double ymargin2) { final double spaceArroundBlackBar = 20; final double xMargin = 14; Ftile tmp; - tmp = FtileUtils.addHorizontalMargin(ftile, xMargin); + tmp = FtileUtils.addHorizontalMargin(ftile, xMargin, xMargin + getSuppForIncomingArrow(ftile)); tmp = new FtileHeightFixedCentered(tmp, maxHeight + 2 * spaceArroundBlackBar); + tmp = new FtileHeightFixedMarged(ymargin1, tmp, ymargin2); return tmp; } + private double getSuppForIncomingArrow(Ftile ftile) { + final double x1 = getXSuppForDisplay(ftile, ftile.getInLinkRendering().getDisplay()); + final double x2 = getXSuppForDisplay(ftile, ftile.getOutLinkRendering().getDisplay()); + return Math.max(x1, x2); + } + + private double getXSuppForDisplay(Ftile ftile, Display label) { + final TextBlock text = getTextBlock(label); + if (text == null) + return 0; + + final double textWidth = text.calculateDimension(getStringBounder()).getWidth(); + final FtileGeometry ftileDim = ftile.calculateDimension(getStringBounder()); + final double pos2 = ftileDim.getLeft() + textWidth; + if (pos2 > ftileDim.getWidth()) + return pos2 - ftileDim.getWidth(); + + return 0; + } + final protected double computeMaxHeight(List all) { double height = 0; for (Ftile tmp : all) diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderFork.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderFork.java index ea53f7dc4..053470efe 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderFork.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ParallelBuilderFork.java @@ -75,48 +75,6 @@ public class ParallelBuilderFork extends AbstractParallelFtilesBuilder { this.out = out; } - protected List getFoo2(List all) { - final double maxHeight = computeMaxHeight(all); - final double ymargin1 = getSuppSpace1(all, getStringBounder()); - final double ymargin2 = getSuppSpace2(all, getStringBounder()); - final List result = new ArrayList<>(); - for (Ftile ftile : all) { - final Ftile newFtile = computeNewFtile(ftile, maxHeight, ymargin1, ymargin2); - result.add(newFtile); - } - return result; - } - - private Ftile computeNewFtile(Ftile ftile, double maxHeight, double ymargin1, double ymargin2) { - final double spaceArroundBlackBar = 20; - final double xMargin = 14; - Ftile tmp; - tmp = FtileUtils.addHorizontalMargin(ftile, xMargin, xMargin + getSuppForIncomingArrow(ftile)); - tmp = new FtileHeightFixedCentered(tmp, maxHeight + 2 * spaceArroundBlackBar); - tmp = new FtileHeightFixedMarged(ymargin1, tmp, ymargin2); - return tmp; - } - - private double getSuppForIncomingArrow(Ftile ftile) { - final double x1 = getXSuppForDisplay(ftile, ftile.getInLinkRendering().getDisplay()); - final double x2 = getXSuppForDisplay(ftile, ftile.getOutLinkRendering().getDisplay()); - return Math.max(x1, x2); - } - - private double getXSuppForDisplay(Ftile ftile, Display label) { - final TextBlock text = getTextBlock(label); - if (text == null) - return 0; - - final double textWidth = text.calculateDimension(getStringBounder()).getWidth(); - final FtileGeometry ftileDim = ftile.calculateDimension(getStringBounder()); - final double pos2 = ftileDim.getLeft() + textWidth; - if (pos2 > ftileDim.getWidth()) - return pos2 - ftileDim.getWidth(); - - return 0; - } - @Override protected Swimlane swimlaneOutForStep2() { return out; @@ -145,33 +103,6 @@ public class ParallelBuilderFork extends AbstractParallelFtilesBuilder { return new FtileAssemblySimple(black, result); } - private double getSuppSpace1(List all, StringBounder stringBounder) { - double result = 0; - for (Ftile child : all) { - final TextBlock text = getTextBlock(child.getInLinkRendering().getDisplay()); - if (text == null) - continue; - - final XDimension2D dim = text.calculateDimension(stringBounder); - result = Math.max(result, dim.getHeight()); - - } - return result; - } - - private double getSuppSpace2(List all, StringBounder stringBounder) { - double result = 0; - for (Ftile child : all) { - final TextBlock text = getTextBlock(child.getOutLinkRendering().getDisplay()); - if (text == null) - continue; - - final XDimension2D dim = text.calculateDimension(stringBounder); - result = Math.max(result, dim.getHeight()); - } - return result; - } - private double getJustBeforeBar2(Ftile middle, StringBounder stringBounder) { return barHeight + getHeightOfMiddle(middle); } @@ -181,7 +112,7 @@ public class ParallelBuilderFork extends AbstractParallelFtilesBuilder { final Swimlane swimlaneBlack = out; final Ftile out = new FtileBlackBlock(skinParam(), swimlaneBlack); ((FtileBlackBlock) out).setBlackBlockDimension(result.calculateDimension(getStringBounder()).getWidth(), - barHeight); + barHeight); if (label != null) ((FtileBlackBlock) out).setLabel(getTextBlock(Display.getWithNewlines(label))); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java index c76ea8e4b..1e5c15a6a 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java @@ -64,20 +64,22 @@ public class FtileIfWithDiamonds extends FtileIfNude { return Arrays.asList(diamond1, diamond2, tile1, tile2); } - public int getYdelta1a(StringBounder stringBounder) { - if (getSwimlanes().size() > 1) { + protected int getYdelta1a(StringBounder stringBounder) { + if (getSwimlanes().size() > 1) return 20; - } return 10; } - public int getYdelta1b(StringBounder stringBounder) { - if (getSwimlanes().size() > 1) { + protected int getYdelta1b(StringBounder stringBounder) { + if (getSwimlanes().size() > 1) return 10; - } return hasTwoBranches(stringBounder) ? 6 : 0; } + protected double getYdeltaForLabels(StringBounder stringBounder) { + return 0; + } + @Override protected double widthInner(StringBounder stringBounder) { final FtileGeometry dim1 = diamond1.calculateDimension(stringBounder); @@ -93,7 +95,8 @@ public class FtileIfWithDiamonds extends FtileIfNude { final FtileGeometry all = dim1.appendBottom(dimNude).appendBottom(dim2); - return all.addDim(0, getYdelta1a(stringBounder) + getYdelta1b(stringBounder)); + return all.addDim(0, + getYdelta1a(stringBounder) + getYdelta1b(stringBounder) + getYdeltaForLabels(stringBounder)); } @@ -140,9 +143,9 @@ public class FtileIfWithDiamonds extends FtileIfNude { final double widthLabelBranch1 = label1.getWidth(); final double dxDiamond = getTranslateDiamond1(stringBounder).getDx(); final double diff = widthLabelBranch1 - dxDiamond; - if (diff > 0) { + if (diff > 0) return diff; - } + return 0; } @@ -151,9 +154,9 @@ public class FtileIfWithDiamonds extends FtileIfNude { final double theoricalEndNeeded = getTranslateDiamond1(stringBounder).getDx() + diamond1.calculateDimension(stringBounder).getWidth() + widthLabelBranch2; final double diff = theoricalEndNeeded - calculateDimension(stringBounder).getWidth(); - if (diff > 0) { + if (diff > 0) return diff; - } + return 0; } @@ -163,9 +166,9 @@ public class FtileIfWithDiamonds extends FtileIfNude { final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); final double dyDiamond = dimDiamond1.getHeight(); final double diff = heightLabels - dyDiamond; - if (diff > 0) { + if (diff > 0) return diff; - } + return 0; } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java index 64acfa9e9..93fd36c37 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java @@ -50,6 +50,7 @@ import net.sourceforge.plantuml.activitydiagram3.ftile.MergeStrategy; import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.UGraphicInterceptorOneSwimlane; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamond; import net.sourceforge.plantuml.decoration.Rainbow; import net.sourceforge.plantuml.klimt.UTranslate; import net.sourceforge.plantuml.klimt.drawing.UGraphic; @@ -76,6 +77,14 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { } + @Override + protected double getYdeltaForLabels(StringBounder stringBounder) { + if (diamond2 instanceof FtileDiamond) + return ((FtileDiamond) diamond2).getWestEastLabelHeight(stringBounder); + + return 0; + } + class ConnectionHorizontalThenVertical extends AbstractConnection implements ConnectionTranslatable { private final Rainbow color; diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamond.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamond.java index cadd8cf1c..ce0940858 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamond.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamond.java @@ -60,16 +60,16 @@ public class FtileDiamond extends FtileDiamondWIP { } public FtileDiamond withWest(TextBlock west1) { - if (west1 == null) { + if (west1 == null) return this; - } + return new FtileDiamond(skinParam(), backColor, borderColor, swimlane, north, south, east, west1); } public FtileDiamond withEast(TextBlock east1) { - if (east1 == null) { + if (east1 == null) return this; - } + return new FtileDiamond(skinParam(), backColor, borderColor, swimlane, north, south, east1, west); } @@ -115,6 +115,12 @@ public class FtileDiamond extends FtileDiamondWIP { return withWest(tb1).withEast(tb2); } + public double getWestEastLabelHeight(StringBounder stringBounder) { + final XDimension2D dimEast = east.calculateDimension(stringBounder); + final XDimension2D dimWest = west.calculateDimension(stringBounder); + return Math.max(dimEast.getHeight(), dimWest.getHeight()); + } + public double getEastLabelWidth(StringBounder stringBounder) { final XDimension2D dimEast = east.calculateDimension(stringBounder); return dimEast.getWidth(); diff --git a/src/net/sourceforge/plantuml/regexdiagram/PSystemRegex.java b/src/net/sourceforge/plantuml/regexdiagram/PSystemRegex.java index 7a79788a3..ab25d895e 100644 --- a/src/net/sourceforge/plantuml/regexdiagram/PSystemRegex.java +++ b/src/net/sourceforge/plantuml/regexdiagram/PSystemRegex.java @@ -176,6 +176,8 @@ public class PSystemRegex extends TitledDiagram { repetitionOneOrMore(); else if (token.getType() == ReTokenType.QUANTIFIER && token.getData().startsWith("?")) optional(); + else if (token.getType() == ReTokenType.QUANTIFIER && token.getData().startsWith("{")) + repetitionOneOrMore(token.getData()); else throw new UnsupportedOperationException(token.toString()); @@ -216,6 +218,12 @@ public class PSystemRegex extends TitledDiagram { stack.addFirst(new ETileOneOrMore(arg1)); } + private void repetitionOneOrMore(String repetition) { + final ETile arg1 = stack.removeFirst(); + stack.addFirst(new ETileOneOrMore(arg1, repetition, fontConfiguration.bigger(-2), getSkinParam())); + + } + private void alternation() { final ETile arg1 = stack.removeFirst(); final ETile arg2 = stack.removeFirst(); diff --git a/src/net/sourceforge/plantuml/tim/EaterTheme.java b/src/net/sourceforge/plantuml/tim/EaterTheme.java index f7152852b..5545cdaff 100644 --- a/src/net/sourceforge/plantuml/tim/EaterTheme.java +++ b/src/net/sourceforge/plantuml/tim/EaterTheme.java @@ -75,7 +75,8 @@ public class EaterTheme extends Eater { final int x = this.name.toLowerCase().indexOf(" from "); if (x != -1) { - this.from = this.name.substring(x + " from ".length()); + final String fromTmp = this.name.substring(x + " from ".length()); + this.from = context.applyFunctionsAndVariables(memory, getLineLocation(), fromTmp); this.name = this.name.substring(0, x).trim(); this.context = context; } @@ -101,8 +102,9 @@ public class EaterTheme extends Eater { Logme.error(e); } throw EaterException.located("Cannot load " + realName); + } - } else if (from.startsWith("<") && from.endsWith(">")) { + if (from.startsWith("<") && from.endsWith(">")) { final ReadLine reader = ThemeUtils.getReaderTheme(realName, from); if (reader == null) throw EaterException.located("No such theme " + realName + " in " + from);