centering custom font

To resolve an issue with the lack of "A", "P" in the number fonts on the 920XT, I made a custom font with the BMFONT tool.
It's just Roboto that I got from Google Fonts, but packaged to only include "%0123456789AP:", so I'm not using a filter on it. It's only used for time and battery.
I'm having the hardest time getting it to center in the screen! It's like Eclipse thinks the center of the text is several pixels above them. y="-5" on the smaller font, to be exact.
<layout id="elements">

<label id="time" x="left" y="-5" justification="Gfx.TEXT_JUSTIFY_LEFT" />
<label id="batt" x="right" y="-5" justification="Gfx.TEXT_JUSTIFY_RIGHT" />
<label id="superClock_text" x="center" y="center" justification="Gfx.TEXT_JUSTIFY_CENTER" />

</layout>

if(_superClock_state && _isAwake){ var _superClock_text = findDrawableById("superClock_text");
_superClock_text.setText(timeText + ampm);
_superClock_text.setFont(superFont);
_superClock_text.setLocation(dc.getWidth()/2, (dc.getHeight()/2)-(_superClock_text.height/2));
_superClock_text.setColor(_colorTable_bkgrd[_themeIndex]);
_superClock_text.setBackgroundColor(Gfx.COLOR_TRANSPARENT);
var x = 0;
var y = _superClock_text.locY;
var w = dc.getWidth();
var h = _superClock_text.height;
dc.setColor(_colorTable_text[_themeIndex],Gfx.COLOR_RED);
dc.fillRectangle(x, y, w, h);
_superClock_text.draw(dc);
}

I tried using justification="Gfx.TEXT_JUSTIFY_VCENTER" and this did put the text in the center of Y, but cause it to go off the left side of the screen, like it was justified right.
The fonts that come on the device don't do this, they center/center just fine.
In BMFont I set the export options to all 0 padding, and all 0 spacing.
What am I missing?
  • What happens if you use

    justification="Gfx.TEXT_JUSTIFY_VCENTER+Gfx.TEXT_JUSTIFY_CENTER"

    As VCENTER is vertical center, not horizontal - horizontal is CENTER.
  • What happens if you use

    justification="Gfx.TEXT_JUSTIFY_VCENTER+Gfx.TEXT_JUSTIFY_CENTER"

    As VCENTER is vertical center, not horizontal - horizontal is CENTER.


    well.. I figured it would just bork it all up, but no it compiled and ran!
    However...
    The text is now above center, I'd say centered on a top 1/3 line, if such an alignment existed.
    But the rectangle that is drawn behind it, thinks it exists dead center, because it's position is determined by the text's drawn position.. weird
    If any of that makes sense haha
  • Alright.. now it's in the center/center like I was expecting... all I did was remove "Gfx.TEXT_JUSTIFY_VCENTER+" from the XML, save and run.
    I don't understand what's going on here.


    edit: nevermind it went back to the top of the text being aligned to center Y. I didn't change anything this time, just ran it again
    wth...
  • Here's what's wrong:

    dc.getWidth()/2, (dc.getHeight()/2)-(_superClock_text.height/2)

    should just be:

    dc.getWidth/2,dc.getHeight/2

    as you are shifting it with the height of the font above the center and you don't need that with the VCENTER
  • Here's what's wrong:

    dc.getWidth()/2, (dc.getHeight()/2)-(_superClock_text.height/2)

    should just be:

    dc.getWidth/2,dc.getHeight/2

    as you are shifting it with the height of the font above the center and you don't need that with the VCENTER


    Sorry about that, the first time I tried to start this thread the site got hung up and didn't post, so I had to type it all over.
    The second time around I forgot to mention, that line is how I was getting around it not centering properly, which is currently remarked out.
    But you're right, "dc.getWidth/2,dc.getHeight/2" == (center, center), but for some reason it isn't, so I had to negative offset the Y by half the text height :\
  • If it's working right for std fonts, I'd say there's something off in the .fnt for your custom font, such as the characters being different heights
  • If it's working right for std fonts, I'd say there's something off in the .fnt for your custom font, such as the characters being different heights


    arg.. alright, I guess I'll go back to using the standard fonts and try to figure some other way around the 920's lack of letters in the numbers font :\
    Thanks for helping
  • Or you can edit the .fnt file (it's just a text file) and see what's wrong.

    BTW, one of the things I've done for the A and P, is figure out the width of the "hh:ss" and then use a different font for the a/p and position it based on the width of the time.
  • I'm having the hardest time getting it to center in the screen! It's like Eclipse thinks the center of the text is several pixels above them.

    You should not have to change your code (other than to reference the new font) to get this to work correctly. Have you tried to go back and regenerate your font with different options selected? Did you try using the options shown in the Fonts section of the Programmer's Guide?

    justification="Gfx.TEXT_JUSTIFY_VCENTER+Gfx.TEXT_JUSTIFY_CENTER"

    While the result is the same in this case, it is probably a good idea to use the binary or operator instead of addition when dealing with justification values.

    Travis
  • While the result is the same in this case, it is probably a good idea to use the binary or operator instead of addition when dealing with justification values.
    Travis


    I see it as a bit of a style/readability thing....
    Since they are bits, (0,1,2,4), using "+", to me it reads that I'm doing both of the justifications (horizontal plus vertical), while if I see "|" or "or", it could be one or both (& would result in 0, so that shouldn't be used though)

    If I was checking for specific bits, "|" would be more readable to me (CENTER or CENTERV)

    ("never say "or" to an old c programmer" as many times the answer is just "true" :) )