CanvasRenderingContext2D.textBaseline
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since иÑÐ»Ñ 2015 г..
CanvasRenderingContext2D.textBaseline - ÑвойÑÑво Canvas 2D API, ÑказÑваÑÑее на ÑекÑÑÑÑ Ð±Ð°Ð·Ð¾Ð²ÑÑ Ð»Ð¸Ð½Ð¸Ñ Ð¿Ñи ÑиÑовании ÑекÑÑа.
СинÑакÑиÑ
ctx.textBaseline = "top" || "hanging" || "middle" || "alphabetic" || "ideographic" || "bottom";
ÐпÑии
ÐозможнÑе знаÑениÑ:
"top"-
The text baseline is the top of the em square.
"hanging"-
The text baseline is the hanging baseline. (Used by Tibetan and other Indic scripts.)
"middle"-
The text baseline is the middle of the em square.
"alphabetic"-
The text baseline is the normal alphabetic baseline. ÐнаÑение по ÑмолÑаниÑ.
"ideographic"-
The text baseline is the ideographic baseline; this is the bottom of the body of the characters, if the main body of characters protrudes beneath the alphabetic baseline. (Used by Chinese, Japanese, and Korean scripts.)
"bottom"-
The text baseline is the bottom of the bounding box. This differs from the ideographic baseline in that the ideographic baseline doesn't consider descenders.
ÐÑимеÑÑ
>СÑавнение знаÑений ÑвойÑÑва
ÐÑÐ¾Ñ Ð¿ÑÐ¸Ð¼ÐµÑ Ð´ÐµÐ¼Ð¾Ð½ÑÑÑиÑÑÐµÑ ÑазлиÑнÑе знаÑÐµÐ½Ð¸Ñ ÑвойÑÑва textBaseline и оÑобÑажение линий пÑи иÑ
пÑименениÑÑ
.
HTML
<canvas id="canvas" width="550" height="500"></canvas>
JavaScript
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const baselines = [
"top",
"hanging",
"middle",
"alphabetic",
"ideographic",
"bottom",
];
ctx.font = "36px serif";
ctx.strokeStyle = "red";
baselines.forEach(function (baseline, index) {
ctx.textBaseline = baseline;
let y = 75 + index * 75;
ctx.beginPath();
ctx.moveTo(0, y + 0.5);
ctx.lineTo(550, y + 0.5);
ctx.stroke();
ctx.fillText("Abcdefghijklmnop (" + baseline + ")", 0, y);
});
РезÑлÑÑаÑ
СпеÑиÑикаÑии
| Specification |
|---|
| HTML > # dom-context-2d-textbaseline-dev > |
СовмеÑÑимоÑÑÑ Ñ Ð±ÑаÑзеÑами
СмоÑÑиÑе Ñакже
- ÐнÑеÑÑÐµÐ¹Ñ Ð¾Ð¿ÑеделÑÑÑий ÑÑо ÑвойÑÑво:
CanvasRenderingContext2D