Skip to content

Commit

Permalink
chore(zh-cn): sync translate content (#18409)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuchunhui authored Mar 5, 2024
1 parent 5dd82e8 commit 90e4e73
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions files/zh-cn/web/api/canvasrenderingcontext2d/textbaseline/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,53 @@ baselines.forEach((baseline, index) => {

{{ EmbedLiveSample('属性值比较', 700, 550) }}

### 基于同一水平线比较各个属性值

与前面的示例一样,本示例演示了各种 `textBaseline` 属性值,但在本例中,所有属性值都沿同一条线水平排列,以便更容易看到它们之间的差异。

#### HTML

```html
<canvas id="canvas" width="724" height="160"></canvas>
```

#### JavaScript

```js
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");

const baselines = [
"top",
"hanging",
"middle",
"alphabetic",
"ideographic",
"bottom",
];
ctx.font = "20px serif";
ctx.strokeStyle = "red";

ctx.beginPath();
ctx.moveTo(0, 100);
ctx.lineTo(840, 100);
ctx.moveTo(0, 55);
ctx.stroke();

baselines.forEach((baseline, index) => {
ctx.save();
ctx.textBaseline = baseline;
let x = index * 120 + 10;
ctx.fillText("Abcdefghijk", x, 100);
ctx.restore();
ctx.fillText(baseline, x + 5, 50);
});
```

#### 结果

{{ EmbedLiveSample('基于同一水平线比较属性值的差异', 900, 200) }}

## 规范

{{Specifications}}
Expand Down

0 comments on commit 90e4e73

Please sign in to comment.