Blackberry OS 5.0 上的字体提前计算问题
我目前正在为 BlackBerry 应用程序开发自己的选项卡栏,其中每个选项卡栏都有一个右对齐的标题(即每个选项卡中的最后一个字符与屏幕右侧的距离应相同)。为了确定在哪里绘制文本,我使用以下计算:
屏幕宽度 - 标题提前 - 缩进。
我使用的字体是“BBAlpha Sans”(高度 28)。使用 BlackBerry OS 4.6 时,一切似乎都能正确计算,并且当我在选项卡之间移动时文本会对齐,但是我发现当我使用 OS 5.0 时,它无法正确计算提前量,因此对齐可能会偏离 5像素左右。使用默认字体(也是 BBAlpha Sans,但高度为 24 - 至少对于 OS 5.0),它在两个版本中都可以正常工作..但我不一定总是想使用默认字体/大小,所以任何想法可能会发生什么错误的?这是 5.0 API 中的错误吗?
谢谢。
代码:
public class TitleBarBackground extends Background {
..
public void draw(Graphics graphics, XYRect rect) {
graphics.pushRegion(rect);
..
Font titleBarFont = FontFamily.forName("BBAlpha Sans").getFont(Font.PLAIN, 28);
...
int textWidth = titleBarFont.getAdvance(title);
graphics.drawText(title, rect.width - textWidth - TITLE_OFFSET, textYOffset);
graphics.popContext();
}
..
}
I am currently working on my own implementation of a tab bar for a BlackBerry app, where each tab bar has a title that is right aligned (i.e. the last character in each should be the same distance from the right hand side of the screen). To work out where to draw the text I am using the following calculation:
screen width - advance of title - indent.
The font I am using is 'BBAlpha Sans' (height 28). Using BlackBerry OS 4.6 everything seems to be calculated properly and the text is aligned when I move between tabs, however I am finding that when I use OS 5.0 it doesn't calculate the advance properly and as a result the alignment is off by maybe 5 pixels or so. With the default font (also BBAlpha Sans, but height 24 - for OS 5.0 at least) it works fine in both versions.. but I don't necessarily always want to use the default font/size, so any ideas what could be going wrong? Is this a bug in the 5.0 API?
Thanks.
Code:
public class TitleBarBackground extends Background {
..
public void draw(Graphics graphics, XYRect rect) {
graphics.pushRegion(rect);
..
Font titleBarFont = FontFamily.forName("BBAlpha Sans").getFont(Font.PLAIN, 28);
...
int textWidth = titleBarFont.getAdvance(title);
graphics.drawText(title, rect.width - textWidth - TITLE_OFFSET, textYOffset);
graphics.popContext();
}
..
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在
graphics.drawText()
之前调用graphics.setFont(titleBarFont)
?Are you calling
graphics.setFont(titleBarFont)
beforegraphics.drawText()
?