diff --git a/common/changes/@visactor/vrender-core/fix-multiline-rt-fontSize_2025-02-10-09-47.json b/common/changes/@visactor/vrender-core/fix-multiline-rt-fontSize_2025-02-10-09-47.json new file mode 100644 index 000000000..6b532bc55 --- /dev/null +++ b/common/changes/@visactor/vrender-core/fix-multiline-rt-fontSize_2025-02-10-09-47.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vrender-core", + "comment": "fix: fix issue with multiline richtext lineHeight", + "type": "none" + } + ], + "packageName": "@visactor/vrender-core" +} \ No newline at end of file diff --git a/packages/vrender-core/src/graphic/richtext.ts b/packages/vrender-core/src/graphic/richtext.ts index b593d41c1..56ce3ccff 100644 --- a/packages/vrender-core/src/graphic/richtext.ts +++ b/packages/vrender-core/src/graphic/richtext.ts @@ -448,7 +448,18 @@ export class RichText extends Graphic implements IRic // 如果有文字内有换行符,将该段文字切为多段,并在后一段加入newLine标记 const textParts = richTextConfig.text.split('\n'); for (let j = 0; j < textParts.length; j++) { - paragraphs.push(new Paragraph(textParts[j], j !== 0, richTextConfig, ascentDescentMode)); + if (j === 0) { + paragraphs.push(new Paragraph(textParts[j], false, richTextConfig, ascentDescentMode)); + } else if (textParts[j] || i === textConfig.length - 1) { + paragraphs.push(new Paragraph(textParts[j], true, richTextConfig, ascentDescentMode)); + } else { + // 空行的话,config应该要和下一行对齐 + const nextRichTextConfig = this.combinedStyleToCharacter( + textConfig[i + 1] as IRichTextParagraphCharacter + ) as IRichTextParagraphCharacter; + paragraphs.push(new Paragraph(textParts[j], true, nextRichTextConfig, ascentDescentMode)); + } + // paragraphs.push(new Paragraph(textParts[j], j !== 0, richTextConfig, ascentDescentMode)); } } else if (richTextConfig.text) { paragraphs.push(new Paragraph(richTextConfig.text, false, richTextConfig, ascentDescentMode));