mirror of
https://github.com/octoleo/plantuml.git
synced 2025-01-03 07:12:29 +00:00
Allow Transparent Background for Ditaa Diagrams
This commit is contained in:
parent
8066a3f730
commit
473a8fce42
@ -34,6 +34,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.ditaa;
|
package net.sourceforge.plantuml.ditaa;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -62,12 +63,13 @@ public class PSystemDitaa extends AbstractPSystem {
|
|||||||
private final boolean dropShadows;
|
private final boolean dropShadows;
|
||||||
private final String data;
|
private final String data;
|
||||||
private final float scale;
|
private final float scale;
|
||||||
|
private final boolean transparentBackground;
|
||||||
private final Font font;
|
private final Font font;
|
||||||
private final boolean performSeparationOfCommonEdges;
|
private final boolean performSeparationOfCommonEdges;
|
||||||
private final boolean allCornersAreRound;
|
private final boolean allCornersAreRound;
|
||||||
|
|
||||||
public PSystemDitaa(UmlSource source, String data, boolean performSeparationOfCommonEdges, boolean dropShadows,
|
public PSystemDitaa(UmlSource source, String data, boolean performSeparationOfCommonEdges, boolean dropShadows,
|
||||||
boolean allCornersAreRound, float scale, Font font) {
|
boolean allCornersAreRound, boolean transparentBackground, float scale, Font font) {
|
||||||
super(source);
|
super(source);
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.dropShadows = dropShadows;
|
this.dropShadows = dropShadows;
|
||||||
@ -85,13 +87,14 @@ public class PSystemDitaa extends AbstractPSystem {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.processingOptions = null;
|
this.processingOptions = null;
|
||||||
}
|
}
|
||||||
|
this.transparentBackground = transparentBackground;
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
this.font = font;
|
this.font = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
PSystemDitaa add(String line) {
|
PSystemDitaa add(String line) {
|
||||||
return new PSystemDitaa(getSource(), data + line + BackSlash.NEWLINE, performSeparationOfCommonEdges,
|
return new PSystemDitaa(getSource(), data + line + BackSlash.NEWLINE, performSeparationOfCommonEdges,
|
||||||
dropShadows, allCornersAreRound, scale, font);
|
dropShadows, allCornersAreRound, transparentBackground, scale, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiagramDescription getDescription() {
|
public DiagramDescription getDescription() {
|
||||||
@ -116,6 +119,10 @@ public class PSystemDitaa extends AbstractPSystem {
|
|||||||
final Field f_renderingOptions = options.getClass().getField("renderingOptions");
|
final Field f_renderingOptions = options.getClass().getField("renderingOptions");
|
||||||
final Object renderingOptions = f_renderingOptions.get(options);
|
final Object renderingOptions = f_renderingOptions.get(options);
|
||||||
|
|
||||||
|
// renderingOptions.setBackgroundColor(font);
|
||||||
|
final Method setBackgroundColor = renderingOptions.getClass().getMethod("setBackgroundColor", Color.class);
|
||||||
|
setBackgroundColor.invoke(renderingOptions, transparentBackground ? new Color(0, 0, 0, 0) : Color.WHITE);
|
||||||
|
|
||||||
// renderingOptions.setFont(font);
|
// renderingOptions.setFont(font);
|
||||||
final Method setFont = renderingOptions.getClass().getMethod("setFont", Font.class);
|
final Method setFont = renderingOptions.getClass().getMethod("setFont", Font.class);
|
||||||
setFont.invoke(renderingOptions, font);
|
setFont.invoke(renderingOptions, font);
|
||||||
|
@ -70,12 +70,16 @@ public class PSystemDitaaFactory extends PSystemBasicFactory<PSystemDitaa> {
|
|||||||
if (startLine != null && (startLine.contains("-r") || startLine.contains("--round-corners")))
|
if (startLine != null && (startLine.contains("-r") || startLine.contains("--round-corners")))
|
||||||
allCornersAreRound = true;
|
allCornersAreRound = true;
|
||||||
|
|
||||||
|
boolean transparentBackground = false;
|
||||||
|
if (startLine != null && (startLine.contains("-T") || startLine.contains("--transparent")))
|
||||||
|
transparentBackground = true;
|
||||||
|
|
||||||
final float scale = extractScale(startLine);
|
final float scale = extractScale(startLine);
|
||||||
final Font font = extractFont(startLine);
|
final Font font = extractFont(startLine);
|
||||||
if (getDiagramType() == DiagramType.UML)
|
if (getDiagramType() == DiagramType.UML)
|
||||||
return null;
|
return null;
|
||||||
else if (getDiagramType() == DiagramType.DITAA)
|
else if (getDiagramType() == DiagramType.DITAA)
|
||||||
return new PSystemDitaa(source, "", performSeparationOfCommonEdges, dropShadows, allCornersAreRound, scale, font);
|
return new PSystemDitaa(source, "", performSeparationOfCommonEdges, dropShadows, allCornersAreRound, transparentBackground, scale, font);
|
||||||
else
|
else
|
||||||
throw new IllegalStateException(getDiagramType().name());
|
throw new IllegalStateException(getDiagramType().name());
|
||||||
|
|
||||||
@ -96,9 +100,13 @@ public class PSystemDitaaFactory extends PSystemBasicFactory<PSystemDitaa> {
|
|||||||
if (line.contains("-r") || line.contains("--round-corners"))
|
if (line.contains("-r") || line.contains("--round-corners"))
|
||||||
allCornersAreRound = true;
|
allCornersAreRound = true;
|
||||||
|
|
||||||
|
boolean transparentBackground = false;
|
||||||
|
if (line.contains("-T") || line.contains("--transparent"))
|
||||||
|
transparentBackground = true;
|
||||||
|
|
||||||
final float scale = extractScale(line);
|
final float scale = extractScale(line);
|
||||||
final Font font = extractFont(line);
|
final Font font = extractFont(line);
|
||||||
return new PSystemDitaa(source, "", performSeparationOfCommonEdges, dropShadows, allCornersAreRound, scale, font);
|
return new PSystemDitaa(source, "", performSeparationOfCommonEdges, dropShadows, allCornersAreRound, transparentBackground, scale, font);
|
||||||
}
|
}
|
||||||
if (system == null)
|
if (system == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -42,6 +42,8 @@ public class RenderingOptions {
|
|||||||
|
|
||||||
private float scale = 1;
|
private float scale = 1;
|
||||||
|
|
||||||
|
private Color backgroundColor = Color.white;
|
||||||
|
|
||||||
private Font font = new Font("Dialog", Font.BOLD, 12);
|
private Font font = new Font("Dialog", Font.BOLD, 12);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,6 +118,18 @@ public class RenderingOptions {
|
|||||||
antialias = b;
|
antialias = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Color getBackgroundColor() {
|
||||||
|
return backgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackgroundColor(Color backgroundColor) {
|
||||||
|
this.backgroundColor = backgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean needsTransparency() {
|
||||||
|
return backgroundColor.getAlpha() < 255;
|
||||||
|
}
|
||||||
|
|
||||||
public Font getFont()
|
public Font getFont()
|
||||||
{
|
{
|
||||||
return font;
|
return font;
|
||||||
|
@ -55,13 +55,19 @@ public class BitmapRenderer {
|
|||||||
Stroke normalStroke;
|
Stroke normalStroke;
|
||||||
Stroke dashStroke;
|
Stroke dashStroke;
|
||||||
|
|
||||||
|
|
||||||
public RenderedImage renderToImage(Diagram diagram, RenderingOptions options){
|
public RenderedImage renderToImage(Diagram diagram, RenderingOptions options){
|
||||||
BufferedImage image = new BufferedImage(
|
BufferedImage image;
|
||||||
|
if(options.needsTransparency()) {
|
||||||
|
image = new BufferedImage(
|
||||||
|
diagram.getWidth(),
|
||||||
|
diagram.getHeight(),
|
||||||
|
BufferedImage.TYPE_INT_ARGB);
|
||||||
|
} else {
|
||||||
|
image = new BufferedImage(
|
||||||
diagram.getWidth(),
|
diagram.getWidth(),
|
||||||
diagram.getHeight(),
|
diagram.getHeight(),
|
||||||
BufferedImage.TYPE_INT_RGB);
|
BufferedImage.TYPE_INT_RGB);
|
||||||
|
}
|
||||||
return render(diagram, image, options);
|
return render(diagram, image, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +81,7 @@ public class BitmapRenderer {
|
|||||||
|
|
||||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasSetting);
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasSetting);
|
||||||
|
|
||||||
g2.setColor(Color.white);
|
g2.setColor(options.getBackgroundColor());
|
||||||
//TODO: find out why the next line does not work
|
//TODO: find out why the next line does not work
|
||||||
g2.fillRect(0, 0, image.getWidth()+10, image.getHeight()+10);
|
g2.fillRect(0, 0, image.getWidth()+10, image.getHeight()+10);
|
||||||
/*for(int y = 0; y < diagram.getHeight(); y ++)
|
/*for(int y = 0; y < diagram.getHeight(); y ++)
|
||||||
|
Loading…
Reference in New Issue
Block a user