[OpenJDK 2D-Dev] Strange text rendering with SRC + Extra Alpha

Phil Race philip.race at oracle.com
Wed Oct 27 23:27:22 UTC 2010


  With the composite we theoretically back off the LCD text anyway, so 
modulo
pipe selection bugs both hints ought to end up in the grayscale path 
which is
showing the poor rendering - on some builds.

I'm not sure of the details of why its so poor or if in fact its 
semi-reasonable for that
composite but it doesn't occur in current JDK 7 builds - not since b17 -
when back in those early days of JDK 7 (Summer 2007), I fixed
6263951: Java does not use fast AA text loops when regular AA hint is set
That is presumably what cures this garbage although I'm not sure we 
should be using
the regular loops in this case, ie its not so much fixed as incorrectly 
masked.

As for why its not happening in OpenJDK, in either case, if you are 
talking about 6 open,
or the current jdk 7 source, since openjdk6  forked off jdk7 b23, it 
inherited the fix.

Anyway, here's a (full) program that for me on jdk6u22 and jdk7 b115 
looks exactly
as bad as you report and you'll notice its not really text rendering at 
all. Just filling
a path.

import javax.swing.*;
import java.awt.*;
import java.awt.font.*;
import static java.awt.RenderingHints.*;

public class SRC_EA extends Component {

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add("Center", new SRC_EA());
        f.pack();
        f.setVisible(true);
    }

    public Dimension getPreferredSize() {
      return new Dimension(100,100);
    }
    public void paint(Graphics g) {
       Font f = new Font("Dialog", Font.PLAIN, 12);
       g.setFont(f);
       g.setColor(Color.white);
       g.fillRect(0,0,400,300);
       g.setColor(Color.black);
       Graphics2D g2 = (Graphics2D)g;
       g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 
0.01f));
       g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
       FontRenderContext frc = g2.getFontRenderContext();
       GlyphVector gv = f.createGlyphVector(frc, "ABCDEFGHIJKL");
       Shape s = gv.getOutline(20,20);
       g2.fill(s);
    }
}


-phil.

On 10/27/2010 2:06 PM, Denis Lila wrote:
> Hi Clemens.
>
> It's interesting to note that this doesn't happen on OpenJDK, and
> on closed java the subpixel hint is not necessary to reproduce this.
> Simply using VALUE_ANTIALIAS_ON and the SRC composite is enough.
>
> Regards,
> Denis.
>
> ----- "Clemens Eisserer"<linuxhippy at gmail.com>  wrote:
>
>> Hi,
>>
>> While playing arround with the SRC composition rule I found what
>> seems
>> to be a bug.
>> When rendering text with an AlphaComposite(SRC, EA) I get garbage
>> when
>> enabling subpixel antialising:
>>
>>        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC,
>> 0.01f));
>>        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
>> RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR);
>>
>> g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
>>
>>        g2d.setColor(Color.black);
>>        g2d.drawString("This text is painted with black color", 50,
>> 50);
>>
>> If I comment out the KEY_ANTIALIASING hint, which shouldn't have any
>> effect on text rendering, extra alpha is ignored but the text is
>> rendered correctly.
>>
>> Should I file a but?
>>
>> Thanks, Clemens




More information about the 2d-dev mailing list