GraphvizCrash.java
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
*
* 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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* 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.crash;
import net.atmp.PixelImage;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.dot.GraphvizRuntimeEnvironment;
import net.sourceforge.plantuml.flashcode.FlashCodeFactory;
import net.sourceforge.plantuml.fun.IconLoader;
import net.sourceforge.plantuml.klimt.AffineTransformType;
import net.sourceforge.plantuml.klimt.awt.PortableImage;
import net.sourceforge.plantuml.klimt.awt.XColor;
import net.sourceforge.plantuml.klimt.color.HColor;
import net.sourceforge.plantuml.klimt.color.HColors;
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.klimt.geom.GraphicPosition;
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.shape.GraphicStrings;
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.klimt.shape.TextBlockMemoized;
import net.sourceforge.plantuml.klimt.shape.TextBlockUtils;
import net.sourceforge.plantuml.klimt.shape.UImage;
import net.sourceforge.plantuml.svek.IEntityImage;
import net.sourceforge.plantuml.svek.Margins;
import net.sourceforge.plantuml.svek.ShapeType;
import net.sourceforge.plantuml.teavm.TeaVM;
public class GraphvizCrash extends TextBlockMemoized implements IEntityImage {
private final TextBlock text1;
private final String flash;
private final PortableImage flashCode;
private GraphvizCrash(String flash, Throwable rootCause) {
this.flash = flash;
if (!TeaVM.isTeaVM())
this.flashCode = FlashCodeFactory.getFlashCodeUtils().exportFlashcode(flash, XColor.BLACK, XColor.WHITE);
else
this.flashCode = null;
final ReportLog strings = new ReportLog();
init(strings, rootCause);
this.text1 = GraphicStrings.createBlackOnWhite(strings.asList(), IconLoader.getRandom(),
GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT);
}
public static IEntityImage build(String text, Throwable rootCause) {
return new GraphvizCrash(text, rootCause);
}
private void init(ReportLog strings, Throwable rootCause) {
strings.anErrorHasOccurred(null, flash);
strings.add("For some reason, dot/GraphViz has crashed.");
strings.addEmptyLine();
strings.add("RootCause " + rootCause);
if (rootCause != null)
strings.addAll(CommandExecutionResult.getStackTrace(rootCause));
strings.addEmptyLine();
strings.addProperties();
strings.addEmptyLine();
if (!TeaVM.isTeaVM())
try {
final String dotVersion = GraphvizRuntimeEnvironment.getInstance().dotVersion();
strings.add("Default dot version: " + dotVersion);
} catch (Throwable e) {
strings.add("Cannot determine dot version: " + e.toString());
}
strings.pleaseCheckYourGraphVizVersion();
strings.youShouldSendThisDiagram();
if (flashCode != null)
strings.addDecodeHint();
}
public boolean isHidden() {
return false;
}
public HColor getBackcolor() {
return HColors.WHITE;
}
@Override
public XDimension2D calculateDimensionSlow(StringBounder stringBounder) {
return getMain().calculateDimension(stringBounder);
}
@Override
public void drawU(UGraphic ug) {
getMain().drawU(ug);
}
private TextBlock getMain() {
if (!TeaVM.isTeaVM()) {
return text1;
} else {
TextBlock result = text1;
if (flashCode != null) {
final UImage flash = new UImage(new PixelImage(flashCode, AffineTransformType.TYPE_NEAREST_NEIGHBOR))
.scale(3);
result = TextBlockUtils.mergeTB(result, flash, HorizontalAlignment.LEFT);
}
return result;
}
}
public ShapeType getShapeType() {
return ShapeType.RECTANGLE;
}
public Margins getShield(StringBounder stringBounder) {
return Margins.NONE;
}
public double getOverscanX(StringBounder stringBounder) {
return 0;
}
@Override
public boolean isCrash() {
return true;
}
}