From 84d2f43265e593fcb2a388e9f71ea8ccc06abd70 Mon Sep 17 00:00:00 2001 From: Lyu Zong-Hong Date: Sat, 6 Mar 2021 21:15:33 +0900 Subject: [PATCH] Fix crash issue in TextRenderer --- .../src/forge/assets/TextRenderer.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/forge-gui-mobile/src/forge/assets/TextRenderer.java b/forge-gui-mobile/src/forge/assets/TextRenderer.java index b9c1eebe24e..ad51fcf6ae6 100644 --- a/forge-gui-mobile/src/forge/assets/TextRenderer.java +++ b/forge-gui-mobile/src/forge/assets/TextRenderer.java @@ -437,22 +437,31 @@ public class TextRenderer { } } } - Piece lastPiece = pieces.get(lastPieceIdx); - lineWidths.add(lastPiece.x + lastPiece.w); - x = 0; - for (int j = lastPieceIdx + 1; j < pieces.size(); j++) { - Piece piece = pieces.get(j); - piece.x = x; - piece.y += lineHeight; - piece.lineNum++; - x += piece.w; - } - y += lineHeight; - totalHeight += lineHeight; - lineNum++; - if (totalHeight > height) { - //try next font size down if out of space + if (lastPieceIdx >= 0) { + Piece lastPiece = pieces.get(lastPieceIdx); + lineWidths.add(lastPiece.x + lastPiece.w); + x = 0; + for (int j = lastPieceIdx + 1; j < pieces.size(); j++) { + Piece piece = pieces.get(j); + piece.x = x; + piece.y += lineHeight; + piece.lineNum++; + x += piece.w; + } + y += lineHeight; + totalHeight += lineHeight; + lineNum++; + if (totalHeight > height) { + //try next font size down if out of space + if (font.canShrink()) { + updatePieces(font.shrink()); + return; + } + needClip = true; + } + } else { if (font.canShrink()) { + //try next font size down if out of space updatePieces(font.shrink()); return; }