mirror of
https://github.com/octoleo/plantuml.git
synced 2024-12-01 09:14:01 +00:00
Add a new !pragma svginterface to control INTERACTIVE mode on SVG output
This commit is contained in:
parent
2ca7dca0e3
commit
9c79c1256c
@ -43,10 +43,7 @@ import java.io.OutputStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.sourceforge.plantuml.Dimension2DDouble;
|
import net.sourceforge.plantuml.*;
|
||||||
import net.sourceforge.plantuml.EmptyImageBuilder;
|
|
||||||
import net.sourceforge.plantuml.FileFormat;
|
|
||||||
import net.sourceforge.plantuml.SpriteContainerEmpty;
|
|
||||||
import net.sourceforge.plantuml.api.ImageDataSimple;
|
import net.sourceforge.plantuml.api.ImageDataSimple;
|
||||||
import net.sourceforge.plantuml.core.ImageData;
|
import net.sourceforge.plantuml.core.ImageData;
|
||||||
import net.sourceforge.plantuml.cucadiagram.Display;
|
import net.sourceforge.plantuml.cucadiagram.Display;
|
||||||
@ -90,7 +87,7 @@ public class GraphicsSudoku {
|
|||||||
public ImageData writeImageSvg(OutputStream os) throws IOException {
|
public ImageData writeImageSvg(OutputStream os) throws IOException {
|
||||||
final UGraphicSvg ug = new UGraphicSvg(HColorUtils.WHITE, true, new Dimension2DDouble(0, 0),
|
final UGraphicSvg ug = new UGraphicSvg(HColorUtils.WHITE, true, new Dimension2DDouble(0, 0),
|
||||||
new ColorMapperIdentity(), false, 1.0, null, null, 0, "none", FileFormat.SVG.getDefaultStringBounder(),
|
new ColorMapperIdentity(), false, 1.0, null, null, 0, "none", FileFormat.SVG.getDefaultStringBounder(),
|
||||||
LengthAdjust.defaultValue());
|
LengthAdjust.defaultValue(), new Pragma());
|
||||||
drawInternal(ug);
|
drawInternal(ug);
|
||||||
ug.writeToStream(os, null, -1); // dpi param is not used
|
ug.writeToStream(os, null, -1); // dpi param is not used
|
||||||
return ImageDataSimple.ok();
|
return ImageDataSimple.ok();
|
||||||
|
@ -62,6 +62,7 @@ import javax.xml.transform.TransformerException;
|
|||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.Pragma;
|
||||||
import org.w3c.dom.CDATASection;
|
import org.w3c.dom.CDATASection;
|
||||||
import org.w3c.dom.Comment;
|
import org.w3c.dom.Comment;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@ -129,7 +130,8 @@ public class SvgGraphics {
|
|||||||
private final boolean svgDimensionStyle;
|
private final boolean svgDimensionStyle;
|
||||||
private final LengthAdjust lengthAdjust;
|
private final LengthAdjust lengthAdjust;
|
||||||
|
|
||||||
private final boolean INTERACTIVE = false;
|
private final Pragma pragma;
|
||||||
|
private final boolean INTERACTIVE;
|
||||||
|
|
||||||
final protected void ensureVisible(double x, double y) {
|
final protected void ensureVisible(double x, double y) {
|
||||||
if (x > maxX) {
|
if (x > maxX) {
|
||||||
@ -141,7 +143,7 @@ public class SvgGraphics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SvgGraphics(String backcolor, boolean svgDimensionStyle, Dimension2D minDim, double scale, String hover,
|
public SvgGraphics(String backcolor, boolean svgDimensionStyle, Dimension2D minDim, double scale, String hover,
|
||||||
long seed, String preserveAspectRatio, LengthAdjust lengthAdjust, DarkStrategy darkStrategy) {
|
long seed, String preserveAspectRatio, LengthAdjust lengthAdjust, DarkStrategy darkStrategy, Pragma pragma) {
|
||||||
try {
|
try {
|
||||||
this.lengthAdjust = lengthAdjust;
|
this.lengthAdjust = lengthAdjust;
|
||||||
this.svgDimensionStyle = svgDimensionStyle;
|
this.svgDimensionStyle = svgDimensionStyle;
|
||||||
@ -149,6 +151,7 @@ public class SvgGraphics {
|
|||||||
this.document = getDocument();
|
this.document = getDocument();
|
||||||
this.backcolor = backcolor;
|
this.backcolor = backcolor;
|
||||||
this.preserveAspectRatio = preserveAspectRatio;
|
this.preserveAspectRatio = preserveAspectRatio;
|
||||||
|
this.pragma = pragma;
|
||||||
ensureVisible(minDim.getWidth(), minDim.getHeight());
|
ensureVisible(minDim.getWidth(), minDim.getHeight());
|
||||||
|
|
||||||
this.root = getRootNode();
|
this.root = getRootNode();
|
||||||
@ -164,6 +167,12 @@ public class SvgGraphics {
|
|||||||
if (hover != null)
|
if (hover != null)
|
||||||
defs.appendChild(getPathHover(hover));
|
defs.appendChild(getPathHover(hover));
|
||||||
|
|
||||||
|
if (!pragma.isDefine("svginteractive"))
|
||||||
|
INTERACTIVE = false;
|
||||||
|
else {
|
||||||
|
INTERACTIVE = Boolean.valueOf(pragma.getValue("svginteractive"));
|
||||||
|
}
|
||||||
|
|
||||||
if (INTERACTIVE) {
|
if (INTERACTIVE) {
|
||||||
final Element styles = getStylesForInteractiveMode();
|
final Element styles = getStylesForInteractiveMode();
|
||||||
if (styles != null)
|
if (styles != null)
|
||||||
|
@ -54,6 +54,7 @@ import java.util.Set;
|
|||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
|
|
||||||
import net.sourceforge.plantuml.Dimension2DDouble;
|
import net.sourceforge.plantuml.Dimension2DDouble;
|
||||||
|
import net.sourceforge.plantuml.Pragma;
|
||||||
import net.sourceforge.plantuml.graphic.FontConfiguration;
|
import net.sourceforge.plantuml.graphic.FontConfiguration;
|
||||||
import net.sourceforge.plantuml.graphic.UDrawable;
|
import net.sourceforge.plantuml.graphic.UDrawable;
|
||||||
import net.sourceforge.plantuml.security.SImageIO;
|
import net.sourceforge.plantuml.security.SImageIO;
|
||||||
@ -159,7 +160,7 @@ public class FontChecker {
|
|||||||
|
|
||||||
private String getSvgImage(char c) throws IOException, TransformerException {
|
private String getSvgImage(char c) throws IOException, TransformerException {
|
||||||
final SvgGraphics svg = new SvgGraphics(null, true, new Dimension2DDouble(0, 0), 1.0, null, 42, "none",
|
final SvgGraphics svg = new SvgGraphics(null, true, new Dimension2DDouble(0, 0), 1.0, null, 42, "none",
|
||||||
LengthAdjust.defaultValue(), DarkStrategy.IGNORE_DARK_COLOR);
|
LengthAdjust.defaultValue(), DarkStrategy.IGNORE_DARK_COLOR, new Pragma());
|
||||||
svg.setStrokeColor("black");
|
svg.setStrokeColor("black");
|
||||||
svg.svgImage(getBufferedImage(c), 0, 0);
|
svg.svgImage(getBufferedImage(c), 0, 0);
|
||||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
|
@ -51,24 +51,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
import net.sourceforge.plantuml.AnimatedGifEncoder;
|
import net.sourceforge.plantuml.*;
|
||||||
import net.sourceforge.plantuml.AnnotatedWorker;
|
|
||||||
import net.sourceforge.plantuml.CMapData;
|
|
||||||
import net.sourceforge.plantuml.ColorParam;
|
|
||||||
import net.sourceforge.plantuml.CornerParam;
|
|
||||||
import net.sourceforge.plantuml.Dimension2DDouble;
|
|
||||||
import net.sourceforge.plantuml.EmptyImageBuilder;
|
|
||||||
import net.sourceforge.plantuml.FileFormat;
|
|
||||||
import net.sourceforge.plantuml.FileFormatOption;
|
|
||||||
import net.sourceforge.plantuml.FileUtils;
|
|
||||||
import net.sourceforge.plantuml.ISkinParam;
|
|
||||||
import net.sourceforge.plantuml.LineParam;
|
|
||||||
import net.sourceforge.plantuml.OptionFlags;
|
|
||||||
import net.sourceforge.plantuml.Scale;
|
|
||||||
import net.sourceforge.plantuml.SvgCharSizeHack;
|
|
||||||
import net.sourceforge.plantuml.TitledDiagram;
|
|
||||||
import net.sourceforge.plantuml.Url;
|
|
||||||
import net.sourceforge.plantuml.UseStyle;
|
|
||||||
import net.sourceforge.plantuml.anim.AffineTransformation;
|
import net.sourceforge.plantuml.anim.AffineTransformation;
|
||||||
import net.sourceforge.plantuml.anim.Animation;
|
import net.sourceforge.plantuml.anim.Animation;
|
||||||
import net.sourceforge.plantuml.api.ImageDataComplex;
|
import net.sourceforge.plantuml.api.ImageDataComplex;
|
||||||
@ -272,7 +255,7 @@ public class ImageBuilder {
|
|||||||
/ 96.0;
|
/ 96.0;
|
||||||
if (scaleFactor <= 0)
|
if (scaleFactor <= 0)
|
||||||
throw new IllegalStateException("Bad scaleFactor");
|
throw new IllegalStateException("Bad scaleFactor");
|
||||||
UGraphic ug = createUGraphic(fileFormatOption, dim, animationArg, dx, dy, scaleFactor);
|
UGraphic ug = createUGraphic(fileFormatOption, dim, animationArg, dx, dy, scaleFactor, titledDiagram.getPragma());
|
||||||
maybeDrawBorder(ug, dim);
|
maybeDrawBorder(ug, dim);
|
||||||
if (randomPixel) {
|
if (randomPixel) {
|
||||||
drawRandomPoint(ug);
|
drawRandomPoint(ug);
|
||||||
@ -401,12 +384,12 @@ public class ImageBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private UGraphic createUGraphic(FileFormatOption option, final Dimension2D dim, Animation animationArg, double dx,
|
private UGraphic createUGraphic(FileFormatOption option, final Dimension2D dim, Animation animationArg, double dx,
|
||||||
double dy, double scaleFactor) {
|
double dy, double scaleFactor, Pragma pragma) {
|
||||||
switch (option.getFileFormat()) {
|
switch (option.getFileFormat()) {
|
||||||
case PNG:
|
case PNG:
|
||||||
return createUGraphicPNG(scaleFactor, dim, animationArg, dx, dy, option.getWatermark());
|
return createUGraphicPNG(scaleFactor, dim, animationArg, dx, dy, option.getWatermark());
|
||||||
case SVG:
|
case SVG:
|
||||||
return createUGraphicSVG(scaleFactor, dim);
|
return createUGraphicSVG(scaleFactor, dim, pragma);
|
||||||
case EPS:
|
case EPS:
|
||||||
return new UGraphicEps(backcolor, colorMapper, stringBounder, EpsStrategy.getDefault2());
|
return new UGraphicEps(backcolor, colorMapper, stringBounder, EpsStrategy.getDefault2());
|
||||||
case EPS_TEXT:
|
case EPS_TEXT:
|
||||||
@ -432,14 +415,14 @@ public class ImageBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private UGraphic createUGraphicSVG(double scaleFactor, Dimension2D dim) {
|
private UGraphic createUGraphicSVG(double scaleFactor, Dimension2D dim, Pragma pragma) {
|
||||||
final String hoverPathColorRGB = getHoverPathColorRGB();
|
final String hoverPathColorRGB = getHoverPathColorRGB();
|
||||||
final LengthAdjust lengthAdjust = skinParam == null ? LengthAdjust.defaultValue() : skinParam.getlengthAdjust();
|
final LengthAdjust lengthAdjust = skinParam == null ? LengthAdjust.defaultValue() : skinParam.getlengthAdjust();
|
||||||
final String preserveAspectRatio = getPreserveAspectRatio();
|
final String preserveAspectRatio = getPreserveAspectRatio();
|
||||||
final boolean svgDimensionStyle = skinParam == null || skinParam.svgDimensionStyle();
|
final boolean svgDimensionStyle = skinParam == null || skinParam.svgDimensionStyle();
|
||||||
final String svgLinkTarget = getSvgLinkTarget();
|
final String svgLinkTarget = getSvgLinkTarget();
|
||||||
final UGraphicSvg ug = new UGraphicSvg(backcolor, svgDimensionStyle, dim, colorMapper, false, scaleFactor,
|
final UGraphicSvg ug = new UGraphicSvg(backcolor, svgDimensionStyle, dim, colorMapper, false, scaleFactor,
|
||||||
svgLinkTarget, hoverPathColorRGB, seed, preserveAspectRatio, stringBounder, lengthAdjust);
|
svgLinkTarget, hoverPathColorRGB, seed, preserveAspectRatio, stringBounder, lengthAdjust, pragma);
|
||||||
return ug;
|
return ug;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.Pragma;
|
||||||
import net.sourceforge.plantuml.Url;
|
import net.sourceforge.plantuml.Url;
|
||||||
import net.sourceforge.plantuml.graphic.StringBounder;
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
||||||
import net.sourceforge.plantuml.posimo.DotPath;
|
import net.sourceforge.plantuml.posimo.DotPath;
|
||||||
@ -89,10 +90,10 @@ public class UGraphicSvg extends AbstractUGraphic<SvgGraphics> implements ClipCo
|
|||||||
|
|
||||||
public UGraphicSvg(HColor defaultBackground, boolean svgDimensionStyle, Dimension2D minDim, ColorMapper colorMapper,
|
public UGraphicSvg(HColor defaultBackground, boolean svgDimensionStyle, Dimension2D minDim, ColorMapper colorMapper,
|
||||||
boolean textAsPath, double scale, String linkTarget, String hover, long seed, String preserveAspectRatio,
|
boolean textAsPath, double scale, String linkTarget, String hover, long seed, String preserveAspectRatio,
|
||||||
StringBounder stringBounder, LengthAdjust lengthAdjust) {
|
StringBounder stringBounder, LengthAdjust lengthAdjust, Pragma pragma) {
|
||||||
this(defaultBackground, minDim, colorMapper,
|
this(defaultBackground, minDim, colorMapper,
|
||||||
new SvgGraphics(colorMapper.toSvg(defaultBackground), svgDimensionStyle, minDim, scale, hover, seed,
|
new SvgGraphics(colorMapper.toSvg(defaultBackground), svgDimensionStyle, minDim, scale, hover, seed,
|
||||||
preserveAspectRatio, lengthAdjust, DarkStrategy.IGNORE_DARK_COLOR),
|
preserveAspectRatio, lengthAdjust, DarkStrategy.IGNORE_DARK_COLOR, pragma),
|
||||||
textAsPath, linkTarget, stringBounder);
|
textAsPath, linkTarget, stringBounder);
|
||||||
if (defaultBackground instanceof HColorGradient) {
|
if (defaultBackground instanceof HColorGradient) {
|
||||||
final SvgGraphics svg = getGraphicObject();
|
final SvgGraphics svg = getGraphicObject();
|
||||||
|
Loading…
Reference in New Issue
Block a user