Skip to content

Commit

Permalink
version 1.2020.8
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Apr 26, 2020
1 parent 9077d97 commit 138cfb9
Show file tree
Hide file tree
Showing 130 changed files with 969 additions and 612 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<groupId>net.sourceforge.plantuml</groupId>
<artifactId>plantuml</artifactId>
<version>1.2020.8-SNAPSHOT</version>
<version>1.2020.9-SNAPSHOT</version>
<packaging>jar</packaging>

<name>PlantUML</name>
Expand Down
2 changes: 1 addition & 1 deletion src/jcckit/util/ConfigParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private Color parseColor(String value, String key) {
static private HColorSet colors = HColorSet.instance();
private Color decodeInternal(String value) {
if (colors.getColorIfValid(value)!=null) {
return new ColorMapperIdentity().getMappedColor(colors.getColorIfValid(value));
return new ColorMapperIdentity().toColor(colors.getColorIfValid(value));
}
return Color.decode(value);
}
Expand Down
6 changes: 3 additions & 3 deletions src/net/sourceforge/plantuml/AnnotatedWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public TextBlock addFrame(final TextBlock original) {
final double y1 = 10;
final double y2 = 10;

final SymbolContext symbolContext = new SymbolContext(getSkinParam().getBackgroundColor(), HColorUtils.BLACK)
final SymbolContext symbolContext = new SymbolContext(getSkinParam().getBackgroundColor(false), HColorUtils.BLACK)
.withShadow(getSkinParam().shadowing(null) ? 3 : 0);
final MinMax originalMinMax = TextBlockUtils.getMinMax(original, stringBounder);
final MinMax originalMinMax = TextBlockUtils.getMinMax(original, stringBounder, false);
final TextBlock title = mainFrame.create(new FontConfiguration(getSkinParam(), FontParam.CAPTION, null),
HorizontalAlignment.CENTER, getSkinParam());
final Dimension2D dimTitle = title.calculateDimension(stringBounder);
Expand All @@ -118,7 +118,7 @@ public void drawU(UGraphic ug) {
}

public MinMax getMinMax(StringBounder stringBounder) {
return TextBlockUtils.getMinMax(this, stringBounder);
return TextBlockUtils.getMinMax(this, stringBounder, false);
}

public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
Expand Down
1 change: 1 addition & 0 deletions src/net/sourceforge/plantuml/ColorParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public enum ColorParam {
interfaceBackground(HColorUtils.MY_YELLOW, true, ColorType.BACK),
interfaceBorder(HColorUtils.MY_RED, ColorType.LINE),
arrow(HColorUtils.MY_RED, ColorType.ARROW),
arrowHead(HColorUtils.MY_RED, null),

stateBackground(HColorUtils.MY_YELLOW, true, ColorType.BACK),
stateBorder(HColorUtils.MY_RED, ColorType.LINE),
Expand Down
85 changes: 78 additions & 7 deletions src/net/sourceforge/plantuml/EmptyImageBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@
package net.sourceforge.plantuml;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
Expand All @@ -50,11 +55,11 @@ public class EmptyImageBuilder {
private final BufferedImage im;
private final Graphics2D g2d;

public EmptyImageBuilder(double width, double height, Color background) {
this((int) width, (int) height, background);
public EmptyImageBuilder(String watermark, double width, double height, Color background) {
this(watermark, (int) width, (int) height, background);
}

public EmptyImageBuilder(int width, int height, Color background) {
public EmptyImageBuilder(String watermark, int width, int height, Color background) {
if (width > GraphvizUtils.getenvImageLimit()) {
Log.info("Width too large " + width + ". You should set PLANTUML_LIMIT_SIZE");
width = GraphvizUtils.getenvImageLimit();
Expand All @@ -64,18 +69,84 @@ public EmptyImageBuilder(int width, int height, Color background) {
height = GraphvizUtils.getenvImageLimit();
}
Log.info("Creating image " + width + "x" + height);
im = new BufferedImage(width, height, background == null ? BufferedImage.TYPE_INT_ARGB
: BufferedImage.TYPE_INT_RGB);
im = new BufferedImage(width, height, getType(background));
g2d = im.createGraphics();
UAntiAliasing.ANTI_ALIASING_ON.apply(g2d);
if (background != null) {
g2d.setColor(background);
g2d.fillRect(0, 0, width, height);
}
if (watermark != null) {
final int gray = 200;
g2d.setColor(new Color(gray, gray, gray));
printWatermark(watermark, width, height);
}
}

private int getType(Color background) {
if (background == null) {
return BufferedImage.TYPE_INT_ARGB;
}
if (background.getAlpha() != 255) {
return BufferedImage.TYPE_INT_ARGB;
}
return BufferedImage.TYPE_INT_RGB;
}

private void printWatermark(String watermark, int maxWidth, int maxHeight) {
final Font javaFont = g2d.getFont();
final FontMetrics fm = g2d.getFontMetrics(javaFont);
final Rectangle2D rect = fm.getStringBounds(watermark, g2d);
final int height = (int) rect.getHeight();
final int width = (int) rect.getWidth();
if (height < 2 || width < 2) {
return;
}
if (width <= maxWidth)
for (int y = height; y < maxHeight; y += height + 1) {
for (int x = 0; x < maxWidth; x += width + 10) {
g2d.drawString(watermark, x, y);
}
}
else {
final List<String> withBreaks = withBreaks(watermark, javaFont, fm, maxWidth);
int y = 0;
while (y < maxHeight) {
for (String s : withBreaks) {
g2d.drawString(s, 0, y);
y += (int) fm.getStringBounds(s, g2d).getHeight();
}
y += 10;
}
}
}

private int getWidth(String line, Font javaFont, FontMetrics fm) {
final Rectangle2D rect = fm.getStringBounds(line, g2d);
return (int) rect.getWidth();
}

private List<String> withBreaks(String watermark, Font javaFont, FontMetrics fm, int maxWidth) {
final String[] words = watermark.split("\\s+");
final List<String> result = new ArrayList<String>();
String pending = "";
for (String word : words) {
final String candidate = pending.length() == 0 ? word : pending + " " + word;
if (getWidth(candidate, javaFont, fm) < maxWidth) {
pending = candidate;
} else {
result.add(pending);
pending = word;
}
}
if (pending.length() > 0) {
result.add(pending);
}
return result;
}

public EmptyImageBuilder(int width, int height, Color background, double dpiFactor) {
this(width * dpiFactor, height * dpiFactor, background);
public EmptyImageBuilder(String watermark, int width, int height, Color background, double dpiFactor) {
this(watermark, width * dpiFactor, height * dpiFactor, background);
if (dpiFactor != 1.0) {
g2d.setTransform(AffineTransform.getScaleInstance(dpiFactor, dpiFactor));
}
Expand Down
70 changes: 41 additions & 29 deletions src/net/sourceforge/plantuml/FileFormatOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,26 @@ public final class FileFormatOption implements Serializable {
private final TikzFontDistortion tikzFontDistortion;
private final double scale;
private final String preserveAspectRatio;
private final String watermark;

public double getScaleCoef() {
return scale;
}

public FileFormatOption(FileFormat fileFormat) {
this(fileFormat, null, true, false, "_top", false, null, TikzFontDistortion.getDefault(), 1.0, "none");
}

public StringBounder getDefaultStringBounder() {
return fileFormat.getDefaultStringBounder(tikzFontDistortion);
}

public String getSvgLinkTarget() {
return svgLinkTarget;
}

public final boolean isWithMetadata() {
return withMetadata;
}

public final String getPreserveAspectRatio() {
return preserveAspectRatio;
this(fileFormat, null, true, false, "_top", false, null, TikzFontDistortion.getDefault(), 1.0, "none", null);
}

public FileFormatOption(FileFormat fileFormat, boolean withMetadata) {
this(fileFormat, null, withMetadata, false, "_top", false, null, TikzFontDistortion.getDefault(), 1.0, "none");
this(fileFormat, null, withMetadata, false, "_top", false, null, TikzFontDistortion.getDefault(), 1.0, "none",
null);
}

private FileFormatOption(FileFormat fileFormat, AffineTransform at, boolean withMetadata, boolean useRedForError,
String svgLinkTarget, boolean debugsvek, String hoverColor, TikzFontDistortion tikzFontDistortion,
double scale, String preserveAspectRatio) {
double scale, String preserveAspectRatio, String watermark) {
this.hoverColor = hoverColor;
this.watermark = watermark;
this.fileFormat = fileFormat;
this.affineTransform = at;
this.withMetadata = withMetadata;
Expand All @@ -105,34 +92,55 @@ private FileFormatOption(FileFormat fileFormat, AffineTransform at, boolean with
}
}

public StringBounder getDefaultStringBounder() {
return fileFormat.getDefaultStringBounder(tikzFontDistortion);
}

public String getSvgLinkTarget() {
return svgLinkTarget;
}

public final boolean isWithMetadata() {
return withMetadata;
}

public final String getPreserveAspectRatio() {
return preserveAspectRatio;
}

public FileFormatOption withUseRedForError() {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, true, svgLinkTarget, debugsvek,
hoverColor, tikzFontDistortion, scale, preserveAspectRatio);
hoverColor, tikzFontDistortion, scale, preserveAspectRatio, watermark);
}

public FileFormatOption withTikzFontDistortion(TikzFontDistortion tikzFontDistortion) {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, true, svgLinkTarget, debugsvek,
hoverColor, tikzFontDistortion, scale, preserveAspectRatio);
hoverColor, tikzFontDistortion, scale, preserveAspectRatio, watermark);
}

public FileFormatOption withSvgLinkTarget(String svgLinkTarget) {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget,
debugsvek, hoverColor, tikzFontDistortion, scale, preserveAspectRatio);
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget, debugsvek,
hoverColor, tikzFontDistortion, scale, preserveAspectRatio, watermark);
}

public FileFormatOption withPreserveAspectRatio(String preserveAspectRatio) {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget,
debugsvek, hoverColor, tikzFontDistortion, scale, preserveAspectRatio);
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget, debugsvek,
hoverColor, tikzFontDistortion, scale, preserveAspectRatio, watermark);
}

public FileFormatOption withHoverColor(String hoverColor) {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget,
debugsvek, hoverColor, tikzFontDistortion, scale, preserveAspectRatio);
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget, debugsvek,
hoverColor, tikzFontDistortion, scale, preserveAspectRatio, watermark);
}

public FileFormatOption withScale(double scale) {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget,
debugsvek, hoverColor, tikzFontDistortion, scale, preserveAspectRatio);
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget, debugsvek,
hoverColor, tikzFontDistortion, scale, preserveAspectRatio, watermark);
}

public FileFormatOption withWartermark(String watermark) {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget, debugsvek,
hoverColor, tikzFontDistortion, scale, preserveAspectRatio, watermark);
}

@Override
Expand Down Expand Up @@ -174,4 +182,8 @@ public final TikzFontDistortion getTikzFontDistortion() {
return tikzFontDistortion;
}

public final String getWatermark() {
return watermark;
}

}
2 changes: 1 addition & 1 deletion src/net/sourceforge/plantuml/ISkinParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface ISkinParam extends ISkinSimple {

public boolean useUnderlineForHyperlink();

public HColor getBackgroundColor();
public HColor getBackgroundColor(boolean replaceTransparentByWhite);

public HColor getHtmlColor(ColorParam param, Stereotype stereotype, boolean clickable);

Expand Down
12 changes: 8 additions & 4 deletions src/net/sourceforge/plantuml/SkinParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,14 @@ public HColor getHyperlinkColor() {
return result;
}

public HColor getBackgroundColor() {
public HColor getBackgroundColor(boolean replaceTransparentByWhite) {
final HColor result = getHtmlColor(ColorParam.background, null, false);
if (result == null) {
return HColorUtils.WHITE;
}
if (replaceTransparentByWhite && HColorUtils.transparent().equals(result)) {
return HColorUtils.WHITE;
}
return result;
}

Expand Down Expand Up @@ -310,16 +313,17 @@ public HColor getHtmlColor(ColorParam param, Stereotype stereotype, boolean clic
if (value == null) {
return null;
}
if (param == ColorParam.background && value.equalsIgnoreCase("transparent")) {
return null;
if ((param == ColorParam.background || param == ColorParam.arrowHead)
&& (value.equalsIgnoreCase("transparent") || value.equalsIgnoreCase("none"))) {
return HColorUtils.transparent();
}
if (param == ColorParam.background) {
return getIHtmlColorSet().getColorIfValid(value);
}
assert param != ColorParam.background;
// final boolean acceptTransparent = param == ColorParam.background
// || param == ColorParam.sequenceGroupBodyBackground || param == ColorParam.sequenceBoxBackground;
return getIHtmlColorSet().getColorIfValid(value, getBackgroundColor());
return getIHtmlColorSet().getColorIfValid(value, getBackgroundColor(false));
}

public char getCircledCharacter(Stereotype stereotype) {
Expand Down
4 changes: 2 additions & 2 deletions src/net/sourceforge/plantuml/SkinParamBackcolored.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public SkinParamBackcolored(ISkinParam skinParam, HColor backColorElement, HColo
}

@Override
public HColor getBackgroundColor() {
public HColor getBackgroundColor(boolean replaceTransparentByWhite) {
if (backColorGeneral != null) {
return backColorGeneral;
}
return super.getBackgroundColor();
return super.getBackgroundColor(replaceTransparentByWhite);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/net/sourceforge/plantuml/SkinParamDelegator.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public HColor getHyperlinkColor() {
return skinParam.getHyperlinkColor();
}

public HColor getBackgroundColor() {
return skinParam.getBackgroundColor();
public HColor getBackgroundColor(boolean replaceTransparentByWhite) {
return skinParam.getBackgroundColor(replaceTransparentByWhite);
}

public int getCircledCharacterRadius() {
Expand Down
25 changes: 1 addition & 24 deletions src/net/sourceforge/plantuml/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import net.sourceforge.plantuml.command.regex.MyPattern;
import net.sourceforge.plantuml.command.regex.Pattern2;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.svek.DotStringFactory;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorBackground;
Expand Down Expand Up @@ -385,30 +386,6 @@ public static List<String> splitComma(String s) {
return Collections.unmodifiableList(result);
}

public static String getAsHtml(Color color) {
if (color == null) {
return null;
}
return getAsHtml(color.getRGB());
}

public static String getAsSvg(ColorMapper mapper, HColor color) {
if (color == null) {
return "none";
}
if (color instanceof HColorBackground) {
return ((HColorBackground) color).getSvg(mapper);
}
return getAsHtml(mapper.getMappedColor(color));
}

public static String getAsHtml(int color) {
final int v = 0xFFFFFF & color;
String s = "000000" + Integer.toHexString(v).toUpperCase();
s = s.substring(s.length() - 6);
return "#" + s;
}

public static String getUid(String uid1, int uid2) {
return uid1 + String.format("%04d", uid2);
}
Expand Down
Loading

0 comments on commit 138cfb9

Please sign in to comment.