Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

J2ME - drawString font related question

Thread view: 
Dave Ekhaus - 08 May 2005 06:24 GMT
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
Darryl Pierce - 08 May 2005 13:19 GMT
> hi
>
[quoted text clipped - 5 lines]
> 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) ;
[quoted text clipped - 23 lines]
> 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.

Signature

Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard

Dave Ekhaus - 09 May 2005 06:24 GMT
>> hi
>>
[quoted text clipped - 12 lines]
> 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 ...
>>
[quoted text clipped - 29 lines]
> 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.
Darryl Pierce - 10 May 2005 12:41 GMT
>>>     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
[quoted text clipped - 15 lines]
> 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
[quoted text clipped - 8 lines]
> 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?

Signature

Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.