Comment #7 on issue 117 by heue...@gmail.com: Text rendering in PText and
JLabel via PSwing appear not to respect antialiasing rendering hints
http://code.google.com/p/piccolo2d/issues/detail?id=117
Further analysis:
Swing text rendering is dependent on operating system and installed Look
and Feel. See jlabel-*, pswing-*, jtextcomponent-*, and phtmlview-* in the
text rendering benchmark.
Java2D text rendering using Graphics2D.drawSwing respects LCD_* text
rendering hints of the current graphics context on all platforms. See
java2d-* in the text rendering benchmark.
PText text rendering using java.awt.font.TextLayout.draw() ignores any text
rendering hints specified in the current graphics context. See ptext-* in
the text rendering benchmark.
TextLayout receives its text rendering hints from
PPaintContext.RENDER_QUALITY_HIGH_FRC passed to a
java.awt.font.LineBreakMeasurer ctr.
http://code.google.com/p/piccolo2d/source/browse/piccolo2d.java/trunk/core/src/main/java/org/piccolo2d/nodes/PText.java#436
RENDER_QUALITY_HIGH_FRC is currently implemented as new
FontRenderContext(null, true, true)
http://code.google.com/p/piccolo2d/source/browse/piccolo2d.java/trunk/core/src/main/java/org/piccolo2d/util/PPaintContext.java#63
http://download.java.net/jdk7/docs/api/java/awt/font/FontRenderContext.html#FontRenderContext(java.awt.geom.AffineTransform,%20boolean,%20boolean)
It is not possible to modify the text rendering hints supplied to
TextLayout or LineBreakMeasurer after they have been constructed.
The javadoc for FontRenderContext reads
Typically, instances of FontRenderContext are obtained from a Graphics2D
object. A FontRenderContext which is directly constructed will most likely
not represent any actual graphics device, and may lead to unexpected or
incorrect results.
Incorrect results such as the poorly anti-aliased text shown in the text
rendering benchmark.
Looking forward, I see a few options
1) Attempt to instantiate a "better" FontRenderContext for
PPaintContext.RENDER_QUALITY_HIGH_FRC.
2) Re-implement PText to create a new instance of TextLayout with the
current text rendering hints from the graphics context every time
PText.paintText is called.
3) Re-implement PText to use the instance of TextLayout created with
PPaintContext.RENDER_QUALITY_HIGH_FRC only for layout purposes and render
the text in PText.paintText with Graphics2D.drawString.
4) Re-implement PText with the same pattern as PHtmlView, delegating text
rendering to a JLabel.
There are pros and cons to each, thought I should post this analysis and
await comment before proceeding.
--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en