Skip to content

Commit 98585bf

Browse files
MagsticAShiningRay
authored andcommitted
fix: add line break support to Graphics.drawString()
Wizardry Chapter 1 uses line breaks in `game.en.0` but standard MIDP ignores them, causing text overflow. Modified drawString() to handle line breaks. Note: May affect other games using line breaks differently.
1 parent 8f87bf1 commit 98585bf

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/org/recompile/mobile/PlatformGraphics.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,38 @@ public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int
740740
drawArc(x + width - arcWidth - 1, y + height - arcHeight - 1, arcWidth, arcHeight, 270, 90); // Bottom-right corner
741741
}
742742

743+
// Patch: Line break support (May affect other games)
743744
public void drawString(String str, int x, int y, int anchor)
745+
{
746+
if(str == null || str.length() == 0) { return; }
747+
if(str.indexOf('\n') < 0 && str.indexOf('\r') < 0)
748+
{
749+
drawStringSingleLine(str, x, y, anchor);
750+
return;
751+
}
752+
753+
int lineHeight = 0;
754+
if(Mobile.isDoJa) { lineHeight = dojaFont.getHeight(); }
755+
else { lineHeight = font.getHeight(); }
756+
757+
int lineStart = 0;
758+
int lineIndex = 0;
759+
for(int i = 0; i <= str.length(); i++)
760+
{
761+
boolean end = (i == str.length());
762+
char ch = end ? 0 : str.charAt(i);
763+
if(end || ch == '\n' || ch == '\r')
764+
{
765+
String line = str.substring(lineStart, i);
766+
drawStringSingleLine(line, x, y + (lineIndex * lineHeight), anchor);
767+
lineIndex++;
768+
if(!end && ch == '\r' && i + 1 < str.length() && str.charAt(i + 1) == '\n') { i++; }
769+
lineStart = i + 1;
770+
}
771+
}
772+
}
773+
774+
private void drawStringSingleLine(String str, int x, int y, int anchor)
744775
{
745776
if(str != null && str.length() > 0)
746777
{

0 commit comments

Comments
 (0)