public class GrannyTextRenderer
extends java.lang.Object
!A shift up one half line !B shift down one half line (e.g. !A3!n-!B4!n is 3/4). !C newline !D subscript 0.62 of old font size. !U superscript of 0.62 of old font size. !E superscript 0.44 of old font size. !I subscript 0.44 of old font size. !N return to the original font size. !R restore position to last saved position !S save the current position. !K reduce the font size. (Not in IDL's set.) !! the exclamation point (!) !(ext;args) where ext can be: !(color;saddleBrown) switch to color. !(painter;codeId;codeArg1) Plug-in Java code for painting regions. !(bold) switch to bold !(italic) switch to italic !(unbold) switch off bold by switching to plain !(unitalic) switch off italic by switching to plain !(underline) switch to underline !(ununderline) switch to underlineFor Greek and math symbols, Unicode characters should be used like so: ☎ (☎ phone symbol), or symbols like Ω and ω The GrannyTextRenderer object is created and then the method setString is called and layout is performed, in Jython:
def paint(g): gtr= GrannyTextRenderer() gtr.setString( g, 'E=mc!e2' ) gtr.draw( g, 0, g.getFont().getHeight() )
https://github.com/das-developers/das2java/wiki/Granny-Text-Strings
,
java.awt.font.TextLayout, which may do some of the same things.
,
org.das2.graph.GrannyTextLabeller
Modifier and Type | Class and Description |
---|---|
static interface |
GrannyTextRenderer.Painter |
Modifier and Type | Field and Description |
---|---|
static float |
CENTER_ALIGNMENT |
static float |
LEFT_ALIGNMENT |
static java.lang.String |
PROP_GLOW |
static float |
RIGHT_ALIGNMENT |
Constructor and Description |
---|
GrannyTextRenderer() |
Modifier and Type | Method and Description |
---|---|
void |
addPainter(java.lang.String id,
GrannyTextRenderer.Painter p)
add a painter for the grannyTextRenderer.
|
void |
clearPainters()
remove all the painters
|
void |
draw(java.awt.Graphics ig,
float ix,
float iy)
draw the current string.
|
float |
getAlignment()
returns the current alignment, by default LEFT_ALIGNMENT.
|
double |
getAscent()
return the amount that the bounding box will go above the baseline.
|
java.awt.Rectangle |
getBounds()
returns the bounds of the current string.
|
java.awt.geom.Rectangle2D |
getBounds2D()
return a rectangle backed by floating point numbers.
|
double |
getDescent()
return the amount that the bounding box will go below the baseline.
|
double |
getHeight()
returns the hieght of the calculated bounding box.
|
double |
getLineOneWidth()
returns the width in pixels of the first line.
|
java.lang.String |
getString()
return the string.
|
double |
getWidth()
returns the width of the bounding box, in pixels.
|
boolean |
isGlow() |
static int |
lineCount(java.lang.String s)
count the number of lines in the string, breaking on "!c" or "<br>", ignoring empty lines at the beginning.
|
void |
removePainter(java.lang.String id)
remove the painter with the given id.
|
void |
setAlignment(float a)
set the alignment for rendering, one of LEFT_ALIGNMENT CENTER_ALIGNMENT or RIGHT_ALIGNMENT.
|
void |
setGlow(boolean glow) |
void |
setString(java.awt.Component c,
java.lang.String str)
Deprecated.
use setString( Graphics g, String str ) instead.
|
void |
setString(java.awt.Font font,
java.lang.String label)
reset the current string for the GTR to draw, calculating the boundaries
of the string.
|
void |
setString(java.awt.Graphics g,
java.lang.String str)
reset the current string for the GTR to draw, calculating the boundaries
of the string.
|
java.lang.String |
toString() |
public static final float LEFT_ALIGNMENT
public static final float CENTER_ALIGNMENT
public static final float RIGHT_ALIGNMENT
public static final java.lang.String PROP_GLOW
public void addPainter(java.lang.String id, GrannyTextRenderer.Painter p)
id
- id for the painter, where the id is found in the granny text stringp
- the painter code which draws on a graphics context.public void removePainter(java.lang.String id)
id
- id for the painter, where the id is found in the granny text stringpublic void clearPainters()
public java.awt.Rectangle getBounds()
java.lang.IllegalArgumentException
- if the string has not been set.public java.awt.geom.Rectangle2D getBounds2D()
public double getWidth()
java.lang.IllegalArgumentException
- if the string has not been set.public double getLineOneWidth()
java.lang.IllegalArgumentException
- if the string has not been set.public double getHeight()
java.lang.IllegalArgumentException
- if the string has not been set.public double getAscent()
java.lang.IllegalArgumentException
- if the string has not been set.public double getDescent()
java.lang.IllegalArgumentException
- if the string has not been set.public void setString(java.awt.Component c, java.lang.String str)
c
- the component which will provide the graphics.str
- the granny string, such as "E=mc!e2"public void setString(java.awt.Graphics g, java.lang.String str)
g
- the graphics context which will supply the FontMetrics.str
- the granny string, such as "E=mc!e2"public void setString(java.awt.Font font, java.lang.String label)
font
- the font. This should be consistent
with the Font used when drawing.label
- the granny string, such as "E=mc!e2"public java.lang.String getString()
public float getAlignment()
public void setAlignment(float a)
a
- the alignment, one of LEFT_ALIGNMENT CENTER_ALIGNMENT or RIGHT_ALIGNMENT.public boolean isGlow()
public void setGlow(boolean glow)
public void draw(java.awt.Graphics ig, float ix, float iy)
ig
- Graphic object to use to render the text.ix
- The x position of the first character of text.iy
- The y position of the baseline of the first line of text.public java.lang.String toString()
toString
in class java.lang.Object
public static int lineCount(java.lang.String s)
s
- the string