diff --git a/engine/src/core/com/jme3/font/BitmapText.java b/engine/src/core/com/jme3/font/BitmapText.java index 3b840a8cc..1b7857fb8 100644 --- a/engine/src/core/com/jme3/font/BitmapText.java +++ b/engine/src/core/com/jme3/font/BitmapText.java @@ -382,6 +382,7 @@ public class BitmapText extends Node { * @param wrap NoWrap : Letters over the text bound is not shown. the last character is set to '...'(0x2026) * Character: Character is split at the end of the line. * Word : Word is split at the end of the line. + * Clip : The text is hard-clipped at the border including showing only a partial letter if it goes beyond the text bound. */ public void setLineWrapMode(LineWrapMode wrap) { if (block.getLineWrapMode() != wrap) { diff --git a/engine/src/core/com/jme3/font/LetterQuad.java b/engine/src/core/com/jme3/font/LetterQuad.java index ac68f0ebb..7977a154e 100644 --- a/engine/src/core/com/jme3/font/LetterQuad.java +++ b/engine/src/core/com/jme3/font/LetterQuad.java @@ -173,6 +173,23 @@ class LetterQuad { return x0 > 0 && bound.x+bound.width-gap < getX1(); } + void clip(StringBlock block) { + Rectangle bound = block.getTextBox(); + if (bound == null) + return; + + // Clip the right x position and texture coordinate + // to the string block + float x1 = Math.min(bound.x + bound.width, x0 + width); + float newWidth = x1 - x0; + if( newWidth == width ) + return; + + float rescale = newWidth / width; + u1 = u0 + (u1 - u0) * rescale; + width = newWidth; + } + float getX0() { return x0; } diff --git a/engine/src/core/com/jme3/font/Letters.java b/engine/src/core/com/jme3/font/Letters.java index 2d36959f7..e8b8c8270 100644 --- a/engine/src/core/com/jme3/font/Letters.java +++ b/engine/src/core/com/jme3/font/Letters.java @@ -144,8 +144,7 @@ class Letters { } } break; - case NoWrap: - // search last blank character before this word + case NoWrap: LetterQuad cursor = l.getPrevious(); while (cursor.isInvalid(block, ellipsisWidth) && !cursor.isLineStart()) { cursor = cursor.getPrevious(); @@ -159,6 +158,16 @@ class Letters { cursor = cursor.getNext(); } break; + case Clip: + // Clip the character that falls out of bounds + l.clip(block); + + // Clear the rest up to the next line feed. + for( LetterQuad q = l.getNext(); !q.isTail() && !q.isLineFeed(); q = q.getNext() ) { + q.setBitmapChar(null); + q.update(block); + } + break; } } } else if (current.isInvalid(block)) { diff --git a/engine/src/core/com/jme3/font/LineWrapMode.java b/engine/src/core/com/jme3/font/LineWrapMode.java index 5a5455b7c..eef029b35 100644 --- a/engine/src/core/com/jme3/font/LineWrapMode.java +++ b/engine/src/core/com/jme3/font/LineWrapMode.java @@ -38,5 +38,6 @@ package com.jme3.font; public enum LineWrapMode { NoWrap, Character, - Word + Word, + Clip }