Added a form of line wrap mode that does a hard

clip, to include truncating the letter quad at
the border.  This is better when text needs to
be hard constrained for UI type fields.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9947 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 12 years ago
parent 580579285b
commit 4610dbdacc
  1. 1
      engine/src/core/com/jme3/font/BitmapText.java
  2. 17
      engine/src/core/com/jme3/font/LetterQuad.java
  3. 13
      engine/src/core/com/jme3/font/Letters.java
  4. 3
      engine/src/core/com/jme3/font/LineWrapMode.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) * @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. * Character: Character is split at the end of the line.
* Word : Word 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) { public void setLineWrapMode(LineWrapMode wrap) {
if (block.getLineWrapMode() != wrap) { if (block.getLineWrapMode() != wrap) {

@ -173,6 +173,23 @@ class LetterQuad {
return x0 > 0 && bound.x+bound.width-gap < getX1(); 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() { float getX0() {
return x0; return x0;
} }

@ -144,8 +144,7 @@ class Letters {
} }
} }
break; break;
case NoWrap: case NoWrap:
// search last blank character before this word
LetterQuad cursor = l.getPrevious(); LetterQuad cursor = l.getPrevious();
while (cursor.isInvalid(block, ellipsisWidth) && !cursor.isLineStart()) { while (cursor.isInvalid(block, ellipsisWidth) && !cursor.isLineStart()) {
cursor = cursor.getPrevious(); cursor = cursor.getPrevious();
@ -159,6 +158,16 @@ class Letters {
cursor = cursor.getNext(); cursor = cursor.getNext();
} }
break; 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)) { } else if (current.isInvalid(block)) {

@ -38,5 +38,6 @@ package com.jme3.font;
public enum LineWrapMode { public enum LineWrapMode {
NoWrap, NoWrap,
Character, Character,
Word Word,
Clip
} }

Loading…
Cancel
Save