1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-09 11:42:43 +00:00
plantuml/src/net/sourceforge/plantuml/ugraphic/txt/UGraphicTxt.java

129 lines
3.9 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
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
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.
*
*
* Original Author: Arnaud Roques
*
*/
package net.sourceforge.plantuml.ugraphic.txt;
2013-12-10 19:36:50 +00:00
import java.awt.geom.Dimension2D;
2018-06-25 19:05:58 +00:00
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.Dimension2DDouble;
2018-06-25 19:05:58 +00:00
import net.sourceforge.plantuml.FileFormat;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.Url;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.asciiart.TextStringBounder;
import net.sourceforge.plantuml.asciiart.TranslatedCharArea;
2011-04-19 16:50:40 +00:00
import net.sourceforge.plantuml.asciiart.UmlCharArea;
import net.sourceforge.plantuml.asciiart.UmlCharAreaImpl;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.graphic.FontStyle;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.ClipContainer;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
2018-06-25 19:05:58 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic2;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.ugraphic.UImage;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ugraphic.UShape;
import net.sourceforge.plantuml.ugraphic.UText;
2018-06-25 19:05:58 +00:00
public class UGraphicTxt extends AbstractCommonUGraphic implements ClipContainer, UGraphic2 {
2013-12-10 19:36:50 +00:00
private final UmlCharArea charArea;
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
@Override
protected AbstractCommonUGraphic copyUGraphic() {
return new UGraphicTxt(this);
}
private UGraphicTxt(UGraphicTxt other) {
super(other);
this.charArea = other.charArea;
}
2010-11-15 20:35:36 +00:00
2011-08-08 17:48:29 +00:00
public UGraphicTxt() {
super(new ColorMapperIdentity());
2013-12-10 19:36:50 +00:00
this.charArea = new UmlCharAreaImpl();
2011-08-08 17:48:29 +00:00
}
2010-11-15 20:35:36 +00:00
public StringBounder getStringBounder() {
return new TextStringBounder();
}
2013-12-10 19:36:50 +00:00
public void draw(UShape shape) {
2015-04-07 18:18:37 +00:00
// final UClip clip = getClip();
2010-11-15 20:35:36 +00:00
if (shape instanceof UText) {
final UText txt = (UText) shape;
2015-04-07 18:18:37 +00:00
final int y = ((int) (getTranslateY() + txt.getDescent())) / 10;
2010-11-15 20:35:36 +00:00
if (txt.getFontConfiguration().containsStyle(FontStyle.WAVE)) {
2013-12-10 19:36:50 +00:00
charArea.drawHLine('^', y, getDx(), txt.getText().length());
2018-06-25 19:05:58 +00:00
charArea.drawStringLR(txt.getText(), getDx(), y + 1);
2013-12-10 19:36:50 +00:00
} else {
2018-06-25 19:05:58 +00:00
charArea.drawStringLR(txt.getText(), getDx(), y);
2010-11-15 20:35:36 +00:00
}
return;
2015-04-07 18:18:37 +00:00
} else if (shape instanceof UImage) {
return;
2010-11-15 20:35:36 +00:00
}
2018-06-25 19:05:58 +00:00
return;
// throw new UnsupportedOperationException("cl=" + shape.getClass());
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
public final UmlCharArea getCharArea() {
return new TranslatedCharArea(charArea, getDx(), getDy());
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
private int getDy() {
return (int) getTranslateY();
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
private int getDx() {
return (int) getTranslateX();
}
public void startUrl(Url url) {
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
public void closeAction() {
}
public Dimension2D getDimension() {
return new Dimension2DDouble(0, 0);
2011-04-19 16:50:40 +00:00
}
2018-06-25 19:05:58 +00:00
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
final PrintStream ps = new PrintStream(os, true, "UTF-8");
getCharArea().print(ps);
}
2010-11-15 20:35:36 +00:00
}