## org.das2.util.GrannyTextRenderer

Utility class for rendering "Granny" strings, which use the codes identified by Grandle and Nystrom in their 1980 paper to provide rich formatting such as new lines and superscripts. This has been extended significantly to include some html support, and extensions which paint arbitrary graphics. Granny are strings like "E=mc!e2" where the "!e" indicates the pen should be moved to the exponent position before drawing. This supports sequences including:

     !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 underline

For Greek and math symbols, Unicode characters should be used like so: &#9742; (☎ phone symbol), or symbols like `&Omega;` and `&omega;` 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() )

## GrannyTextRenderer( )

## LEFT_ALIGNMENT

## CENTER_ALIGNMENT

## RIGHT_ALIGNMENT

## PROP_GLOW

## addPainter

addPainter( String id, org.das2.util.GrannyTextRenderer.Painter p ) → void

add a painter for the grannyTextRenderer. This is done by associating a Painter code with an id, and the id is used within the annotation string.

### Parameters

id - id for the painter, where the id is found in the granny text string
p - the painter code which draws on a graphics context.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## clearPainters

clearPainters( ) → void

remove all the painters

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## draw

draw( java.awt.Graphics ig, float ix, float iy ) → void

draw the current string. Note the first line will be above iy, and following lines will be below iy. This is to be consistent with Graphics2D.drawString.

### Parameters

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.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getAlignment

getAlignment( ) → float

returns the current alignment, by default LEFT_ALIGNMENT.

### Returns:

the current alignment.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getAscent

getAscent( ) → double

return the amount that the bounding box will go above the baseline. This is also the height of the first line.

### Returns:

the amount that the bounding box will go above the baseline.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getBounds

getBounds( ) → java.awt.Rectangle

returns the bounds of the current string. The lower-left corner of the first character will be roughly (0,0), to be compatible with FontMetrics.getStringBounds().

### Returns:

a Rectangle indicating the text boundaries.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getBounds2D

getBounds2D( ) → java.awt.geom.Rectangle2D

return a rectangle backed by floating point numbers.

### Returns:

Rectangle2D.Double
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getDescent

getDescent( ) → double

return the amount that the bounding box will go below the baseline.

### Returns:

the amount that the bounding box will go below the baseline.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getHeight

getHeight( ) → double

returns the hieght of the calculated bounding box.

### Returns:

the height of the bounding box, in pixels.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getLineOneWidth

getLineOneWidth( ) → double

returns the width in pixels of the first line.

### Returns:

the width in pixels of the first line.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getString

getString( ) → String

return the string.

### Returns:

a String
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getWidth

getWidth( ) → double

returns the width of the bounding box, in pixels.

### Returns:

the width of the bounding box, in pixels.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## isGlow

isGlow( ) → boolean

### Returns:

boolean
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## lineCount

lineCount( String s ) → int

count the number of lines in the string, breaking on "!c" or "<br>", ignoring empty lines at the beginning.

### Parameters

s - the string

### Returns:

the number of lines
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## removePainter

removePainter( String id ) → void

remove the painter with the given id.

### Parameters

id - id for the painter, where the id is found in the granny text string

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## setAlignment

setAlignment( float a ) → void

set the alignment for rendering, one of LEFT_ALIGNMENT CENTER_ALIGNMENT or RIGHT_ALIGNMENT.

### Parameters

a - the alignment, one of LEFT_ALIGNMENT CENTER_ALIGNMENT or RIGHT_ALIGNMENT.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## setGlow

setGlow( boolean glow ) → void

### Parameters

glow - a boolean

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## setString

Deprecated: use setString( Graphics g, String str ) instead.

## setString

setString( java.awt.Graphics g, String str ) → void

reset the current string for the GTR to draw, calculating the boundaries of the string. For greek and math symbols, unicode characters should be used. (See www.unicode.org).

### Parameters

g - the graphics context which will supply the FontMetrics.
str - the granny string, such as "E=mc!e2"

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## setString

setString( java.awt.Font font, String label ) → void

reset the current string for the GTR to draw, calculating the boundaries of the string. For greek and math symbols, unicode characters should be used. (See www.unicode.org).

### Parameters

font - the font. This should be consistent with the Font used when drawing.
label - the granny string, such as "E=mc!e2"

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## toString

toString( ) → String

### Returns:

java.lang.String
[search for examples] [view on GitHub] [view on old javadoc] [view source]