SVGTextContentElement: getExtentOfChar() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Phương thức getExtentOfChar() của giao diện SVGTextContentElement đại diện cho hộp giới hạn chặt chẽ được tính toán của ô nét chữ tương ứng với một ký tự đánh máy đã cho.
Cú pháp
js
getExtentOfChar(index)
Tham số
index-
Một
integer; chỉ số của ký tự.
Giá trị trả về
Một đối tượng DOMRect; hộp giới hạn chặt chẽ của ký tự được chỉ định.
Ngoại lệ
IndexSizeErrorDOMException-
Được ném nếu không tìm thấy ký tự nào tại
index.
Ví dụ
>Lấy phạm vi của một ký tự
html
<svg width="300" height="100">
<text id="exampleText" x="10" y="50" font-size="16">Hello, SVG World!</text>
</svg>
js
const textElement = document.getElementById("exampleText");
// Get the extent (bounding box) of the character at index 0 (the first character)
const extent = textElement.getExtentOfChar(0);
// The bounding box of the first character
console.dir(extent); // Output: DOMRect { x: 10, y: 38, width: 11.55, height: 16 }
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Scalable Vector Graphics (SVG) 2> # __svg__SVGTextContentElement__getExtentOfChar> |