D
Dave Ekhaus
hi
i'm trying to write a J2ME app and i'm having some trouble placing
text precisely. the problem is that the font and subsequent font
metrics on two different phones are different. specifically the
getBaselinePosition() and getHeight() methods of the Font object return
different values on the different phones and i'm trying to use the
drawString method to display text in the exact same relative position
on each respective phone. here's what i'm trying to do ...
Font font = Font.getFont (Font.FACE_MONOSPACE, Font.STYLE_BOLD,
Font.SIZE_SMALL) ;
int width = getWidth () ;
int refX = 10 ;
int refY = 15 ;
// draw reference line that subsequent text drawing will be relative to ...
g.setColor (0x00,0x99,0xCC) ;
g.drawLine (0, refY + 1, width, refY + 1) ;
StringBuffer buf = new StringBuffer () ;
buf.append ("H = ") ;
buf.append (font.getHeight()) ;
buf.append ("BLP = ") ;
buf.append (font.getBaselinePosition()) ;
g.drawString (buf.toString(),
refX,
refY - font.getBaselinePosition(),
Graphics.LEFT | Graphics.TOP) ;
my goal is to have the text drawn by the 'drawString' method above
drawn in the same relative position to the 'reference' line draw above
on all phones. i thought that making the anchor the 'TOP' and
subtracting the amount of the 'baseline' from the position of the
reference line - would result in the text being drawn the same distance
from the reference line on ANY phone. what i'm seeing (on two different
phones) is different number of pixels between the bottom the text and
my reference line.
any help the group can provide would be greatly appreciated.
thanks
dave
i'm trying to write a J2ME app and i'm having some trouble placing
text precisely. the problem is that the font and subsequent font
metrics on two different phones are different. specifically the
getBaselinePosition() and getHeight() methods of the Font object return
different values on the different phones and i'm trying to use the
drawString method to display text in the exact same relative position
on each respective phone. here's what i'm trying to do ...
Font font = Font.getFont (Font.FACE_MONOSPACE, Font.STYLE_BOLD,
Font.SIZE_SMALL) ;
int width = getWidth () ;
int refX = 10 ;
int refY = 15 ;
// draw reference line that subsequent text drawing will be relative to ...
g.setColor (0x00,0x99,0xCC) ;
g.drawLine (0, refY + 1, width, refY + 1) ;
StringBuffer buf = new StringBuffer () ;
buf.append ("H = ") ;
buf.append (font.getHeight()) ;
buf.append ("BLP = ") ;
buf.append (font.getBaselinePosition()) ;
g.drawString (buf.toString(),
refX,
refY - font.getBaselinePosition(),
Graphics.LEFT | Graphics.TOP) ;
my goal is to have the text drawn by the 'drawString' method above
drawn in the same relative position to the 'reference' line draw above
on all phones. i thought that making the anchor the 'TOP' and
subtracting the amount of the 'baseline' from the position of the
reference line - would result in the text being drawn the same distance
from the reference line on ANY phone. what i'm seeing (on two different
phones) is different number of pixels between the bottom the text and
my reference line.
any help the group can provide would be greatly appreciated.
thanks
dave