cz.cuni.jagrlib.piece
Class JavaText

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.piece.JavaText
All Implemented Interfaces:
Breakable, Property, Render, TextRender, Template

public class JavaText
extends Piece
implements TextRender

Text drawing using Graphics implementation.

Since:
0.25
See Also:
JavaText.java

Nested Class Summary
 
Nested classes/interfaces inherited from interface cz.cuni.jagrlib.iface.TextRender
TextRender.TextExtent
 
Field Summary
protected  boolean actAntialiasing
          Use antialiasing?
protected  int antialiasing
          Antialiasing logic.
protected static int CACHE_GRANUL
          Font cache size granularity.
protected static java.lang.String CATEGORY
          Object category.
protected  double coso
          Accelerator: cos( orientation ).
protected  java.awt.Font[] fonts
          Font slots.
protected  java.awt.Graphics2D graphics
          Graphics associated with the current surface.
protected  boolean chAntialiasing
          Change anti-aliasing mode before next text rendering?
protected static double INV255
          Multiplier 1 / 255.
protected  double orientation
          Actual font orientation.
static RegPiece reg
          Static registration instance for this class.
protected  double sino
          Accelerator: sin( orientation ).
protected  java.awt.image.BufferedImage surface
          Font rendering surface.
protected  int surfaceHei
          Actual surface height in pixels (granularity CACHE_GRANUL).
protected  int surfaceWid
          Actual surface width in pixels (granularity CACHE_GRANUL).
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.iface.TextRender
ANTI_DEPEND, ANTI_MODE, ANTI_OFF, ANTI_ON, CREATE_APPROX, CREATE_EXACT, CREATE_FAIL, FONT_BOLD, FONT_DECORATIVE, FONT_ICON, FONT_ITALIC, FONT_MONOSPACED, FONT_SCRIPT, FONT_SERIF, FONT_UNDERLINE, MAX_SLOT, PROP_BITMAP, PROP_FILL, PROP_MONOSPACED, PROP_STROKE
 
Fields inherited from interface cz.cuni.jagrlib.iface.Render
LINE_CAP, LINE_CAP_BUTT, LINE_CAP_ROUND, LINE_CAP_SQUARE, LINE_JOIN, LINE_JOIN_BEVEL, LINE_JOIN_DISJOINT, LINE_JOIN_MITER, LINE_JOIN_OVERLAP, LINE_JOIN_ROUND, LINE_WIDTH, PROJECTION, RENDER_STYLE, RENDER_STYLE_FLAT, RENDER_STYLE_GOURAUD, RENDER_STYLE_LINE, RENDER_STYLE_PHONG, RENDER_STYLE_TEXTURE
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Fields inherited from interface cz.cuni.jagrlib.Template
ALL_PLUGS, C_1D, C_2D, C_3D, C_ALPHA, C_BINARY, C_BREP, C_CAMERA, C_CIRCLE, C_CLIP, C_COMPRESSION, C_CURVE, C_DATA, C_DRAW, C_EDITOR, C_ELLIPSE, C_FILL, C_FILTER, C_FLOAT, C_FUNCTION, C_IMAGE, C_INTEGER, C_IO, C_LIGHT, C_LINE, C_METRIC, C_POLYGON, C_PROJECTION, C_RADIOSITY, C_RASTER, C_RENDER, C_SAMPLE, C_SCENE, C_SET, C_SOLID, C_TEXT, C_TRANSFORM, C_VECTOR, C_VIEWER, C_WORKER, CAT_EMPTY, EMPTY, IFACE, JAGRLIB, JAGRLIB2, MANIPULATOR_COMBO, MANIPULATOR_CUSTOM, MANIPULATOR_DEFAULT, MANIPULATOR_MULTILINE, PL_ALPHAMASK, PL_BITMASK, PL_CAUSTIC, PL_CODEC, PL_COLORMAP, PL_COMPARE, PL_DATA, PL_DIRECT, PL_EDITOR, PL_FILTER, PL_FUNCTION, PL_IMAGE, PL_IMPORT, PL_INPUT, PL_INTERSECTION, PL_LIGHTSOURCE, PL_ORDER, PL_OUTPUT, PL_PALETTE, PL_PHOTON, PL_PROPERTY, PL_QUANTIZER, PL_RASTER, PL_RENDER, PL_SHADOW, PL_STREAM, PL_TRANSFORM, PL_TRIGGER, PL_VOLUME, PL_WINDOW, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LONG, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
JavaText()
           
 
Method Summary
 int createFont(java.lang.String name, int style, double size)
          Creates a new font and places it in slot A (actual, working font).
 void drawText(double x0, double y0, java.lang.String text, TextRender.TextExtent ext)
          Draws the given text.
 double fontOrientation(double angle)
          Changes the actual font's orientation.
 int fontProperties()
          Returns properties (flags) of the actual font (slot A).
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 void getFont(int slot)
          Assigns the actual font (slot A) from the given slot.
 TextRender.TextExtent getKern(char c1, char c2, TextRender.TextExtent ext)
          Returns the kerning (space correction) which should be used between two given characters.
