1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-05 10:00:47 +00:00

wip on prefers-color-scheme:dark

This commit is contained in:
Arnaud Roques 2022-01-28 22:45:34 +01:00
parent ed2535bd75
commit 9d611cf988
46 changed files with 1230 additions and 390 deletions

View File

@ -71,6 +71,7 @@ import net.sourceforge.plantuml.error.PSystemErrorUtils;
import net.sourceforge.plantuml.flowdiagram.FlowDiagramFactory;
import net.sourceforge.plantuml.font.PSystemListFontsFactory;
import net.sourceforge.plantuml.gitlog.GitDiagramFactory;
import net.sourceforge.plantuml.hcl.HclDiagramFactory;
import net.sourceforge.plantuml.help.HelpFactory;
import net.sourceforge.plantuml.jcckit.PSystemJcckitFactory;
import net.sourceforge.plantuml.jsondiagram.JsonDiagramFactory;
@ -223,6 +224,7 @@ public class PSystemBuilder {
factories.add(new GitDiagramFactory());
factories.add(new BoardDiagramFactory());
factories.add(new YamlDiagramFactory());
factories.add(new HclDiagramFactory());
}
private boolean isOk(Diagram ps) {

View File

@ -123,6 +123,9 @@ public class SkinParam implements ISkinParam {
if (type == UmlDiagramType.YAML) {
UseStyle.setBetaStyle(true);
}
if (type == UmlDiagramType.HCL) {
UseStyle.setBetaStyle(true);
}
if (type == UmlDiagramType.NWDIAG) {
UseStyle.setBetaStyle(true);
}

View File

@ -39,7 +39,7 @@ import net.sourceforge.plantuml.style.SName;
public enum UmlDiagramType {
SEQUENCE, STATE, CLASS, OBJECT, ACTIVITY, DESCRIPTION, COMPOSITE, FLOW, TIMING, BPM, NWDIAG, MINDMAP, WBS, WIRE,
HELP, GANTT, SALT, JSON, GIT, BOARD, YAML;
HELP, GANTT, SALT, JSON, GIT, BOARD, YAML, HCL;
public SName getStyleName() {
if (this == SEQUENCE) {
@ -78,6 +78,9 @@ public enum UmlDiagramType {
if (this == YAML) {
return SName.yamlDiagram;
}
if (this == HCL) {
return SName.yamlDiagram;
}
if (this == JSON) {
return SName.jsonDiagram;
}

View File

@ -51,6 +51,7 @@ import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandFootboxIgnored;
import net.sourceforge.plantuml.command.CommandRankDir;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.command.note.CommandFactoryNoteActivity;
import net.sourceforge.plantuml.command.note.CommandFactoryNoteOnLink;
import net.sourceforge.plantuml.core.UmlSource;
@ -66,7 +67,7 @@ public class ActivityDiagramFactory extends PSystemCommandFactory {
protected List<Command> createCommands() {
final List<Command> cmds = new ArrayList<>();
cmds.add(new CommandFootboxIgnored());
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
cmds.add(new CommandRankDir());
cmds.add(new CommandPartition());

View File

@ -88,6 +88,7 @@ import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandDecoratorMultine;
import net.sourceforge.plantuml.command.CommandFootboxIgnored;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.core.UmlSource;
public class ActivityDiagramFactory3 extends PSystemCommandFactory {
@ -98,7 +99,7 @@ public class ActivityDiagramFactory3 extends PSystemCommandFactory {
final List<Command> cmds = new ArrayList<>();
cmds.add(new CommandFootboxIgnored());
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
cmds.add(new CommandSwimlane());
cmds.add(new CommandSwimlane2());
cmds.add(new CommandPartition3());
@ -129,11 +130,11 @@ public class ActivityDiagramFactory3 extends PSystemCommandFactory {
cmds.add(new CommandBackwardLong3());
cmds.add(new CommandWhile3());
cmds.add(new CommandWhileEnd3());
cmds.add(new CommandFork3());
cmds.add(new CommandForkAgain3());
cmds.add(new CommandForkEnd3());
cmds.add(new CommandSplit3());
cmds.add(new CommandSplitAgain3());
cmds.add(new CommandSplitEnd3());

View File

@ -328,25 +328,27 @@ class FtileRepeat extends AbstractFtile {
final double y2 = p2.getY() + dimDiamond1.getHeight() / 2;
final double x1_a = p1.getX() + dimDiamond2.getWidth();
final double x1_b = p1.getX() + dimDiamond2.getWidth() / 2 + dimRepeat.getWidth() / 2
+ Hexagon.hexagonHalfSize;
UPolygon arrow = Arrows.asToLeft();
if (x1_b < x2) {
arrow = Arrows.asToRight();
x2 = p2.getX();
}
final Snake snake = Snake.create(arrowColor, arrow).emphasizeDirection(Direction.UP);
snake.addPoint(x1_a, y1);
if (x1_a < x1_b) {
snake.addPoint(x1_b, y1);
snake.addPoint(x1_b, y2);
final Snake snake;
if (x2 < x1_a) {
snake = Snake.create(arrowColor, Arrows.asToLeft()).emphasizeDirection(Direction.UP);
snake.addPoint(x1_a, y1);
if (x1_a < x1_b) {
snake.addPoint(x1_b, y1);
snake.addPoint(x1_b, y2);
} else {
snake.addPoint(x1_a + 10, y1);
snake.addPoint(x1_a + 10, y2);
}
} else {
snake.addPoint(x1_a + 10, y1);
snake.addPoint(x1_a + 10, y2);
x2 = p2.getX();
snake = Snake.create(arrowColor, Arrows.asToRight()).emphasizeDirection(Direction.UP);
snake.addPoint(x1_a, y1);
final double middle = x1_a / 4 + x2 * 3 / 4;
snake.addPoint(middle, y1);
snake.addPoint(middle, y2);
}
snake.addPoint(x2, y2);
ug.draw(snake);

View File

@ -41,6 +41,7 @@ import java.util.List;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
@ -54,7 +55,7 @@ public class BoardDiagramFactory extends PSystemCommandFactory {
protected List<Command> createCommands() {
final List<Command> cmds = new ArrayList<>();
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
cmds.add(new CommandBoardPlus());
// cmds.add(new CommandMindMapTabulation());
// cmds.add(new CommandMindMapOrgmode());

View File

@ -65,6 +65,7 @@ import net.sourceforge.plantuml.command.CommandPackage;
import net.sourceforge.plantuml.command.CommandPackageEmpty;
import net.sourceforge.plantuml.command.CommandRankDir;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.command.note.CommandConstraintOnLinks;
import net.sourceforge.plantuml.command.note.CommandFactoryNote;
import net.sourceforge.plantuml.command.note.CommandFactoryNoteOnEntity;
@ -97,7 +98,7 @@ public class ClassDiagramFactory extends PSystemCommandFactory {
cmds.add(new CommandAddMethod());
addCommonHides(cmds);
CommonCommands.addCommonHides(cmds);
cmds.add(new CommandHideShow2());
cmds.add(new CommandRemoveRestore());
@ -154,8 +155,8 @@ public class ClassDiagramFactory extends PSystemCommandFactory {
cmds.add(new CommandCreateElementMultilines(0));
cmds.add(new CommandCreateElementMultilines(1));
addTitleCommands(cmds);
addCommonCommands2(cmds);
CommonCommands.addTitleCommands(cmds);
CommonCommands.addCommonCommands2(cmds);
return cmds;
}

View File

@ -50,8 +50,8 @@ import net.sourceforge.plantuml.command.regex.IRegex;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexResult;
import net.sourceforge.plantuml.security.SImageIO;
import net.sourceforge.plantuml.security.SFile;
import net.sourceforge.plantuml.security.SImageIO;
import net.sourceforge.plantuml.sprite.Sprite;
import net.sourceforge.plantuml.sprite.SpriteImage;
import net.sourceforge.plantuml.sprite.SpriteSvg;

View File

@ -0,0 +1,109 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.command;
import java.util.List;
import net.sourceforge.plantuml.classdiagram.command.CommandHideShowByGender;
import net.sourceforge.plantuml.classdiagram.command.CommandHideShowByVisibility;
import net.sourceforge.plantuml.sequencediagram.command.CommandSkin;
import net.sourceforge.plantuml.statediagram.command.CommandHideEmptyDescription;
import net.sourceforge.plantuml.style.CommandStyleImport;
import net.sourceforge.plantuml.style.CommandStyleMultilinesCSS;
public final class CommonCommands {
private CommonCommands() {
}
static public void addCommonCommands1(List<Command> cmds) {
addTitleCommands(cmds);
addCommonCommands2(cmds);
addCommonHides(cmds);
}
static public void addCommonCommands2(List<Command> cmds) {
cmds.add(new CommandNope());
cmds.add(new CommandPragma());
cmds.add(new CommandAssumeTransparent());
cmds.add(new CommandSkinParam());
cmds.add(new CommandSkinParamMultilines());
cmds.add(new CommandSkin());
cmds.add(new CommandMinwidth());
cmds.add(new CommandPage());
cmds.add(new CommandRotate());
cmds.add(new CommandScale());
cmds.add(new CommandScaleWidthAndHeight());
cmds.add(new CommandScaleWidthOrHeight());
cmds.add(new CommandScaleMaxWidth());
cmds.add(new CommandScaleMaxHeight());
cmds.add(new CommandScaleMaxWidthAndHeight());
cmds.add(new CommandAffineTransform());
cmds.add(new CommandAffineTransformMultiline());
final CommandFactorySprite factorySpriteCommand = new CommandFactorySprite();
cmds.add(factorySpriteCommand.createMultiLine(false));
cmds.add(factorySpriteCommand.createSingleLine());
cmds.add(new CommandSpriteFile());
cmds.add(new CommandStyleMultilinesCSS());
cmds.add(new CommandStyleImport());
}
static public void addCommonHides(List<Command> cmds) {
cmds.add(new CommandHideEmptyDescription());
cmds.add(new CommandHideShowByVisibility());
cmds.add(new CommandHideShowByGender());
}
static public void addTitleCommands(List<Command> cmds) {
cmds.add(new CommandTitle());
cmds.add(new CommandMainframe());
cmds.add(new CommandCaption());
cmds.add(new CommandMultilinesCaption());
cmds.add(new CommandMultilinesTitle());
cmds.add(new CommandMultilinesLegend());
cmds.add(new CommandLegend());
cmds.add(new CommandFooter());
cmds.add(new CommandMultilinesFooter());
cmds.add(new CommandHeader());
cmds.add(new CommandMultilinesHeader());
}
}

View File

@ -35,9 +35,6 @@
*/
package net.sourceforge.plantuml.command;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.sourceforge.plantuml.AbstractPSystem;
@ -46,17 +43,11 @@ import net.sourceforge.plantuml.ErrorUmlType;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.LineLocation;
import net.sourceforge.plantuml.StringLocated;
import net.sourceforge.plantuml.classdiagram.command.CommandHideShowByGender;
import net.sourceforge.plantuml.classdiagram.command.CommandHideShowByVisibility;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.error.PSystemError;
import net.sourceforge.plantuml.error.PSystemErrorUtils;
import net.sourceforge.plantuml.sequencediagram.command.CommandSkin;
import net.sourceforge.plantuml.statediagram.command.CommandHideEmptyDescription;
import net.sourceforge.plantuml.style.CommandStyleImport;
import net.sourceforge.plantuml.style.CommandStyleMultilinesCSS;
import net.sourceforge.plantuml.utils.StartUtils;
import net.sourceforge.plantuml.version.IteratorCounter2;
@ -64,6 +55,10 @@ public abstract class PSystemCommandFactory extends PSystemAbstractFactory {
private List<Command> cmds;
protected abstract List<Command> createCommands();
public abstract AbstractPSystem createEmptyDiagram(UmlSource source, ISkinSimple skinParam);
protected PSystemCommandFactory() {
this(DiagramType.UML);
}
@ -76,23 +71,22 @@ public abstract class PSystemCommandFactory extends PSystemAbstractFactory {
final public Diagram createSystem(UmlSource source, ISkinSimple skinParam) {
final IteratorCounter2 it = source.iterator2();
final StringLocated startLine = it.next();
if (StartUtils.isArobaseStartDiagram(startLine.getString()) == false) {
if (StartUtils.isArobaseStartDiagram(startLine.getString()) == false)
throw new UnsupportedOperationException();
}
if (source.isEmpty()) {
if (it.hasNext()) {
if (it.hasNext())
it.next();
}
return buildEmptyError(source, startLine.getLocation(), it.getTrace());
}
AbstractPSystem sys = createEmptyDiagram(source, skinParam);
while (it.hasNext()) {
if (StartUtils.isArobaseEndDiagram(it.peek().getString())) {
if (sys == null) {
if (sys == null)
return null;
}
final String err = sys.checkFinalError();
if (err != null) {
final LineLocation location = it.next().getLocation();
@ -103,15 +97,15 @@ public abstract class PSystemCommandFactory extends PSystemAbstractFactory {
return buildEmptyError(source, location, it.getTrace());
}
sys.makeDiagramReady();
if (sys.isOk() == false) {
if (sys.isOk() == false)
return null;
}
return sys;
}
sys = executeFewLines(sys, source, it);
if (sys instanceof PSystemError) {
if (sys instanceof PSystemError)
return sys;
}
}
return sys;
@ -132,9 +126,9 @@ public abstract class PSystemCommandFactory extends PSystemAbstractFactory {
location);
sys = PSystemErrorUtils.buildV2(source, err, result.getDebugLines(), it.getTrace());
}
if (result.getNewDiagram() != null) {
if (result.getNewDiagram() != null)
sys = result.getNewDiagram();
}
return sys;
}
@ -152,9 +146,9 @@ public abstract class PSystemCommandFactory extends PSystemAbstractFactory {
private Step getCandidate(final IteratorCounter2 it) {
final BlocLines single = BlocLines.single(it.peek());
if (cmds == null) {
if (cmds == null)
cmds = createCommands();
}
for (Command cmd : cmds) {
final CommandControl result = cmd.isValid(single);
if (result == CommandControl.OK) {
@ -164,9 +158,9 @@ public abstract class PSystemCommandFactory extends PSystemAbstractFactory {
if (result == CommandControl.OK_PARTIAL) {
final IteratorCounter2 cloned = it.cloneMe();
final BlocLines lines = isMultilineCommandOk(cloned, cmd);
if (lines == null) {
if (lines == null)
continue;
}
it.copyStateFrom(cloned);
assert lines != null;
return new Step(cmd, lines);
@ -181,16 +175,16 @@ public abstract class PSystemCommandFactory extends PSystemAbstractFactory {
while (it.hasNext()) {
lines = addOneSingleLineManageEmbedded2(it, lines);
final CommandControl result = cmd.isValid(lines);
if (result == CommandControl.NOT_OK) {
if (result == CommandControl.NOT_OK)
return null;
}
if (result == CommandControl.OK) {
if (result == CommandControl.OK)
return lines;
}
nb++;
if (cmd instanceof CommandDecoratorMultine && nb > ((CommandDecoratorMultine) cmd).getNbMaxLines()) {
if (cmd instanceof CommandDecoratorMultine && nb > ((CommandDecoratorMultine) cmd).getNbMaxLines())
return null;
}
}
return null;
}
@ -202,84 +196,12 @@ public abstract class PSystemCommandFactory extends PSystemAbstractFactory {
while (it.hasNext()) {
final StringLocated s = it.next();
lines = lines.add(s);
if (s.getTrimmed().getString().equals("}}")) {
if (s.getTrimmed().getString().equals("}}"))
return lines;
}
}
}
return lines;
}
// -----------------------------------
protected abstract List<Command> createCommands();
public abstract AbstractPSystem createEmptyDiagram(UmlSource source, ISkinSimple skinParam);
final protected void addCommonCommands1(List<Command> cmds) {
addTitleCommands(cmds);
addCommonCommands2(cmds);
addCommonHides(cmds);
}
final protected void addCommonCommands2(List<Command> cmds) {
cmds.add(new CommandNope());
cmds.add(new CommandPragma());
cmds.add(new CommandAssumeTransparent());
cmds.add(new CommandSkinParam());
cmds.add(new CommandSkinParamMultilines());
cmds.add(new CommandSkin());
cmds.add(new CommandMinwidth());
cmds.add(new CommandPage());
cmds.add(new CommandRotate());
cmds.add(new CommandScale());
cmds.add(new CommandScaleWidthAndHeight());
cmds.add(new CommandScaleWidthOrHeight());
cmds.add(new CommandScaleMaxWidth());
cmds.add(new CommandScaleMaxHeight());
cmds.add(new CommandScaleMaxWidthAndHeight());
cmds.add(new CommandAffineTransform());
cmds.add(new CommandAffineTransformMultiline());
final CommandFactorySprite factorySpriteCommand = new CommandFactorySprite();
cmds.add(factorySpriteCommand.createMultiLine(false));
cmds.add(factorySpriteCommand.createSingleLine());
cmds.add(new CommandSpriteFile());
cmds.add(new CommandStyleMultilinesCSS());
cmds.add(new CommandStyleImport());
}
final protected void addCommonHides(List<Command> cmds) {
cmds.add(new CommandHideEmptyDescription());
cmds.add(new CommandHideShowByVisibility());
cmds.add(new CommandHideShowByGender());
}
final protected void addTitleCommands(List<Command> cmds) {
cmds.add(new CommandTitle());
cmds.add(new CommandMainframe());
cmds.add(new CommandCaption());
cmds.add(new CommandMultilinesCaption());
cmds.add(new CommandMultilinesTitle());
cmds.add(new CommandMultilinesLegend());
cmds.add(new CommandLegend());
cmds.add(new CommandFooter());
cmds.add(new CommandMultilinesFooter());
cmds.add(new CommandHeader());
cmds.add(new CommandMultilinesHeader());
}
final public List<String> getDescription() {
final List<String> result = new ArrayList<>();
for (Command cmd : createCommands()) {
result.addAll(Arrays.asList(cmd.getDescription()));
}
return Collections.unmodifiableList(result);
}
}

View File

@ -41,6 +41,7 @@ import java.util.List;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.compositediagram.command.CommandCreateBlock;
import net.sourceforge.plantuml.compositediagram.command.CommandCreatePackageBlock;
import net.sourceforge.plantuml.compositediagram.command.CommandEndPackageBlock;
@ -62,7 +63,7 @@ public class CompositeDiagramFactory extends PSystemCommandFactory {
cmds.add(new CommandLinkBlock());
cmds.add(new CommandCreatePackageBlock());
cmds.add(new CommandEndPackageBlock());
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
return cmds;
}

View File

@ -38,84 +38,86 @@ package net.sourceforge.plantuml.core;
import net.sourceforge.plantuml.utils.StartUtils;
public enum DiagramType {
UML, BPM, DITAA, DOT, PROJECT, JCCKIT, SALT, FLOW, CREOLE, JUNGLE, CUTE, MATH, LATEX,
DEFINITION, GANTT, NW, MINDMAP, WBS, WIRE, JSON, GIT, BOARD, YAML,
UNKNOWN;
UML, BPM, DITAA, DOT, PROJECT, JCCKIT, SALT, FLOW, CREOLE, JUNGLE, CUTE, MATH, LATEX, DEFINITION, GANTT, NW,
MINDMAP, WBS, WIRE, JSON, GIT, BOARD, YAML, HCL, UNKNOWN;
static public DiagramType getTypeFromArobaseStart(String s) {
s = s.toLowerCase();
// if (s.startsWith("@startuml2")) {
// return UML2;
// }
if (StartUtils.startsWithSymbolAnd("startwire", s)) {
if (StartUtils.startsWithSymbolAnd("startwire", s))
return WIRE;
}
if (StartUtils.startsWithSymbolAnd("startbpm", s)) {
if (StartUtils.startsWithSymbolAnd("startbpm", s))
return BPM;
}
if (StartUtils.startsWithSymbolAnd("startuml", s)) {
if (StartUtils.startsWithSymbolAnd("startuml", s))
return UML;
}
if (StartUtils.startsWithSymbolAnd("startdot", s)) {
if (StartUtils.startsWithSymbolAnd("startdot", s))
return DOT;
}
if (StartUtils.startsWithSymbolAnd("startjcckit", s)) {
if (StartUtils.startsWithSymbolAnd("startjcckit", s))
return JCCKIT;
}
if (StartUtils.startsWithSymbolAnd("startditaa", s)) {
if (StartUtils.startsWithSymbolAnd("startditaa", s))
return DITAA;
}
if (StartUtils.startsWithSymbolAnd("startproject", s)) {
if (StartUtils.startsWithSymbolAnd("startproject", s))
return PROJECT;
}
if (StartUtils.startsWithSymbolAnd("startsalt", s)) {
if (StartUtils.startsWithSymbolAnd("startsalt", s))
return SALT;
}
if (StartUtils.startsWithSymbolAnd("startflow", s)) {
if (StartUtils.startsWithSymbolAnd("startflow", s))
return FLOW;
}
if (StartUtils.startsWithSymbolAnd("startcreole", s)) {
if (StartUtils.startsWithSymbolAnd("startcreole", s))
return CREOLE;
}
if (StartUtils.startsWithSymbolAnd("starttree", s)) {
if (StartUtils.startsWithSymbolAnd("starttree", s))
return JUNGLE;
}
if (StartUtils.startsWithSymbolAnd("startcute", s)) {
if (StartUtils.startsWithSymbolAnd("startcute", s))
return CUTE;
}
if (StartUtils.startsWithSymbolAnd("startmath", s)) {
if (StartUtils.startsWithSymbolAnd("startmath", s))
return MATH;
}
if (StartUtils.startsWithSymbolAnd("startlatex", s)) {
if (StartUtils.startsWithSymbolAnd("startlatex", s))
return LATEX;
}
if (StartUtils.startsWithSymbolAnd("startdef", s)) {
if (StartUtils.startsWithSymbolAnd("startdef", s))
return DEFINITION;
}
if (StartUtils.startsWithSymbolAnd("startgantt", s)) {
if (StartUtils.startsWithSymbolAnd("startgantt", s))
return GANTT;
}
if (StartUtils.startsWithSymbolAnd("startnwdiag", s)) {
if (StartUtils.startsWithSymbolAnd("startnwdiag", s))
return NW;
}
if (StartUtils.startsWithSymbolAnd("startmindmap", s)) {
if (StartUtils.startsWithSymbolAnd("startmindmap", s))
return MINDMAP;
}
if (StartUtils.startsWithSymbolAnd("startwbs", s)) {
if (StartUtils.startsWithSymbolAnd("startwbs", s))
return WBS;
}
if (StartUtils.startsWithSymbolAnd("startjson", s)) {
if (StartUtils.startsWithSymbolAnd("startjson", s))
return JSON;
}
if (StartUtils.startsWithSymbolAnd("startgit", s)) {
if (StartUtils.startsWithSymbolAnd("startgit", s))
return GIT;
}
if (StartUtils.startsWithSymbolAnd("startboard", s)) {
if (StartUtils.startsWithSymbolAnd("startboard", s))
return BOARD;
}
if (StartUtils.startsWithSymbolAnd("startyaml", s)) {
if (StartUtils.startsWithSymbolAnd("startyaml", s))
return YAML;
}
if (StartUtils.startsWithSymbolAnd("starthcl", s))
return HCL;
return UNKNOWN;
}
}

View File

@ -46,9 +46,9 @@ import net.sourceforge.plantuml.classdiagram.command.CommandUrl;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandEndPackage;
import net.sourceforge.plantuml.command.CommandFootboxIgnored;
import net.sourceforge.plantuml.command.CommandPage;
import net.sourceforge.plantuml.command.CommandRankDir;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.command.note.CommandFactoryNote;
import net.sourceforge.plantuml.command.note.CommandFactoryNoteOnEntity;
import net.sourceforge.plantuml.command.note.CommandFactoryNoteOnLink;
@ -78,7 +78,7 @@ public class DescriptionDiagramFactory extends PSystemCommandFactory {
cmds.add(new CommandNamespaceSeparator());
cmds.add(new CommandRankDir());
cmds.add(new CommandNewpage(this));
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
cmds.add(new CommandLinkElement());
cmds.add(new CommandHideShow2());
@ -92,7 +92,7 @@ public class DescriptionDiagramFactory extends PSystemCommandFactory {
final CommandFactoryNoteOnLink factoryNoteOnLinkCommand = new CommandFactoryNoteOnLink();
cmds.add(factoryNoteOnLinkCommand.createSingleLine());
cmds.add(factoryNoteOnLinkCommand.createMultiLine(false));
final CommandFactoryNoteOnEntity factoryNoteOnEntityCommand = new CommandFactoryNoteOnEntity("desc",
new RegexOr("ENTITY", //
new RegexLeaf("[%pLN_.]+"), //
@ -115,7 +115,6 @@ public class DescriptionDiagramFactory extends PSystemCommandFactory {
cmds.add(factoryNoteOnEntityCommand.createMultiLine(false));
cmds.add(factoryNoteCommand.createMultiLine(false));
// cmds.add(new CommandHideShowSpecificClass());
cmds.add(new CommandArchimate());

View File

@ -0,0 +1,91 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.hcl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.command.PSystemAbstractFactory;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.json.JsonValue;
import net.sourceforge.plantuml.jsondiagram.JsonDiagram;
import net.sourceforge.plantuml.jsondiagram.StyleExtractor;
public class HclDiagramFactory extends PSystemAbstractFactory {
public HclDiagramFactory() {
super(DiagramType.HCL);
}
@Override
public Diagram createSystem(UmlSource source, ISkinSimple skinParam) {
final List<String> highlighted = new ArrayList<>();
JsonValue data = null;
StyleExtractor styleExtractor = null;
try {
final HclSource list = new HclSource();
styleExtractor = new StyleExtractor(source.iterator2());
final Iterator<String> it = styleExtractor.getIterator();
it.next();
while (true) {
final String line = it.next();
if (it.hasNext() == false)
break;
list.add(line);
}
HclParser parser = new HclParser(list);
data = parser.parseMe();
} catch (Exception e) {
e.printStackTrace();
}
final JsonDiagram result = new JsonDiagram(source, UmlDiagramType.HCL, data, highlighted);
// if (styleExtractor != null) {
// styleExtractor.applyStyles(result.getSkinParam());
// final String title = styleExtractor.getTitle();
// if (title != null)
// result.setTitle(DisplayPositioned.single(Display.getWithNewlines(title), HorizontalAlignment.CENTER,
// VerticalAlignment.CENTER));
// }
return result;
}
}

View File

@ -0,0 +1,258 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.hcl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.sourceforge.plantuml.json.Json;
import net.sourceforge.plantuml.json.JsonArray;
import net.sourceforge.plantuml.json.JsonObject;
import net.sourceforge.plantuml.json.JsonString;
import net.sourceforge.plantuml.json.JsonValue;
public class HclParser {
private final List<HclTerm> terms = new ArrayList<HclTerm>();
public HclParser(Iterable<Character> source) {
parse(source.iterator());
}
public JsonObject parseMe() {
final Map<String, JsonObject> map = new LinkedHashMap<>();
final Iterator<HclTerm> it = terms.iterator();
while (it.hasNext())
map.putAll(getModuleOrSomething(it));
if (map.size() == 1)
return map.values().iterator().next();
final JsonObject result = new JsonObject();
for (Entry<String, JsonObject> ent : map.entrySet())
result.add(ent.getKey(), ent.getValue());
return result;
}
private Map<String, JsonObject> getModuleOrSomething(Iterator<HclTerm> it) {
final StringBuilder name = new StringBuilder();
while (true) {
final HclTerm current = it.next();
if (current.is(SymbolType.STRING_QUOTED))
name.append("\"" + current.getData() + "\" ");
else if (current.is(SymbolType.STRING_SIMPLE))
name.append(current.getData() + " ");
else if (current.is(SymbolType.CURLY_BRACKET_OPEN)) {
return Collections.singletonMap(name.toString().trim(), getBracketData(it));
} else
throw new IllegalStateException(current.toString());
}
}
private JsonValue getFunctionData(String functionName, Iterator<HclTerm> it) {
final JsonArray args = new JsonArray();
if (it.next().is(SymbolType.PARENTHESIS_OPEN) == false)
throw new IllegalStateException();
while (true) {
final Object value = getValue(it);
if (value instanceof HclTerm && ((HclTerm) value).is(SymbolType.PARENTHESIS_CLOSE)) {
if (args.size() == 0)
return Json.value(functionName + "()");
final JsonObject result = new JsonObject();
result.add(functionName + "()", args);
return result;
}
if (value instanceof HclTerm && ((HclTerm) value).is(SymbolType.COMMA))
continue;
if (value instanceof String)
args.add((String) value);
else if (value instanceof JsonArray)
args.add((JsonArray) value);
else if (value instanceof JsonObject)
args.add((JsonObject) value);
else if (value instanceof JsonString)
args.add((JsonString) value);
else
throw new IllegalStateException();
}
}
private JsonObject getBracketData(Iterator<HclTerm> it) {
final JsonObject result = new JsonObject();
while (true) {
final HclTerm current = it.next();
if (current.is(SymbolType.CURLY_BRACKET_CLOSE))
return result;
if (current.is(SymbolType.STRING_SIMPLE) || current.is(SymbolType.STRING_QUOTED)) {
final String fieldName = current.getData();
final HclTerm next = it.next();
if (next.is(SymbolType.EQUALS, SymbolType.TWO_POINTS) == false)
throw new IllegalStateException(current.toString());
final Object value = getValue(it);
if (value instanceof String)
result.add(fieldName, (String) value);
else if (value instanceof JsonArray)
result.add(fieldName, (JsonArray) value);
else if (value instanceof JsonObject)
result.add(fieldName, (JsonObject) value);
else if (value instanceof JsonString)
result.add(fieldName, (JsonString) value);
else
throw new IllegalStateException();
} else
throw new IllegalStateException(current.toString());
}
}
private Object getValue(Iterator<HclTerm> it) {
final HclTerm current = it.next();
if (current.is(SymbolType.COMMA, SymbolType.PARENTHESIS_CLOSE))
return current;
if (current.is(SymbolType.STRING_QUOTED))
return current.getData();
if (current.is(SymbolType.STRING_SIMPLE))
return current.getData();
if (current.is(SymbolType.SQUARE_BRACKET_OPEN))
return getArray(it);
if (current.is(SymbolType.CURLY_BRACKET_OPEN))
return getBracketData(it);
if (current.is(SymbolType.FUNCTION_NAME))
return getFunctionData(current.getData(), it);
throw new IllegalStateException(current.toString());
}
private Object getArray(Iterator<HclTerm> it) {
final JsonArray result = new JsonArray();
while (true) {
final HclTerm current = it.next();
if (current.is(SymbolType.CURLY_BRACKET_OPEN))
result.add(getBracketData(it));
if (current.is(SymbolType.SQUARE_BRACKET_CLOSE))
return result;
if (current.is(SymbolType.COMMA))
continue;
if (current.is(SymbolType.STRING_QUOTED))
result.add(current.getData());
}
}
@Override
public String toString() {
return terms.toString();
}
private void parse(Iterator<Character> it) {
final StringBuilder pendingString = new StringBuilder();
while (it.hasNext()) {
final char c = it.next();
final SymbolType type = getType(c);
if (type == SymbolType.PARENTHESIS_OPEN) {
if (pendingString.length() == 0)
throw new IllegalArgumentException();
terms.add(new HclTerm(SymbolType.FUNCTION_NAME, pendingString.toString()));
pendingString.setLength(0);
} else if (type != null && pendingString.length() > 0) {
terms.add(new HclTerm(SymbolType.STRING_SIMPLE, pendingString.toString()));
pendingString.setLength(0);
}
if (type == SymbolType.SPACE)
continue;
if (type != null) {
terms.add(new HclTerm(type));
continue;
}
if (c == '\"') {
final String s = eatUntilDoubleQuote(it);
terms.add(new HclTerm(SymbolType.STRING_QUOTED, s));
continue;
}
pendingString.append(c);
}
}
private String eatUntilDoubleQuote(Iterator<Character> it) {
final StringBuilder sb = new StringBuilder();
while (it.hasNext()) {
final char c = it.next();
if (c == '\\') {
sb.append(it.next());
continue;
}
if (c == '\"')
return sb.toString();
sb.append(c);
}
return sb.toString();
}
private SymbolType getType(final char c) {
if (Character.isSpaceChar(c))
return SymbolType.SPACE;
else if (c == '{')
return SymbolType.CURLY_BRACKET_OPEN;
else if (c == '}')
return SymbolType.CURLY_BRACKET_CLOSE;
else if (c == '[')
return SymbolType.SQUARE_BRACKET_OPEN;
else if (c == ']')
return SymbolType.SQUARE_BRACKET_CLOSE;
else if (c == '(')
return SymbolType.PARENTHESIS_OPEN;
else if (c == ')')
return SymbolType.PARENTHESIS_CLOSE;
else if (c == '=')
return SymbolType.EQUALS;
else if (c == ',')
return SymbolType.COMMA;
else if (c == ':')
return SymbolType.TWO_POINTS;
return null;
}
}

View File

@ -0,0 +1,59 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.hcl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class HclSource implements Iterable<Character> {
final private List<Character> all = new ArrayList<>();
public void add(String line) {
if (line.trim().startsWith("#"))
return;
for (char c : line.toCharArray())
all.add(c);
}
@Override
public Iterator<Character> iterator() {
return Collections.unmodifiableList(all).iterator();
}
}

View File

@ -0,0 +1,79 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.hcl;
import java.util.Objects;
public class HclTerm {
private final SymbolType type;
private final String data;
public HclTerm(SymbolType type) {
this.type = type;
this.data = null;
}
public HclTerm(SymbolType type, String data) {
this.type = type;
this.data = Objects.requireNonNull(data);
}
@Override
public String toString() {
if (data == null)
return type.toString();
return type + "(" + data + ")";
}
public SymbolType getType() {
return type;
}
public String getData() {
return data;
}
public boolean is(SymbolType type) {
return this.type == type;
}
public boolean is(SymbolType type1, SymbolType type2) {
return this.type == type1 || this.type == type2;
}
}

View File

@ -0,0 +1,53 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.hcl;
public enum SymbolType {
STRING_SIMPLE, //
STRING_QUOTED, //
FUNCTION_NAME, //
SQUARE_BRACKET_OPEN, //
SQUARE_BRACKET_CLOSE, //
CURLY_BRACKET_OPEN, //
CURLY_BRACKET_CLOSE, //
PARENTHESIS_OPEN, //
PARENTHESIS_CLOSE, //
TWO_POINTS, //
EQUALS, //
COMMA, //
SPACE; //
}

View File

@ -81,6 +81,9 @@ public class JsonDiagram extends TitledDiagram {
if (getUmlDiagramType() == UmlDiagramType.YAML) {
return new DiagramDescription("(Yaml)");
}
if (getUmlDiagramType() == UmlDiagramType.HCL) {
return new DiagramDescription("(HCL)");
}
return new DiagramDescription("(Json)");
}

View File

@ -110,7 +110,9 @@ public class SmetanaForJson {
}
private SName getDiagramType() {
return skinParam.getUmlDiagramType() == UmlDiagramType.YAML ? SName.yamlDiagram : SName.jsonDiagram;
if (skinParam.getUmlDiagramType() == UmlDiagramType.JSON)
return SName.jsonDiagram;
return SName.yamlDiagram;
}
private Style getStyleArrow() {

View File

@ -41,6 +41,7 @@ import java.util.List;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
@ -54,7 +55,7 @@ public class MindMapDiagramFactory extends PSystemCommandFactory {
protected List<Command> createCommands() {
final List<Command> cmds = new ArrayList<>();
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
// cmds.add(new CommandMindMapTabulation());
cmds.add(new CommandMindMapOrgmode());
cmds.add(new CommandMindMapOrgmodeMultiline());

View File

@ -42,6 +42,7 @@ import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandFootboxIgnored;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
@ -60,7 +61,7 @@ public class NwDiagramFactory extends PSystemCommandFactory {
protected List<Command> createCommands() {
final List<Command> cmds = new ArrayList<>();
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
cmds.add(new CommandNwDiagInit());
cmds.add(new CommandComment());
cmds.add(new CommandElement());

View File

@ -44,6 +44,7 @@ import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandNope;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.project.command.CommandColorTask;
@ -88,8 +89,8 @@ public class GanttDiagramFactory extends PSystemCommandFactory {
@Override
protected List<Command> createCommands() {
final List<Command> cmds = new ArrayList<>();
addTitleCommands(cmds);
addCommonCommands2(cmds);
CommonCommands.addTitleCommands(cmds);
CommonCommands.addCommonCommands2(cmds);
cmds.add(new CommandStyleMultilinesCSS());
cmds.add(new CommandStyleImport());

View File

@ -41,6 +41,7 @@ import java.util.List;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
@ -57,8 +58,8 @@ public class PSystemSaltFactory2 extends PSystemCommandFactory {
if (getDiagramType() == DiagramType.UML) {
cmds.add(new CommandSalt());
}
addCommonCommands2(cmds);
addTitleCommands(cmds);
CommonCommands.addCommonCommands2(cmds);
CommonCommands.addTitleCommands(cmds);
cmds.add(new CommandAnything());
return cmds;

View File

@ -41,6 +41,7 @@ import java.util.List;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.command.note.sequence.FactorySequenceNoteAcrossCommand;
import net.sourceforge.plantuml.command.note.sequence.FactorySequenceNoteCommand;
import net.sourceforge.plantuml.command.note.sequence.FactorySequenceNoteOnArrowCommand;
@ -92,7 +93,7 @@ public class SequenceDiagramFactory extends PSystemCommandFactory {
final List<Command> cmds = new ArrayList<>();
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
cmds.add(new CommandHideUnlinked());
cmds.add(new CommandActivate());

View File

@ -41,6 +41,7 @@ import java.util.List;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.core.UmlSource;
public class ListSpriteDiagramFactory extends PSystemCommandFactory {
@ -49,8 +50,8 @@ public class ListSpriteDiagramFactory extends PSystemCommandFactory {
protected List<Command> createCommands() {
final List<Command> cmds = new ArrayList<>();
addCommonCommands1(cmds);
addCommonCommands2(cmds);
CommonCommands.addCommonCommands1(cmds);
CommonCommands.addCommonCommands2(cmds);
cmds.add(new CommandListSprite());
return cmds;
}

View File

@ -47,6 +47,7 @@ import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandFootboxIgnored;
import net.sourceforge.plantuml.command.CommandRankDir;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.command.note.CommandFactoryNote;
import net.sourceforge.plantuml.command.note.CommandFactoryNoteOnEntity;
import net.sourceforge.plantuml.command.note.CommandFactoryNoteOnLink;
@ -101,7 +102,7 @@ public class StateDiagramFactory extends PSystemCommandFactory {
cmds.add(factoryNoteCommand.createSingleLine());
cmds.add(factoryNoteCommand.createMultiLine(false));
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
cmds.add(new CommandHideShow2());
cmds.add(new CommandNamespaceSeparator());

View File

@ -39,14 +39,18 @@ public enum PName {
Shadowing, //
FontName, //
FontColor, //
DARK_FontColor, //
FontSize, //
FontStyle, //
BackGroundColor, //
DARK_BackGroundColor, //
RoundCorner, //
LineThickness, //
DiagonalCorner, //
HyperLinkColor, //
DARK_HyperLinkColor, //
LineColor, //
DARK_LineColor, //
LineStyle, //
Padding, //
Margin, //
@ -58,13 +62,30 @@ public enum PName {
ShowStereotype, //
ImagePosition;
public static PName getFromName(String name) {
public static PName getFromName(String name, StyleScheme scheme) {
for (PName prop : values()) {
if (prop.name().equalsIgnoreCase(name)) {
if (scheme == StyleScheme.DARK)
return dark(prop);
return prop;
}
}
return null;
}
private static PName dark(PName name) {
switch (name) {
case FontColor:
return DARK_FontColor;
case BackGroundColor:
return DARK_BackGroundColor;
case HyperLinkColor:
return DARK_HyperLinkColor;
case LineColor:
return DARK_LineColor;
default:
return name;
}
}
}

View File

@ -69,26 +69,25 @@ public class Style {
}
public Style deltaPriority(int delta) {
if (signature.isStarred() == false) {
if (signature.isStarred() == false)
throw new UnsupportedOperationException();
}
final EnumMap<PName, Value> copy = new EnumMap<PName, Value>(PName.class);
for (Entry<PName, Value> ent : this.map.entrySet()) {
for (Entry<PName, Value> ent : this.map.entrySet())
copy.put(ent.getKey(), new ValueDeltaPriority(ent.getValue(), delta));
}
return new Style(this.signature, copy);
}
public void printMe() {
if (map.size() == 0) {
if (map.size() == 0)
return;
}
System.err.println(signature + " {");
for (Entry<PName, Value> ent : map.entrySet()) {
for (Entry<PName, Value> ent : map.entrySet())
System.err.println(" " + ent.getKey() + ": " + ent.getValue().asString());
}
System.err.println("}");
}
@ -100,9 +99,16 @@ public class Style {
public Value value(PName name) {
final Value result = map.get(name);
if (result == null) {
if (result == null)
return ValueNull.NULL;
if (name == PName.BackGroundColor) {
final Value resultDark = map.get(PName.DARK_BackGroundColor);
if (resultDark != null)
return new ValueForDark(result, resultDark);
}
return result;
}
@ -111,41 +117,40 @@ public class Style {
}
public Style mergeWith(Style other) {
if (other == null) {
if (other == null)
return this;
}
final EnumMap<PName, Value> both = new EnumMap<PName, Value>(this.map);
for (Entry<PName, Value> ent : other.map.entrySet()) {
final Value previous = this.map.get(ent.getKey());
if (previous == null || ent.getValue().getPriority() > previous.getPriority()) {
if (previous == null || ent.getValue().getPriority() > previous.getPriority())
both.put(ent.getKey(), ent.getValue());
}
}
return new Style(this.signature.mergeWith(other.getSignature()), both);
}
private Style mergeIfUnknownWith(Style other) {
if (other == null) {
return this;
}
final EnumMap<PName, Value> both = new EnumMap<PName, Value>(this.map);
for (Entry<PName, Value> ent : other.map.entrySet()) {
final Value previous = this.map.get(ent.getKey());
if (previous == null) {
both.put(ent.getKey(), ent.getValue());
}
}
return new Style(this.signature.mergeWith(other.getSignature()), both);
}
// private Style mergeIfUnknownWith(Style other) {
// if (other == null) {
// return this;
// }
// final EnumMap<PName, Value> both = new EnumMap<PName, Value>(this.map);
// for (Entry<PName, Value> ent : other.map.entrySet()) {
// final Value previous = this.map.get(ent.getKey());
// if (previous == null)
// both.put(ent.getKey(), ent.getValue());
//
// }
// return new Style(this.signature.mergeWith(other.getSignature()), both, this.scheme);
// }
public Style eventuallyOverride(PName param, HColor color) {
if (color == null) {
if (color == null)
return this;
}
final EnumMap<PName, Value> result = new EnumMap<PName, Value>(this.map);
final Value old = result.get(param);
result.put(param, new ValueColor(color, old.getPriority()));
// return new Style(kind, name + "-" + color, result);
return new Style(this.signature, result);
}
@ -163,17 +168,17 @@ public class Style {
Style result = this;
if (colors != null) {
final HColor back = colors.getColor(ColorType.BACK);
if (back != null) {
if (back != null)
result = result.eventuallyOverride(PName.BackGroundColor, back);
}
final HColor line = colors.getColor(ColorType.LINE);
if (line != null) {
if (line != null)
result = result.eventuallyOverride(PName.LineColor, line);
}
final HColor text = colors.getColor(ColorType.TEXT);
if (text != null) {
if (text != null)
result = result.eventuallyOverride(PName.FontColor, text);
}
}
return result;
}
@ -182,9 +187,9 @@ public class Style {
Style result = this;
if (symbolContext != null) {
final HColor back = symbolContext.getBackColor();
if (back != null) {
if (back != null)
result = result.eventuallyOverride(PName.BackGroundColor, back);
}
}
return result;
}
@ -215,9 +220,9 @@ public class Style {
}
public Style eventuallyOverride(UStroke stroke) {
if (stroke == null) {
if (stroke == null)
return this;
}
Style result = this.eventuallyOverride(PName.LineThickness, stroke.getThickness());
final double space = stroke.getDashSpace();
final double visible = stroke.getDashVisible();
@ -228,16 +233,16 @@ public class Style {
public UStroke getStroke() {
final double thickness = value(PName.LineThickness).asDouble();
final String dash = value(PName.LineStyle).asString();
if (dash.length() == 0) {
if (dash.length() == 0)
return new UStroke(thickness);
}
try {
final StringTokenizer st = new StringTokenizer(dash, "-;,");
final double dashVisible = Double.parseDouble(st.nextToken().trim());
double dashSpace = dashVisible;
if (st.hasMoreTokens()) {
if (st.hasMoreTokens())
dashSpace = Double.parseDouble(st.nextToken().trim());
}
return new UStroke(dashVisible, dashSpace, thickness);
} catch (Exception e) {
return new UStroke(thickness);
@ -246,9 +251,9 @@ public class Style {
public UStroke getStroke(Colors colors) {
final UStroke stroke = colors.getSpecificLineStroke();
if (stroke == null) {
if (stroke == null)
return getStroke();
}
return stroke;
}
@ -294,11 +299,11 @@ public class Style {
public UGraphic applyStrokeAndLineColor(UGraphic ug, HColorSet colorSet, ThemeStyle themeStyle) {
final HColor color = value(PName.LineColor).asColor(themeStyle, colorSet);
if (color == null) {
if (color == null)
ug = ug.apply(new HColorNone());
} else {
else
ug = ug.apply(color);
}
ug = ug.apply(getStroke());
return ug;
}

View File

@ -53,9 +53,9 @@ public class StyleBuilder implements AutomaticCounter {
private int counter;
public void printMe() {
for (Entry<StyleSignature, Style> ent : styles.entrySet()) {
for (Entry<StyleSignature, Style> ent : styles.entrySet())
ent.getValue().printMe();
}
}
private StyleBuilder(SkinParam skinParam, Set<StyleSignature> printedForLog) {
@ -72,15 +72,15 @@ public class StyleBuilder implements AutomaticCounter {
}
public Style createStyle(String name) {
if (name.contains("*")) {
if (name.contains("*"))
throw new IllegalArgumentException();
}
name = name.toLowerCase();
final StyleSignature signature = new StyleSignature(name);
final Style result = styles.get(signature);
if (result == null) {
if (result == null)
return new Style(signature, new EnumMap<PName, Value>(PName.class));
}
return result;
}
@ -101,9 +101,9 @@ public class StyleBuilder implements AutomaticCounter {
}
public void loadInternal(StyleSignature styleName, Style newStyle) {
if (styleName.isStarred()) {
if (styleName.isStarred())
throw new IllegalArgumentException();
}
this.styles.put(styleName, newStyle);
}
@ -113,20 +113,19 @@ public class StyleBuilder implements AutomaticCounter {
public Style getMergedStyle(StyleSignature signature) {
boolean added = this.printedForLog.add(signature);
if (added) {
if (added)
Log.info("Using style " + signature);
}
Style result = null;
for (Entry<StyleSignature, Style> ent : styles.entrySet()) {
final StyleSignature key = ent.getKey();
if (key.matchAll(signature) == false) {
if (key.matchAll(signature) == false)
continue;
}
if (result == null) {
if (result == null)
result = ent.getValue();
} else {
else
result = result.mergeWith(ent.getValue());
}
}
return result;
@ -134,24 +133,23 @@ public class StyleBuilder implements AutomaticCounter {
public Style getMergedStyleSpecial(StyleSignature signature, int deltaPriority) {
boolean added = this.printedForLog.add(signature);
if (added) {
if (added)
Log.info("Using style " + signature);
}
Style result = null;
for (Entry<StyleSignature, Style> ent : styles.entrySet()) {
final StyleSignature key = ent.getKey();
if (key.matchAll(signature) == false) {
if (key.matchAll(signature) == false)
continue;
}
Style tmp = ent.getValue();
if (key.isStarred()) {
if (key.isStarred())
tmp = tmp.deltaPriority(deltaPriority);
}
if (result == null) {
if (result == null)
result = tmp;
} else {
else
result = result.mergeWith(tmp);
}
}
return result;

View File

@ -71,9 +71,9 @@ public class StyleLoader {
InputStream internalIs = null;
SFile localFile = new SFile(filename);
Log.info("Trying to load style " + filename);
if (localFile.exists() == false) {
if (localFile.exists() == false)
localFile = FileSystem.getInstance().getFile(filename);
}
if (localFile.exists()) {
Log.info("File found : " + localFile.getPrintablePath());
internalIs = localFile.openFile();
@ -99,9 +99,9 @@ public class StyleLoader {
}
private void loadSkinInternal(final BlocLines lines) {
for (Style newStyle : getDeclaredStyles(lines, styleBuilder)) {
for (Style newStyle : getDeclaredStyles(lines, styleBuilder))
this.styleBuilder.loadInternal(newStyle.getSignature(), newStyle);
}
}
private final static String KEYNAMES = "[\\w(), ]+?";
@ -112,6 +112,7 @@ public class StyleLoader {
public static Collection<Style> getDeclaredStyles(BlocLines lines, AutomaticCounter counter) {
lines = lines.eventuallyMoveAllEmptyBracket();
final List<Style> result = new ArrayList<>();
StyleScheme scheme = StyleScheme.REGULAR;
Context context = new Context();
final List<Map<PName, Value>> maps = new ArrayList<Map<PName, Value>>();
@ -134,28 +135,33 @@ public class StyleLoader {
if (inComment)
continue;
final int x = trimmed.lastIndexOf("//");
if (x != -1) {
trimmed = trimmed.substring(0, x).trim();
if (trimmed.matches("@media.*dark.*\\{")) {
scheme = StyleScheme.DARK;
continue;
}
final int x = trimmed.lastIndexOf("//");
if (x != -1)
trimmed = trimmed.substring(0, x).trim();
final Matcher2 mKeyNames = keyName.matcher(trimmed);
if (mKeyNames.find()) {
String names = mKeyNames.group(1).replace(" ", "");
final boolean isRecurse = mKeyNames.group(2) != null;
if (isRecurse) {
if (isRecurse)
names += "*";
}
context = context.push(names);
maps.add(new EnumMap<PName, Value>(PName.class));
continue;
}
final Matcher2 mPropertyAndValue = propertyAndValue.matcher(trimmed);
if (mPropertyAndValue.find()) {
final PName key = PName.getFromName(mPropertyAndValue.group(1));
final PName key = PName.getFromName(mPropertyAndValue.group(1), scheme);
final String value = mPropertyAndValue.group(2);
if (key != null && maps.size() > 0) {
if (key != null && maps.size() > 0)
maps.get(maps.size() - 1).put(key, new ValueImpl(value, counter));
}
continue;
}
final Matcher2 mCloseBracket = closeBracket.matcher(trimmed);
@ -168,6 +174,8 @@ public class StyleLoader {
}
context = context.pop();
maps.remove(maps.size() - 1);
} else {
scheme = StyleScheme.REGULAR;
}
}
}

View File

@ -0,0 +1,42 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.style;
public enum StyleScheme {
REGULAR, DARK
}

View File

@ -51,9 +51,9 @@ public class StyleSignature {
private final Set<String> names = new LinkedHashSet<>();
public StyleSignature(String s) {
if (s.contains("*") || s.contains("&") || s.contains("-")) {
if (s.contains("*") || s.contains("&") || s.contains("-"))
throw new IllegalArgumentException();
}
this.names.add(clean(s));
}
@ -69,9 +69,9 @@ public class StyleSignature {
}
public StyleSignature addClickable(Url url) {
if (url == null) {
if (url == null)
return this;
}
final Set<String> result = new LinkedHashSet<>(names);
result.add(SName.clickable.name());
return new StyleSignature(result);
@ -79,12 +79,12 @@ public class StyleSignature {
}
public StyleSignature add(String s) {
if (s == null) {
if (s == null)
return this;
}
if (s.contains("*") || s.contains("&") || s.contains("-")) {
if (s.contains("*") || s.contains("&") || s.contains("-"))
throw new IllegalArgumentException();
}
final Set<String> result = new LinkedHashSet<>(names);
result.add(clean(s));
return new StyleSignature(result);
@ -119,25 +119,25 @@ public class StyleSignature {
public String toString() {
final StringBuilder result = new StringBuilder();
for (String n : names) {
if (result.length() > 0) {
if (result.length() > 0)
result.append('.');
}
result.append(n);
}
return result.toString();
}
public boolean matchAll(StyleSignature other) {
if (other.isStarred() && names.contains("*") == false) {
if (other.isStarred() && names.contains("*") == false)
return false;
}
for (String token : names) {
if (token.equals("*")) {
if (token.equals("*"))
continue;
}
if (other.names.contains(token) == false) {
if (other.names.contains(token) == false)
return false;
}
}
return true;
}
@ -148,30 +148,28 @@ public class StyleSignature {
public static StyleSignature of(SName... names) {
final List<String> result = new ArrayList<>();
for (SName name : names) {
for (SName name : names)
result.add(name.name().toLowerCase().replace("_", ""));
}
return new StyleSignature(result);
}
public StyleSignature forStereotypeItself(Stereotype stereotype) {
final List<String> result = new ArrayList<>(names);
if (stereotype != null) {
for (String name : stereotype.getStyleNames()) {
if (stereotype != null)
for (String name : stereotype.getStyleNames())
result.add(clean(name));
}
}
result.add(SName.stereotype.name().toLowerCase().replace("_", ""));
return new StyleSignature(result);
}
public StyleSignature with(Stereotype stereotype) {
final List<String> result = new ArrayList<>(names);
if (stereotype != null) {
for (String name : stereotype.getStyleNames()) {
if (stereotype != null)
for (String name : stereotype.getStyleNames())
result.add(clean(name));
}
}
return new StyleSignature(result);
}
@ -179,9 +177,9 @@ public class StyleSignature {
if (stereostyles.isEmpty())
return this;
final List<String> result = new ArrayList<>(names);
for (String name : stereostyles.getStyleNames()) {
for (String name : stereostyles.getStyleNames())
result.add(clean(name));
}
return new StyleSignature(result);
}
@ -191,11 +189,10 @@ public class StyleSignature {
public StyleSignature mergeWith(List<Style> others) {
final List<String> copy = new ArrayList<>(names);
for (Style other : others) {
for (String s : other.getSignature().getNames()) {
for (Style other : others)
for (String s : other.getSignature().getNames())
copy.add(s);
}
}
return new StyleSignature(copy);
}
@ -206,17 +203,17 @@ public class StyleSignature {
}
public Style getMergedStyle(StyleBuilder styleBuilder) {
if (styleBuilder == null) {
if (styleBuilder == null)
return null;
}
return styleBuilder.getMergedStyle(this);
}
public boolean match(Stereotype stereotype) {
for (String s : stereotype.getMultipleLabels()) {
if (names.contains(clean(s))) {
if (names.contains(clean(s)))
return true;
}
}
return false;
}

View File

@ -0,0 +1,97 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.style;
import net.sourceforge.plantuml.ThemeStyle;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
import net.sourceforge.plantuml.ugraphic.color.HColorSimple;
public class ValueForDark implements Value {
private final Value regular;
private final Value dark;
public ValueForDark(Value regular, Value dark) {
this.regular = regular;
this.dark = dark;
}
@Override
public String asString() {
throw new UnsupportedOperationException();
}
@Override
public HColor asColor(ThemeStyle themeStyle, HColorSet set) {
final HColor result = regular.asColor(themeStyle, set);
if (result instanceof HColorSimple)
return ((HColorSimple) result).withDark(dark.asColor(themeStyle, set));
return result;
}
@Override
public int asInt() {
throw new UnsupportedOperationException();
}
@Override
public double asDouble() {
throw new UnsupportedOperationException();
}
@Override
public boolean asBoolean() {
throw new UnsupportedOperationException();
}
@Override
public int asFontStyle() {
throw new UnsupportedOperationException();
}
@Override
public HorizontalAlignment asHorizontalAlignment() {
throw new UnsupportedOperationException();
}
@Override
public int getPriority() {
throw new UnsupportedOperationException();
}
}

View File

@ -47,7 +47,7 @@ import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class EntityImageProtected extends AbstractTextBlock implements IEntityImage, Untranslated {
public class EntityImageProtected extends AbstractTextBlock implements IEntityImage, Untranslated, WithPorts {
private final IEntityImage orig;
private final double border;
@ -100,4 +100,9 @@ public class EntityImageProtected extends AbstractTextBlock implements IEntityIm
return orig.getOverscanX(stringBounder);
}
@Override
public Ports getPorts(StringBounder stringBounder) {
return ((WithPorts) orig).getPorts(stringBounder);
}
}

View File

@ -44,7 +44,9 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -107,6 +109,8 @@ public class SvgGraphics {
final private Element gRoot;
private String fill = "black";
private String fillDark = "black";
private Collection<String> classesForDarkness = new LinkedHashSet<>();
private String stroke = "black";
private String strokeWidth;
private String strokeDasharray = null;
@ -156,19 +160,17 @@ public class SvgGraphics {
this.filterUid = "b" + getSeed(seed);
this.shadowId = "f" + getSeed(seed);
this.gradientId = "g" + getSeed(seed);
if (hover != null) {
if (hover != null)
defs.appendChild(getPathHover(hover));
}
if (INTERACTIVE) {
final Element styles = getStylesForInteractiveMode();
if (styles != null) {
if (styles != null)
defs.appendChild(styles);
}
final Element script = getScriptForInteractiveMode();
if (script != null) {
if (script != null)
defs.appendChild(script);
}
}
} catch (ParserConfigurationException e) {
e.printStackTrace();
@ -179,21 +181,42 @@ public class SvgGraphics {
private Element getStylesForInteractiveMode() {
final Element style = simpleElement("style");
final String text = getData("default.css");
if (text == null) {
if (text == null)
return null;
}
final CDATASection cdata = document.createCDATASection(text);
style.setAttribute("type", "text/css");
style.appendChild(cdata);
return style;
}
private Element getStylesForDarkness() {
final Element style = simpleElement("style");
final StringBuilder text1 = new StringBuilder();
final StringBuilder text2 = new StringBuilder("@media (prefers-color-scheme:dark) {");
final Pattern p = Pattern.compile("^(\\w)_(\\w+)_(\\w+)$");
for (String s : this.classesForDarkness) {
final Matcher m = p.matcher(s);
if (m.matches() == false)
throw new IllegalStateException();
final String color1 = m.group(2);
final String color2 = m.group(3);
text1.append("*." + s + " {fill:#" + color1 + ";}");
text2.append("*." + s + " {fill:#" + color2 + ";}");
}
text2.append("}");
final CDATASection cdata = document.createCDATASection(text1.toString() + text2.toString());
style.setAttribute("type", "text/css");
style.appendChild(cdata);
return style;
}
private Element getScriptForInteractiveMode() {
final Element script = document.createElement("script");
final String text = getData("default.js");
if (text == null) {
if (text == null)
return null;
}
script.setTextContent(text);
return script;
}
@ -343,6 +366,12 @@ public class SvgGraphics {
public final void setFillColor(String fill) {
this.fill = fill == null ? "none" : fill;
this.fillDark = this.fill;
}
public final void setFillColor(String fill, String fillDark) {
this.fill = fill == null ? "none" : fill;
this.fillDark = fillDark == null ? "none" : fillDark;
}
public final void setStrokeColor(String stroke) {
@ -357,9 +386,9 @@ public class SvgGraphics {
private final List<Element> pendingAction = new ArrayList<>();
public final Element getG() {
if (pendingAction.size() == 0) {
if (pendingAction.size() == 0)
return gRoot;
}
return pendingAction.get(0);
}
@ -378,12 +407,12 @@ public class SvgGraphics {
elt.setAttribute("rx", format(rx));
elt.setAttribute("ry", format(ry));
}
if (id != null) {
if (id != null)
elt.setAttribute("id", id);
}
if (codeLine != null) {
if (codeLine != null)
elt.setAttribute("codeLine", codeLine);
}
getG().appendChild(elt);
}
ensureVisible(x + width + 2 * deltaShadow, y + height + 2 * deltaShadow);
@ -420,12 +449,12 @@ public class SvgGraphics {
final StringBuilder style = new StringBuilder();
style.append("stroke:" + stroke + ";");
style.append("stroke-width:" + strokeWidth + ";");
if (fill.equals("#00000000")) {
if (fill.equals("#00000000"))
style.append("fill:none;");
}
if (strokeDasharray != null) {
if (strokeDasharray != null)
style.append("stroke-dasharray:" + strokeDasharray + ";");
}
return style.toString();
}
@ -434,12 +463,12 @@ public class SvgGraphics {
final StringBuilder style = new StringBuilder();
style.append("stroke:" + stroke + ";");
style.append("stroke-width:" + strokeWidth + ";");
if (fill.equals("#00000000")) {
if (fill.equals("#00000000"))
style.append("fill:none;");
}
if (strokeDasharray != null) {
if (strokeDasharray != null)
style.append("stroke-dasharray:" + strokeDasharray + ";");
}
return style.toString();
}
@ -450,9 +479,9 @@ public class SvgGraphics {
final Element elt = (Element) document.createElement("polygon");
final StringBuilder sb = new StringBuilder();
for (double coord : points) {
if (sb.length() > 0) {
if (sb.length() > 0)
sb.append(",");
}
sb.append(format(coord));
}
elt.setAttribute("points", sb.toString());
@ -489,15 +518,15 @@ public class SvgGraphics {
elt.setAttribute("textLength", format(textLength));
}
if (fontWeight != null) {
if (fontWeight != null)
elt.setAttribute("font-weight", fontWeight);
}
if (fontStyle != null) {
if (fontStyle != null)
elt.setAttribute("font-style", fontStyle);
}
if (textDecoration != null) {
if (textDecoration != null)
elt.setAttribute("text-decoration", textDecoration);
}
if (fontFamily != null) {
// http://plantuml.sourceforge.net/qa/?qa=5432/svg-monospace-output-has-wrong-font-family
if ("monospaced".equalsIgnoreCase(fontFamily)) {
@ -513,9 +542,9 @@ public class SvgGraphics {
final String backFilterId = getFilterBackColor(textBackColor);
elt.setAttribute("filter", "url(#" + backFilterId + ")");
}
for (Map.Entry<String, String> ent : attributes.entrySet()) {
for (Map.Entry<String, String> ent : attributes.entrySet())
elt.setAttribute(ent.getKey(), ent.getValue());
}
elt.setTextContent(text);
getG().appendChild(elt);
@ -549,9 +578,9 @@ public class SvgGraphics {
private String getFilterBackColor(String color) {
String id = filterBackColor.get(color);
if (id != null) {
if (id != null)
return id;
}
id = getIdFilterBackColor(color);
final Element filter = (Element) document.createElement("filter");
filter.setAttribute("id", id);
@ -600,10 +629,8 @@ public class SvgGraphics {
}
private void createXmlInternal(OutputStream os) throws TransformerException {
// // Add lines
// for (Line l : lines) {
// l.drawNow();
// }
if (this.classesForDarkness.size() > 0)
defs.appendChild(getStylesForDarkness());
// Get a DOMSource object that represents the
// Document object
@ -612,9 +639,9 @@ public class SvgGraphics {
final int maxXscaled = (int) (maxX * scale);
final int maxYscaled = (int) (maxY * scale);
String style = "width:" + maxXscaled + "px;height:" + maxYscaled + "px;";
if (backcolor != null) {
if (backcolor != null)
style += "background:" + backcolor + ";";
}
if (svgDimensionStyle) {
root.setAttribute("style", style);
root.setAttribute("width", format(maxX) + "px");
@ -629,7 +656,6 @@ public class SvgGraphics {
if (pendingBackground != null) {
pendingBackground.setAttribute("width", format(maxX));
pendingBackground.setAttribute("height", format(maxY));
}
// Get a StreamResult object that points to the
@ -682,22 +708,34 @@ public class SvgGraphics {
elt.setAttribute("style", getStyle());
fillMe(elt);
final String id = path.getComment();
if (id != null) {
if (id != null)
elt.setAttribute("id", id);
}
final String codeLine = path.getCodeLine();
if (codeLine != null) {
if (codeLine != null)
elt.setAttribute("codeLine", codeLine);
}
addFilterShadowId(elt, deltaShadow);
getG().appendChild(elt);
}
}
private String getFillClassForDark() {
final String result = "f_" + fill.toLowerCase().replaceAll("\\#", "") + "_"
+ fillDark.toLowerCase().replaceAll("\\#", "");
this.classesForDarkness.add(result);
return result;
}
private void fillMe(Element elt) {
if (fill.equals("#00000000")) {
if (fill.equals("#00000000"))
return;
if (fill.equals(fillDark) == false) {
elt.setAttribute("class", getFillClassForDark());
return;
}
if (fill.matches("#[0-9A-Fa-f]{8}")) {
elt.setAttribute("fill", fill.substring(0, 7));
final double opacity = Integer.parseInt(fill.substring(7), 16) / 255.0;
@ -708,9 +746,9 @@ public class SvgGraphics {
}
private void addFilterShadowId(final Element elt, double deltaShadow) {
if (deltaShadow > 0) {
if (deltaShadow > 0)
elt.setAttribute("filter", "url(#" + shadowId + ")");
}
}
private StringBuilder currentPath = null;
@ -776,19 +814,18 @@ public class SvgGraphics {
final double coord[] = new double[6];
while (path.isDone() == false) {
final int code = path.currentSegment(coord);
if (code == PathIterator.SEG_MOVETO) {
if (code == PathIterator.SEG_MOVETO)
this.moveto(coord[0] + x, coord[1] + y);
} else if (code == PathIterator.SEG_LINETO) {
else if (code == PathIterator.SEG_LINETO)
this.lineto(coord[0] + x, coord[1] + y);
} else if (code == PathIterator.SEG_CLOSE) {
else if (code == PathIterator.SEG_CLOSE)
this.closepath();
} else if (code == PathIterator.SEG_CUBICTO) {
else if (code == PathIterator.SEG_CUBICTO)
this.curveto(coord[0] + x, coord[1] + y, coord[2] + x, coord[3] + y, coord[4] + x, coord[5] + y);
} else if (code == PathIterator.SEG_QUADTO) {
else if (code == PathIterator.SEG_QUADTO)
this.quadto(coord[0] + x, coord[1] + y, coord[2] + x, coord[3] + y);
} else {
else
throw new UnsupportedOperationException("code=" + code);
}
path.next();
}
@ -831,9 +868,9 @@ public class SvgGraphics {
private String manageScale(UImageSvg svgImage) {
final double svgScale = svgImage.getScale();
String svg = svgImage.getSvg(false);
if (svgScale * scale == 1) {
if (svgScale * scale == 1)
return svg;
}
final String svg2 = svg.replace('\n', ' ').replace('\r', ' ');
if (svg2.contains("<g ") == false && svg2.contains("<g>") == false) {
svg = svg.replaceFirst("\\<svg\\>", "<svg><g>");
@ -883,9 +920,9 @@ public class SvgGraphics {
private void addFilter(Element filter, String name, String... data) {
assert data.length % 2 == 0;
final Element elt = (Element) document.createElement(name);
for (int i = 0; i < data.length; i += 2) {
for (int i = 0; i < data.length; i += 2)
elt.setAttribute(data[i], data[i + 1]);
}
filter.appendChild(elt);
}
@ -914,11 +951,9 @@ public class SvgGraphics {
// javascript: security issue
if (SecurityUtils.ignoreThisLink(url))
return;
if (pendingAction.size() > 0) {
if (pendingAction.size() > 0)
closeLink();
}
pendingAction.add(0, (Element) document.createElement("a"));
pendingAction.get(0).setAttribute("target", target);

View File

@ -42,6 +42,7 @@ import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandFootboxIgnored;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.timingdiagram.command.CommandAnalog;
import net.sourceforge.plantuml.timingdiagram.command.CommandAtPlayer;
@ -76,7 +77,7 @@ public class TimingDiagramFactory extends PSystemCommandFactory {
final List<Command> cmds = new ArrayList<>();
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
cmds.add(new CommandFootboxIgnored());
cmds.add(new CommandRobustConcise());
cmds.add(new CommandClock());

View File

@ -54,4 +54,6 @@ public interface HColor extends UChange {
public HColor reverse();
public HColor darkSchemeTheme();
}

View File

@ -75,5 +75,10 @@ abstract class HColorAbstract implements HColor {
public String asString() {
return "?" + getClass().getSimpleName();
}
@Override
public HColor darkSchemeTheme() {
return this;
}
}

View File

@ -43,6 +43,7 @@ public class HColorSimple extends HColorAbstract implements HColor {
private final Color color;
private final boolean monochrome;
private HColor dark;
@Override
public int hashCode() {
@ -112,6 +113,13 @@ public class HColorSimple extends HColorAbstract implements HColor {
public HColorSimple(Color c, boolean monochrome) {
this.color = c;
this.monochrome = monochrome;
this.dark = this;
}
private HColorSimple(Color c, boolean monochrome, HColor dark) {
this.color = c;
this.monochrome = monochrome;
this.dark = dark;
}
public Color getColor999() {
@ -188,4 +196,13 @@ public class HColorSimple extends HColorAbstract implements HColor {
return (x + (y - x) * factor);
}
public HColor withDark(HColor dark) {
return new HColorSimple(color, monochrome, dark);
}
@Override
public HColor darkSchemeTheme() {
return dark;
}
}

View File

@ -79,7 +79,7 @@ public class DriverEllipseSvg implements UDriver<UEllipse, SvgGraphics> {
final String backcolor = mapper.toSvg(back);
svg.setFillColor(backcolor);
}
DriverRectangleSvg.applyColor(svg, mapper, param);
DriverRectangleSvg.applyStrokeColor(svg, mapper, param);
// svg.setStrokeColor(StringUtils.getAsSvg(mapper, param.getColor()));
svg.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDasharraySvg());

View File

@ -66,11 +66,17 @@ public class DriverRectangleSvg implements UDriver<URectangle, SvgGraphics> {
final String id = svg.createSvgGradient(mapper.toRGB(gr.getColor1()), mapper.toRGB(gr.getColor2()),
gr.getPolicy());
svg.setFillColor("url(#" + id + ")");
applyColor(svg, mapper, param);
applyStrokeColor(svg, mapper, param);
} else {
final String backcolor = mapper.toSvg(back);
svg.setFillColor(backcolor);
applyColor(svg, mapper, param);
final HColor dark = back == null ? null : back.darkSchemeTheme();
if (dark == back) {
svg.setFillColor(backcolor);
} else {
final String darkcolor = mapper.toSvg(dark);
svg.setFillColor(backcolor, darkcolor);
}
applyStrokeColor(svg, mapper, param);
}
svg.setStrokeWidth(param.getStroke().getThickness(), param.getStroke().getDasharraySvg());
@ -90,7 +96,7 @@ public class DriverRectangleSvg implements UDriver<URectangle, SvgGraphics> {
rect.getCodeLine());
}
public static void applyColor(SvgGraphics svg, ColorMapper mapper, UParam param) {
public static void applyStrokeColor(SvgGraphics svg, ColorMapper mapper, UParam param) {
final HColor color = param.getColor();
if (color instanceof HColorGradient) {
final HColorGradient gr = (HColorGradient) color;

View File

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

View File

@ -41,6 +41,7 @@ import java.util.List;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
@ -54,7 +55,7 @@ public class WBSDiagramFactory extends PSystemCommandFactory {
protected List<Command> createCommands() {
final List<Command> cmds = new ArrayList<>();
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
cmds.add(new CommandWBSItem());
cmds.add(new CommandWBSItemMultiline());

View File

@ -41,6 +41,7 @@ import java.util.List;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
@ -54,7 +55,7 @@ public class WireDiagramFactory extends PSystemCommandFactory {
protected List<Command> createCommands() {
final List<Command> cmds = new ArrayList<>();
addCommonCommands1(cmds);
CommonCommands.addCommonCommands1(cmds);
cmds.add(new CommandComponent());
cmds.add(new CommandSpot());
cmds.add(new CommandGoto());