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-11-26 13:57:59 +01:00
parent 8b03ff71b9
commit fae0dfdf02
7 changed files with 52 additions and 30 deletions

View File

@ -173,8 +173,10 @@ public class SvgNanoParser implements Sprite {
final HColor stroke = getTrueColor(strokeString, colorForMonochrome); final HColor stroke = getTrueColor(strokeString, colorForMonochrome);
ugs = ugs.apply(stroke); ugs = ugs.apply(stroke);
final String strokeWidth = extractData("stroke-width", s); final String strokeWidth = extractData("stroke-width", s);
if (strokeWidth != null) if (strokeWidth != null) {
ugs = ugs.apply(new UStroke(Double.parseDouble(strokeWidth))); final double scale = ugs.getScale();
ugs = ugs.apply(new UStroke(scale * Double.parseDouble(strokeWidth)));
}
} else { } else {
final HColor fill = getTrueColor(fillString, colorForMonochrome); final HColor fill = getTrueColor(fillString, colorForMonochrome);
@ -234,6 +236,7 @@ public class SvgNanoParser implements Sprite {
} }
private void drawEllipse(UGraphicWithScale ugs, String s, HColor colorForMonochrome) { private void drawEllipse(UGraphicWithScale ugs, String s, HColor colorForMonochrome) {
final boolean debug = false;
ugs = applyFill(ugs, s, colorForMonochrome); ugs = applyFill(ugs, s, colorForMonochrome);
ugs = applyTransform(ugs, s); ugs = applyTransform(ugs, s);
@ -244,22 +247,31 @@ public class SvgNanoParser implements Sprite {
UPath path = new UPath(); UPath path = new UPath();
path.moveTo(0, ry); path.moveTo(0, ry);
// path.lineTo(rx, 0);
path.arcTo(rx, ry, 0, 0, 1, rx, 0);
// path.lineTo(2 * rx, ry); if (debug)
path.arcTo(rx, ry, 0, 0, 1, 2 * rx, ry); path.lineTo(rx, 0);
else
path.arcTo(rx, ry, 0, 0, 1, rx, 0);
// path.lineTo(rx, 2 * ry); if (debug)
path.arcTo(rx, ry, 0, 0, 1, rx, 2 * ry); path.lineTo(2 * rx, ry);
else
path.arcTo(rx, ry, 0, 0, 1, 2 * rx, ry);
// path.lineTo(0, ry); if (debug)
path.arcTo(rx, ry, 0, 0, 1, 0, ry); path.lineTo(rx, 2 * ry);
else
path.arcTo(rx, ry, 0, 0, 1, rx, 2 * ry);
if (debug)
path.lineTo(0, ry);
else
path.arcTo(rx, ry, 0, 0, 1, 0, ry);
path.closePath(); path.closePath();
path = path.translate(cx - rx, cy - ry); path = path.translate(cx - rx, cy - ry);
path = path.affine(ugs.getAffineTransform(), ugs.getAngle()); path = path.affine(ugs.getAffineTransform(), ugs.getAngle(), ugs.getScale());
ugs.draw(path); ugs.draw(path);

View File

@ -46,15 +46,17 @@ public class UGraphicWithScale {
final private UGraphic ug; final private UGraphic ug;
final private AffineTransform at; final private AffineTransform at;
final private double angle; final private double angle;
final private double scale;
public UGraphicWithScale(UGraphic ug, double scale) { public UGraphicWithScale(UGraphic ug, double scale) {
this(ug, AffineTransform.getScaleInstance(scale, scale), 0); this(ug, AffineTransform.getScaleInstance(scale, scale), 0, scale);
} }
private UGraphicWithScale(UGraphic ug, AffineTransform at, double angle) { private UGraphicWithScale(UGraphic ug, AffineTransform at, double angle, double scale) {
this.ug = ug; this.ug = ug;
this.at = at; this.at = at;
this.angle = angle; this.angle = angle;
this.scale = scale;
} }
public UGraphic getUg() { public UGraphic getUg() {
@ -62,13 +64,15 @@ public class UGraphicWithScale {
} }
public UGraphicWithScale apply(UChange change) { public UGraphicWithScale apply(UChange change) {
return new UGraphicWithScale(ug.apply(change), at, angle); return new UGraphicWithScale(ug.apply(change), at, angle, scale);
} }
public UGraphicWithScale applyScale(double changex, double changey) { public UGraphicWithScale applyScale(double changex, double changey) {
if (changex != changey)
throw new IllegalArgumentException();
final AffineTransform copy = new AffineTransform(at); final AffineTransform copy = new AffineTransform(at);
copy.scale(changex, changey); copy.scale(changex, changey);
return new UGraphicWithScale(ug, copy, angle); return new UGraphicWithScale(ug, copy, angle, 1 * changex);
} }
public void draw(UShape shape) { public void draw(UShape shape) {
@ -78,13 +82,13 @@ public class UGraphicWithScale {
public UGraphicWithScale applyRotate(double delta_angle, double x, double y) { public UGraphicWithScale applyRotate(double delta_angle, double x, double y) {
final AffineTransform copy = new AffineTransform(at); final AffineTransform copy = new AffineTransform(at);
copy.rotate(delta_angle * Math.PI / 180, x, y); copy.rotate(delta_angle * Math.PI / 180, x, y);
return new UGraphicWithScale(ug, copy, this.angle + delta_angle); return new UGraphicWithScale(ug, copy, this.angle + delta_angle, this.scale);
} }
public UGraphicWithScale applyTranslate(double x, double y) { public UGraphicWithScale applyTranslate(double x, double y) {
final AffineTransform copy = new AffineTransform(at); final AffineTransform copy = new AffineTransform(at);
copy.translate(x, y); copy.translate(x, y);
return new UGraphicWithScale(ug, copy, angle); return new UGraphicWithScale(ug, copy, angle, this.scale);
} }
public AffineTransform getAffineTransform() { public AffineTransform getAffineTransform() {
@ -94,11 +98,15 @@ public class UGraphicWithScale {
public UGraphicWithScale applyMatrix(double v1, double v2, double v3, double v4, double v5, double v6) { public UGraphicWithScale applyMatrix(double v1, double v2, double v3, double v4, double v5, double v6) {
final AffineTransform copy = new AffineTransform(at); final AffineTransform copy = new AffineTransform(at);
copy.concatenate(new AffineTransform(new double[] { v1, v2, v3, v4, v5, v6 })); copy.concatenate(new AffineTransform(new double[] { v1, v2, v3, v4, v5, v6 }));
return new UGraphicWithScale(ug, copy, angle); return new UGraphicWithScale(ug, copy, angle, this.scale);
} }
public final double getAngle() { public final double getAngle() {
return angle; return angle;
} }
public double getScale() {
return scale;
}
} }

View File

@ -39,6 +39,7 @@ import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.StringLocated; import net.sourceforge.plantuml.StringLocated;
import net.sourceforge.plantuml.UrlBuilder; import net.sourceforge.plantuml.UrlBuilder;
import net.sourceforge.plantuml.baraye.IEntity; import net.sourceforge.plantuml.baraye.IEntity;
import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram;
import net.sourceforge.plantuml.command.BlocLines; import net.sourceforge.plantuml.command.BlocLines;
import net.sourceforge.plantuml.command.CommandControl; import net.sourceforge.plantuml.command.CommandControl;
import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.CommandExecutionResult;
@ -60,10 +61,9 @@ import net.sourceforge.plantuml.graphic.color.ColorType;
import net.sourceforge.plantuml.json.Json.DefaultHandler; import net.sourceforge.plantuml.json.Json.DefaultHandler;
import net.sourceforge.plantuml.json.JsonParser; import net.sourceforge.plantuml.json.JsonParser;
import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.json.JsonValue;
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;
import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException; import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException;
public class CommandCreateJson extends CommandMultilines2<AbstractClassOrObjectDiagram> { public class CommandCreateJson extends CommandMultilines2<AbstractEntityDiagram> {
public CommandCreateJson() { public CommandCreateJson() {
super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE, Trim.BOTH); super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE, Trim.BOTH);
@ -91,7 +91,7 @@ public class CommandCreateJson extends CommandMultilines2<AbstractClassOrObjectD
} }
@Override @Override
protected CommandExecutionResult executeNow(AbstractClassOrObjectDiagram diagram, BlocLines lines) protected CommandExecutionResult executeNow(AbstractEntityDiagram diagram, BlocLines lines)
throws NoSuchColorException { throws NoSuchColorException {
lines = lines.trim().removeEmptyLines(); lines = lines.trim().removeEmptyLines();
final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString()); final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString());
@ -141,7 +141,7 @@ public class CommandCreateJson extends CommandMultilines2<AbstractClassOrObjectD
return sb.toString(); return sb.toString();
} }
private IEntity executeArg0(AbstractClassOrObjectDiagram diagram, RegexResult line0) throws NoSuchColorException { private IEntity executeArg0(AbstractEntityDiagram diagram, RegexResult line0) throws NoSuchColorException {
final String name = line0.get("NAME", 1); final String name = line0.get("NAME", 1);
final Ident ident = diagram.buildLeafIdent(name); final Ident ident = diagram.buildLeafIdent(name);
final Code code = diagram.V1972() ? ident : diagram.buildCode(name); final Code code = diagram.V1972() ? ident : diagram.buildCode(name);

View File

@ -715,7 +715,7 @@ public class SvgGraphics {
ensureVisible(coord[4] + x + 2 * deltaShadow, coord[5] + y + 2 * deltaShadow); ensureVisible(coord[4] + x + 2 * deltaShadow, coord[5] + y + 2 * deltaShadow);
} else if (type == USegmentType.SEG_ARCTO) { } else if (type == USegmentType.SEG_ARCTO) {
// A25,25 0,0 5,395,40 // A25,25 0,0 5,395,40
sb.append("A" + format(coord[0]) + "," + format(coord[1]) + " " + formatBoolean(coord[2]) + " " sb.append("A" + format(coord[0]) + "," + format(coord[1]) + " " + format(coord[2]) + " "
+ formatBoolean(coord[3]) + " " + formatBoolean(coord[4]) + " " + format(coord[5] + x) + "," + formatBoolean(coord[3]) + " " + formatBoolean(coord[4]) + " " + format(coord[5] + x) + ","
+ format(coord[6] + y) + " "); + format(coord[6] + y) + " ");
ensureVisible(coord[5] + coord[0] + x + 2 * deltaShadow, coord[6] + coord[1] + y + 2 * deltaShadow); ensureVisible(coord[5] + coord[0] + x + 2 * deltaShadow, coord[6] + coord[1] + y + 2 * deltaShadow);

View File

@ -102,10 +102,10 @@ public class UPath extends AbstractShadowable implements Iterable<USegment>, USh
return result; return result;
} }
public UPath affine(AffineTransform transform, double angle) { public UPath affine(AffineTransform transform, double angle, double scale) {
final UPath result = new UPath(comment, codeLine); final UPath result = new UPath(comment, codeLine);
for (USegment seg : segments) for (USegment seg : segments)
result.addInternal(seg.affine(transform, angle)); result.addInternal(seg.affine(transform, angle, scale));
return result; return result;
} }

View File

@ -88,14 +88,16 @@ public class USegment {
return new USegment(new double[] { p1.getX(), p1.getY() }, pathType); return new USegment(new double[] { p1.getX(), p1.getY() }, pathType);
} }
public USegment affine(AffineTransform transform, double angle) { public USegment affine(AffineTransform transform, double angle, double scale) {
if (pathType == USegmentType.SEG_ARCTO) { if (pathType == USegmentType.SEG_ARCTO) {
XPoint2D p1 = new XPoint2D(coord[5], coord[6]); XPoint2D p1 = new XPoint2D(coord[5], coord[6]);
p1 = p1.transform(transform); p1 = p1.transform(transform);
return new USegment(
new double[] { coord[0], coord[1], coord[2] + angle, coord[3], coord[4], p1.getX(), p1.getY() }, final double large_arc_flag = coord[3];
pathType); final double sweep_flag = coord[4];
return new USegment(new double[] { coord[0] * scale, coord[1] * scale, coord[2] + angle, large_arc_flag,
sweep_flag, p1.getX(), p1.getY() }, pathType);
} }
if (coord.length != 2) if (coord.length != 2)

View File

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