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?
  • 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.


    This is how I was doing it before, utilizing the XTINY and just showing "P". But there was some drawing issues with it, the P's position wasn't being updated when the time was updated, so when 9:59 turned to 10:00, the last 0 would draw on top of the P. Conversely, 12:59 to 1:00 let the dude straggling off by himself. :\
    I really liked doing it this way, I felt the P was far less intrusive, but hated this loitering of the character. Additionally, on different watches, its alignment would be off. It really irked my OCD ;Þ

    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?

    Went back and tried it again, I had one of the drop downs changed to something other than "glyph"
    I'll give it another shot.
  • 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)

    As I said, this isn't really a problem for the expression you're looking at. For you, an experienced programmer, this is not a problem. For a guy just getting started, it will end up being a problem after they copy your code and modify it later not realizing the consequences of using addition where a bitwise or was more appropriate. For most people, it is easier to learn rules if they are simple and there are few exceptions. For them it is typically much simpler to learn to use use bitwise operators when dealing with bit masks, and just leave it at that.

    For those who are following this discussion, here is an example of why using addition to combine bitmask values can cause problems.

    class Thing
    {
    enum {
    REQUIREMENT_1_SATISFIED = 1,
    REQUIREMENT_2_SATISFIED = 2
    }

    hidden var requirements = 0;

    function satisfyRequirement1() {
    requirements = requirements + REQUIREMENT_1_SATISFIED;
    }

    function satisfyRequirement2() {
    requirements = requirements + REQUIREMENT_2_SATISFIED;
    }
    }


    Now consider the following code...

    var thing = new Thing();
    thing.satisfyRequirement1();
    thing.satisfyRequirement1();


    The result would be that requirements indicate requirement 2 had been satisfied, even though it had never been. If the bitwise or operator was used, this would not be an issue.
  • I see your point Travis. I'm a "bit" set in my ways!