Class Glyph
- java.lang.Object
-
- com.metsci.glimpse.jogamp.opengl.util.awt.text.Glyph
-
public final class Glyph extends Object
Representation of one or multiple unicode characters to be drawn.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.
Positioning
In an effort to make positioning glyphs more intuitive for both Java2D's and OpenGL's coordinate systems,
Glyphnow 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,
Glyphstores 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,
Glyphalso 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
-
-
Constructor Summary
Constructors Constructor Description Glyph(int id, GlyphVector gv)Constructs aGlyphrepresenting an individual Unicode character.Glyph(String str, GlyphVector gv)Constructs aGlyphrepresenting a sequence of characters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearTextureCoordinates()com.jogamp.opengl.util.texture.TextureCoordsgetTextureCoordinates(int textureWidth, int textureHeight)StringtoString()
-
-
-
Constructor Detail
-
Glyph
public Glyph(int id, GlyphVector gv)Constructs aGlyphrepresenting an individual Unicode character.- Parameters:
id- Unicode ID of charactergv- Vector shape of character- Throws:
IllegalArgumentException- if ID is negativeNullPointerException- if glyph is null
-
Glyph
public Glyph(String str, GlyphVector gv)
Constructs aGlyphrepresenting a sequence of characters.- Parameters:
str- Sequence of charactersgv- Vector shape of sequence- Throws:
NullPointerException- if string or glyph vector is null
-
-