Class SimpleTextLayout
- java.lang.Object
-
- com.metsci.glimpse.core.support.font.SimpleTextLayout
-
- Direct Known Subclasses:
SimpleTextLayoutCenter
public class SimpleTextLayout extends Object
Performs simple text layout so text can be wrapped in small areas or broken on words or newlines. This implementation currently makes the following assumptions which are valid for latin text:- mapping chars to glyphs is 1:1 in order, (no Unicode surrogate pairs or multi-glyph characters)
- left-to-right and top-to-bottom text layout
All coordinates are in the same space as the text is being drawn (typically pixels).
- Author:
- borkholder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSimpleTextLayout.TextBoundingBoxWhen drawing using the JOGLTextRenderer, theSimpleTextLayout.TextBoundingBox.leftXandSimpleTextLayout.TextBoundingBox.baselineYshould be used as the text origin.
-
Constructor Summary
Constructors Constructor Description SimpleTextLayout(Font font, FontRenderContext frc)SimpleTextLayout(Font font, FontRenderContext frc, BreakIterator breaker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddoLayout(String text, float leftX, float topY, float maxWidth)Takes the text and performs the layout.doublegetAscent()booleangetBreakOnEol()Whether to force a break on the end of line characters (\r \f \n).doublegetDescent()SimpleTextLayout.TextBoundingBoxgetLine(int line)doublegetLineHeight()List<SimpleTextLayout.TextBoundingBox>getLines()floatgetLineSpacing()The spacing between the bottom (descent) of one line of text to the top (ascent) of the next line.StringgetSourceText()intnumberOfLines()voidsetAscent(float ascent)voidsetBreakOnEol(boolean breakOnEol)voidsetLineSpacing(float lineSpacing)
-
-
-
Constructor Detail
-
SimpleTextLayout
public SimpleTextLayout(Font font, FontRenderContext frc)
- Parameters:
font- The font to use for the layoutfrc- The FontRenderContext used to rasterize the font. This will help define the character bounds
-
SimpleTextLayout
public SimpleTextLayout(Font font, FontRenderContext frc, BreakIterator breaker)
- Parameters:
font- The font to use for the layoutfrc- The FontRenderContext used to rasterize the font. This will help define the character boundsbreaker- The BreakIterator that is used to break the text (also seeforceBreakAfter(int))
-
-
Method Detail
-
getLineHeight
public double getLineHeight()
-
getDescent
public double getDescent()
-
getAscent
public double getAscent()
-
setAscent
public void setAscent(float ascent)
-
setBreakOnEol
public void setBreakOnEol(boolean breakOnEol)
-
getBreakOnEol
public boolean getBreakOnEol()
Whether to force a break on the end of line characters (\r \f \n).
-
setLineSpacing
public void setLineSpacing(float lineSpacing)
-
getLineSpacing
public float getLineSpacing()
The spacing between the bottom (descent) of one line of text to the top (ascent) of the next line.
-
doLayout
public void doLayout(String text, float leftX, float topY, float maxWidth)
Takes the text and performs the layout. The provided constraints determine the top-left position of the text and the maximum width. SeenumberOfLines(),getLine(int)and#getBounds(int)for the results of the layout.- Parameters:
text- The text to lay outleftX- The leftmost X value of any pixel of texttopY- The topmost Y value of any pixel of textmaxWidth- The suggested maximum width of any line of the text
-
getSourceText
public String getSourceText()
-
numberOfLines
public int numberOfLines()
-
getLine
public SimpleTextLayout.TextBoundingBox getLine(int line)
-
getLines
public List<SimpleTextLayout.TextBoundingBox> getLines()
-
-