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 / GUI / December 2003

Tip: Looking for answers? Try searching our database.

WYSIWYG problems: sun.java2d.SunGraphics2D  verses sun.awt.windows.WPathGraphics

Thread view: 
Karl Mueller - 23 Dec 2003 05:54 GMT
I am running into some differences in string metrics for certain TrueType
fonts on my XP box with a sun.java2d.SunGraphics2D object verses a
sun.awt.windows.WPathGraphics (i.e., my actual printer) object. All I'm
trying to do is to right justify some text, and when I compute the x
coordinate based on the string width for a string, it always comes out
perfect on the sun.java2d.SunGraphics2D object for all fonts but sometimes
it also comes out perfect on a sun.awt.windows.WPathGraphics object (i.e.,
that is my printer (the piece of paper I ultimately hold in my hand) which
happens to be a LaserJet 6P for testing).

I use the following lines to compute the string width and that computation
is used to right justify the text:

FontRenderContext fontRenderContext = ((Graphics2D) pGraphics).

getFontRenderContext ();

Rectangle2D rectangle = pFont.getStringBounds(pText, fontRenderContext);

float stringWidth = ((float) (rectangle.getWidth () - rectangle.getX ()));

Afterwards I call the Graphics drawString method like this:

((Graphics2D) pGraphics).drawString(someString, x, y); where x and y are
float values.

I even tried experimenting with setting fractional font rendering hints like
this:

fFractionalMetricsRenderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,

RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);

fFractionalMetricsRenderingHints.put(RenderingHints.KEY_FRACTIONALMETRICS,

RenderingHints.VALUE_FRACTIONALMETRICS_ON);

and setting it like this:

graphics2D.setRenderingHints(fFractionalMetricsRenderingHints);

But so far nothing has worked with certain fonts; Arial, Times Roman, etc.,
work fine, but other "fancier" TrueType fonts do not! Again with this
"problem" fonts, when I try to right justify the text, it looks perfect on
the screen (i.e., sun.java2d.SunGraphics2D) but the right end of the strings
do not line up at all for the printer (i.e., sun.awt.windows.WPathGraphics).

Does anyone have any ideas on how to solve this seemingly simple problem?

Thanx.

Karl
Harald Hein - 23 Dec 2003 07:05 GMT
> Does anyone have any ideas on how to solve this seemingly simple
> problem?

AFAIR this is a known bug with some Java versions. Check Sun's
bugparade.


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



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