1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-22 10:59:01 +00:00
This commit is contained in:
Arnaud Roques 2022-03-26 16:11:48 +01:00
parent ebf1b1b622
commit d6afa3fb5a
14 changed files with 74 additions and 50 deletions

View File

@ -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) * -> 64 byte (ARGON2_PREHASH_DIGEST_LENGTH)
*/ */
static byte[] initialHash(byte[] lanes, byte[] outputLength, static byte[] initialHash(byte[] lanes, byte[] outputLength,

View File

@ -55,6 +55,9 @@ import net.sourceforge.plantuml.eps.EpsGraphics;
import net.sourceforge.plantuml.ugraphic.UPath; import net.sourceforge.plantuml.ugraphic.UPath;
import net.sourceforge.plantuml.ugraphic.USegment; import net.sourceforge.plantuml.ugraphic.USegment;
import net.sourceforge.plantuml.ugraphic.USegmentType; 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; import net.sourceforge.plantuml.version.Version;
public class TikzGraphics { public class TikzGraphics {
@ -65,19 +68,21 @@ public class TikzGraphics {
private final List<String> cmd = new ArrayList<>(); private final List<String> cmd = new ArrayList<>();
private final boolean withPreamble; private final boolean withPreamble;
private Color color = Color.BLACK; private HColor color = HColorUtils.BLACK;
private Color fillcolor = Color.BLACK; private HColor fillcolor = HColorUtils.BLACK;
private Color fillcolorGradient2 = null; private HColor fillcolorGradient2 = null;
private char gradientPolicy; private char gradientPolicy;
private double thickness = 1.0; private double thickness = 1.0;
private final double scale; private final double scale;
private String dash = null; private String dash = null;
private final ColorMapper mapper;
private final Map<Color, String> colornames = new LinkedHashMap<Color, String>(); private final Map<Color, String> colornames = new LinkedHashMap<Color, String>();
public TikzGraphics(double scale, boolean withPreamble) { public TikzGraphics(double scale, boolean withPreamble, ColorMapper mapper) {
this.withPreamble = withPreamble; this.withPreamble = withPreamble;
this.scale = scale; this.scale = scale;
this.mapper = mapper;
} }
private final Map<String, Integer> styles = new LinkedHashMap<String, Integer>(); private final Map<String, Integer> styles = new LinkedHashMap<String, Integer>();
@ -103,17 +108,32 @@ public class TikzGraphics {
} }
} }
private String getColorName(Color c) { private String getColorName(HColor hcolor) {
if (c.equals(Color.WHITE)) final Color color = mapper.toColor(hcolor);
if (color.equals(Color.WHITE))
return "white"; return "white";
if (c.equals(Color.BLACK)) if (color.equals(Color.BLACK))
return "black"; return "black";
final String result = colornames.get(c); final String result = colornames.get(color);
return Objects.requireNonNull(result); 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 { public void createData(OutputStream os) throws IOException {
if (withPreamble) { if (withPreamble) {
out(os, "\\documentclass{standalone}"); out(os, "\\documentclass{standalone}");
@ -227,7 +247,8 @@ public class TikzGraphics {
sb.append("color=" + getColorName(color) + ","); sb.append("color=" + getColorName(color) + ",");
if (mustApplyFillColor()) { if (mustApplyFillColor()) {
sb.append("fill=" + getColorName(fillcolor) + ","); appendFillColor(sb, true);
// sb.append("fill=" + getColorName(fillcolor) + ",");
if (color == null) if (color == null)
sb.append("color=" + getColorName(fillcolor) + ","); sb.append("color=" + getColorName(fillcolor) + ",");
@ -438,7 +459,8 @@ public class TikzGraphics {
sb.append("bottom color=" + getColorName(fillcolorGradient2) + ","); sb.append("bottom color=" + getColorName(fillcolorGradient2) + ",");
sb.append("shading=axis,shading angle=" + getAngleFromGradientPolicy() + ","); sb.append("shading=axis,shading angle=" + getAngleFromGradientPolicy() + ",");
} else if (mustApplyFillColor()) { } else if (mustApplyFillColor()) {
sb.append("fill=" + getColorName(fillcolor) + ","); appendFillColor(sb, false);
// sb.append("fill=" + getColorName(fillcolor) + ",");
if (color == null) if (color == null)
sb.append("color=" + getColorName(fillcolor) + ","); sb.append("color=" + getColorName(fillcolor) + ",");
@ -448,7 +470,11 @@ public class TikzGraphics {
private boolean mustApplyFillColor() { private boolean mustApplyFillColor() {
if (fillcolor == null) if (fillcolor == null)
return false; return false;
if (fillcolor.getAlpha() == 0)
if (HColorUtils.isTransparent(fillcolor))
return false;
if (mapper.toColor(fillcolor).getAlpha() == 0)
return false; return false;
return true; return true;
} }
@ -592,38 +618,42 @@ public class TikzGraphics {
} }
public void setFillColor(Color c) { public void setFillColor(HColor c) {
// if (c == null) {
// c = Color.WHITE;
// }
this.fillcolor = c; this.fillcolor = c;
this.fillcolorGradient2 = null; 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.fillcolor = c1;
this.fillcolorGradient2 = c2; this.fillcolorGradient2 = c2;
this.gradientPolicy = policy; this.gradientPolicy = policy;
addColor(c1); if (mustApplyFillColor())
addColor(c2); addColor(fillcolor);
addColor(fillcolorGradient2);
} }
public void setStrokeColor(Color c) { public void setStrokeColor(HColor c) {
// Objects.requireNonNull(c); // Objects.requireNonNull(c);
this.color = c; this.color = c;
addColor(c); addColor(c);
} }
private void addColor(Color c) { private void addColor(HColor hcolor) {
if (c == null) if (hcolor == null)
return;
final Color color = mapper.toColor(hcolor);
if (color == null)
return; return;
if (colornames.containsKey(c)) if (colornames.containsKey(color))
return; return;
final String name = "plantucolor" + String.format("%04d", colornames.size()); final String name = "plantucolor" + String.format("%04d", colornames.size());
colornames.put(c, name); colornames.put(color, name);
} }
public void setStrokeWidth(double thickness, String dash) { public void setStrokeWidth(double thickness, String dash) {

View File

@ -50,7 +50,7 @@ public class DriverAtomTextTikz implements UDriver<AtomText, TikzGraphics> {
final FontConfiguration fontConfiguration = text.getFontConfiguration(); final FontConfiguration fontConfiguration = text.getFontConfiguration();
final UFont font = fontConfiguration.getFont(); final UFont font = fontConfiguration.getFont();
final HColor col = fontConfiguration.getColor(); final HColor col = fontConfiguration.getColor();
tikz.setStrokeColor(mapper.toColor(col)); tikz.setStrokeColor(col);
final boolean underline = fontConfiguration.containsStyle(FontStyle.UNDERLINE); final boolean underline = fontConfiguration.containsStyle(FontStyle.UNDERLINE);
final boolean italic = font.isItalic(); final boolean italic = font.isItalic();
final boolean bold = font.isBold(); final boolean bold = font.isBold();

View File

@ -57,7 +57,7 @@ public class DriverCenteredCharacterTikz implements UDriver<UCenteredCharacter,
final double ypos = y - unusedSpace.getCenterY() - 0.5; final double ypos = y - unusedSpace.getCenterY() - 0.5;
final TextLayout t = createTextLayout(font, "" + c); final TextLayout t = createTextLayout(font, "" + c);
tikz.setStrokeColor(mapper.toColor(param.getColor())); tikz.setStrokeColor(param.getColor());
tikz.drawPathIterator(xpos, ypos, t.getOutline(null).getPathIterator(null)); tikz.drawPathIterator(xpos, ypos, t.getOutline(null).getPathIterator(null));
} }

View File

@ -45,7 +45,7 @@ public class DriverCenteredCharacterTikz2 implements UDriver<UCenteredCharacter,
public void draw(UCenteredCharacter centeredCharacter, double x, double y, ColorMapper mapper, UParam param, TikzGraphics tikz) { public void draw(UCenteredCharacter centeredCharacter, double x, double y, ColorMapper mapper, UParam param, TikzGraphics tikz) {
final char c = centeredCharacter.getChar(); final char c = centeredCharacter.getChar();
tikz.setStrokeColor(mapper.toColor(param.getColor())); tikz.setStrokeColor(param.getColor());
tikz.drawSingleCharacter(x, y, c); tikz.drawSingleCharacter(x, y, c);
} }

View File

@ -44,7 +44,7 @@ public class DriverDotPathTikz implements UDriver<DotPath, TikzGraphics> {
public void draw(DotPath path, double x, double y, ColorMapper mapper, UParam param, TikzGraphics tikz) { public void draw(DotPath path, double x, double y, ColorMapper mapper, UParam param, TikzGraphics tikz) {
tikz.setFillColor(null); tikz.setFillColor(null);
tikz.setStrokeColor(mapper.toColor(param.getColor())); tikz.setStrokeColor(param.getColor());
tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz()); tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz());
tikz.upath(x, y, path.toUPath()); tikz.upath(x, y, path.toUPath());
} }

View File

@ -50,8 +50,8 @@ public class DriverEllipseTikz implements UDriver<UEllipse, TikzGraphics> {
final double extend = shape.getExtend(); final double extend = shape.getExtend();
final double cx = x + width / 2; final double cx = x + width / 2;
final double cy = y + height / 2; final double cy = y + height / 2;
tikz.setFillColor(mapper.toColor(param.getBackcolor())); tikz.setFillColor(param.getBackcolor());
tikz.setStrokeColor(mapper.toColor(param.getColor())); tikz.setStrokeColor(param.getColor());
tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz()); tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz());
if (start == 0 && extend == 0) { if (start == 0 && extend == 0) {
tikz.ellipse(cx, cy, width / 2, height / 2); tikz.ellipse(cx, cy, width / 2, height / 2);

View File

@ -45,7 +45,7 @@ public class DriverLineTikz implements UDriver<ULine, TikzGraphics> {
public void draw(ULine line, double x, double y, ColorMapper mapper, UParam param, TikzGraphics tikz) { public void draw(ULine line, double x, double y, ColorMapper mapper, UParam param, TikzGraphics tikz) {
double x2 = x + line.getDX(); double x2 = x + line.getDX();
double y2 = y + line.getDY(); double y2 = y + line.getDY();
tikz.setStrokeColor(mapper.toColor(param.getColor())); tikz.setStrokeColor(param.getColor());
tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz()); tikz.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz());
tikz.line(x, y, x2, y2); tikz.line(x, y, x2, y2);
} }

View File

@ -50,13 +50,11 @@ public class DriverPathTikz implements UDriver<UPath, TikzGraphics> {
final HColor back = param.getBackcolor(); final HColor back = param.getBackcolor();
if (back instanceof HColorGradient) { if (back instanceof HColorGradient) {
final HColorGradient gr = (HColorGradient) back; final HColorGradient gr = (HColorGradient) back;
final Color color1 = mapper.toColor(gr.getColor1()); tikz.setGradientColor(gr.getColor1(), gr.getColor2(), gr.getPolicy());
final Color color2 = mapper.toColor(gr.getColor2());
tikz.setGradientColor(color1, color2, gr.getPolicy());
} else { } 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.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz());
tikz.upath(x, y, path); tikz.upath(x, y, path);
} }

View File

@ -52,13 +52,11 @@ public class DriverPolygonTikz implements UDriver<UPolygon, TikzGraphics> {
final HColor back = param.getBackcolor(); final HColor back = param.getBackcolor();
if (back instanceof HColorGradient) { if (back instanceof HColorGradient) {
final HColorGradient gr = (HColorGradient) back; final HColorGradient gr = (HColorGradient) back;
final Color color1 = mapper.toColor(gr.getColor1()); tikz.setGradientColor(gr.getColor1(), gr.getColor2(), gr.getPolicy());
final Color color2 = mapper.toColor(gr.getColor2());
tikz.setGradientColor(color1, color2, gr.getPolicy());
} else { } 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.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz());
tikz.polygon(points); tikz.polygon(points);

View File

@ -55,13 +55,11 @@ public class DriverRectangleTikz implements UDriver<URectangle, TikzGraphics> {
final HColor back = param.getBackcolor(); final HColor back = param.getBackcolor();
if (back instanceof HColorGradient) { if (back instanceof HColorGradient) {
final HColorGradient gr = (HColorGradient) back; final HColorGradient gr = (HColorGradient) back;
final Color color1 = mapper.toColor(gr.getColor1()); tikz.setGradientColor(gr.getColor1(), gr.getColor2(), gr.getPolicy());
final Color color2 = mapper.toColor(gr.getColor2());
tikz.setGradientColor(color1, color2, gr.getPolicy());
} else { } 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.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDashTikz());
if (r == 0) { if (r == 0) {
tikz.rectangle(x, y, width, height); tikz.rectangle(x, y, width, height);

View File

@ -50,7 +50,7 @@ public class DriverTextTikz implements UDriver<UText, TikzGraphics> {
final FontConfiguration fontConfiguration = shape.getFontConfiguration(); final FontConfiguration fontConfiguration = shape.getFontConfiguration();
final UFont font = fontConfiguration.getFont(); final UFont font = fontConfiguration.getFont();
final HColor col = fontConfiguration.getColor(); final HColor col = fontConfiguration.getColor();
tikz.setStrokeColor(mapper.toColor(col)); tikz.setStrokeColor(col);
final boolean underline = fontConfiguration.containsStyle(FontStyle.UNDERLINE); final boolean underline = fontConfiguration.containsStyle(FontStyle.UNDERLINE);
final boolean italic = font.isItalic(); final boolean italic = font.isItalic();
final boolean bold = font.isBold(); final boolean bold = font.isBold();

View File

@ -60,7 +60,7 @@ import net.sourceforge.plantuml.ugraphic.color.HColor;
public class UGraphicTikz extends AbstractUGraphic<TikzGraphics> implements ClipContainer { public class UGraphicTikz extends AbstractUGraphic<TikzGraphics> implements ClipContainer {
public UGraphicTikz(HColor defaultBackground, ColorMapper colorMapper, StringBounder stringBounder, double scale, boolean withPreamble) { 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(); register();
} }

View File

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