Unwind a previous clipSave and pop cache stack if necessary
Conditionally clip a region
if true, save cache to stack and clip region
left of region
top of region
width of region
height of region
The conditional paramater indicates whether a region is to be clipped. If so, then the cache is saved to the stack.
Always call a matching clipRestore to unwind this clipSave
even if conditional was false
Optional
maxWidth: numberGets the height, ascent and descent in pixels of the current font.
A TextHeight interface with height, ascent and descent encompassing the main characters in the font.
Gets the height, ascent and descent in pixels of a text string using the current font.
string whose height is to be obtained.
A TextHeight interface with height, ascent and descent of string.
Gets the width of a string using the current font.
Text to measure.
Width of string in pixels.
Calculates the width of a string in pixels by adding the widths of each character in the string. The widths of each character is either obtained from a map or (if not in map) calculated using
measureText()
and stored in map.
NOTE: There is a minor measuring error when taking the sum of the pixel widths of individual characters that make up a string vs. the pixel width of the string taken as a whole. This is possibly due to kerning or rounding. The error is typically about 0.1%.
Gets a map of the width (value) of characters (key) for a particular font
the name of the font
A wrapper around CanvasRenderingContext2D which accesses values from CanvasRenderingContext2D from a cache.
Remarks
Supports saving and restoring by pushing and popping cached values onto/from a stack. Cache also stores the width and height of strings so that these widths and heights can be re-used without needing to be constantly recalculated