BitmapText getLineWidth() always returns 0

BitmapText getLineWidth() always returns 0 because it reads that from its local lineWidth variable, which is never changed.



http://code.google.com/p/jmonkeyengine/source/browse/branches/jme3/src/core/com/jme3/font/BitmapText.java



[java] /**

  • @return width of line

    */

    public float getLineWidth() {

    if (needRefresh) {

    assemble(); // (Does not change lineWidth)

    }

    return lineWidth;

    }[/java]



    The only required change to make it work with be to get the width from the underlying Letters object instead:



    [java] /**
  • @return width of line

    */

    public float getLineWidth() {

    if (needRefresh) {

    assemble();

    }

    return letters.getTotalWidth();

    }[/java]

Thank you!

fixed. rev. 6803.

Thanks for fixing it so quickly. While we’re at it, could BitmapText also expose more information? Things like the number of lines when it’s in wrapping mode, number of lines that its current bounds can hold, etc. Thanks~

Added BitmapText.getLineCount()

rev. 6809

You can get the maximum lines by bound.height / bitmapText.getLineHeight().

Currently, there is no limitation when the text exceeds the bound height.

I don’t know BitmapText should crop the lines over the bound or not.

Thank you!

Hey, it’s me again with another bug!



Here is a sample application that creates BitmapTexts of different colors.



[java]import com.jme3.app.SimpleApplication;

import com.jme3.font.BitmapText;

import com.jme3.math.ColorRGBA;



public class testtext extends SimpleApplication

{

public static void main(final String[] args)

{

new testtext().start();

}



@Override

public void simpleInitApp()

{

guiNode.detachAllChildren();



BitmapText red = new BitmapText(assetManager.loadFont(“Interface/Fonts/Default.fnt”));

red.setText(“This is red”);

red.setColor(ColorRGBA.Red);

red.setLocalTranslation(100, 100, 0);

guiNode.attachChild(red);



BitmapText green = new BitmapText(assetManager.loadFont(“Interface/Fonts/Default.fnt”));

green.setText(“This is green”);

green.setColor(ColorRGBA.Green);

green.setLocalTranslation(200, 100, 0);

guiNode.attachChild(green);



BitmapText blue = new BitmapText(assetManager.loadFont(“Interface/Fonts/Default.fnt”));

blue.setText(“This is blue”);

blue.setColor(ColorRGBA.Blue);

blue.setLocalTranslation(100, 200, 0);

guiNode.attachChild(blue);



BitmapText gray = new BitmapText(assetManager.loadFont(“Interface/Fonts/Default.fnt”));

gray.setText(“This is gray”);

gray.setColor(ColorRGBA.Gray);

gray.setLocalTranslation(200, 200, 0);

guiNode.attachChild(gray);



BitmapText white = new BitmapText(assetManager.loadFont(“Interface/Fonts/Default.fnt”));

white.setText(“This is white”);

white.setColor(ColorRGBA.White);

white.setLocalTranslation(300, 200, 0);

guiNode.attachChild(white);

}

}[/java]



But here is what happens:

http://i56.tinypic.com/2hyuvc6.png



As you can see, it seems that only the red color channel is taken into account sometimes. I say sometimes, because the white text is indeed white like it should. But the rest isn’t; the gray one isn’t gray, and the green and blue ones are completely black.

This sounds like the bug I reported here introduced in r6768. It’s not just a particular channel either, sometimes it gets a transparent alpha value too.



-davidc

The color was incorrectly set, abgr instead of rgba

Fixed in svn. rev. 6814

Thanks again~