Skip to content

Commit

Permalink
Merge pull request plantuml#1771 from jimnelson372/fixasciiart
Browse files Browse the repository at this point in the history
Fix for issue plantuml#728 titled "off by one errors" in text output
  • Loading branch information
arnaudroques authored May 8, 2024
2 parents 2709ad2 + 68fc22b commit d55f9d8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
6 changes: 4 additions & 2 deletions src/net/sourceforge/plantuml/asciiart/ComponentTextActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public double getPreferredHeight(StringBounder stringBounder) {
}

public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWcWidth(stringsToDisplay) + 2;
// make all widths odd sized by converting the string widths to even,
// adding 3 to make it both odd and padded by 1 on each side, then return the result
// as a double.
return (double) ((StringUtils.getWcWidth(stringsToDisplay) / 2 * 2) + 3);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ public void drawU(UGraphic ug, Area area, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight();
charArea.fillRect(' ', 0, 0, width, height);
int textWidth = StringUtils.getWcWidth(stringsToDisplay);
int boxWidth = textWidth+2;

charArea.fillRect(' ', 0, 0, boxWidth, height);
if (fileFormat == FileFormat.UTXT) {
charArea.drawBoxSimpleUnicode(0, 0, width, height);
charArea.drawBoxSimpleUnicode(0, 0, boxWidth, height);
if (type == ComponentType.PARTICIPANT_TAIL) {
charArea.drawChar('\u2534', (width - 1) / 2, 0);
}
if (type == ComponentType.PARTICIPANT_HEAD) {
charArea.drawChar('\u252c', (width - 1) / 2, height - 1);
}
} else {
charArea.drawBoxSimple(0, 0, width, height);
charArea.drawBoxSimple(0, 0, boxWidth, height);
if (type == ComponentType.PARTICIPANT_TAIL) {
charArea.drawChar('+', (width - 1) / 2, 0);
}
Expand All @@ -93,7 +96,10 @@ public double getPreferredHeight(StringBounder stringBounder) {
}

public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWcWidth(stringsToDisplay) + 2;
// make all widths odd sized by converting the string widths to even,
// adding 3 to make it both odd and padded by 1 on each side, then return the result
// as a double.
return (double) ((StringUtils.getWcWidth(stringsToDisplay) / 2 * 2) + 3);
}

}
32 changes: 16 additions & 16 deletions src/net/sourceforge/plantuml/asciiart/ComponentTextSelfArrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,32 @@ public void drawU(UGraphic ug, Area area, Context2D context) {
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight() - 1;

charArea.fillRect(' ', 0, 0, width, height);
charArea.fillRect(' ', 1, 0, width-2, height);

if (fileFormat == FileFormat.UTXT) {
if (config.isDotted()) {
charArea.drawStringLR("\u2500 \u2500 \u2510", 0, 0);
charArea.drawStringLR("|", 4, 1);
charArea.drawStringLR("< \u2500 \u2518", 0, 2);
charArea.drawStringLR("\u2500 \u2500 \u2510", 1, 0);
charArea.drawStringLR("|", 5, 1);
charArea.drawStringLR("< \u2500 \u2518", 1, 2);
} else {
charArea.drawStringLR("\u2500\u2500\u2500\u2500\u2510", 0, 0);
charArea.drawStringLR("\u2502", 4, 1);
charArea.drawStringLR("<\u2500\u2500\u2500\u2518", 0, 2);
charArea.drawStringLR("\u2500\u2500\u2500\u2500\u2510", 1, 0);
charArea.drawStringLR("\u2502", 5, 1);
charArea.drawStringLR("<\u2500\u2500\u2500\u2518", 1, 2);
}
} else if (config.isDotted()) {
charArea.drawStringLR("- - .", 0, 0);
charArea.drawStringLR("|", 4, 1);
charArea.drawStringLR("< - '", 0, 2);
charArea.drawStringLR("- - .", 1, 0);
charArea.drawStringLR("|", 5, 1);
charArea.drawStringLR("< - '", 1, 2);
} else {
charArea.drawStringLR("----.", 0, 0);
charArea.drawStringLR("|", 4, 1);
charArea.drawStringLR("<---'", 0, 2);
charArea.drawStringLR("----.", 1, 0);
charArea.drawStringLR("|", 5, 1);
charArea.drawStringLR("<---'", 1, 2);
}

if (fileFormat == FileFormat.UTXT) {
charArea.drawStringsLRUnicode(stringsToDisplay.asList(), 6, 1);
charArea.drawStringsLRUnicode(stringsToDisplay.asList(), 7, 1);
} else {
charArea.drawStringsLRSimple(stringsToDisplay.asList(), 6, 1);
charArea.drawStringsLRSimple(stringsToDisplay.asList(), 7, 1);
}
}

Expand All @@ -107,7 +107,7 @@ public double getPreferredHeight(StringBounder stringBounder) {
}

public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWcWidth(stringsToDisplay) + 6;
return StringUtils.getWcWidth(stringsToDisplay) + 8;
}

public XPoint2D getStartPoint(StringBounder stringBounder, XDimension2D dimensionToUse) {
Expand Down
6 changes: 4 additions & 2 deletions src/net/sourceforge/plantuml/asciiart/ComponentTextShape.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public double getPreferredHeight(StringBounder stringBounder) {
}

public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWcWidth(stringsToDisplay) + 2;
// make all widths odd sized by converting the string widths to even,
// adding 3 to make it both odd and padded by 1 on each side, then return the result
// as a double.
return (double) ((StringUtils.getWcWidth(stringsToDisplay) / 2 * 2) + 3);
}

}

0 comments on commit d55f9d8

Please sign in to comment.