08-25-2009 06:26 PM
My app has this simple rendering command:
graphics.drawText( String.valueOf( integer ), x, y )
integer is a 2-digit number. y = (clip.height / 2) - (font.getHeight() / 2). x = (clip.width / 2) - (font.getAdvance( String.valueOf( integer ) ) / 2).
So it's supposed to just draw a 2-digit number in the middle of the screen, in a big font like size 180. Font is BBAlpha Sans.
... and it works, on every device, except a select few Storms and Tours, where it only draws the 1st digit, and occasionally nothing, and the behavior is sporadic -- sometimes after a while it will render both digits, then 1, then nothing, etc.
One of the Storms is running 18.104.22.168, so I got the simulator for that exact build, and it works perfectly in the simulator.
Where the problem renders only the 1st digit, it's centered, which means it's not even trying to render the 2nd digit. The integer and the String.valueOf(integer) are correct since rendering in a small font works perfectly. It's only in the big font that it messes up.
On my Curve, and on all the simulators including 22.214.171.124, if I set the font really big it still renders both digits, but both sides go off the screen. It never fails to render, or renders only 1 digit.
Can anyone enlighten me, please? I have 1500 users who are _not_ experiencing the problem, and 3 who are. Their system font settings should not matter, I do font selection and sizing, and in screenshots it's obvious the sizing is correct and not the problem.
I'm getting the font like this:
bigfontheight = (clip.height / 2);
bigfont = bigfontfam.getFont(Font.BOLD, bigfontheight); // get closest predefined size
bigfont = bigfont.derive(Font.EXTRA_BOLD, bigfontheight, Ui.UNITS_px, Font.ANTIALIAS_STANDARD, 0); // scale exactly + antialias
Thanks for anyone who can clue me in about what might be the problem.
08-26-2009 02:54 PM
08-26-2009 04:11 PM
Thanks for the reply,
>> Where are you drawing this? Is it to a Bitmap, a Field or a Screen?
It's a Bitmap that exactly fills the space under the title bar on a MainScreen. The Bitmap is set in a BitmapField that's the sole field added to the MainScreen's VerticalFieldManager. The drawing is being done inside the BitmapField's paint() using the Graphics that's passed in, clipping width is confirmed at 360 and clipping height is 480 minus the titlebar height.
>>Do you see any differences when the width is even versus and odd number?
The worst part of the problem is that I can't reproduce this locally to step through or experiment much. I keep sending the few users diagnostic builds that test changes and print debugging info on the screen, which they report back.
Using this method, I am printing what's returned by getAdvance() and drawText(), they're always equal. Input has always been a 2-digit integer converted with String.valueOf(), which when it's working, has had even pixel width... in one example getAdvance() and drawText() both returned 256. When it's not working and rendering nothing, both getAdvance() and drawText() return 0, even though the String is correct. I confirmed the String by printing it on the same Bitmap using the same drawText(String.valueOf(value),x,y), but with a smaller font set. Rendering with the smaller font has always worked perfectly, rendered just after the large-font drawText. The rendering style now that I'm using Bold is confirmed at 1 at render time, it was 64 when using ExtraBold, and both ways I confirmed it was a supported style. Font height is confirmed just before rendering, so the font seems to be derived OK as far as I can tell -- it's not zero size. Alpha and color are set fine, sometimes it only renders the 1st digit of the 2-digit number, but it's centered, which means that's all drawText is even trying to render, right?
>>Is anything else being drawn? If so, is it truncated as well?
Yes, there are several other elements, all of which are fine, except for one strange thing -- an ellipse element goes slightly off the right end of the screen even though its rightmost defining point is at clip.width. No other text normally, but when I print the debug info it's right there on the same bitmap rendered at the same time, though in a smaller font, and it's all perfect, no truncation even with the same exact input to drawText.
>>Is this drawn as an animation or a static image that is displayed on the screen?
It's redrawn many times a second, and doesn't flicker, but users report sometimes after 10-20 min it self-corrects. So the sporadic changes in behavior don't happen quickly, it goes for a long run of renderings the same way, then changes behavior and stays that way for another long run of renderings. Everything else works perfectly, and even the large text works perfectly in 99% of all cases, and 100% of cases on devices with pre-4.7 DS.
I've confirmed it's so far only been reported on 4.7, but is not specific to one build or minor version. It occurs on 126.96.36.199, and 188.8.131.52 on real devices, but works fine on the simulators for those exact builds.
One user has reported that a previous release of the app that did not use antialiasing did not have this problem. It's not absolutely confirmed that it never happens without antialiasing (I'm reluctant to request too many reinstallations and lengthy testing from the users), but I think I can confirm that it's at least not been seen when antialiasing was off. The only changes made in the problematic version were switching from Bold to Extra_Bold, and using Antialiasing_Standard. I switched back to Bold, and they say it's happening less now, but still happens. Antialiasing is still on, and frankly I do need the antialiasing if possible.
In the font.derive(), effect is 0. I use an effect on <4.7 but it's apparently not supported in 4.7+ .
For the font selected, the largest size in Font.getHeights() is 72, but requesting size 180 returns a font with that size even without using derive. Then I use derive to add antialiasing, and it does render antialiased.
Thank you for your assistance!