From e4759f068e1fd2941b1457814711377e1b1ffc2d Mon Sep 17 00:00:00 2001 From: jocs Date: Mon, 15 Apr 2024 21:05:39 +0800 Subject: [PATCH] fix: the strickthough position is wrong when fontsize is different --- .../engine-render/src/components/docs/extensions/line.ts | 6 +++--- .../src/components/docs/layout/shaping-engine/font-cache.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/engine-render/src/components/docs/extensions/line.ts b/packages/engine-render/src/components/docs/extensions/line.ts index dee7244ca84..6e5f92b2675 100644 --- a/packages/engine-render/src/components/docs/extensions/line.ts +++ b/packages/engine-render/src/components/docs/extensions/line.ts @@ -65,7 +65,7 @@ export class Line extends docExtension { if (strikethrough) { // strikethrough position is the middle of bounding box ascent and descent. - let startY = strikeoutPosition - DELTA; + let startY = asc + bd - strikeoutPosition - DELTA; /** * --------- superscript strikethrough position ------- @@ -75,9 +75,9 @@ export class Line extends docExtension { * --------- subscript offset ----------------------- */ if (baselineOffset === BaselineOffset.SUPERSCRIPT) { - startY = asc + bd - spo - strikeoutPosition; + startY -= spo; } else if (baselineOffset === BaselineOffset.SUBSCRIPT) { - startY = asc + bd + sbo - strikeoutPosition; + startY += sbo; } this._drawLine(ctx, span, strikethrough, startY, scale); diff --git a/packages/engine-render/src/components/docs/layout/shaping-engine/font-cache.ts b/packages/engine-render/src/components/docs/layout/shaping-engine/font-cache.ts index 3785b8fcb9e..5760240fd62 100644 --- a/packages/engine-render/src/components/docs/layout/shaping-engine/font-cache.ts +++ b/packages/engine-render/src/components/docs/layout/shaping-engine/font-cache.ts @@ -369,7 +369,7 @@ export class FontCache { bd, aba, abd, - sp: (ba + bd) / 2, + sp: (fontBoundingBoxAscent + fontBoundingBoxDescent) / 2, sbr: 0.6, spr: 0.6, // https://en.wikipedia.org/wiki/Subscript_and_superscript Microsoft Word 2015