protected  void prepareSurface(int width, int height)
          Asserts enough space for the given text bounds (and clears the surface).
 void putFont(int slot)
          Puts the actual font (slot A) into the given slot.
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 TextRender.TextExtent textExtent(double x0, double y0, java.lang.String text, TextRender.TextExtent ext)
          Computes the extent of the given text string (without any output change).
 void textPath(java.lang.String text)
          Generates path of the given text string and appends it to the current path.
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, init, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, commit, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, stringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.jagrlib.iface.Property
commit
 

Field Detail

CACHE_GRANUL

protected static final int CACHE_GRANUL
Font cache size granularity.

See Also:
Constant Field Values

INV255

protected static final double INV255
Multiplier 1 / 255.

See Also:
Constant Field Values

surface

protected java.awt.image.BufferedImage surface
Font rendering surface.


graphics

protected java.awt.Graphics2D graphics
Graphics associated with the current surface.


surfaceWid

protected int surfaceWid
Actual surface width in pixels (granularity CACHE_GRANUL).


surfaceHei

protected int surfaceHei
Actual surface height in pixels (granularity CACHE_GRANUL).


orientation

protected double orientation
Actual font orientation.


sino

protected double sino
Accelerator: sin( orientation ).


coso

protected double coso
Accelerator: cos( orientation ).


actAntialiasing

protected boolean actAntialiasing
Use antialiasing? Actual status, depends either on output module type or on TextRender.ANTI_MODE property.


chAntialiasing

protected boolean chAntialiasing
Change anti-aliasing mode before next text rendering?


antialiasing

protected int antialiasing
Antialiasing logic.


fonts

protected java.awt.Font[] fonts
Font slots. Active font is in fonts[0].


TEMPLATE_NAME

protected static final java.lang.String TEMPLATE_NAME
Object template identifier.

See Also:
Constant Field Values

CATEGORY

protected static final java.lang.String CATEGORY
Object category.

See Also:
Constant Field Values

reg

public static final RegPiece reg
Static registration instance for this class. Automatically initialized in class-loading time.

Constructor Detail

JavaText

public JavaText()
Method Detail

prepareSurface

protected void prepareSurface(int width,
                              int height)
Asserts enough space for the given text bounds (and clears the surface).


createFont

public int createFont(java.lang.String name,
                      int style,
                      double size)
Creates a new font and places it in slot A (actual, working font).

Specified by:
createFont in interface TextRender
Parameters:
name - Font name.
style - Font style - used if exact font match was not successful (bitwise OR of TextRender.FONT_* constants).
size - Font size (distance between two regularly spaced text lines).
Returns:
Result code (one of TextRender.CREATE_* constants).
See Also:
TextRender.FONT_BOLD, TextRender.CREATE_EXACT, VCommand.CreateFont

fontOrientation

public double fontOrientation(double angle)
Changes the actual font's orientation.

