Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(render-engine): optimize underline postion (#2164)
Ran Luob0ccb91a7067
diff --git a/packages/engine-render/src/basics/i-document-skeleton-cached.ts b/packages/engine-render/src/basics/i-document-skeleton-cached.tsindex a496e29ee1..152e2f56b1 100644--- a/packages/engine-render/src/basics/i-document-skeleton-cached.ts+++ b/packages/engine-render/src/basics/i-document-skeleton-cached.ts@@ -130,7 +130,8 @@ export interface IDocumentSkeletonLine {lineHeight: number; // 行总体高度 lineHeight =max(glyph.fontBoundingBoxAscent + glyph.fontBoundingBoxDescent, glyph2.....) + spacecontentHeight: number; // contentHeight 行内容高度,contentHeight,=max(glyph.fontBoundingBoxAscent + glyph.fontBoundingBoxDescent, glyph2.....)top: number; // top paragraph(spaceAbove, spaceBelow, lineSpacing*PreLineHeight)- asc: number; // =max(glyph.textMetrics.asc) alphabet对齐,需要校准+ asc: number; // =max(glyph.textMetrics.ba) alphabet 对齐,需要校准+ dsc: number; // =max(glyph.textMetrics.bd) alphabet 对齐,需要校准paddingTop: number; // paddingTop 内容到顶部的距离paddingBottom: number; // paddingBottom 内容到底部的距离marginTop: number; // marginTop 针对段落的spaceAbovediff --git a/packages/engine-render/src/components/docs/extensions/line.ts b/packages/engine-render/src/components/docs/extensions/line.tsindex 2b28bb826f..76f365dea8 100644--- a/packages/engine-render/src/components/docs/extensions/line.ts+++ b/packages/engine-render/src/components/docs/extensions/line.ts@@ -37,18 +37,16 @@ export class Line extends docExtension {private _preBackgroundColor = '';- override draw(ctx: UniverRenderingContext, parentScale: IScale, span: IDocumentSkeletonGlyph) {- const line = span.parent?.parent;- if (!line) {- return;- }+ override draw(ctx: UniverRenderingContext, parentScale: IScale, glyph: IDocumentSkeletonGlyph) {+ const line = glyph.parent?.parent;+ const { ts: textStyle, bBox } = glyph;- const { contentHeight = 0, asc } = line;- const { ts: textStyle, bBox } = span;- if (!textStyle) {+ if (line == null || textStyle == null) {return;}+ const { asc, dsc } = line;+const { sp: strikeoutPosition, spo, sbo, bd } = bBox;const scale = getScale(parentScale);@@ -58,9 +56,9 @@ export class Line extends docExtension {const { ul: underline, st: strikethrough, ol: overline, va: baselineOffset } = textStyle;if (underline) {- const startY = contentHeight + DEFAULT_OFFSET_SPACING - 3;+ const startY = asc + dsc;- this._drawLine(ctx, span, underline, startY, scale);+ this._drawLine(ctx, glyph, underline, startY, scale);}if (strikethrough) {@@ -80,13 +78,13 @@ export class Line extends docExtension {startY += sbo;}- this._drawLine(ctx, span, strikethrough, startY, scale);+ this._drawLine(ctx, glyph, strikethrough, startY, scale);}if (overline) {const startY = -DEFAULT_OFFSET_SPACING - DELTA;- this._drawLine(ctx, span, overline, startY, scale);+ this._drawLine(ctx, glyph, overline, startY, scale);}}@@ -96,7 +94,7 @@ export class Line extends docExtension {private _drawLine(ctx: UniverRenderingContext,- span: IDocumentSkeletonGlyph,+ glyph: IDocumentSkeletonGlyph,line: ITextDecoration,startY: number,_scale: number@@ -113,7 +111,7 @@ export class Line extends docExtension {renderConfig = {},} = this.extensionOffset;- const { left, width } = span;+ const { left, width } = glyph;const { centerAngle: centerAngleDeg = 0, vertexAngle: vertexAngleDeg = 0 } = renderConfig;@@ -125,7 +123,7 @@ export class Line extends docExtension {ctx.translateWithPrecisionRatio(FIX_ONE_PIXEL_BLUR_OFFSET, FIX_ONE_PIXEL_BLUR_OFFSET);const color =- (c === BooleanNumber.TRUE ? getColorStyle(span.ts?.cl) : getColorStyle(colorStyle)) || COLOR_BLACK_RGB;+ (c === BooleanNumber.TRUE ? getColorStyle(glyph.ts?.cl) : getColorStyle(colorStyle)) || COLOR_BLACK_RGB;ctx.strokeStyle = color;this._setLineType(ctx, lineType || TextDecoration.SINGLE);diff --git a/packages/engine-render/src/components/docs/layout/model/line.ts b/packages/engine-render/src/components/docs/layout/model/line.tsindex 42ae49c89f..b5b31df207 100644--- a/packages/engine-render/src/components/docs/layout/model/line.ts+++ b/packages/engine-render/src/components/docs/layout/model/line.ts@@ -479,7 +479,8 @@ function _getLineSke(lineType: LineType, paragraphIndex: number): IDocumentSkelelineHeight: 0, // lineHeight =max(glyph.fontBoundingBoxAscent + glyph.fontBoundingBoxDescent, span2.....) + spacecontentHeight: 0, // contentHeight =max(glyph.fontBoundingBoxAscent + glyph.fontBoundingBoxDescent, span2.....)top: 0, // top paragraph(spaceAbove, spaceBelow, lineSpacing*PreLineHeight)- asc: 0, // =max(glyph.textMetrics.asc) alphaBeta对齐,需要校准+ asc: 0, // =max(glyph.textMetrics.ba) alphaBeta对齐,需要校准+ dsc: 0, // =max(glyph.textMetrics.bd) alphaBeta对齐,需要校准paddingTop: 0, // paddingTop 内容到顶部的距离paddingBottom: 0, // paddingBottom 内容到底部的距离marginTop: 0, // marginTop 针对段落的spaceAbovediff --git a/packages/engine-render/src/components/docs/layout/tools.ts b/packages/engine-render/src/components/docs/layout/tools.tsindex 896c33871e..3496d920a6 100644--- a/packages/engine-render/src/components/docs/layout/tools.ts+++ b/packages/engine-render/src/components/docs/layout/tools.ts@@ -337,6 +337,7 @@ export function updateBlockIndex(pages: IDocumentSkeletonPage[], start: number =let preDivideStartIndex = lineStartIndex;let actualWidth = 0;let maxLineAsc = 0;+ let macLineDsc = 0;columnHeight += lineHeight;const divideLength = divides.length;@@ -353,9 +354,10 @@ export function updateBlockIndex(pages: IDocumentSkeletonPage[], start: number =divEndIndex += increaseValue;const bBox = glyph.bBox;- const { ba } = bBox;+ const { ba, bd } = bBox;maxLineAsc = Math.max(maxLineAsc, ba);+ macLineDsc = Math.max(macLineDsc, bd);if (i === divideLength - 1) {actualWidth += glyph.width;@@ -393,6 +395,7 @@ export function updateBlockIndex(pages: IDocumentSkeletonPage[], start: number =line.ed = preDivideStartIndex >= line.st ? preDivideStartIndex : line.st;line.width = actualWidth;line.asc = maxLineAsc;+ line.dsc = macLineDsc;maxColumnWidth = Math.max(maxColumnWidth, actualWidth);// Please do not use pre line's top and height to calculate the current's top,// because of float objects will between lines.