The Source for Java Technology Collaboration

Home » java.net Forums » Java Desktop Technologies » Java 2D

Thread: Native text rasterizer and translucent graphics

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 12 - Last Post: Sep 18, 2008 10:58 AM by: kirillcool Threads: [ Previous | Next ]
kirillcool

Posts: 795
Native text rasterizer and translucent graphics
Posted: Apr 11, 2008 3:22 PM
  Click to reply to this thread Reply

Reposting from "Swing & AWT" forum since it was suggested that this is a better place.

It looks like the new native text rasterizer is not used when the current graphics composite is translucent. Here is the test app that i'm running on Vista SP1 with 6u10 b14:

package test;
 
import java.awt.*;
import java.util.*;
 
import javax.swing.*;
 
public class TextRenderingPanel extends JPanel {
 
	private static Map desktopHints(Graphics2D g2) {
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		GraphicsDevice device = g2.getDeviceConfiguration().getDevice();
		Map desktopHints = (Map) toolkit
				.getDesktopProperty("awt.font.desktophints");
		// It is possible to get a non-empty map but with disabled AA.
		if (desktopHints != null) {
			Object aaHint = desktopHints
					.get(RenderingHints.KEY_TEXT_ANTIALIASING);
			if ((aaHint == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
					|| (aaHint == RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT)) {
				desktopHints = null;
			}
		}
		return desktopHints;
	}
 
	@Override
	protected void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g.create();
		
		Map desktopHints = desktopHints(g2d);
		if (desktopHints != null && !desktopHints.isEmpty()) {
			g2d.addRenderingHints(desktopHints);
		}
		
		g2d.setColor(Color.white);
		g2d.fillRect(0, 0, getWidth(), getHeight());
		g2d.setColor(Color.black);
		g2d.setFont(new Font("Segoe UI", Font.PLAIN, 12));
		g2d.drawString("Text rendering", 10, 30);
		g2d.setComposite(AlphaComposite.SrcOver.derive(0.5f));
		workaroundBug6576507(g2d);
		g2d.drawString("Text rendering", 10, 60);
		g2d.dispose();
	}
	
	public static void workaroundBug6576507(Graphics graphics) {
		Font font = graphics.getFont();
		font = font.deriveFont(font.getStyle(), font.getSize2D());
		graphics.setFont(font);
	}
 
 
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				JFrame frame = new JFrame("Text rendering");
				frame.add(new TextRenderingPanel(), BorderLayout.CENTER);
				frame.setSize(300, 200);
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
			}
		});
	}
 
}



Running this you can see that the 'e's on the second line of text do not come from the same rasterizer as the 'e's on the first line of text. Is this the expected result, and if so, would i have to create a temporary image, render the full-opacity text there and then render that image back (with translucency) to get consistent rendering?

Note that I have to use deriveFont as the workaround for bug 6576507 as suggested in [1]. Doesn't look like the fix in JDK 7 was backported to 6u10.

Last thing - letter 'g' is one pixel narrower than in the "real" native rendering (from the title pane of the same frame).

Thanks
Kirill

[1] http://forums.java.net/jive/thread.jspa?threadID=28226

linuxhippy

Posts: 646
Re: Native text rasterizer and translucent graphics
Posted: Apr 12, 2008 2:30 AM   in response to: kirillcool
  Click to reply to this thread Reply

I guess stuff like the native text renderer will cause a lot of troubles and maintenance.
I can't understand why so much effort is driven into this direction, only to get some letters rendered with one pixel different.

kirillcool

Posts: 795
Re: Native text rasterizer and translucent graphics
Posted: Apr 14, 2008 12:24 AM   in response to: linuxhippy
  Click to reply to this thread Reply

> I can't understand why so much effort is driven into
> this direction, only to get some letters rendered
> with one pixel different.

Would i be right to say that you don't work with Windows Vista? The difference in rendering the default Vista UI font (Segoe UI 12 pixels / 9 points) is quite large, as any non-casual Vista user will note. You can argue that Vista is seen as a commercial failure, people are switching back to XP, Ubuntu rules, real developers use Macs, but that has nothing to do with the objective rasterization quality on a major target platform.

linuxhippy

Posts: 646
Re: Native text rasterizer and translucent graphics
Posted: Apr 14, 2008 3:57 AM   in response to: kirillcool
  Click to reply to this thread Reply

> Would i be right to say that you don't work with
> Windows Vista?
Yes, of course I don't use windows vista.
I use Fedora-7, and I use the DeJaVu Fonts as default.
Also there rendering is quite different, they differ even more than Java and Vista's rasterizer, but after all for me its not a problem.
I would also argue against a freetype-backend to support more native "unix font rendering".

