开发者

How does Java draw text under Windows operating system?

My question relates to the underlying rendering mechanism. Does it use Windows APIs e.g. drawtext, ex开发者_如何学Cttextout or does it use a proprietary drawing mechanism? Is this documented anywhere?

More specifically

java.awt.Graphics.drawString
java.awt.Graphics2D.drawString

Under Sun JDK for windows


Actually, I've researched this when developping a PDF library.

Java, more specifically an implementation of Java, since it's not part of the public java-API, has libraries for parsing font-files and returning so-called "glyphs". These glyphs are then rendered using Graphics.

(Edit: glyphs are vectorgraphical (i.e. java.awt.Shapes) components that make readible symbols (Latin charset for instance, but also Hebrew or Arabic).)

To answer your question: it does not use Windows APIs such as drawtext. It may use Windows APIs to get font glyphs (depends on implementation of Java). As far as I know, Sun Java have closed-source font libraries which give you the glyphs.

You can, though, use glyphs provided by the libraries of any implementation of Java:

createGlyphVector(FontRenderContext frc, String str)

in java.awt.Font.

That should be a nice jumpstart. If you'd need anything: the rest is quite nicely documentated in the JavaDocs, i.e. http://java.sun.com/j2se/1.4.2/docs/api/java/awt/font/GlyphVector.html


For desktop applications, the Swing windowing API does all the work, including drawing text to the screen. The only thing Swing relies on from the operating system is a window context, and a canvas to draw on. All widgets within the window are handled entirely within Swing.

AWT, by comparison, uses operating system constructs to do its rendering.


It doesn't matter. It's supposed to work the same way on every operating system, so it could be done using OpenGL or DirectDraw or some other technology on windows. And of course on other operating systems it's going to work differently.

If you're really curious, you can download the JDK source code see how the functions are actually implemented.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