for (int i = 0; i < text.length(); i++) {
char theChar = text.charAt(i);
BitmapCharacter c = charSet.getCharacter((int) theChar);
- if (c == null) {
- // logger.warning("Character '" + text.charAt(i) +
- // "' is not in alphabet, skipping it.");
- } else if (theChar == 'n' || theChar == 'r' || theChar == 't') {
- // dont print these characters
- continue;
+ if (c == null && (text.charAt(i) != 'n' && text.charAt(i) != 'r')) {
+ Logger.getLogger("").log(Level.FINE,
+ "Character '" + text.charAt(i) + "' is not in alphabet, skipping it.");
+ } else if(text.charAt(i) == ' ' && firstCharOfLine) {
+ Logger.getLogger("").log(Level.FINE,
+ "Character '" + text.charAt(i) + "' is blank, skipping it because first char in line.");
} else {
- float xOffset = c.getXOffset() * sizeScale;
- float yOffset = c.getYOffset() * sizeScale;
- float xAdvance = c.getXAdvance() * sizeScale;
- float width = c.getWidth() * sizeScale;
- float height = c.getHeight() * sizeScale;
+ float xOffset = 0;
+ float yOffset = 0;
+ float xAdvance = 0;
+ float width = 0;
+ float height = 0;
+ if (c != null) {
+ xOffset = c.getXOffset() * sizeScale;
+ yOffset = c.getYOffset() * sizeScale;
+ xAdvance = c.getXAdvance() * sizeScale;
+ width = c.getWidth() * sizeScale;
+ height = c.getHeight() * sizeScale;
+ }
+
+ if (text.charAt(i) == 'n' || text.charAt(i) == 'r') {
+ x = 0;
+ y -= charSet.getLineHeight() * sizeScale;
+ // float offset = 0f;
+
+ // Justify the last (now complete) line
+ if (alignment == Align.Center) {
+ for (int k = 0; k < target.getQuantity(); k++) {
+ FontQuad q = target.getQuad(k);
+ if (q.getLineNumber() == lineNumber) {
+ q.setX(q.getX() - lineWidth / 2f);
+ } // if
+ } // for
+ } // if
+ if (alignment == Align.Right) {
+ for (int k = 0; k < target.getQuantity(); k++) {
+ FontQuad q = target.getQuad(k);
+ if (q.getLineNumber() == lineNumber) {
+ q.setX(q.getX() - lineWidth);
+ } // if
+ } // for
+ } // if
+ if (rightToLeft) {
+ // move all characters so that the current X = 0
+ for (int k = 0; k < target.getQuantity(); k++) {
+ FontQuad q = target.getQuad(k);
+ if (q.getLineNumber() == lineNumber) {
+ q.setX(q.getX() + lineWidth);
+ } // if
+ } // for
+ } // if
+
+ // New line without any "carry-down" word
+ firstCharOfLine = true;
+ lastLineWidth = lineWidth;
+ lineWidth = 0f;
+ wordNumber = 1;
+ lineNumber++;
+ continue;
+ } // End new line check
+
// Adjust for kerning
float kernAmount = 0f;
@@ -179,7 +231,6 @@
} // else
} // for
- Align alignment = block.getAlignment();
// Justify the last (now complete) line
if (alignment == Align.Center) {
for (int k = 0; k < target.getQuantity(); k++) {
@@ -245,18 +296,25 @@
+import com.jme.input.MouseInput;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Spatial.CullHint;
@@ -56,15 +57,19 @@
public class TestBitmapFont {
public static void main(String[] args) throws Exception {
- final StandardGame game = new StandardGame("Test 3D Flat Text");
+ final StandardGame game = new StandardGame("Test BitmapFont & BitmapText");
game.start();
- final String txtB = "This extension provides a mechanism to specify vertex attrib and "
+ final String txtB = "This extension provides a mechanismn to specify vertex attrib and "
+ "element array locations using GPU addresses.";
+
+ final String txtC = "This extension provides a mechanism to specify vertex attrib and "
+ + "element array locations using GPU addresses.";
public Void call() throws Exception {
+ MouseInput.get().setCursorVisible(true);
final DebugGameState debug = new DebugGameState();
GameStateManager.getInstance().attachChild(debug);
debug.setActive(true);
@@ -104,20 +109,21 @@
txt3.setSize(32);
txt3.setAlignment(Align.Right);
txt3.setDefaultColor(ColorRGBA.blue.clone());
- txt3.setText(txtB);
+ txt3.setText(txtC);
txt3.update();
BitmapText txt4 = new BitmapText(fnt, false);
txt4.setSize(32);
- txt4.setText("Text without restriction. Text without restriction. Text without restriction. Text without restriction");
+ txt4.setAlignment(Align.Center);
+ txt4.setText("Text without restriction.n Text withoutn restriction.n Text without restriction. Text without restriction");
txt4.setDefaultColor(ColorRGBA.red.clone());
txt4.update();
- txt4.setLocalTranslation(40, -game.getDisplay().getHeight() + txt2.getLineHeight() * 2, 0);
+ txt4.setLocalTranslation(140, -game.getDisplay().getHeight() + txt2.getLineHeight() * 5, 0);