The difference in rendering the
> default Vista UI font (Segoe UI 12 pixels / 9 points)
> is quite large, as any non-casual Vista user will
> note. You can argue that Vista is seen as a
> commercial failure, people are switching back to XP,
> Ubuntu rules, real developers use Macs, but that has
> nothing to do with the objective rasterization
> quality on a major target platform.
Well, I did not say that rasterization differences are not problematic, there are people who sit in front of the screen and look at every font and ask themself why it looks different.

What I am against is the resolution that was choosen - it introduces new code-paths, new bugs and complicates the whole architecture.
Wouldn't it have been enough to adopt Sun's rasterizer to look like the MS one, at least for "Segoe". Its very unlikely anyway to find this font on Unix or Mac ;)

lg Clemens

mthornton

Posts: 528
Re: Native text rasterizer and translucent graphics
Posted: Apr 14, 2008 6:37 AM   in response to: linuxhippy
  Click to reply to this thread Reply

> Wouldn't it have been enough to adopt Sun's
> rasterizer to look like the MS one, at least for
> "Segoe". Its very unlikely anyway to find this font
> on Unix or Mac ;)

Possibly they have got tired of chasing the rendering of various commonly used fonts in Windows.

Phil Race
Re: [JAVA2D] Native text rasterizer and translucent graphics
Posted: Apr 15, 2008 5:04 PM   in response to: kirillcool
  Click to reply to this thread Reply

The first line is LCD text, the second line is greyscale.
The problem is that we do not have loops - in either software
or hardware, that work for LCD text with the composite you have specified.
There's an open bug on this: 6274808.

-phil.


