この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!
この記事を English (US) で読むこともできます。

The TextMetrics interface represents the dimension of a text in the canvas, as created by the CanvasRenderingContext2D.measureText() method.

Properties

TextMetrics.width Read only
Is a 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
Is a 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
Is a 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
Is a 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
Is a 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
Is a 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
Is a 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
Is a 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
Is a 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
Is a 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
Is a 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
Is a 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.

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'TextMetrics' in that specification.
Living Standard Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 4Edge Full support YesFirefox Full support 1.5IE Full support 9Opera Full support 9Safari Full support 3.1WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 31Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes
width
Experimental
Chrome Full support 4Edge Full support 12Firefox Full support 1.5IE Full support 9Opera Full support 9Safari Full support 3.1WebView Android Full support 2Chrome Android ? Edge Mobile ? Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support 3.2Samsung Internet Android ?
Advanced text metrics properties
Experimental
Chrome Full support Yes
Disabled
Full support Yes
Disabled
Disabled This feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge No support NoFirefox No support No
Notes
No support No
Notes
Notes Firefox does not implement this feature yet. See the related bug 1102584.
IE No support NoOpera ? Safari ? WebView Android ? Chrome Android ? Edge Mobile ? Firefox Android No support No
Notes
No support No
Notes
Notes Firefox does not implement this feature yet. See the related bug 1102584.
Opera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also

ドキュメントのタグと貢献者

最終更新者: fscholz,