diff --git a/common/changes/@visactor/vrender-core/fix-multiline-text-bounds_2024-04-02-08-52.json b/common/changes/@visactor/vrender-core/fix-multiline-text-bounds_2024-04-02-08-52.json new file mode 100644 index 000000000..016bbebff --- /dev/null +++ b/common/changes/@visactor/vrender-core/fix-multiline-text-bounds_2024-04-02-08-52.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vrender-core", + "comment": "fix: fix issue with multiline text render pos", + "type": "none" + } + ], + "packageName": "@visactor/vrender-core" +} \ No newline at end of file diff --git a/packages/vrender-core/src/core/contributions/textMeasure/layout.ts b/packages/vrender-core/src/core/contributions/textMeasure/layout.ts index a07963c2d..3a73ddd29 100644 --- a/packages/vrender-core/src/core/contributions/textMeasure/layout.ts +++ b/packages/vrender-core/src/core/contributions/textMeasure/layout.ts @@ -222,7 +222,8 @@ export class CanvasTextLayout { } // line.topOffset = lineHeight * 0.79 + origin[1]; // 渲染默认使用alphabetic - line.topOffset = (lineHeight - this.textOptions.fontSize) / 2 + this.textOptions.fontSize * 0.79 + origin[1]; + // 0.79在中文会超出,使用0.82 + line.topOffset = (lineHeight - this.textOptions.fontSize) / 2 + this.textOptions.fontSize * 0.82 + origin[1]; origin[1] += lineHeight; return line; diff --git a/packages/vrender/__tests__/browser/src/pages/text.ts b/packages/vrender/__tests__/browser/src/pages/text.ts index 1ef8b0353..715788331 100644 --- a/packages/vrender/__tests__/browser/src/pages/text.ts +++ b/packages/vrender/__tests__/browser/src/pages/text.ts @@ -166,6 +166,24 @@ export const page = () => { }); graphics.push(circle); + const wt = createText({ + text: ['省/自治区字段信息jfkdlafjkdag'], + ellipsis: '...', + fill: 'red', + fontSize: 68, + fontWeight: 'bold', + textAlign: 'center', + textBaseline: 'top', + width: 1628, + maxLineWidth: 1628, + x: 814, + y: 100, + _debug_bounds: true, + wrap: true + }); + graphics.push(wt); + console.log('wt', wt); + const rect = createRect({ x: t.AABBBounds.x1, y: t.AABBBounds.y1,