antvis / antvis/F2

基础 shape 中 Text 添加 描边 strokeStyle 将 样式FillStyle 的文本覆盖掉了。

Open
#1,078 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
8k
Forks
637
PR merge metrics
No merged PRs in 30d

Description

文件位置:https://github.com/antvis/F2/blob/1c613cc5f9c632212c5e30c8151bf9252bad77ae/src/graphic/shape/text.js

// 输入文本
if (self.hasFill()) {
const fillOpacity = attrs.fillOpacity;
if (!isNil(fillOpacity) && fillOpacity !== 1) {
context.globalAlpha = fillOpacity;
}
if (textArr) {
for (let i = 0, len = textArr.length; i < len; i++) {
const subText = textArr[i];
subY = y + i * (spaceingY + fontSize) - height + fontSize; // bottom;
if (textBaseline === 'middle') {
subY += height - fontSize - (height - fontSize) / 2;
}
if (textBaseline === 'top') {
subY += height - fontSize;
}
context.fillText(subText, x, subY);
}
} else {
context.fillText(text, x, y);
}
}

// 添加描边
if (self.hasStroke()) {
if (textArr) {
for (let i = 0, len = textArr.length; i < len; i++) {
const subText = textArr[i];
subY = y + i * (spaceingY + fontSize) - height + fontSize; // bottom;
if (textBaseline === 'middle') {
subY += height - fontSize - (height - fontSize) / 2;
}
if (textBaseline === 'top') {
subY += height - fontSize;
}
context.strokeText(subText, x, subY);
}
} else {
context.strokeText(text, x, y);
}
}
}

上述代码中,能否把两个方法换下位置 先执行 strokeText 在执行 fillText 可以实现文本描边功能

The issue which is not created via https://antv-issue-helper.surge.sh will be closed immediately.

---

注意:不是用 https://antv-issue-helper.surge.sh 创建的 issue 会被立即关闭。

Contributor guide

Open the contributing guide

Research direction

Open src/graphic/shape/text.js at the fillText and strokeText branches. Check the rendering order for text with both fill and stroke enabled, then verify that the intended outline remains visible after the ordering change; no test file is mentioned in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.