1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-22 21:15:09 +00:00

Simplify StringBounder code in ImageBuilder

This commit is contained in:
matthew16550 2021-10-03 06:11:03 +11:00
parent 102d67271c
commit c38b269089

View File

@ -121,6 +121,7 @@ public class ImageBuilder {
private String metadata; private String metadata;
private long seed = 42; private long seed = 42;
private ISkinParam skinParam; private ISkinParam skinParam;
private StringBounder stringBounder;
private int status = 0; private int status = 0;
private TitledDiagram titledDiagram; private TitledDiagram titledDiagram;
private boolean randomPixel; private boolean randomPixel;
@ -140,6 +141,7 @@ public class ImageBuilder {
private ImageBuilder(FileFormatOption fileFormatOption) { private ImageBuilder(FileFormatOption fileFormatOption) {
this.fileFormatOption = fileFormatOption; this.fileFormatOption = fileFormatOption;
this.stringBounder = fileFormatOption.getDefaultStringBounder(SvgCharSizeHack.NO_HACK);
} }
public ImageBuilder annotations(boolean annotations) { public ImageBuilder annotations(boolean annotations) {
@ -198,10 +200,6 @@ public class ImageBuilder {
return this; return this;
} }
private SvgCharSizeHack getSvgCharSizeHack() {
return skinParam == null ? SvgCharSizeHack.NO_HACK : skinParam;
}
private String getSvgLinkTarget() { private String getSvgLinkTarget() {
if (fileFormatOption.getSvgLinkTarget() != null) { if (fileFormatOption.getSvgLinkTarget() != null) {
return fileFormatOption.getSvgLinkTarget(); return fileFormatOption.getSvgLinkTarget();
@ -219,6 +217,7 @@ public class ImageBuilder {
public ImageBuilder styled(TitledDiagram diagram) { public ImageBuilder styled(TitledDiagram diagram) {
skinParam = diagram.getSkinParam(); skinParam = diagram.getSkinParam();
stringBounder = fileFormatOption.getDefaultStringBounder(skinParam);
animation = diagram.getAnimation(); animation = diagram.getAnimation();
annotations = true; annotations = true;
backcolor = diagram.calculateBackColor(); backcolor = diagram.calculateBackColor();
@ -235,8 +234,6 @@ public class ImageBuilder {
if (annotations && titledDiagram != null) { if (annotations && titledDiagram != null) {
if (!(udrawable instanceof TextBlock)) if (!(udrawable instanceof TextBlock))
throw new IllegalStateException("udrawable is not a TextBlock"); throw new IllegalStateException("udrawable is not a TextBlock");
final ISkinParam skinParam = titledDiagram.getSkinParam();
final StringBounder stringBounder = fileFormatOption.getDefaultStringBounder(skinParam);
final AnnotatedWorker annotatedWorker = new AnnotatedWorker(titledDiagram, skinParam, stringBounder); final AnnotatedWorker annotatedWorker = new AnnotatedWorker(titledDiagram, skinParam, stringBounder);
udrawable = annotatedWorker.addAdd((TextBlock) udrawable); udrawable = annotatedWorker.addAdd((TextBlock) udrawable);
} }
@ -325,8 +322,7 @@ public class ImageBuilder {
private Dimension2D getFinalDimension() { private Dimension2D getFinalDimension() {
if (dimension == null) { if (dimension == null) {
final LimitFinder limitFinder = new LimitFinder( final LimitFinder limitFinder = new LimitFinder(stringBounder, true);
fileFormatOption.getDefaultStringBounder(getSvgCharSizeHack()), true);
udrawable.drawU(limitFinder); udrawable.drawU(limitFinder);
dimension = new Dimension2DDouble(limitFinder.getMaxX() + 1 + margin.getLeft() + margin.getRight(), dimension = new Dimension2DDouble(limitFinder.getMaxX() + 1 + margin.getLeft() + margin.getRight(),
limitFinder.getMaxY() + 1 + margin.getTop() + margin.getBottom()); limitFinder.getMaxY() + 1 + margin.getTop() + margin.getBottom());
@ -418,9 +414,9 @@ public class ImageBuilder {
case VDX: case VDX:
return new UGraphicVdx(backcolor, colorMapper); return new UGraphicVdx(backcolor, colorMapper);
case LATEX: case LATEX:
return new UGraphicTikz(backcolor, colorMapper, FileFormat.LATEX.getDefaultStringBounder(option.getTikzFontDistortion()), scaleFactor, true); return new UGraphicTikz(backcolor, colorMapper, stringBounder, scaleFactor, true);
case LATEX_NO_PREAMBLE: case LATEX_NO_PREAMBLE:
return new UGraphicTikz(backcolor, colorMapper, FileFormat.LATEX.getDefaultStringBounder(option.getTikzFontDistortion()), scaleFactor, false); return new UGraphicTikz(backcolor, colorMapper, stringBounder, scaleFactor, false);
case BRAILLE_PNG: case BRAILLE_PNG:
return new UGraphicBraille(backcolor, colorMapper); return new UGraphicBraille(backcolor, colorMapper);
case UTXT: case UTXT:
@ -441,7 +437,7 @@ public class ImageBuilder {
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, FileFormat.SVG.getDefaultStringBounder(getSvgCharSizeHack()), lengthAdjust); svgLinkTarget, hoverPathColorRGB, seed, preserveAspectRatio, stringBounder, lengthAdjust);
return ug; return ug;
} }
@ -461,7 +457,6 @@ public class ImageBuilder {
backColor = new Color(0, 0, 0, 0); backColor = new Color(0, 0, 0, 0);
} }
final StringBounder stringBounder = FileFormat.PNG.getDefaultStringBounder();
final EmptyImageBuilder builder = new EmptyImageBuilder(watermark, (int) (dim.getWidth() * scaleFactor), final EmptyImageBuilder builder = new EmptyImageBuilder(watermark, (int) (dim.getWidth() * scaleFactor),
(int) (dim.getHeight() * scaleFactor), backColor, stringBounder); (int) (dim.getHeight() * scaleFactor), backColor, stringBounder);
final Graphics2D graphics2D = builder.getGraphics2D(); final Graphics2D graphics2D = builder.getGraphics2D();