The TextMetrics
interface represents the dimension of a text in the canvas, as created by the CanvasRenderingContext2D.measureText()
method.
TextMetrics.width
Read only
double
giving the calculated width of a segment of inline text in CSS pixels. It takes into account the current font of the context.TextMetrics.actualBoundingBoxLeft
Read only
double
giving the distance parallel to the baseline from the alignment point given by the CanvasRenderingContext2D.textAlign
property to the left side of the bounding rectangle of the given text, in CSS pixels.TextMetrics.actualBoundingBoxRight
Read only
double
giving the distance parallel to the baseline from the alignment point given by the CanvasRenderingContext2D.textAlign
property to the right side of the bounding rectangle of the given text, in CSS pixels.TextMetrics.fontBoundingBoxAscent
Read only
double
giving the distance from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
attribute to the top of the highest bounding rectangle of all the fonts used to render the text, in CSS pixels.TextMetrics.fontBoundingBoxDescent
Read only
double
giving the distance from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
attribute to the bottom of the bounding rectangle of all the fonts used to render the text, in CSS pixels.TextMetrics.actualBoundingBoxAscent
Read only
double
giving the distance from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
attribute to the top of the bounding rectangle used to render the text, in CSS pixels.TextMetrics.actualBoundingBoxDescent
Read only
double
giving the distance from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
attribute to the bottom of the bounding rectangle used to render the text, in CSS pixels.TextMetrics.emHeightAscent
Read only
double
giving the distance from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
property to the top of the em square in the line box, in CSS pixels.TextMetrics.emHeightDescent
Read only
double
giving the distance from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
property to the bottom of the em square in the line box, in CSS pixels.TextMetrics.hangingBaseline
Read only
double
giving the distance from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
property to the hanging baseline of the line box, in CSS pixels.TextMetrics.alphabeticBaseline
Read only
double
giving the distance from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
property to the alphabetic baseline of the line box, in CSS pixels.TextMetrics.ideographicBaseline
Read only
double
giving the distance from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
property to the ideographic baseline of the line box, in CSS pixels.Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'TextMetrics' in that specification. | Living Standard | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 4 | Yes | 1.5 | 9 | 9 | 3.1 |
width
|
4 | 12 | 1.5 | 9 | 9 | 3.1 |
Advanced text metrics properties | Yes
|
No | No
|
No | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | ? | 31 | Yes | No | Yes |
width
|
2 | ? | ? | 4 | Yes | 3.2 | ? |
Advanced text metrics properties | ? | ? | ? | No
|
? | ? | ? |
CanvasRenderingContext2D
.<canvas>
element and its associated interface, HTMLCanvasElement
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics