Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > J2ME - drawString font related question

Reply
Thread Tools

J2ME - drawString font related question

 
 
Dave Ekhaus
Guest
Posts: n/a
 
      05-08-2005
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


 
Reply With Quote
 
 
 
 
Darryl Pierce
Guest
Posts: n/a
 
      05-08-2005
Dave Ekhaus wrote:
> 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.

--
Darryl L. Pierce <(E-Mail Removed)>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard
 
Reply With Quote
 
 
 
 
Dave Ekhaus
Guest
Posts: n/a
 
      05-09-2005
On 2005-05-08 05:19:45 -0700, Darryl Pierce <(E-Mail Removed)> said:

> Dave Ekhaus wrote:
>> 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.


i am aware that the two phones are using different fonts.

using the 'baseline position' of the font is an attempt to adapt the
app to each 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.

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



i am changing the 'y offset' used and making it sensitive to the font
used on each respective phone by using the 'baseline position' of each
font. 'refY' is a reference and should not have to change to
accomodate the differences of one font to another.



 
Reply With Quote
 
Darryl Pierce
Guest
Posts: n/a
 
      05-10-2005
Dave Ekhaus wrote:
>>> 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.

>
> i am aware that the two phones are using different fonts.
>
> using the 'baseline position' of the font is an attempt to adapt the app
> to each phone.


What I'm saying is that you should adjust the location where you want
the baseline, basing it on the phone's font rather than on a static value.

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

>
> i am changing the 'y offset' used and making it sensitive to the font
> used on each respective phone by using the 'baseline position' of each
> font. 'refY' is a reference and should not have to change to
> accomodate the differences of one font to another.


What if the font is taller than 15 pixels?

--
Darryl L. Pierce <(E-Mail Removed)>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swing Font, it's Java Font? ot native? how install new font? mttc Java 2 07-03-2009 07:29 PM
make drawString render fonts identically to PhotoShop 7.0 opalpa@gmail.com opalinski from opalpaweb Java 9 03-01-2006 01:19 PM
Re: drawString with special Unicode characters to Graphics object Chris Smith Java 1 05-31-2004 07:33 PM
No Focused View on DrawString Xiaolei Li Java 3 04-18-2004 03:59 AM
Special characters with DrawString?! Jonah Olsson ASP .Net 3 10-03-2003 07:03 AM



Advertisments