dojox.gfx 0.9 documentation
Underlying concepts
dojox.gfx is a cross-platform declarative interactive graphics package. It follows SVG loosely as the underlying model. At present time SVG and VML back-ends are implemented.
On conceptual level dojox.gfx has a simple declarative model:
-
All basic primitives required for 2D graphics are defined:
-
2D coordinates
-
2D linear transformation matrices
-
colors
-
There is a surface, which serves as a visual rectangular container for shapes:
-
A web page can have several surfaces defined.
-
Each surface has its own local coordinate system:
-
(0, 0) point is in the left-top corner, where the X axis is horizontal pointing right, and the Y axis is vertical pointing down.
-
Positive direction of rotation is defined as clockwise (CW).
-
There is a notion of a shape description object, which represent a simple description of geometry, with corresponding shape objects. dojox.gfx supports following shapes:
-
Rectangle (optionally with rounded corners).
-
Circle.
-
Ellipse.
-
Line.
-
Polyline/polygon.
-
Path (the most versatile shape). It implements the full SVG path language.
-
Image.
-
Text.
-
TextPath (highly experimental at the moment).
-
Shapes support following set of properties:
-
Geometric properties:
-
Shape description (shape-specific).
-
Linear transformation specified by 3 x 3 2D matrix.
-
Font (only for text shapes).
-
Visual properties (not supported by the image shape):
-
Stroke (outline of a shape).
-
Fill (interior of a shape).
-
Shapes are stacked from bottom to top in an order of their definition. This z-order can be changed dynamically.
-
There is a group, which is a pseudo-shape. It combines other shapes (and possibly groups), and can be used to apply transformation to a group. All group members share a single z-order, but can be re-arranged within a group.
In order to draw a picture a programmer constructs a pseudo-DOM from a surface object, shapes, and groups, sets appropriate attributes, and picture is drawn automatically by a browser. Modifications of shapes change picture automatically. It is possible to attach event handlers to shapes using dojox.connect().
Following conventions are used:
-
While a path is the most universal geometric shape, which can emulate almost all other shapes (exceptions: image, and text shapes), all frequently-used shapes are provided as a convenience: rectangle (with optionally rounded corners), circle, ellipse, line, polyline/polygon.
-
All shape description properties are defined using a duck-typing technique. Incomplete shape description definitions are supported. All missing members will be taken from corresponding default shape definitions listed in common.js or from the current shape description object. Example: rect.setShape({width: 200}) - all missing members will be taken from dojox.gfx.defaultRect object making it equivalent to rect.setShape({x: 0, y: 0, width: 200, height: 100, r: 0}).
-
All shape description objects and visual property objects have a member called "type", which uniquely identifies a property type. This is a provision for a possible serialization.
-
Certain shape properties can be defined using shortcuts:
-
Path can be defined as a string of path commands (more on path later):
-
path.setShape("m 0,0 l 100, 100 e") is equivalent to path.setShape({path: "m 0,0 l 100, 100 e"}).
-
Polylines/polygons can be defined as an array of points:
-
poly.setShape([{x: 0, y: 0}, {x: 100, y: 100}]) is equivalent to poly.setShape({points: [{x: 0, y: 0}, {x: 100, y: 100}]}).
-
Stroke can be defined by specifying a color as a string:
-
shape.setStroke("black") is equivalent to shape.setStroke({color: "black"}).
-
All methods without an apparent return type return their object itself. It is used for chaining multiple operations:
-
surface.createRect({x: 100, y: 50}).setFill("red").setStroke("blue");
Common shape methods
All shape objects support following methods:
-
getShape()/setShape(shape) accesses an underlying shape description object. A group shape ignores this property.
-
getStroke()/setStroke(stroke) accesses a stroke applied to a shape. Value of "null" means "do not stroke this shape". Image and group shapes ignore this property.
-
getFill()/setFill(fill) accesses a fill applied to a shape. Value of "null" means "do not fill this shape". Image and group shapes ignore this property.
-
getTransform()/setTransform(matrix) accesses a transformation matrix applied to a shape.
-
applyRightTransform(matrix)/applyLeftTransform(matrix) combines the existing matrix with new matrix. See "Transformation matrix" for details.
-
applyTransform(matrix) is an alias for applyRightTransform(matrix). It is defined for convenience.
-
moveToFront()/moveToBack() changes a z-order of a shape. It moves an object to the front or to the back respectively of its parent container (a surface or a group).
-
removeShape() removes a shape from its parent container.
-
getParent() accesses shape's parent container.
-
getBoundingBox() returns a bounding box of a shape. A text shape is a point-based object, so it doesn't define a bounding box.
-
getNode() returns a top node of a shape implementation (some shapes are implemented as a combination of nodes). It can be used for some low-level manipulations.
-
getEventSource() returns an object (usually a node), which can be used to attach an event processing handlers. It can be different from a top node.
Visual properties
Color
Anywhere color is accepted following objects can be used to define it:
-
A valid color name, like: "white", "black", "red", "green", "lime", "blue", "navy", "gray", "silver". If you want to support all CSS3 color names, don't forget to require dojo.colors module, which provides all necessary CSS3 compatibility.
-
A valid CSS color code, e.g., "#FF0000" or "#f00".
-
An array of RGB or RGBA values, e.g, [255, 0, 0] or [255, 0, 0, 1.0].
-
A valid dojo.Color object.
Stroke property
A stroke property is an object that defines how to draw an outline of a shape. It is not supported by an image and a group shapes. Following properties are recognized:
-
color defines a color of an outline. Default: "black".
-
style defines a dash pattern. Accepted values: "Solid", "ShortDash", "ShortDot", "ShortDashDot", "ShortDashDotDot", "Dot", "Dash", "LongDash", "DashDot", "LongDashDot", "LongDashDotDot", and "none" (the same as "Solid"). These values have been modeled after VML's dashStyle parameter, and behave similarly (dash pattern is specified in terms of line width).
-
width defines a width of a stroke in pixels. It should be a positive number. Default: 1.
-
cap defines a shape of opening and closing of a line. Accepted values: "butt", "round", "square" (see SVG 1.1 'stroke-linecap' definition for details). Default: "butt".
-
join defines a shape of joints. Accepted values: "round", "bevel", or a positive number. In case of a number a "miter" style is used with the number defining a miter limit (see SVG 1.1 'stroke-linejoin' definition and SVG 1.1 'stroke-miterlimit' definition for details). Default: 4.
By default all shapes are created with "null" stroke meaning "no stroke is performed".
If a string was specified as a stroke property, it is interpreted as a color, the rest is taken from defaults.
Fill property
A fill property is an object that defines how to fill a shape. It is not supported by an image and a group shapes. Four types of fills can be used:
-
Solid color fill. It is in effect when a color was specified as a fill property.
-
Linear gradient defines a smooth transition between a set of colors (so-called "stops") on a line. Following properties are recognized:
-
x1, y1 define a start point of linear gradient. Defaults: 0, 0.
-
x2, y2 define an end point of a linear gradient. Defaults: 100, 100.
-
colors defines an array of stop objects, which have following structure:
-
offset a number from 0 to 1, which defines a position of a color on our line. 0 corresponds to x1, y1 point. 1 corresponds to x2, y2 point. 0.5 will be directly in the middle of a line.
-
color a color for this stop.
-
colors has a following default value: [{offset: 0, color: "black"}, {offset: 1, color: "white"}].
-
Radial gradient defines a smooth transition between stops on a circle. Following properties are recognized:
-
cx, cy define a center of a radial gradient. Defaults: 0, 0.
-
r defines a radius of a radial gradient.
-
colors defines an array of stops in the same way as a linear gradient object. 0 corresponds to a center of a circle. 1 corresponds to a circle's border. Defaults: [{offset: 0, color: "black"}, {offset: 1, color: "white"}].
-
Pattern defines an infinite tiling of an image. Following properties are recognized:
-
x, y define an offset of a reference rectangle for an image. Defaults: 0, 0.
-
width, height define a size of a reference rectangle. An image will be fit into this reference rectangle using scaling. Defaults: 0, 0.
-
src defines a URL of an image to be tiled.
By default all shapes are created with "null" fill meaning "no fill is performed".
Important implementation details for VML renderer:
-
Linear gradient should start and stop on a border of a shape. All other line definitions will be visually incompatible with the SVG implementation of the linear gradient.
-
Radial gradient repeats the shape of an object. It means that the only way to define a compatible radial gradient for SVG and VML renderers is to define it from a center of a circle shape.
Geometric properties
Coordinates and transformations
Linear transformations are a very important part of any graphics library. We deal with 2D graphics, and we operate with 3 by 3 matrices:
xx xy dx
yx yy dy
0 0 1
Because the third row is always constant we use an abbreviated way to write it: {xx: 1, xy: 0, yx: 0, yy: 1, dx: 0, dy: 0} - this is an identity matrix. The same simplification goes for coordinates:
x
y
1
Because the third element is always 1 we "add" it virtually: {x: 12, y: 33}. The result of application of a matrix to a vector is predictable:
xx * x + xy * y + dx
yx * x + yy * y + dy
(I skipped the dummy third "coordinate").
In order to understand transformations you need to be familiar with fundamentals of
matrices (matrix multiplication, multiplication of a vector by a matrix, order of multiplications). dojox.gfx uses a mnemonic way to describe a matrix: xx scales an X component of a coordinate, yy scales a Y component, xy, and yx affect both components, dx moves an X component, and dy moves a Y component.
Simple examples:
-
{xx: 2} - stretches the X dimension by 2.
-
{yy: 0.5} - "stretches" the Y dimension by 0.5 (reduces by 2).
-
{dx: 5, dy: 10} - shifts an X coordinate by 5, a Y coordinate by 10.
More complex examples:
-
{xx: 0.866, xy: 0.5, yx: -0.5, yy: 0.866} - rotates everything by 30 degrees clockwise (CW) around point (0, 0).
-
{xx: 0, xy: 1, yx: -1, yy: 0, dx: 100} - rotates everything by 90 degrees CW around (0, 0), and moves things right by 100.
Don't worry, in most cases you don't need to calculate all members of a transformation matrix directly. As you can see not all members of matrix should be specified - all skipped members going to be copied from the identity matrix. There is a shortcut for scaling - if a number N is used instead of a matrix, it is assumed that it represents a uniform scaling matrix {xx: N, yy: N}.
The way to apply a matrix to a coordinate:
-
o = M * i - where, i is an input vector (e.g., {x: 1, y: 2}), M is a transformation matrix, o is a resulting vector, and * denotes a multiplication operation.
The way to combine transformations together:
-
A * B * C * p == (A * B) * C * p == A * (B * C) * p == (A * B * C) * p == A * B * (C * p), and so on, where A, B, and C are transformation matrices, p is a coordinate vector, and * is a multiplication operation. The result of all these calculations is the same final coordinate.
Effectively all transformations are always applied from right to left sequentially, and they can be combined producing a matrix, which defines a complex transformation. dojox.gfx.matrix defines Matrix2D class, as well as numerous helpers (Matrix2D is propagated to dojox.gfx namespace for convenience). Most important of them (all in dojox.gfx.matrix namespace) are listed below. In all signatures a, b, c, and e are numbers (coordinate components or scaling factors), p is a 2D coordinate, r is an angle in radians, d is an angle in degrees (positive value of an angle is CW), m is a matrix.
Constants:
-
identity - a constant, which defines an identity matrix. This matrix doesn't change a picture at all.
-
flipX - a constant matrix, which changes a sign of all X coordinates. This matrix mirrors the picture around the Y axis.
-
flipY - a constant matrix, which changes a sign of all Y coordinates. This matrix mirrors the picture around the X axis.
-
flipXY - a constant matrix, which changes a sign of all coordinates. This matrix rotates the picture by 180 degrees around (0, 0) point. Another way to say it: it mirrors all points around (0, 0).
Matrix creators:
-
translate(a, b), translate(p) - shifts everything:
-
by {dx: a, dy: b}
-
by {dx: p.x, dy: p.y}
-
scale(a, b), scale(a), scale(p) - scales a picture:
-
by {xx: a, yy: b}
-
by {xx: a, yy: a}
-
by {xx: p.x, yy: p.y}
-
rotate(r), rotateg(d) - rotates a picture around (0, 0):
-
by r radians
-
by d degrees
-
skewX(r), skewXg(d) - skews a picture around (0, 0) in the X dimension:
-
by r radians
-
by d degrees
-
skewY(r), skewYg(d) - skews a picture around (0, 0) in the Y dimension:
-
by r radians
-
by d degrees
Useful operations:
-
invert(m) - inverts a matrix. This useful function calculates a matrix, which will do the opposite transformation to the m matrix effectively undoing it. For example, scale(2) produces a matrix to scale uniformly a picture by 2. The opposite matrix is going to be scale(0.5). We can produce the same result with invert(scale(2)). While it seems complicated for such a simple case, frequently it is the only way to calculate an inverted matrix for complex transformation, especially when we don't know how it was produced initially.
-
clone(m) - creates a copy of the m matrix.
-
multiplyPoint(m, a, b), multiplyPoint(m, p) - applies a transformation to a coordinate.
-
multiply(m1, m2, ...) - multiplies all its parameters to create a single matrix.
The last function is extremely useful and there is a shortcut for it: anywhere a matrix is expected, an array of matrices can be specified as well. Examples:
-
[2, rotateg(45)] - rotates everything 45 degrees CW around (0, 0) and scales everything by 2 after that.
-
[{dy: 10}, scale(2, 1)] - scales all X coordinates by 2, and moves the result down by 10.
More complex example: imagine you have a surface 500 by 500 pixels, and you want everything in it to be magnified around its center by 2, and rotated (around the center as well) by 30 degrees CW. It is easy: [translate(250, 250), rotateg(-30), scale(2), translate(-250, -250)]. Explanations:
-
All scaling, rotating, and skewing operations work around (0, 0) point. Let's move the center of our picture to (0, 0): translate(-250, -250).
-
Now we can scale it: scale(2).
-
Now we can rotate it: rotateg(-30).
-
Now let's move our center back: translate(250, 250).
This "around the point" operations are so important that there are several helpers for common transformations:
-
scaleAt(a, p), scaleAt(a, b, c), scaleAt(a, b, p), scaleAt(a, b, c, e):
-
scale(a) around (p.x, p.y)
-
scale(a) around (b, c)
-
scale(a, b) around (p.x, p.y)
-
scale(a, b) around (c, e)
-
rotateAt(r, p), rotateAt(r, a, b), rotategAt(d, p), rotategAt(d, a, b):
-
rotate(r) at (p.x, p.y)
-
rotate(r) at (a, b)
-
rotateg(d) at (p.x, p.y)
-
rotateg(d) at (a, b)
-
skewXAt(r, p), skewXAt(r, a, b), skewXgAt(d, p), skewXgAt(d, a, b), skewYAt(r, p), skewYAt(r, a, b), skewYgAt(d, p), skewYgAt(d, a, b):
-
skewX(r) at (p.x, p.y)
-
skewX(r) at (a, b)
-
skewXg(d) at (p.x, p.y)
-
skewXg(d) at (a, b)
-
skewY(r) at (p.x, p.y)
-
skewY(r) at (a, b)
-
skewYg(d) at (p.x, p.y)
-
skewYg(d) at (a, b)
There is one more useful function:
normalize(m), which returns a matrix in its canonical representation:
-
normalize(2)
-
normalize({dy: 5})
-
normalize([scale(2), translate(100, 200)])
The same effect can be achieved with creating a matrix directly: new dojox.gfx.Matrix2D(m).
Font property
Text shapes (Text and TextPath) require a font in order to be rendered. A font description follows familiar CSS conventions. Following properties of font are recognized:
-
style - the same as the CSS font-style property: "normal", "italic", "oblique". Default: "normal".
-
variant - the same as the CSS font-variant property: "normal", "small-caps". Default: "normal".
-
weight - the same as the CSS font-weight property: "normal", "bold", "bolder", "lighter", 100, 200, 300, 400, 500, 600, 700, 800, 900. Default: "normal".
-
size - the same as the CSS font-size property. Default: "10pt".
-
family - a string which defines a font family. Default: "serif".
There is a useful shortcut: you can specify a font using a string similar to
the CSS font property.
Implementation notes:
-
IE7 broke a lot of VML stuff. The family property doesn't work in IE7 at the moment but does work in IE6. IE7 uses Arial always. Unfortunately there is no workaround for that.
Individual graphics objects
This is a list of all important graphics objects and geometric shapes.
Surface
A surface is the main object, which represents a collection of shapes. No shapes can be drawn or created without a surface.
Following functions can be used to create a surface object:
-
dojox.gfx.createSurface(parentNode, width, height) returns a newly created surface object.
-
dojox.gfx.attachSurface(node) returns a re-created surface object built from an existing node. The node argument is assumed to be created by createSurface() function (rawNode member).
Surface supports following methods:
-
getEventSource() returns an object (usually a node), which can be used to attach an event processing handlers. It can be different from a top node.
-
getDimensions()/setDimensions(widht, height) accesses sizes set on the surface.
-
createShape(shape) creates a shape out of shape description object relying on the "type" member, returns a shape object. Useful for deserialization of shapes from an external source.
-
createPath(path), createRect(rect), createCircle(circle), createEllipse(ellipse), createLine(line), createPolyline(polyline), createImage(image), createText(text), createTextPath(textpath) create a corresponding shape returning a shape object. Note: the "type" member of a shape is implied and not required.
-
createGroup() creates a group object.
-
add(shape) adds a shape to a surface returning the surface itself. It is used to move shapes between groups and a surface.
-
remove(shape) removes a shape from a surface returning the surface itself. The shape can be added later to the same surface or a group.
-
clear() removes all shapes from a surface returning the surface itself.
Group
A group is a pseudo-shape, which represents a collection of shapes. Transformations applied to a group applied to all shapes of that group. It is used to aggregate shapes constructing a more complex shape, or to manage sub-pictures. The other way to use a group is to aggregate an event processing. It is planned to implement setting a (default) visual parameters to group's children including fill, stroke, and font properties.
A group combines features of a shape and a surface. It shares following methods with a shape:
-
getTransform()/setTransform(matrix) accesses a transformation matrix applied to a group.
-
applyRightTransform(matrix)/applyLeftTransform(matrix) combines the existing matrix with new matrix. See "Transformation matrix" for details.
-
applyTransform(matrix) is an alias for applyRightTransform(matrix). It is defined for convenience.
-
moveToFront()/moveToBack() changes a z-order of a group. It moves an object to the front or to the back respectively of its parent container (a surface or a group).
-
removeShape() removes a group from its parent container.
-
getParent() accesses group's parent container.
-
getNode() returns a top node of a group implementation. It can be used for some low-level manipulations.
It shares following methods with a surface:
-
createShape(shape) creates a shape out of shape description object relying on the "type" member, returns a shape object. Useful for deserialization of shapes from an external source.
-
createPath(path), createRect(rect), createCircle(circle), createEllipse(ellipse), createLine(line), createPolyline(polyline), createImage(image), createText(text), createTextPath(textpath) create a corresponding shape returning a shape object. Note: the "type" member of a shape is implied and not required.
-
createGroup() creates a group object.
-
add(shape) adds a shape to a surface returning the surface itself. It is used to move shapes between groups and a surface.
-
remove(shape) removes a shape from a surface returning the surface itself. The shape can be added later to the same surface or a group.
-
clear() removes all shapes from a surface returning the surface itself.
Rectangle
A rectangle is a basic rectangular shape with optionally rounded corners. It can be created by the createRect() method of a surface or a group. The default shape description for rectangle is defined as the dojox.gfx.defaultRect object. Here is a list of all properties and their defaults:
-
type is always "rect".
-
x, y are coordinates of a top-left corner in pixels. Defaults: 0, 0.
-
width, height are dimensions in pixels. Defaults: 100, 100.
-
r is a radius of rounded corners. Default: 0 (no rounded corners).
Circle
A circle is a basic shape. It can be created by the createCircle() method of a surface or a group. The default shape description for circle is defined as the dojox.gfx.defaultCircle object. Here is a list of all properties and their defaults:
-
type is always "circle".
-
cx, cy are coordinates of a center in pixels. Defaults: 0, 0.
-
r is a radius in pixels. Default: 100.
Ellipse
An ellipse is a basic shape. It can be created by the createEllipse() method of a surface or a group. The default shape description for ellipse is defined as the dojox.gfx.defaultEllipse object. Here is a list of all properties and their defaults:
-
type is always "ellipse".
-
cx, cy are coordinates of a center in pixels. Defaults: 0, 0.
-
rx, ry are horizontal and vertical radii (respectively) in pixels. Defaults: 200, 100.
An ellipse can be used to emulate a circle.
Line
A line is a basic shape that connects two points. It can be created by the createLine() method of a surface or a group. The default shape description for line is defined as the dojox.gfx.defaultLine object. Here is a list of all properties and their defaults:
-
type is always "line".
-
x1, y1 are coordinates of a start point in pixels. Defaults: 0, 0.
-
x2, y2 are coordinates of an end point in pixels. Defaults: 100, 100.
Polyline
A polyline is a basic shape, which can be used to represent polylines and polygons. It can be created by the createPolyline() method of a surface or a group. The default shape description for polyline is defined as the dojox.gfx.defaultPolyline object. Here is a list of all properties and their defaults:
-
type is always "polyline".
-
points is an array of 2D coordinates in pixels. Default: [].
Typically a polyline is an unfilled polygon. A polyline can be "open" and "closed". The latter means that the first and the last points are the same. When filling open polylines, an edge connecting the first and the last points is assumed.
A polyline can be used to emulate a line.
Path
A path is the most versatile geometric shape, which can emulate all other geometric shapes. It can be created by the createPath() method of a surface or a group. The default shape description for path is defined as the dojox.gfx.defaultPath object. Here is a list of all properties and their defaults:
-
type is always "path".
-
path is a string , which represents a path encoded in the SVG path language. Default: "".
A path can be open or closed. The latter means that the first and the last points are the same. When filling open paths, a straight line connecting the first and the last points is assumed.
Path supports following methods for building path segments programmatically:
-
moveTo(x,y) starts new segment abandoning the previous segment, if any. It takes a coordinate as a parameter.
-
lineTo(x,y) draws a straight line from the last point to the argument (coordinate).
-
hLineTo(x) draws a straight horizontal line from the last point using the argument (a number) as X position.
-
vLineTo(y) draws a straight vertical line from the last point using the argument (a number) as Y position.
-
curveTo(x1,y1,x2,y2,x,y) draws a cubic Bézier curve from the last point using arguments (two control points, and a final coordinate).
-
smoothCurveTo(x2,y2,x,y) draws a cubic Bézier curve from the last point using arguments. The difference between this method and curveTo() is that it accepts only one control point, which serves as the second control point. The first control is assumed to be a reflection of the second control point of the previous curve command.
-
qCurveTo(x1,y1,x,y) draws a quadratic Bézier curve from the last point using arguments (a control point, and a final point).
-
qSmoothCurveTo(x,y) draws a quadratic Bézier curve from the last point using arguments. The difference between this method and qCurveTo() is that it uses the reflected control point of the previous curve command.
-
arcTo(rx,ry,x_axis_rotation,large_arc_flag,sweep_flag,x,y) draws an elliptic arc from the last point using arguments (please see the above link for details).
-
closePath() closes the segment.
-
setAbsoluteMode(mode) sets an absolute or relative mode for coordinates. In the absolute mode all coordinates are assumed to be literal. In the relative mode all coordinates are offsets from the last point.
-
getAbsoluteMode() returns true, if the current mode is absolute.
-
getLastPosition() returns the last point, if there is one.
Implementation notes:
- All parameters can be repeated, if it makes sense. Example:
path.lineTo(1,1,2,2,3,3) is equivalent to
path.lineTo(1,1).lineTo(2,2).lineTo(3,3).
- A pair of coordinates
can be replaced by a single coordinate object. Example:
path.curveTo({x: 0.5, y: 0}, {x: 0.5, y: 1}, 1, 1) is equivalent to
path.curveTo(0.5, 0, 0.5, 1, 1, 1).
- All arrays are unrolled. Example: path.curveTo([0.5, 0, [0.5, 1]], [{x: 1, y: 1}]) is equivalent to path.curveTo(0.5, 0, 0.5, 1, 1, 1).
- You can specify a well-formed path string as an argument to setShape() metod of the path.
Image
An image is a shape that represents a resolution-independent color bitmap data. It can be created by the createImage() method of a surface or a group. The default shape description for image is defined as the dojox.gfx.defaultImage object. Here is a list of all properties and their defaults:
-
type is always "image".
-
x, y are coordinates of a top-left corner in pixels. Defaults: 0, 0.
-
width, height are dimensions in pixels. Defaults: 0, 0 - don't forget to set them to real values.
-
src is a URL of an image data pointing to a GIF, JPG, or PNG file. Default: "".
Changing width and height parameters you can stretch/shrink an image anisotropically.
Text
A text is a shape that anchors a text string to a point. It can be created by the createText() method of a surface or a group. It implements an additional text-specific method:
-
setFont(font) sets a font object.
The default shape description for text shape is defined as the dojox.gfx.defaultText object. Here is a list of all properties and their defaults:
-
type is always "text".
-
x, y are coordinates of a text anchor. Defaults: 0, 0.
-
text is a string of characters you want to show aligned to the anchor poistion. Default: "".
-
align is an alignment of a text in regards to the anchor position:
-
"start" - a text's baseline starts at the anchor. This is the default value of the align attribute.
-
"middle" - a text's baseline is centered on the anchor point.
-
"end" - a text's baseline ends at the anchor point.
-
decoration is a hint on how to render optional elements of a text:
-
"none" - text is not decorated. This is the default value.
-
"underline" - text is underlined.
-
"overline" - text has a line above it.
-
"line-through" - text has a line through the middle.
-
rotated is a Boolean value, which indicates:
-
false - all glyphs are unrotated. The is the default value.
-
true - all glyphs are rotated 90 degrees counter-clock-wise. This mode is useful for vertically arranged text.
-
kerning is a Boolean value, which indicates:
-
true - kerning is on. This is the default value.
-
false - kerning is off.
Implementation notes:
-
Text properties are loosely based on properties of the SVG text element.
-
IE7 broke a lot of VML stuff. Following things work in IE6 but don't work in IE7 (and there is no workaround for them):
-
decoration - it is always "none".
-
rotated - it is always false.
-
FF2 and Opera9 don't support following properties:
-
decoration - it is always "none".
-
rotated - it is always false.
TextPath
A text path is a shape that flows text along an arbitrary path. Text path properties are based on the text shape properties.
It can be created by the createTextPath() method of a surface or a group. The TextPath shape object implements all methods of a Path shape object, and two additional methods:
-
setFont(font) sets a font object.
-
setText(text) sets a text path shape description.
The default shape description for text path shape is defined as the dojox.gfx.defaultTextPath object. It resembles a lot a text description object. Here is a list of all properties and their defaults:
-
type is always "textpath".
-
text is a string of characters you want to show on a path. Default: "".
-
align is an alignment of a text in regards to the anchor position:
-
"start" - a text starts at the beginning of the path. This is the default value of the align attribute.
-
"middle" - a text is centered on the middle of the path.
-
"end" - a text ends at the end of the path.
-
decoration is a hint on how to render optional elements of a text:
-
"none" - text is not decorated. This is the default value.
-
"underline" - text is underlined.
-
"overline" - text has a line above it.
-
"line-through" - text has a line through the middle.
-
rotated is a Boolean value, which indicates:
-
false - all glyphs are unrotated. The is the default value.
-
true - all glyphs are rotated 90 degrees counter-clock-wise. This mode is useful for vertically arranged text.
-
kerning is a Boolean value, which indicates:
-
true - kerning is on. This is the default value.
-
false - kerning is off.
Implementation notes:
-
This is a highly experimental shape, which is not recommended to be used in production unless you know what you are doing.
-
Text path shape properties mirror properties of a Text shape.
-
When text path object is created its path is set to dojox.gfx.defaultPath.
-
IE7 broke a lot of VML stuff. Following things work in IE6 but don't work in IE7 (and there is no workaround for them):
-
decoration - it is always "none".
-
rotated - it is always false.
-
FF2 and Opera9 don't support following properties:
-
decoration - it is always "none".
-
rotated - it is always false.
-
IE always aligns the vertical middle of the text with a path. FF and Opera both align the baseline with a path. Unfortunately they seem to ignore any other vertical alignment, which leads to a visual discrepancy between SVG and VML implementations. The final version of the text path object will have the IE/VML behavior (as the greater common denominator): the text's middle line follows a path.