HTML Canvas - actualBoundingBoxDescent 属性



HTML Canvas actualBoundingBoxAscentTextMetrics 接口属性是一种只读方法,它返回一个双精度值,给出从 CanvasRenderingContext2D 接口上下文对象的文本基线指示的水平线到渲染文本的边界矩形框“顶部”的距离。双精度值以 CSS 像素为单位给出。

HTML Canvas actualBoundingBoxDescentTextMetrics 接口属性是一种只读方法,它返回一个双精度值,给出从 CanvasRenderingContext2D 接口上下文对象的文本基线指示的水平线到渲染文本的边界矩形框“底部”的距离。双精度值以 CSS 像素为单位给出。

示例 1 −(返回值)

以下示例演示了 HTML Canvas actualBoundingBoxAscentactualBoundingBoxDescent 属性。实现的代码如下。

<!DOCTYPE html>
<html lang="en">
<head>
   <title>Reference API</title>
   <style>
      body {
         margin: 10px;
         padding: 10px;
      }
   </style>
</head>
<body onload="text();">
   <canvas id="canvas" width="500" height="100" style="border: 1px solid black;"></canvas>
   <script>
      function text() {
         var canvas = document.getElementById("canvas");
         var context = canvas.getContext("2d");
         context.font = '50px Verdana';
         context.fillText('TutorialsPoint', 50, 50);
         var word = context.measureText('TutorialsPoint');
         alert("Bounding box ascent : " + word.actualBoundingBoxAscent + "\nBounding box descent : " + word.actualBoundingBoxDescent);
      }
   </script>
</body>
</html>

产出

以上代码在网页上弹出的输出窗口警报为 −

HTML Canvas ActualBoundingBoxDescent Property
html_canvas_text.htm
广告
© . All rights reserved.