1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-22 02:49:06 +00:00
Arnaud Roques 2023-05-17 22:11:36 +02:00
parent 35ec8a700c
commit f72fec23c3
12 changed files with 130 additions and 108 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}

View File

@ -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<Ftile> all) {
this.skinParam = skinParam;
this.stringBounder = stringBounder;
this.list99.addAll(getFoo2(all));
this.list99.addAll(decorateAllTiles(all));
}
protected List<Ftile> getFoo2(List<Ftile> all) {
private List<Ftile> decorateAllTiles(List<Ftile> all) {
final double maxHeight = computeMaxHeight(all);
final double ymargin1 = getSuppSpace1(all, getStringBounder());
final double ymargin2 = getSuppSpace2(all, getStringBounder());
final List<Ftile> 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<Ftile> 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<Ftile> 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<Ftile> all) {
double height = 0;
for (Ftile tmp : all)

View File

@ -75,48 +75,6 @@ public class ParallelBuilderFork extends AbstractParallelFtilesBuilder {
this.out = out;
}
protected List<Ftile> getFoo2(List<Ftile> all) {
final double maxHeight = computeMaxHeight(all);
final double ymargin1 = getSuppSpace1(all, getStringBounder());
final double ymargin2 = getSuppSpace2(all, getStringBounder());
final List<Ftile> 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<Ftile> 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<Ftile> 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)));

View File

@ -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;
}

View File

@ -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;

View File

@ -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();

View File

@ -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();

View File

@ -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);