java2d@JAVADESKTOP.ORG wrote:
> Reposting from "Swing & AWT" forum since it was suggested that this is a better place.
>
> It looks like the new native text rasterizer is not used when the current graphics composite is translucent. Here is the test app that i'm running on Vista SP1 with 6u10 b14:
>
>
> package test;
>  
> import java.awt.*;
> import java.util.*;
>  
> import javax.swing.*;
>  
> public class TextRenderingPanel extends JPanel {
>  
> 	private static Map desktopHints(Graphics2D g2) {
> 		Toolkit toolkit = Toolkit.getDefaultToolkit();
> 		GraphicsDevice device = g2.getDeviceConfiguration().getDevice();
> 		Map desktopHints = (Map) toolkit
> 				.getDesktopProperty("awt.font.desktophints");
> 		// It is possible to get a non-empty map but with disabled AA.
> 		if (desktopHints != null) {
> 			Object aaHint = desktopHints
> 					.get(RenderingHints.KEY_TEXT_ANTIALIASING);
> 			if ((aaHint == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
> 					|| (aaHint == RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT)) {
> 				desktopHints = null;
> 			}
> 		}
> 		return desktopHints;
> 	}
>  
> 	@Override
> 	protected void paintComponent(Graphics g) {
> 		Graphics2D g2d = (Graphics2D) g.create();
> 		
> 		Map desktopHints = desktopHints(g2d);
> 		if (desktopHints != null && !desktopHints.isEmpty()) {
> 			g2d.addRenderingHints(desktopHints);
> 		}
> 		
> 		g2d.setColor(Color.white);
> 		g2d.fillRect(0, 0, getWidth(), getHeight());
> 		g2d.setColor(Color.black);
> 		g2d.setFont(new Font("Segoe UI", Font.PLAIN, 12));
> 		g2d.drawString("Text rendering", 10, 30);
> 		g2d.setComposite(AlphaComposite.SrcOver.derive(0.5f));
> 		workaroundBug6576507(g2d);
> 		g2d.drawString("Text rendering", 10, 60);
> 		g2d.dispose();
> 	}
> 	
> 	public static void workaroundBug6576507(Graphics graphics) {
> 		Font font = graphics.getFont();
> 		font = font.deriveFont(font.getStyle(), font.getSize2D());
> 		graphics.setFont(font);
> 	}
>  
>  
> 	public static void main(String[] args) {
> 		SwingUtilities.invokeLater(new Runnable() {
> 			@Override
> 			public void run() {
> 				JFrame frame = new JFrame("Text rendering");
> 				frame.add(new TextRenderingPanel(), BorderLayout.CENTER);
> 				frame.setSize(300, 200);
> 				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> 				frame.setLocationRelativeTo(null);
> 				frame.setVisible(true);
> 			}
> 		});
> 	}
>  
> }
> 

>
>
> Running this you can see that the 'e's on the second line of text do not come from the same rasterizer as the 'e's on the first line of text. Is this the expected result, and if so, would i have to create a temporary image, render the full-opacity text there and then render that image back (with translucency) to get consistent rendering?
>
> Note that I have to use deriveFont as the workaround for bug 6576507 as suggested in [1]. Doesn't look like the fix in JDK 7 was backported to 6u10.
>
> Last thing - letter 'g' is one pixel narrower than in the "real" native rendering (from the title pane of the same frame).
>
> Thanks
> Kirill
>
> [1] http://forums.java.net/jive/thread.jspa?threadID=28226
> [Message sent by forum member 'kirillcool' (kirillcool)]
>
> http://forums.java.net/jive/thread.jspa?messageID=268874
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".


Dmitri Trembove...
Re: [JAVA2D] Native text rasterizer and translucent graphics
Posted: Apr 15, 2008 5:23 PM   in response to: Phil Race
  Click to reply to this thread Reply

Phil Race wrote:
> The first line is LCD text, the second line is greyscale.
> The problem is that we do not have loops - in either software
> or hardware, that work for LCD text with the composite you have specified.
> There's an open bug on this: 6274808.

Note that this bug mentions that complex clip is
another restriction. This is only the case for
sw pipelines, the hw ones (ogl,d3d) can handle
lcd AA text with complex clip.

Thanks,
Dmitri


>
> -phil.
>
>
> java2d@JAVADESKTOP.ORG wrote:
>> Reposting from "Swing & AWT" forum since it was suggested that this is
>> a better place.
>>
>> It looks like the new native text rasterizer is not used when the
>> current graphics composite is translucent. Here is the test app that
>> i'm running on Vista SP1 with 6u10 b14:
>>
>>
>> package test;
>>  
>> import java.awt.*;
>> import java.util.*;
>>  
>> import javax.swing.*;
>>  
>> public class TextRenderingPanel extends JPanel {
>>  
>>     private static Map desktopHints(Graphics2D g2) {
>>         Toolkit toolkit = Toolkit.getDefaultToolkit();
>>         GraphicsDevice device = g2.getDeviceConfiguration().getDevice();
>>         Map desktopHints = (Map) toolkit
>>                 .getDesktopProperty("awt.font.desktophints");
>>         // It is possible to get a non-empty map but with disabled AA.
>>         if (desktopHints != null) {
>>             Object aaHint = desktopHints
>>                     .get(RenderingHints.KEY_TEXT_ANTIALIASING);
>>             if ((aaHint == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
>>                     || (aaHint == 
>> RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT)) {
>>                 desktopHints = null;
>>             }
>>         }
>>         return desktopHints;
>>     }
>>  
>>     @Override
>>     protected void paintComponent(Graphics g) {
>>         Graphics2D g2d = (Graphics2D) g.create();
>>        
>>         Map desktopHints = desktopHints(g2d);
>>         if (desktopHints != null && !desktopHints.isEmpty()) {
>>             g2d.addRenderingHints(desktopHints);
>>         }
>>        
>>         g2d.setColor(Color.white);
>>         g2d.fillRect(0, 0, getWidth(), getHeight());
>>         g2d.setColor(Color.black);
>>         g2d.setFont(new Font("Segoe UI", Font.PLAIN, 12));
>>         g2d.drawString("Text rendering", 10, 30);
>>         g2d.setComposite(AlphaComposite.SrcOver.derive(0.5f));
>>         workaroundBug6576507(g2d);
>>         g2d.drawString("Text rendering", 10, 60);
>>         g2d.dispose();
>>     }
>>     
>>     public static void workaroundBug6576507(Graphics graphics) {
>>         Font font = graphics.getFont();
>>         font = font.deriveFont(font.getStyle(), font.getSize2D());
>>         graphics.setFont(font);
>>     }
>>  
>>  
>>     public static void main(String[] args) {
>>         SwingUtilities.invokeLater(new Runnable() {
>>             @Override
>>             public void run() {
>>                 JFrame frame = new JFrame("Text rendering");
>>                 frame.add(new TextRenderingPanel(), BorderLayout.CENTER);
>>                 frame.setSize(300, 200);
>>                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>                 frame.setLocationRelativeTo(null);
>>                 frame.setVisible(true);
>>             }
>>         });
>>     }
>>  
>> }
>> 

>>
>>
>> Running this you can see that the 'e's on the second line of text do
>> not come from the same rasterizer as the 'e's on the first line of
>> text. Is this the expected result, and if so, would i have to create a
>> temporary image, render the full-opacity text there and then render
>> that image back (with translucency) to get consistent rendering?
>>
>> Note that I have to use deriveFont as the workaround for bug 6576507
>> as suggested in [1]. Doesn't look like the fix in JDK 7 was backported
>> to 6u10.
>>
>> Last thing - letter 'g' is one pixel narrower than in the "real"
>> native rendering (from the title pane of the same frame).
>>
>> Thanks
>> Kirill
>> [1] http://forums.java.net/jive/thread.jspa?threadID=28226
>> [Message sent by forum member 'kirillcool' (kirillcool)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=268874
>>
>> ===========================================================================
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff JAVA2D-INTEREST". For general help, send
>> email to
>> listserv@java.sun.com and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".


kirillcool

Posts: 795
Re: [JAVA2D] Native text rasterizer and translucent graphics
Posted: Apr 15, 2008 5:45 PM   in response to: Phil Race
  Click to reply to this thread Reply

Phil,

Would that be fixed in the final 6u10?

Thanks
Kirill

Phil Race
Re: [JAVA2D] Native text rasterizer and translucent graphics
Posted: Apr 15, 2008 6:21 PM   in response to: kirillcool
  Click to reply to this thread Reply

java2d@JAVADESKTOP.ORG wrote:
> Phil,
>
> Would that be fixed in the final 6u10?
>

Its not likely to be fixed in 6u10. Its a limitation we've had since LCD
text was implemented. I think even MS need to turn off LCD text in some
cases,
at least that's what I read in a WinHEC (?) presentation a couple of
years ago.

-phil.

> Thanks
> Kirill
> [Message sent by forum member 'kirillcool' (kirillcool)]
>
> http://forums.java.net/jive/thread.jspa?messageID=269392
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".


kirillcool

Posts: 795
Re: [JAVA2D] Native text rasterizer and translucent graphics
Posted: Apr 15, 2008 8:22 PM   in response to: Phil Race
  Click to reply to this thread Reply

Would you suggest emulating translucent text by interpolating the full color with the background color (using full opacity)?

kirillcool

Posts: 795
Re: [JAVA2D] Native text rasterizer and translucent graphics
Posted: Sep 16, 2008 12:51 PM   in response to: Phil Race
  Click to reply to this thread Reply

Phil,

Allow me to reopen this discussion. It looks like there are a lot of bug reports being marked as fixed and those reports sound very similar to the question that i had on Windows native rasterizer and translucent composites. Specifically, i saw 6749069, 6728834 and 6749060. Has this limitation been revisited? Does b32 (or the final planned 6u10) use native rasterizer for translucent target destination?

Thanks
Kirill

Phil Race
Re: [JAVA2D] Native text rasterizer and translucent graphics
Posted: Sep 17, 2008 10:50 AM   in response to: kirillcool
  Click to reply to this thread Reply

No, the only thing that has actually been fixed to date in 6u10 is
6728834: D3D/OGL: LCD AA text becomes bold and blurred when rendering to a non-opaque
destination

which fixes where the D3D renderer was not backing off to greyscale,
and that caused bad artifacts.

6749060 :LCD AA text rendered incorrectly when destination is non opaque (sw pipeline only)

was filed yesterday when Dmitri worked out that the software pipeline was causing
similar artifacts.

6749069 is an RFE to add support for these cases in the pipelines,
which I think is what you really want, but that's for the future.

-phil.

java2d@JAVADESKTOP.ORG wrote:
> Phil,
>
> Allow me to reopen this discussion. It looks like there are a lot of bug
>reports being marked as fixed and those reports sound very similar to the
>question that i had on Windows native rasterizer and translucent composites.
>Specifically, i saw 6749069, 6728834 and 6749060. Has this limitation been
>revisited? Does b32 (or the final planned 6u10) use native rasterizer for
>translucent target destination?
>
> Thanks
> Kirill
> [Message sent by forum member 'kirillcool' (kirillcool)]
>
> http://forums.java.net/jive/thread.jspa?messageID=299669
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".


kirillcool

Posts: 795
Re: [JAVA2D] Native text rasterizer and translucent graphics
Posted: Sep 18, 2008 10:58 AM   in response to: Phil Race
  Click to reply to this thread Reply

> 6749069 is an RFE to add support for these cases in
> the pipelines, which I think is what you really want, but that's for
> the future.

Thanks, Phil.

Looks like the solution that i'm using to emulate the translucency by mixing the required foreground color with the background color of the component is still the way to go to make sure that the native rasterizer is used.

Kirill




 XML java.net RSS