public final class Glyph extends Object
The reason for the dual behavior is so that we can take in a sequence of unicode characters and partition them into runs of individual glyphs, but if we encounter complex text and/or unicode sequences we don't understand, we can render them using the string-by-string method.
In an effort to make positioning glyphs more intuitive for both Java2D's and OpenGL's coordinate
systems, Glyph
now stores its measurements differently. This new way is patterned off
of HTML's box model.
Of course, as expected each glyph maintains its width and height. For spacing however, rather
than storing positions in Java2D space that must be manipulated on a case-by-case basis,
Glyph
stores two separate pre-computed boundaries representing space around the text.
Each of the boundaries has separate top, bottom, left, and right components. These components
should generally be considered positive, but negative values are sometimes necessary in rare
situations.
The first boundary is called padding. Padding is the space between the actual glyph itself and its border. It is included in the width and height of the glyph. The second boundary that a glyph stores is called margin, which is extra space around the glyph's border. The margin is generally used for separating the glyph from other glyphs when it's stored.
The diagram below shows the boundaries of a glyph and how they relate to its width and height. The inner rectangle is the glyph's boundary, and the outer rectangle is the edge of the margin.
+--------------------------------------+ | top margin | | | | |------ WIDTH -------| | | - +--------------------+ | | | | top padding | | | | | l ________ r | | | l | | e / \ i | r | | e | f | | g | i | | f H | t | | h | g | | t E | | | t | h | | I | p | _____ | t | | m G | a | | p | | | a H | d | | a | m | | r T | d | | d | a | | g | i | | d | r | | i | | n | | i | g | | n | | g \________/ n | i | | | | g | n | | | | bottom padding | | | - +--------------------+ | | | | | | bottom margin | +--------------------------------------+
In addition, Glyph
also keeps a few other measurements useful for positioning.
Ascent is the distance between the baseline and the top border, while descent is
the distance between the baseline and the bottom border. Kerning is the distance between
the vertical baseline and the left border. Note that in some cases some of these fields can
match up with padding components, but in general they should be considered separate.
Below is a diagram showing ascent, descent, and kerning.
+--------------------+ - | | | | ________ | | | / \ | | | | | | | | | | | | | | | | | | | _____ | | ascent | | | | | | | | | | | | | | | | | | | | | | | | | | \________/ | - | | | | | | descent +--------------------+ - |--| kerning
Modifier and Type | Field and Description |
---|---|
float |
height
Height of text with inner padding.
|
com.jogamp.opengl.util.packrect.Rect |
location
Position of this glyph in texture.
|
float |
width
Width of text with inner padding.
|
Constructor and Description |
---|
Glyph(int id,
GlyphVector gv)
Constructs a
Glyph representing an individual Unicode character. |
Glyph(String str,
GlyphVector gv)
Constructs a
Glyph representing a sequence of characters. |
Modifier and Type | Method and Description |
---|---|
void |
clearTextureCoordinates() |
com.jogamp.opengl.util.texture.TextureCoords |
getTextureCoordinates(int textureWidth,
int textureHeight) |
String |
toString() |
public float width
public float height
public com.jogamp.opengl.util.packrect.Rect location
public Glyph(int id, GlyphVector gv)
Glyph
representing an individual Unicode character.id
- Unicode ID of charactergv
- Vector shape of characterIllegalArgumentException
- if ID is negativeNullPointerException
- if glyph is nullpublic Glyph(String str, GlyphVector gv)
Glyph
representing a sequence of characters.str
- Sequence of charactersgv
- Vector shape of sequenceNullPointerException
- if string or glyph vector is nullCopyright © 2020 Metron, Inc.. All rights reserved.