Where in the JDK is the source that renders fonts?
Where is the spot in the 开发者_StackOverflow社区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?
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.
精彩评论