Skip to content

Commit

Permalink
🚧 prepare jaws deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Dec 12, 2024
1 parent 3554de7 commit d3b4e7a
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 32 deletions.
14 changes: 8 additions & 6 deletions src/net/atmp/ImageBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
Expand All @@ -61,6 +62,7 @@
import net.sourceforge.plantuml.api.ImageDataSimple;
import net.sourceforge.plantuml.braille.UGraphicBraille;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.jaws.JawsWarning;
import net.sourceforge.plantuml.klimt.UStroke;
import net.sourceforge.plantuml.klimt.UTranslate;
import net.sourceforge.plantuml.klimt.color.ColorMapper;
Expand Down Expand Up @@ -123,7 +125,7 @@ public class ImageBuilder {
private TitledDiagram titledDiagram;
private boolean randomPixel;
private String warningOrError;
private boolean warningNewline;
private Set<JawsWarning> warnings = EnumSet.noneOf(JawsWarning.class);

public static ImageBuilder imageBuilder(FileFormatOption fileFormatOption) {
return new ImageBuilder(fileFormatOption);
Expand Down Expand Up @@ -223,7 +225,7 @@ public ImageBuilder styled(TitledDiagram diagram) {
seed = diagram.seed();
titledDiagram = diagram;
warningOrError = diagram.getWarningOrError();
warningNewline = diagram.getPragma().printBackslashNewlineWarning();
warnings = diagram.getPragma().warnings();
return this;
}

Expand All @@ -250,7 +252,7 @@ public byte[] writeByteArray() throws IOException {
private ImageData writeImageInternal(OutputStream os) throws IOException {
XDimension2D dim = getFinalDimension();
XDimension2D dimWarning = null;
if (warningNewline) {
if (warnings.size() > 0) {
dimWarning = getWarningDimension(fileFormatOption.getFileFormat().getDefaultStringBounder());
dim = dim.atLeast(dimWarning.getWidth(), 0);
dim = dim.delta(15, dimWarning.getHeight() + 20);
Expand All @@ -264,7 +266,7 @@ private ImageData writeImageInternal(OutputStream os) throws IOException {
UGraphic ug = createUGraphic(dim, scaleFactor,
titledDiagram == null ? Pragma.createEmpty() : titledDiagram.getPragma());

if (warningNewline) {
if (warnings.size() > 0) {
drawWarning(dimWarning, ug.apply(UTranslate.dy(5)), dim.getWidth());
ug = ug.apply(UTranslate.dy(dimWarning.getHeight() + 20));
}
Expand Down Expand Up @@ -298,8 +300,8 @@ private void drawWarning(XDimension2D dimWarning, UGraphic ug, double fullWidth)

final HColorSet set = HColorSet.instance();

final HColor back = set.getColorOrWhite("ffffcc");
final HColor border = set.getColorOrWhite("ffdd88");
final HColor back = set.getColorOrWhite("ffffcc");
final HColor border = set.getColorOrWhite("ffdd88");
ug = ug.apply(back.bg()).apply(border);
final URectangle rect = URectangle.build(fullWidth - 10, dimWarning.getHeight() + 10).rounded(5);
ug.apply(new UTranslate(5, 0)).apply(UStroke.withThickness(3)).draw(rect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected CommandExecutionResult executeNow(final AbstractEntityDiagram diagram,
ParserPass currentPass) throws NoSuchColorException {
// StringUtils.trim(lines, false);
final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString());
lines = lines.subExtract(1, 1);
lines = lines.subExtract(1, 1).expandsJaws5();
lines = lines.removeEmptyColumns();
final Display display = lines.toDisplay();
return executeInternal(diagram, line0, display);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public final CommandExecutionResult executeNow(final ActivityDiagram diagram, Bl
throws NoSuchColorException {
// StringUtils.trim(lines, true);
final RegexResult arg = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString());
lines = lines.subExtract(1, 1);
lines = lines.subExtract(1, 1).expandsJaws5();
lines = lines.removeEmptyColumns();

Display strings = lines.toDisplay();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected CommandExecutionResult executeNow(final AbstractEntityDiagram system,
ParserPass currentPass) throws NoSuchColorException {
// StringUtils.trim(lines, false);
final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString());
lines = lines.subExtract(1, 1);
lines = lines.subExtract(1, 1).expandsJaws5();
lines = lines.removeEmptyColumns();
final Display display = lines.toDisplay();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public String getPatternEnd() {
protected CommandExecutionResult executeNow(final CucaDiagram system, BlocLines lines,
ParserPass currentPass) throws NoSuchColorException {
final String line0 = lines.getFirst().getTrimmed().getString();
lines = lines.subExtract(1, 1);
lines = lines.subExtract(1, 1).expandsJaws5();
lines = lines.removeEmptyColumns();
if (lines.size() > 0) {
final RegexResult arg = getStartingPattern().matcher(line0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected CommandExecutionResult executeNow(final AbstractEntityDiagram system,
ParserPass currentPass) throws NoSuchColorException {
// StringUtils.trim(lines, false);
final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString());
lines = lines.subExtract(1, 1);
lines = lines.subExtract(1, 1).expandsJaws5();
lines = lines.removeEmptyColumns();
final Display display = lines.toDisplay();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected CommandExecutionResult executeNow(final SequenceDiagram diagram, BlocL
ParserPass currentPass) throws NoSuchColorException {
final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString());
lines = lines.subExtract(1, 1);
lines = lines.removeEmptyColumns();
lines = lines.removeEmptyColumns().expandsJaws5();
final Display display = lines.toDisplay();
return executeInternal(diagram, line0, diagram.manageVariable(display));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected CommandExecutionResult executeNow(final SequenceDiagram diagram, BlocL
ParserPass currentPass) throws NoSuchColorException {
final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString());
lines = lines.subExtract(1, 1);
lines = lines.removeEmptyColumns();
lines = lines.removeEmptyColumns().expandsJaws5();
final Display display = lines.toDisplay();
return executeInternal(diagram, line0, diagram.manageVariable(display));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public String getPatternEnd() {
protected CommandExecutionResult executeNow(final SequenceDiagram diagram, BlocLines lines,
ParserPass currentPass) throws NoSuchColorException {
final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString());
lines = lines.subExtract(1, 1);
lines = lines.subExtract(1, 1).expandsJaws5();
lines = lines.removeEmptyColumns();
final Display display = lines.toDisplay();
return executeInternal(diagram, line0, diagram.manageVariable(display));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public String getPatternEnd() {
protected CommandExecutionResult executeNow(final SequenceDiagram diagram, BlocLines lines,
ParserPass currentPass) throws NoSuchColorException {
final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString());
lines = lines.subExtract(1, 1);
lines = lines.subExtract(1, 1).expandsJaws5();
lines = lines.removeEmptyColumns();
final Display display = lines.toDisplay();
return executeInternal(diagram, line0, diagram.manageVariable(display));
Expand Down
14 changes: 10 additions & 4 deletions src/net/sourceforge/plantuml/jaws/Jaws.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@
public class Jaws {

public static final char BLOCK_E1_NEWLINE = '\uE100';
public static final char BLOCK_E1_REAL_BACKSLASH = '\uE101';
public static final char BLOCK_E1_START_TEXTBLOCK = '\uE102';
public static final char BLOCK_E1_END_TEXTBLOCK = '\uE103';
public static final char BLOCK_E1_REAL_TABULATION = '\uE104';
public static final char BLOCK_E1_NEWLINE_LEFT_ALIGN = '\uE101';
public static final char BLOCK_E1_NEWLINE_RIGHT_ALIGN = '\uE102';

public static final char BLOCK_E1_REAL_BACKSLASH = '\uE110';
public static final char BLOCK_E1_REAL_TABULATION = '\uE111';

public static final char BLOCK_E1_INVISIBLE_QUOTE = '\uE121';
public static final char BLOCK_E1_START_TEXTBLOCK = '\uE122';
public static final char BLOCK_E1_END_TEXTBLOCK = '\uE123';


private final List<StringLocated> output = new ArrayList<StringLocated>();

public Jaws(List<StringLocated> input) {
Expand Down
46 changes: 46 additions & 0 deletions src/net/sourceforge/plantuml/jaws/JawsWarning.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://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.jaws;

public enum JawsWarning {
BACKSLASH_NEWLINE,
BACKSLASH_LEFT,
BACKSLASH_RIGHT,
BACKSLASH_TABULATION,
BACKSLASH_BACKSLASH,
OTHER

}
22 changes: 19 additions & 3 deletions src/net/sourceforge/plantuml/klimt/creole/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.sourceforge.plantuml.abel.Entity;
import net.sourceforge.plantuml.jaws.Jaws;
import net.sourceforge.plantuml.jaws.JawsStrange;
import net.sourceforge.plantuml.jaws.JawsWarning;
import net.sourceforge.plantuml.klimt.LineBreakStrategy;
import net.sourceforge.plantuml.klimt.UStroke;
import net.sourceforge.plantuml.klimt.color.HColor;
Expand Down Expand Up @@ -270,27 +271,42 @@ else if (sub.startsWith("</math>") || sub.startsWith("</latex>") || sub.startsWi
final char c2 = s.charAt(i + 1);
i++;
if (c2 == 'n' || c2 == 'r' || c2 == 'l') {
if (c2 == 'r')
if (c2 == 'r') {
naturalHorizontalAlignment = HorizontalAlignment.RIGHT;
else if (c2 == 'l')
pragma.addWarning(JawsWarning.BACKSLASH_RIGHT);
} else if (c2 == 'l') {
naturalHorizontalAlignment = HorizontalAlignment.LEFT;
pragma.addWarning(JawsWarning.BACKSLASH_LEFT);
} else {
pragma.addWarning(JawsWarning.BACKSLASH_NEWLINE);
}

result.add(current.toString());
current.setLength(0);
} else if (c2 == 't') {
current.append('\t');
pragma.addWarning(JawsWarning.BACKSLASH_TABULATION);
} else if (c2 == '\\') {
current.append(c2);
pragma.addWarning(JawsWarning.BACKSLASH_BACKSLASH);
} else {
current.append(c);
current.append(c2);
}
pragma.addBackslashNewlineWarning();
pragma.addWarning(JawsWarning.OTHER);
} else if (c == Jaws.BLOCK_E1_REAL_TABULATION) {
// current.append('\t');
current.append(c);
} else if (c == Jaws.BLOCK_E1_REAL_BACKSLASH) {
current.append('\\');
} else if (c == Jaws.BLOCK_E1_NEWLINE_LEFT_ALIGN) {
naturalHorizontalAlignment = HorizontalAlignment.LEFT;
result.add(current.toString());
current.setLength(0);
} else if (c == Jaws.BLOCK_E1_NEWLINE_RIGHT_ALIGN) {
naturalHorizontalAlignment = HorizontalAlignment.RIGHT;
result.add(current.toString());
current.setLength(0);
} else if (rawMode == false && c == Jaws.BLOCK_E1_NEWLINE) {
result.add(current.toString());
current.setLength(0);
Expand Down
3 changes: 2 additions & 1 deletion src/net/sourceforge/plantuml/nwdiag/NwDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.jaws.Jaws;
import net.sourceforge.plantuml.klimt.UTranslate;
import net.sourceforge.plantuml.klimt.color.HColor;
import net.sourceforge.plantuml.klimt.creole.Display;
Expand Down Expand Up @@ -354,7 +355,7 @@ private StyleSignatureBasic getStyleDefinitionNetwork(SName sname) {

private TextBlock toTextBlockForNetworkName(String name, String s) {
if (s != null)
name += "\\n" + s;
name += "" + Jaws.BLOCK_E1_NEWLINE + s;

final StyleBuilder styleBuilder = getSkinParam().getCurrentStyleBuilder();
final Style style = getStyleDefinitionNetwork(SName.network).getMergedStyle(styleBuilder);
Expand Down
6 changes: 4 additions & 2 deletions src/net/sourceforge/plantuml/nwdiag/core/NServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import net.sourceforge.plantuml.decoration.symbol.USymbol;
import net.sourceforge.plantuml.decoration.symbol.USymbols;
import net.sourceforge.plantuml.jaws.Jaws;
import net.sourceforge.plantuml.jaws.JawsStrange;
import net.sourceforge.plantuml.klimt.Fashion;
import net.sourceforge.plantuml.klimt.color.HColor;
Expand Down Expand Up @@ -144,8 +145,9 @@ public TextBlock toTextBlock(SName sname, String s) {
if (s.length() == 0)
return TextBlockUtils.empty(0, 0);

s = s.replace(", ", "\\n");
return Display.getWithNewlines(skinParam.getPragma(), s).create(getFontConfiguration(sname), HorizontalAlignment.LEFT, skinParam);
s = s.replace(", ", "" + Jaws.BLOCK_E1_NEWLINE);
return Display.getWithNewlines(skinParam.getPragma(), s).create(getFontConfiguration(sname),
HorizontalAlignment.LEFT, skinParam);
}

private StyleSignatureBasic getStyleDefinition(SName sname) {
Expand Down
17 changes: 11 additions & 6 deletions src/net/sourceforge/plantuml/skin/Pragma.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@
*/
package net.sourceforge.plantuml.skin;

import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import net.sourceforge.plantuml.jaws.JawsWarning;

public class Pragma {

private final Map<String, String> values = new LinkedHashMap<String, String>();
private boolean backslashNewlineWarning;
private final Set<JawsWarning> warnings = EnumSet.noneOf(JawsWarning.class);

private Pragma() {
}
Expand Down Expand Up @@ -106,12 +110,13 @@ public boolean legacyReplaceBackslashNByNewline() {
return true;
}

public void addBackslashNewlineWarning() {
this.backslashNewlineWarning = true;
public void addWarning(JawsWarning warning) {
this.warnings.add(warning);
}

public boolean printBackslashNewlineWarning() {
return backslashNewlineWarning && isTrue(getValue("warning"));
public Set<JawsWarning> warnings() {
if (isTrue(getValue("warning")))
return this.warnings;
return null;
}

}
7 changes: 6 additions & 1 deletion src/net/sourceforge/plantuml/tim/TContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import net.sourceforge.plantuml.DefinitionsContainer;
import net.sourceforge.plantuml.FileSystem;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.jaws.Jaws;
import net.sourceforge.plantuml.json.Json;
import net.sourceforge.plantuml.json.JsonObject;
import net.sourceforge.plantuml.json.JsonValue;
Expand Down Expand Up @@ -110,6 +111,7 @@
import net.sourceforge.plantuml.tim.builtin.JsonMerge;
import net.sourceforge.plantuml.tim.builtin.JsonRemove;
import net.sourceforge.plantuml.tim.builtin.JsonSet;
import net.sourceforge.plantuml.tim.builtin.LeftAlign;
import net.sourceforge.plantuml.tim.builtin.Lighten;
import net.sourceforge.plantuml.tim.builtin.LoadJson;
import net.sourceforge.plantuml.tim.builtin.LogicalAnd;
Expand All @@ -129,6 +131,7 @@
import net.sourceforge.plantuml.tim.builtin.RetrieveProcedure;
import net.sourceforge.plantuml.tim.builtin.ReverseColor;
import net.sourceforge.plantuml.tim.builtin.ReverseHsluvColor;
import net.sourceforge.plantuml.tim.builtin.RightAlign;
import net.sourceforge.plantuml.tim.builtin.SetVariableValue;
import net.sourceforge.plantuml.tim.builtin.Size;
import net.sourceforge.plantuml.tim.builtin.SplitStr;
Expand Down Expand Up @@ -217,6 +220,7 @@ private void addStandardFunctions(Defines defines) {
functionsSet.addFunction(new JsonMerge());
functionsSet.addFunction(new JsonRemove());
functionsSet.addFunction(new JsonSet());
functionsSet.addFunction(new LeftAlign());
functionsSet.addFunction(new Lighten());
functionsSet.addFunction(new LoadJson());
// functionsSet.addFunction(new LoadJsonLegacy());
Expand All @@ -237,6 +241,7 @@ private void addStandardFunctions(Defines defines) {
functionsSet.addFunction(new RetrieveProcedure());
functionsSet.addFunction(new ReverseColor());
functionsSet.addFunction(new ReverseHsluvColor());
functionsSet.addFunction(new RightAlign());
functionsSet.addFunction(new SetVariableValue());
functionsSet.addFunction(new Size());
functionsSet.addFunction(new SplitStr());
Expand Down Expand Up @@ -848,7 +853,7 @@ public String extractFromResultList(int n1) {
sb.append(resultList.get(n1).getString());
resultList.remove(n1);
if (resultList.size() > n1)
sb.append("\\n");
sb.append(Jaws.BLOCK_E1_NEWLINE);

}
return sb.toString();
Expand Down
Loading

0 comments on commit d3b4e7a

Please sign in to comment.