uavsim.graphics.text
Class VectorText

java.lang.Object
  extended by uavsim.graphics.text.VectorText

public class VectorText
extends java.lang.Object

Renders text strings as scalable vector line drawings. ASCII characters 32 through 126 are supported; any other character appears as a small diamond that indicates it is undefined. In addition, ASCII 127 and 128 are special left and right arrows, respectively.

Author:
Dan Tappan [10.04.11]

Field Summary
private  java.awt.Graphics2D _graphics
          the graphics context
private static int ANCHOR_SIZE
          the size of the anchor in pixels
private static double ITALICS_GRADIENT
          the slant run over rise for italic characters
private static boolean SHOW_ANCHOR
          whether to show the anchor for the text string.
 
Constructor Summary
VectorText(java.awt.Graphics2D graphics)
          Creates a vector text object.
 
Method Summary
static double calculateAngle(double x, double y)
          Calculates the vector angle from a Cartesian coordinate.
static double calculateRadius(double x, double y)
          Calculates the vector length from a Cartesian coordinate.
 java.awt.Polygon generateBoundingPolygon(java.lang.String text, TextProperties textProperties, java.awt.Point anchor)
          Generates a bounding polygon for a formatted text string.
private  int[][][] generateText(java.lang.String text, TextProperties textProperties)
          Generates the staging grid of vector line segments corresponding to a formatted text string.
static java.awt.Dimension getTextDimensions(java.lang.String text, TextProperties textProperties)
          Determines the bounding box of a formatted text string in its canonical form (i.e., not rotated).
static java.awt.Point getTextOrigin(java.lang.String text, TextProperties textProperties)
          Determines the origin of the bounding box of a formatted text string in its canonical form (i.e., not rotated).
 void renderText(java.lang.String text, TextProperties textProperties, java.awt.Point anchor)
          Renders a text string as scalable vector line drawing.
private  void renderText(java.lang.String text, TextProperties textProperties, java.awt.Point anchor, int[][][] stagingGrid)
          Renders the staging grid.
static java.awt.Point rotatePoint(double angleDegrees, double radius)
          Generates a screen coordinate from an angle and radius.
static int round(double value)
          Rounds a value to the nearest integer.
static java.awt.Point transformPoint(int x, int y, java.awt.Point origin, java.awt.Point anchor, double angleDegrees)
          Transforms a point by rotating and translating it.
private  void transformText(java.lang.String text, TextProperties textProperties, java.awt.Point anchor, int[][][] stagingGrid)
          Transforms the staging grid according to through rotation and translation.
static int translate(int value, int anchor)
          Translates a value offset by an anchor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_graphics

private final java.awt.Graphics2D _graphics
the graphics context


ANCHOR_SIZE

private static final int ANCHOR_SIZE
the size of the anchor in pixels

See Also:
Constant Field Values

ITALICS_GRADIENT

private static final double ITALICS_GRADIENT
the slant run over rise for italic characters

See Also:
Constant Field Values

SHOW_ANCHOR

private static final boolean SHOW_ANCHOR
whether to show the anchor for the text string. This is a debugging feature

See Also:
Constant Field Values
Constructor Detail

VectorText

public VectorText(java.awt.Graphics2D graphics)
Creates a vector text object.

Parameters:
graphics - - the graphics context
Method Detail

calculateAngle

public static double calculateAngle(double x,
                                    double y)
Calculates the vector angle from a Cartesian coordinate.

Parameters:
x - - the x value
y - - the y value
Returns:
the angle in radians

calculateRadius

public static double calculateRadius(double x,
                                     double y)
Calculates the vector length from a Cartesian coordinate.

Parameters:
x - - the x value
y - - the y value
Returns:
the length

generateBoundingPolygon

public java.awt.Polygon generateBoundingPolygon(java.lang.String text,
                                                TextProperties textProperties,
                                                java.awt.Point anchor)
Generates a bounding polygon for a formatted text string. This does consider rotation.

Parameters:
text - - the text
textProperties - - the text properties
anchor - - the text anchor
Returns:
the polygon

generateText

private int[][][] generateText(java.lang.String text,
                               TextProperties textProperties)
Generates the staging grid of vector line segments corresponding to a formatted text string.

Parameters:
text - - the text
textProperties - - the text properties
Returns:
the grid as [char_index][segment_index][x1,y1,x2,y2]

getTextDimensions

public static java.awt.Dimension getTextDimensions(java.lang.String text,
                                                   TextProperties textProperties)
Determines the bounding box of a formatted text string in its canonical form (i.e., not rotated).

Parameters:
text - - the text
textProperties - - the text properties
Returns:
the bounding box in pixels

getTextOrigin

public static java.awt.Point getTextOrigin(java.lang.String text,
                                           TextProperties textProperties)
Determines the origin of the bounding box of a formatted text string in its canonical form (i.e., not rotated).

Parameters:
text - - the text
textProperties - - the text properties
Returns:
the origin in pixels

renderText

public void renderText(java.lang.String text,
                       TextProperties textProperties,
                       java.awt.Point anchor)
Renders a text string as scalable vector line drawing.

Parameters:
text - - the text
textProperties - - the text properties
anchor - - the text anchor

renderText

private void renderText(java.lang.String text,
                        TextProperties textProperties,
                        java.awt.Point anchor,
                        int[][][] stagingGrid)
Renders the staging grid.

Parameters:
text - - the text
textProperties - - the text properties
anchor - - the text anchor
stagingGrid - -the grid as [char_index][segment_index][x1,y1,x2,y2]

rotatePoint

public static java.awt.Point rotatePoint(double angleDegrees,
                                         double radius)
Generates a screen coordinate from an angle and radius.

Parameters:
angleDegrees - - the angle in mathematical degrees
radius - - the radius
Returns:
the point in the same units as radius

round

public static int round(double value)
Rounds a value to the nearest integer.

Parameters:
value - - the value
Returns:
the result

transformPoint

public static java.awt.Point transformPoint(int x,
                                            int y,
                                            java.awt.Point origin,
                                            java.awt.Point anchor,
                                            double angleDegrees)
Transforms a point by rotating and translating it.

Parameters:
x - - the x value
y - - the y value
origin - - the origin about which to rotate the point
anchor - - the target position to translate the rotated point to
angleDegrees - - the angle of rotation in degrees
Returns:
the new point

transformText

private void transformText(java.lang.String text,
                           TextProperties textProperties,
                           java.awt.Point anchor,
                           int[][][] stagingGrid)
Transforms the staging grid according to through rotation and translation.

Parameters:
text - - the text
textProperties - - the text properties
anchor - - the text anchor
stagingGrid - -the grid as [char_index][segment_index][x1,y1,x2,y2], which is updated in place

translate

public static int translate(int value,
                            int anchor)
Translates a value offset by an anchor.

Parameters:
value - - the value
anchor - - the anchor to add to the value
Returns:
the result