new AbstractTextDrawBridge()
Different renderer should provide different methods to draw text.
Those different implementations are wrapped in draw bridge classes.
Concrete bridge classes do not need to deprived from this class, but they
do need to implement all those essential methods.
NOTE: Methods of the bridge (measureText, drawText, etc.) only need to handle
left to right text.
Methods
-
addToGroup(elem, group)
-
Add an element to an existing group. Descendants or bridge should override this method.
Parameters:
Name Type Description elemObject groupObject -
canMeasureDrawnText(context) → {Bool}
-
Indicate whether this bridge and context can measure text dimension before drawing it. Raphael is a typical environment of this type. Such a bridge must also has the ability to modify text pos after drawn.
Parameters:
Name Type Description contextObject Returns:
- Type
- Bool
-
canMeasureText(context) → {Bool}
-
Indicate whether this bridge and context can measure text dimension before drawing it. HTML Canvas is a typical environment of this type.
Parameters:
Name Type Description contextObject Returns:
- Type
- Bool
-
canModifyText(context) → {Bool}
-
Indicate whether this bridge and context can change text content or position after drawing it. Raphael is a typical environment of this type.
Parameters:
Name Type Description contextObject Returns:
- Type
- Bool
-
createGroup(context) → {Object}
-
Create a group to store render elements. Descendants or bridge should override this method. Note that not all bridge (like canvas) support group.
Parameters:
Name Type Description contextObject Returns:
- Type
- Object
-
drawText(context, coord, text, options) → {Object}
-
Draw a plain text on context.
Parameters:
Name Type Description contextObject coordObject The top left coord to draw text. textObject optionsObject Draw options, may contain the following fields: {fontSize, fontFamily, color, rotation(based on coord)} Returns:
Null or element drawn on context.- Type
- Object
-
measureDrawnText(context, textElem, options) → {Hash}
-
Mearsure the width and height of text on context after drawing it.
Parameters:
Name Type Description contextObject textElemObject Drawn text element on context. optionsObject Returns:
An object with width and height fields, top and left is optional.- Type
- Hash
-
measureText(context, text, options) → {Hash}
-
Mearsure the width and height of text on context before drawing it.
Parameters:
Name Type Description contextObject textObject optionsObject Returns:
An object with width and height fields.- Type
- Hash
-
modifyDrawnTextCoord(context, textElem, newCoord)
-
Change text drawn on context to a new coord. Not all context can apply this action.
Parameters:
Name Type Description contextObject textElemObject newCoordHash The top left coord of text box. -
removeFromGroup(elem, group)
-
Remove an element to from existing group. Descendants or bridge should override this method.
Parameters:
Name Type Description elemObject groupObject