views:

38

answers:

1

Where is the spot in the JDK source where font rendering occurs? I've tried to look for a paint(Graphics g) in TextArea, JTextArea, TextComponent, JTextComponent, Font ... none of which override paint(Graphics g). Is font information transformed into GlyphVectors which become Shapes that are painted in by ... ? Where and how does font information get painted to the screen?

+1  A: 

The source is in sun.font.*, sun.awt.font.* and javax.swing.text.*.

Firstly JTextArea, JTextComponent etc don't draw themselves, they use a UI delegate. Look at BasicTextUI and BasicLabelUI.

It seems to be that the UI classes hold a GlyphView, which is a "styled chunk of text". They (through a few levels of delegation) use a TextLine to draw a single line of text. The TextLine holds an array of TextLineComponents, each representing (I think) a character.

Those TextLineComponents turn out to be either ShapeGraphicAttributes (which is a container for a Shape) or an ImageGraphicAttribute (a container for an Image). They both draw themselves with the standard Graphics draw methods.

Most of those classes have source included in the JDK.

That's a gross simplification, and there are other paths through the code and classes in the hierarchy. I don't claim to understand it well.

tom
Thanks! I attached the JDK source in eclipse, put a breakpoint on BasicTextUI.paint(), and then ran the example here [1] to figure out how it all worked. [1] http://java.sun.com/docs/books/tutorial/uiswing/examples/components/TextAreaDemoProject/src/components/TextAreaDemo.java
Peter Nore
An interesting source to examine for this issue is WrappedPlainView [1], which implements a basic text wrap painting. [1] http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/WrappedPlainView.html
Peter Nore
A great resource for these issues is this [1] article on the Swing text package by Tim Prinzing, who wrote Swing's text package. [1] http://java.sun.com/products/jfc/tsc/articles/text/overview/
Peter Nore