Specified by:
fontOrientation in interface TextRender
Parameters:
angle - New font orientation (in degrees, counterclockwise).
Returns:
The old orientation.
See Also:
VCommand.FontOrientation

getFont

public void getFont(int slot)
Assigns the actual font (slot A) from the given slot.

Specified by:
getFont in interface TextRender
Parameters:
slot - Slot number (between 0 and MAX_SLOT - 1).
See Also:
TextRender.MAX_SLOT, VCommand.GetFont

putFont

public void putFont(int slot)
Puts the actual font (slot A) into the given slot.

Specified by:
putFont in interface TextRender
Parameters:
slot - Slot number (between 0 and MAX_SLOT - 1).
See Also:
TextRender.MAX_SLOT, VCommand.PutFont

fontProperties

public int fontProperties()
Returns properties (flags) of the actual font (slot A).

Specified by:
fontProperties in interface TextRender
Returns:
Bitwise OR of PROP_* constants.
See Also:
TextRender.PROP_STROKE

textPath

public void textPath(java.lang.String text)
Generates path of the given text string and appends it to the current path. Uses the current point as starting reference point (current point itself will be updated by this command).

Does nothing if the actual font has neither TextRender.PROP_STROKE nor TextRender.PROP_FILL capability.

Specified by:
textPath in interface TextRender
Parameters:
text - The string to be drawn.
See Also:
textExtent(double, double, java.lang.String, cz.cuni.jagrlib.iface.TextRender.TextExtent), drawText(double, double, java.lang.String, cz.cuni.jagrlib.iface.TextRender.TextExtent), VCommand.MoveTo, VectorGraphics.moveTo(double, double), VCommand.TextPath

drawText

public void drawText(double x0,
                     double y0,
                     java.lang.String text,
                     TextRender.TextExtent ext)
Draws the given text. Starting reference point is explicitly specified. If ext parameter is not null, the routine fills the given TextExtent object.

Works with both vector and bitmap fonts.

Specified by:
drawText in interface TextRender
Parameters:
x0 - X coordinate of the starting reference point.
y0 - Y coordinate of the starting reference point.
text - The string to be drawn.
ext - The TextExtent object to be filled (or null).
See Also:
TextRender.TextExtent, textExtent(double, double, java.lang.String, cz.cuni.jagrlib.iface.TextRender.TextExtent), VCommand.DrawText

textExtent

public TextRender.TextExtent textExtent(double x0,
                                        double y0,
                                        java.lang.String text,
                                        TextRender.TextExtent ext)
Computes the extent of the given text string (without any output change).

Specified by:
textExtent in interface TextRender
Parameters:
x0 - X coordinate of the starting reference point.
y0 - Y coordinate of the starting reference point.
text - The string to be drawn.
ext - The TextExtent object to be filled (or null).
Returns:
The filled TextExtent object.
See Also:
TextRender.TextExtent, drawText(double, double, java.lang.String, cz.cuni.jagrlib.iface.TextRender.TextExtent)

getKern

public TextRender.TextExtent getKern(char c1,
                                     char c2,
                                     TextRender.TextExtent ext)
Returns the kerning (space correction) which should be used between two given characters.

Specified by:
getKern in interface TextRender
Parameters:
c1 - First character.
c2 - Second character.
ext - The TextExtent object to be filled (or null).
Returns:
The filled TextExtent object (only dx and dy are used).
See Also:
TextRender.TextExtent, textExtent(double, double, java.lang.String, cz.cuni.jagrlib.iface.TextRender.TextExtent)

set

public void set(java.lang.String key,
                java.lang.Object value)
Sets the given property.

Specified by:
set in interface Property
Overrides:
set in class DefaultProperty
Parameters:
key - Key string.
value - The new value.
See Also:
Property.commit()

get

public java.lang.Object get(java.lang.String key)
Gets the given property.

Specified by:
get in interface Property
Overrides:
get in class DefaultProperty
Parameters:
key - Key string.
Returns:
The actual value or null.

setTemplate

public static int setTemplate(Template t,
                              int ord)
General-purpose registration routine. Sets all plugs, strings, etc. to the given Template.