JDK中渲染字体的源代码在哪里?
JDK 源代码中发生字体渲染的位置在哪里?我试图在 TextArea、JTextArea、TextComponent、JTextComponent、Font 中寻找 Paint(Graphics g),但没有一个覆盖 Paint(Graphics g)。字体信息是否转换为 GlyphVectors,后者成为由...绘制的形状?字体信息在哪里以及如何绘制到屏幕上?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
源代码位于 sun.font.*、sun.awt.font.* 和 javax.swing.text.* 中。
首先,JTextArea、JTextComponent 等不会自行绘制,它们使用 UI 委托。查看 BasicTextUI 和BasicLabelUI。
UI 类似乎持有 GlyphView,这是一个“样式化的文本块”。他们(通过几个级别的委托)使用 TextLine 来绘制单行文本。 TextLine 包含一个 TextLineComponent 数组,每个组件代表(我认为)一个字符。
这些 TextLineComponents 结果是 ShapeGraphicAttributes (它是 Shape 的容器)或 ImageGraphicAttribute(图像的容器)。它们都使用标准的图形绘制方法来绘制自己。
大多数这些类的源代码都包含在 JDK 中。
这是一个总体的简化,并且层次结构中的代码和类还有其他路径。我并不声称自己理解得很好。
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.