O'Reilly logo

Java 2D Graphics by Jonathan Knudsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6.1. Overview

In Java, text is expressed as a series of Unicode characters. Unicode is a standardized list of characters matched up with 16-bit character codes. The Unicode standard includes character codes for the characters that are used in most of the world's written languages. For more information, visit http://www.unicode.org/. Java uses 16-bit Unicode characters in its char type. Strings, furthermore, are an array of Unicode characters.

Rendering text is the task of finding shapes that correspond to characters and rendering the shapes on a drawing surface. In the 2D API, this is the job of Graphics2D, the rendering engine.

6.1.1. Fonts and Glyphs

The shapes that represent characters are called glyphs. Frequently there is a one-to-one correspondence between characters and glyphs, but not all the time. For example, the characters "f " and "i" each have a corresponding glyph. But sometimes, for aesthetic reasons, "f " and "i" together are represented by a single glyph, called a ligature. An example of a ligature is shown in Figure 6.1. Notice how the dot on the "i" has been combined with the ball on the "f " to create an efficient representation of the two characters.

Figure 6.1. A ligature is a single glyph representing two or more characters

Furthermore, different glyphs may be used for a single character depending on the character's context. This is true in Arabic writing, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required