Results 1 to 3 of 3
- 04-28-2011, 05:33 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 20
- Rep Power
- 0
Text Antialiasing Appearance Inconsistent
Hello all,
I am developing an application that displays rotated text, on Mac OS X Snow Leopard antialiasing seems to be consistent and smooth regardless of the fonts size however on Windows 7 and Vista antialiasing is smooth just like on OS X when the font (Arial) is greater then 100pt and noticeably changes when less then 100pt. It seems that on Windows the method of antialiasing changes depending on the fonts size where as on OS X it is consistent.
Here is an image demonstrating this:

I want the text to be antialiased as smooth as possible. On OS X small letters appear very smooth however as you can see in the image on Windows the letter begins to appear rough or jagged. Is there a way to keep the same antialiasing when the font is small? It seems the way the letter is antialiased changes depending on the font size but this only happens on Windows and is undesirable for the application I am developing as it seems to yield less smooth results.
Any help with this would be great. Thank you :)
Here is a sample application I developed. It scales though various font sizes, you should be able to see a noticeable change in antialiasing when the letter is smaller then 100pt on a Windows OS.
Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package smoothtext; import java.awt.*; import javax.swing.*; import javax.swing.Action.*; import com.sun.awt.AWTUtilities.*; import java.awt.Rectangle; import java.awt.font.*; public class SmoothText { /** * @param args the command line arguments */ public static void main(String[] args) { SwingUtilities.invokeLater( new Runnable() { public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception err) { System.out.println(err); } new SmoothText(); } }); } int offset = 1; Font font = new Font("Arial", Font.PLAIN, 80); PaintSurface canvas = new PaintSurface(); JFrame frame = new JFrame("Smooth Text"); public SmoothText() { renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); renderHints.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY); frame.setSize(500,500); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(canvas); frame.setVisible(true); new Thread(new AnimationThread()).start(); } class AnimationThread implements Runnable { public void run() { while(true) { try { Thread.sleep(30); } catch(InterruptedException err) { //handle interrupted exception } if(font.getSize()>120) { offset = -1; } else if(font.getSize()<20) { offset = 1; } font = new Font(font.getFamily(), font.getStyle(), font.getSize()+offset); canvas.repaint(); } } } class PaintSurface extends JComponent { @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); //ALSO HAVE TRIED //g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); g2.addRenderingHints(renderHints); g2.setColor(Color.red); g2.drawString("Font Size: "+font.getSize(), 20, 20); g2.setColor(Color.black); g2.setFont(font); TextLayout layout = new TextLayout("D", font, g2.getFontRenderContext()); Rectangle bounds = layout.getPixelBounds(null, 0, 0); g2.rotate(Math.toRadians(7), (getWidth()/2 - bounds.width/2)+bounds.width/2, ((getHeight()/2 - bounds.height/2)-(int)bounds.getY())+bounds.height/2); g2.drawString("D", getWidth()/2 - bounds.width/2, (getHeight()/2 - bounds.height/2)-(int)bounds.getY()); } } }
- 04-28-2011, 06:42 AM #2
You already have a thread on this.
Rotated Text and Antialiasing on Windows
Don't clutter the forums with re-runs.
db
- 04-28-2011, 08:45 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 20
- Rep Power
- 0
Sorry I did not mean to clutter up the forums. However seeing as I don't think I'm going to get an answer in the Java2D section I thought I could try posting this relevant question in the Advanced Java section seeing as after further research the problem may not lye with Java2D but with the Font and or other Advanced Java programming.
I'm just really not sure where to post this question and can't find an answer anywhere on the web, believe me I've looked :) is there a way to provide more advanced antialiasing hints? It seems the font changes the way it antialiases depending on it's size.
Anyway thank you for your input.
Similar Threads
-
Rotated Text and Antialiasing on Windows
By neptune692 in forum Java 2DReplies: 4Last Post: 05-05-2011, 08:41 PM -
[java3D] set Appearance again
By Dennis in forum Advanced JavaReplies: 0Last Post: 09-12-2010, 04:18 PM -
How to change the appearance of swing components?
By XmisterIS in forum New To JavaReplies: 4Last Post: 08-25-2010, 10:28 AM -
how to change the appearance of jbuttons
By katie in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 10:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks