Hi, Prasanta.

I modified the fix to use deviceFRC if not compatible and in sync with the comment which 
says "obtain a TextLayout with advances for the printer graphics FRC"
I used SwingUtilies2.getStringWidth() which calculates the advances of the 
string if text layouting is used.

http://cr.openjdk.java.net/~psadhukhan/8214702/webrev.2/

Can you please take a look to the existed drawChars() method, which is 
implemented in the similar way as drawStringImpl() and new version of 
drawString(), but they have some small difference. Why we cannot use the same 
logic?

For example in the drawChars:
=========
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {
                 String text = new String(data, offset, length);
                 TextLayout layout = new TextLayout(text, g2d.getFont(),
                               deviceFontRenderContext);
                 String trimmedText = trimTrailingSpaces(text);
                 if (!trimmedText.isEmpty()) {
                     float screenWidth = (float)g2d.getFont().
                         getStringBounds(trimmedText, frc).getWidth();
                     layout = layout.getJustifiedLayout(screenWidth);

==========
Similar but not the same logic in the fix:

 524                 FontRenderContext frc = getFontRenderContext(c);
 525                 if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
 526                     frc = new FontRenderContext(frc.getTransform(), false, 
false);
 527                 }
 528                 FontRenderContext deviceFRC = g2d.getFontRenderContext();
 529                 String trimmedText = trimTrailingSpaces(text);
 530                 if (!trimmedText.isEmpty()) {
 531                     FontMetrics fm = g2d.getFontMetrics();
 532                     float screenWidth = SwingUtilities2.stringWidth(c, fm 
,trimmedText);
 533                     TextLayout layout;
 534                     if (!isFontRenderContextPrintCompatible(frc, 
deviceFRC)) {
 535                         layout = createTextLayout(c, text, g2d.getFont(), 
deviceFRC);
 536                     } else {
 537                         layout = createTextLayout(c, text, g2d.getFont(), 
frc);
 538                     }
 540                     layout = layout.getJustifiedLayout(screenWidth);



--
Best regards, Sergey.

Reply via email to