mirror of
https://github.com/octoleo/plantuml.git
synced 2024-12-22 10:59:01 +00:00
Tikz fix
This commit is contained in:
parent
ebf1b1b622
commit
d6afa3fb5a
@ -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,
|
||||
|
@ -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<String> 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<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.scale = scale;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
private final Map<String, Integer> styles = new LinkedHashMap<String, Integer>();
|
||||
@ -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) {
|
||||
|
@ -50,7 +50,7 @@ public class DriverAtomTextTikz implements UDriver<AtomText, TikzGraphics> {
|
||||
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();
|
||||
|
@ -57,7 +57,7 @@ public class DriverCenteredCharacterTikz implements UDriver<UCenteredCharacter,
|
||||
final double ypos = y - unusedSpace.getCenterY() - 0.5;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
final char c = centeredCharacter.getChar();
|
||||
|
||||
tikz.setStrokeColor(mapper.toColor(param.getColor()));
|
||||
tikz.setStrokeColor(param.getColor());
|
||||
tikz.drawSingleCharacter(x, y, c);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
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());
|
||||
}
|
||||
|
@ -50,8 +50,8 @@ public class DriverEllipseTikz implements UDriver<UEllipse, TikzGraphics> {
|
||||
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);
|
||||
|
@ -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) {
|
||||
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);
|
||||
}
|
||||
|
@ -50,13 +50,11 @@ public class DriverPathTikz implements UDriver<UPath, TikzGraphics> {
|
||||
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);
|
||||
}
|
||||
|
@ -52,13 +52,11 @@ public class DriverPolygonTikz implements UDriver<UPolygon, TikzGraphics> {
|
||||
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);
|
||||
|
@ -55,13 +55,11 @@ public class DriverRectangleTikz implements UDriver<URectangle, TikzGraphics> {
|
||||
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);
|
||||
|
@ -50,7 +50,7 @@ public class DriverTextTikz implements UDriver<UText, TikzGraphics> {
|
||||
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();
|
||||
|
@ -60,7 +60,7 @@ import net.sourceforge.plantuml.ugraphic.color.HColor;
|
||||
public class UGraphicTikz extends AbstractUGraphic<TikzGraphics> 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();
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class Version {
|
||||
}
|
||||
|
||||
public static int beta() {
|
||||
final int beta = 3;
|
||||
final int beta = 4;
|
||||
return beta;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user