drawString font related question
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.
Then we can safely assume that the two handsets are not using the same font. There's no requirement in the MIDP specification that platforms use fonts with exactly the same metrics for FACE_MONOSPACE, FACE_PROPORTIONAL or FACE_SYSTEM. You have to adapt your application so that it will create its display without depend on any specific font metrics value.
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.
Then you need to set the value for refY programmatically rather than statically. As you can see, the fonts are different on each handset, so you'll have to change your code for drawing the line.
Thanks
T shirts printingTee Shirt printing