From d6afa3fb5aca6ea5db234d232824275643c8636f Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Sat, 26 Mar 2022 16:11:48 +0100 Subject: [PATCH] Tikz fix --- .../plantuml/argon2/algorithm/Functions.java | 2 +- .../plantuml/tikz/TikzGraphics.java | 78 +++++++++++++------ .../ugraphic/tikz/DriverAtomTextTikz.java | 2 +- .../tikz/DriverCenteredCharacterTikz.java | 2 +- .../tikz/DriverCenteredCharacterTikz2.java | 2 +- .../ugraphic/tikz/DriverDotPathTikz.java | 2 +- .../ugraphic/tikz/DriverEllipseTikz.java | 4 +- .../ugraphic/tikz/DriverLineTikz.java | 2 +- .../ugraphic/tikz/DriverPathTikz.java | 8 +- .../ugraphic/tikz/DriverPolygonTikz.java | 8 +- .../ugraphic/tikz/DriverRectangleTikz.java | 8 +- .../ugraphic/tikz/DriverTextTikz.java | 2 +- .../plantuml/ugraphic/tikz/UGraphicTikz.java | 2 +- .../sourceforge/plantuml/version/Version.java | 2 +- 14 files changed, 74 insertions(+), 50 deletions(-) diff --git a/src/net/sourceforge/plantuml/argon2/algorithm/Functions.java b/src/net/sourceforge/plantuml/argon2/algorithm/Functions.java index 7f16ddd2e..6caade190 100644 --- a/src/net/sourceforge/plantuml/argon2/algorithm/Functions.java +++ b/src/net/sourceforge/plantuml/argon2/algorithm/Functions.java @@ -17,7 +17,7 @@ class Functions { /** - * H0 = H64(p, τ, m, t, v, y, |P|, P, |S|, S, |L|, K, |X|, X) + * H0 = H64(p, \u03c4, m, t, v, y, |P|, P, |S|, S, |L|, K, |X|, X) * -> 64 byte (ARGON2_PREHASH_DIGEST_LENGTH) */ static byte[] initialHash(byte[] lanes, byte[] outputLength, diff --git a/src/net/sourceforge/plantuml/tikz/TikzGraphics.java b/src/net/sourceforge/plantuml/tikz/TikzGraphics.java index 8bc00cd32..f2dd9237e 100644 --- a/src/net/sourceforge/plantuml/tikz/TikzGraphics.java +++ b/src/net/sourceforge/plantuml/tikz/TikzGraphics.java @@ -55,6 +55,9 @@ import net.sourceforge.plantuml.eps.EpsGraphics; import net.sourceforge.plantuml.ugraphic.UPath; import net.sourceforge.plantuml.ugraphic.USegment; import net.sourceforge.plantuml.ugraphic.USegmentType; +import net.sourceforge.plantuml.ugraphic.color.ColorMapper; +import net.sourceforge.plantuml.ugraphic.color.HColor; +import net.sourceforge.plantuml.ugraphic.color.HColorUtils; import net.sourceforge.plantuml.version.Version; public class TikzGraphics { @@ -65,19 +68,21 @@ public class TikzGraphics { private final List cmd = new ArrayList<>(); private final boolean withPreamble; - private Color color = Color.BLACK; - private Color fillcolor = Color.BLACK; - private Color fillcolorGradient2 = null; + private HColor color = HColorUtils.BLACK; + private HColor fillcolor = HColorUtils.BLACK; + private HColor fillcolorGradient2 = null; private char gradientPolicy; private double thickness = 1.0; private final double scale; private String dash = null; + private final ColorMapper mapper; private final Map colornames = new LinkedHashMap(); - public TikzGraphics(double scale, boolean withPreamble) { + public TikzGraphics(double scale, boolean withPreamble, ColorMapper mapper) { this.withPreamble = withPreamble; this.scale = scale; + this.mapper = mapper; } private final Map styles = new LinkedHashMap(); @@ -103,17 +108,32 @@ public class TikzGraphics { } } - private String getColorName(Color c) { - if (c.equals(Color.WHITE)) + private String getColorName(HColor hcolor) { + final Color color = mapper.toColor(hcolor); + if (color.equals(Color.WHITE)) return "white"; - if (c.equals(Color.BLACK)) + if (color.equals(Color.BLACK)) return "black"; - final String result = colornames.get(c); + final String result = colornames.get(color); return Objects.requireNonNull(result); } + private void appendFillColor(StringBuilder sb, boolean colorBackup) { + if (fillcolor == null) + return; + + if (mustApplyFillColor()) { + sb.append("fill=" + getColorName(fillcolor) + ","); + if (color == null && colorBackup) + sb.append("color=" + getColorName(fillcolor) + ","); + } else { + sb.append("fill opacity=0,"); + } + + } + public void createData(OutputStream os) throws IOException { if (withPreamble) { out(os, "\\documentclass{standalone}"); @@ -227,7 +247,8 @@ public class TikzGraphics { sb.append("color=" + getColorName(color) + ","); if (mustApplyFillColor()) { - sb.append("fill=" + getColorName(fillcolor) + ","); + appendFillColor(sb, true); + // sb.append("fill=" + getColorName(fillcolor) + ","); if (color == null) sb.append("color=" + getColorName(fillcolor) + ","); @@ -438,7 +459,8 @@ public class TikzGraphics { sb.append("bottom color=" + getColorName(fillcolorGradient2) + ","); sb.append("shading=axis,shading angle=" + getAngleFromGradientPolicy() + ","); } else if (mustApplyFillColor()) { - sb.append("fill=" + getColorName(fillcolor) + ","); + appendFillColor(sb, false); + // sb.append("fill=" + getColorName(fillcolor) + ","); if (color == null) sb.append("color=" + getColorName(fillcolor) + ","); @@ -448,7 +470,11 @@ public class TikzGraphics { private boolean mustApplyFillColor() { if (fillcolor == null) return false; - if (fillcolor.getAlpha() == 0) + + if (HColorUtils.isTransparent(fillcolor)) + return false; + + if (mapper.toColor(fillcolor).getAlpha() == 0) return false; return true; } @@ -592,38 +618,42 @@ public class TikzGraphics { } - public void setFillColor(Color c) { - // if (c == null) { - // c = Color.WHITE; - // } + public void setFillColor(HColor c) { this.fillcolor = c; this.fillcolorGradient2 = null; - addColor(c); + if (mustApplyFillColor()) + addColor(fillcolor); + } - public void setGradientColor(Color c1, Color c2, char policy) { + public void setGradientColor(HColor c1, HColor c2, char policy) { this.fillcolor = c1; this.fillcolorGradient2 = c2; this.gradientPolicy = policy; - addColor(c1); - addColor(c2); + if (mustApplyFillColor()) + addColor(fillcolor); + + addColor(fillcolorGradient2); } - public void setStrokeColor(Color c) { + public void setStrokeColor(HColor c) { // Objects.requireNonNull(c); this.color = c; addColor(c); } - private void addColor(Color c) { - if (c == null) + private void addColor(HColor hcolor) { + if (hcolor == null) + return; + final Color color = mapper.toColor(hcolor); + if (color == null) return; - if (colornames.containsKey(c)) + if (colornames.containsKey(color)) return; final String name = "plantucolor" + String.format("%04d", colornames.size()); - colornames.put(c, name); + colornames.put(color, name); } public void setStrokeWidth(double thickness, String dash) { diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverAtomTextTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverAtomTextTikz.java index 868a36d5e..b6d7f6f8b 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverAtomTextTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverAtomTextTikz.java @@ -50,7 +50,7 @@ public class DriverAtomTextTikz implements UDriver { final FontConfiguration fontConfiguration = text.getFontConfiguration(); final UFont font = fontConfiguration.getFont(); final HColor col = fontConfiguration.getColor(); - tikz.setStrokeColor(mapper.toColor(col)); + tikz.setStrokeColor(col); final boolean underline = fontConfiguration.containsStyle(FontStyle.UNDERLINE); final boolean italic = font.isItalic(); final boolean bold = font.isBold(); diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverCenteredCharacterTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverCenteredCharacterTikz.java index 01cbbbca6..85555ac7d 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverCenteredCharacterTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverCenteredCharacterTikz.java @@ -57,7 +57,7 @@ public class DriverCenteredCharacterTikz implements UDriver { public void draw(DotPath path, double x, double y, ColorMapper mapper, UParam param, TikzGraphics tikz) { tikz.setFillColor(null); - tikz.setStrokeColor(mapper.toColor(param.getColor())); + tikz.setStrokeColor(param.getColor()); tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz()); tikz.upath(x, y, path.toUPath()); } diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverEllipseTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverEllipseTikz.java index c6e61e9c2..355496fbf 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverEllipseTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverEllipseTikz.java @@ -50,8 +50,8 @@ public class DriverEllipseTikz implements UDriver { final double extend = shape.getExtend(); final double cx = x + width / 2; final double cy = y + height / 2; - tikz.setFillColor(mapper.toColor(param.getBackcolor())); - tikz.setStrokeColor(mapper.toColor(param.getColor())); + tikz.setFillColor(param.getBackcolor()); + tikz.setStrokeColor(param.getColor()); tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz()); if (start == 0 && extend == 0) { tikz.ellipse(cx, cy, width / 2, height / 2); diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverLineTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverLineTikz.java index 7171e527a..dd395f8e8 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverLineTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverLineTikz.java @@ -45,7 +45,7 @@ public class DriverLineTikz implements UDriver { public void draw(ULine line, double x, double y, ColorMapper mapper, UParam param, TikzGraphics tikz) { double x2 = x + line.getDX(); double y2 = y + line.getDY(); - tikz.setStrokeColor(mapper.toColor(param.getColor())); + tikz.setStrokeColor(param.getColor()); tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz()); tikz.line(x, y, x2, y2); } diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverPathTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverPathTikz.java index 581e51480..5519a87e5 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverPathTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverPathTikz.java @@ -50,13 +50,11 @@ public class DriverPathTikz implements UDriver { final HColor back = param.getBackcolor(); if (back instanceof HColorGradient) { final HColorGradient gr = (HColorGradient) back; - final Color color1 = mapper.toColor(gr.getColor1()); - final Color color2 = mapper.toColor(gr.getColor2()); - tikz.setGradientColor(color1, color2, gr.getPolicy()); + tikz.setGradientColor(gr.getColor1(), gr.getColor2(), gr.getPolicy()); } else { - tikz.setFillColor(mapper.toColor(back)); + tikz.setFillColor(back); } - tikz.setStrokeColor(mapper.toColor(param.getColor())); + tikz.setStrokeColor(param.getColor()); tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz()); tikz.upath(x, y, path); } diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverPolygonTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverPolygonTikz.java index f636ce7e2..85c41e01b 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverPolygonTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverPolygonTikz.java @@ -52,13 +52,11 @@ public class DriverPolygonTikz implements UDriver { final HColor back = param.getBackcolor(); if (back instanceof HColorGradient) { final HColorGradient gr = (HColorGradient) back; - final Color color1 = mapper.toColor(gr.getColor1()); - final Color color2 = mapper.toColor(gr.getColor2()); - tikz.setGradientColor(color1, color2, gr.getPolicy()); + tikz.setGradientColor(gr.getColor1(), gr.getColor2(), gr.getPolicy()); } else { - tikz.setFillColor(mapper.toColor(back)); + tikz.setFillColor(back); } - tikz.setStrokeColor(mapper.toColor(param.getColor())); + tikz.setStrokeColor(param.getColor()); tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz()); tikz.polygon(points); diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverRectangleTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverRectangleTikz.java index 0e96ec91e..073b2883a 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverRectangleTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverRectangleTikz.java @@ -55,13 +55,11 @@ public class DriverRectangleTikz implements UDriver { final HColor back = param.getBackcolor(); if (back instanceof HColorGradient) { final HColorGradient gr = (HColorGradient) back; - final Color color1 = mapper.toColor(gr.getColor1()); - final Color color2 = mapper.toColor(gr.getColor2()); - tikz.setGradientColor(color1, color2, gr.getPolicy()); + tikz.setGradientColor(gr.getColor1(), gr.getColor2(), gr.getPolicy()); } else { - tikz.setFillColor(mapper.toColor(back)); + tikz.setFillColor(back); } - tikz.setStrokeColor(mapper.toColor(param.getColor())); + tikz.setStrokeColor(param.getColor()); tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz()); if (r == 0) { tikz.rectangle(x, y, width, height); diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverTextTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverTextTikz.java index 579c77782..0c0642b7d 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/DriverTextTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/DriverTextTikz.java @@ -50,7 +50,7 @@ public class DriverTextTikz implements UDriver { final FontConfiguration fontConfiguration = shape.getFontConfiguration(); final UFont font = fontConfiguration.getFont(); final HColor col = fontConfiguration.getColor(); - tikz.setStrokeColor(mapper.toColor(col)); + tikz.setStrokeColor(col); final boolean underline = fontConfiguration.containsStyle(FontStyle.UNDERLINE); final boolean italic = font.isItalic(); final boolean bold = font.isBold(); diff --git a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java index 1adad5540..903174443 100644 --- a/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java +++ b/src/net/sourceforge/plantuml/ugraphic/tikz/UGraphicTikz.java @@ -60,7 +60,7 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class UGraphicTikz extends AbstractUGraphic implements ClipContainer { public UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, double scale, boolean withPreamble) { - super(defaultBackground, colorMapper, stringBounder, new TikzGraphics(scale, withPreamble)); + super(defaultBackground, colorMapper, stringBounder, new TikzGraphics(scale, withPreamble, colorMapper)); register(); } diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 62222406c..e42e6f315 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -80,7 +80,7 @@ public class Version { } public static int beta() { - final int beta = 3; + final int beta = 4; return beta; }