1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-09 03:32:33 +00:00
plantuml/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java

175 lines
5.6 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2016-01-09 12:15:40 +00:00
* (C) Copyright 2009-2017, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +00:00
*
* 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
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
*/
package net.sourceforge.plantuml.ugraphic.svg;
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.transform.TransformerException;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.graphic.HtmlColorGradient;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.TextBlockUtils;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.posimo.DotPath;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.svg.SvgGraphics;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ugraphic.AbstractUGraphic;
import net.sourceforge.plantuml.ugraphic.ClipContainer;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.ColorMapper;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.UCenteredCharacter;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ugraphic.UEllipse;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic2;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ugraphic.UImage;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.UImageSvg;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UPath;
import net.sourceforge.plantuml.ugraphic.UPolygon;
import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UText;
2015-04-07 18:18:37 +00:00
public class UGraphicSvg extends AbstractUGraphic<SvgGraphics> implements ClipContainer, UGraphic2 {
2010-11-15 20:35:36 +00:00
private final StringBounder stringBounder;
2013-12-10 19:36:50 +00:00
private final boolean textAsPath2;
2015-05-31 18:56:03 +00:00
private final String target;
2013-12-10 19:36:50 +00:00
@Override
protected AbstractCommonUGraphic copyUGraphic() {
return new UGraphicSvg(this);
}
private UGraphicSvg(UGraphicSvg other) {
super(other);
this.stringBounder = other.stringBounder;
this.textAsPath2 = other.textAsPath2;
2015-05-31 18:56:03 +00:00
this.target = other.target;
2013-12-10 19:36:50 +00:00
register();
}
2015-05-31 18:56:03 +00:00
public UGraphicSvg(ColorMapper colorMapper, String backcolor, boolean textAsPath, double scale, String linkTarget) {
this(colorMapper, new SvgGraphics(backcolor, scale), textAsPath, linkTarget);
2013-12-10 19:36:50 +00:00
}
2015-05-31 18:56:03 +00:00
public UGraphicSvg(ColorMapper colorMapper, boolean textAsPath, double scale, String linkTarget) {
this(colorMapper, new SvgGraphics(scale), textAsPath, linkTarget);
2013-12-10 19:36:50 +00:00
}
2015-05-31 18:56:03 +00:00
public UGraphicSvg(ColorMapper mapper, HtmlColorGradient gr, boolean textAsPath, double scale, String linkTarget) {
this(mapper, new SvgGraphics(scale), textAsPath, linkTarget);
2013-12-10 19:36:50 +00:00
final SvgGraphics svg = getGraphicObject();
svg.paintBackcolorGradient(mapper, gr);
}
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
@Override
protected boolean manageHiddenAutomatically() {
return false;
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
@Override
protected void beforeDraw() {
getGraphicObject().setHidden(getParam().isHidden());
}
@Override
protected void afterDraw() {
getGraphicObject().setHidden(false);
2010-11-15 20:35:36 +00:00
}
2015-05-31 18:56:03 +00:00
private UGraphicSvg(ColorMapper colorMapper, SvgGraphics svg, boolean textAsPath, String linkTarget) {
2011-08-08 17:48:29 +00:00
super(colorMapper, svg);
2015-05-31 18:56:03 +00:00
this.stringBounder = TextBlockUtils.getDummyStringBounder();
2013-12-10 19:36:50 +00:00
this.textAsPath2 = textAsPath;
2015-05-31 18:56:03 +00:00
this.target = linkTarget;
2013-12-10 19:36:50 +00:00
register();
}
private void register() {
2010-11-15 20:35:36 +00:00
registerDriver(URectangle.class, new DriverRectangleSvg(this));
2013-12-10 19:36:50 +00:00
if (textAsPath2) {
registerDriver(UText.class, new DriverTextAsPathSvg(TextBlockUtils.getFontRenderContext(), this));
2010-11-15 20:35:36 +00:00
} else {
registerDriver(UText.class, new DriverTextSvg(getStringBounder(), this));
}
registerDriver(ULine.class, new DriverLineSvg(this));
registerDriver(UPolygon.class, new DriverPolygonSvg(this));
2015-04-07 18:18:37 +00:00
registerDriver(UEllipse.class, new DriverEllipseSvg(this));
registerDriver(UImage.class, new DriverImagePng(this));
2013-12-10 19:36:50 +00:00
registerDriver(UImageSvg.class, new DriverImageSvgSvg());
2010-11-15 20:35:36 +00:00
registerDriver(UPath.class, new DriverPathSvg(this));
2011-08-08 17:48:29 +00:00
registerDriver(DotPath.class, new DriverDotPathSvg());
2013-12-10 19:36:50 +00:00
registerDriver(UCenteredCharacter.class, new DriverCenteredCharacterSvg());
2010-11-15 20:35:36 +00:00
}
public SvgGraphics getSvgGraphics() {
return this.getGraphicObject();
}
public StringBounder getStringBounder() {
return stringBounder;
}
public void createXml(OutputStream os) throws IOException {
try {
getGraphicObject().createXml(os);
} catch (TransformerException e) {
throw new IOException(e.toString());
}
}
2013-12-10 19:36:50 +00:00
public void startUrl(Url url) {
2015-05-31 18:56:03 +00:00
getGraphicObject().openLink(url.getUrl(), url.getTooltip(), target);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
public void closeAction() {
getGraphicObject().closeLink();
2010-11-15 20:35:36 +00:00
}
2011-04-19 16:50:40 +00:00
2015-04-07 18:18:37 +00:00
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
2013-12-10 19:36:50 +00:00
createXml(os);
2011-01-23 19:36:52 +00:00
}
2013-12-10 19:36:50 +00:00
// @Override
// public String startHiddenGroup() {
// getGraphicObject().startHiddenGroup();
// return null;
// }
//
// @Override
// public String closeHiddenGroup() {
// getGraphicObject().closeHiddenGroup();
// return null;
// }
2010-11-15 20:35:36 +00:00
}