Skip to content

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.

fix(docs): line space (#3082)

Ran Luof5dcea0f3706
diff --git a/packages/engine-render/src/components/docs/document.ts b/packages/engine-render/src/components/docs/document.ts
index 179a765a61..dac3eeb2f3 100644
--- a/packages/engine-render/src/components/docs/document.ts
+++ b/packages/engine-render/src/components/docs/document.ts
@@ -313,7 +313,7 @@ export class Documents extends DocComponent {
for (let i = 0; i < linesCount; i++) {
const line = lines[i];
- const { divides, asc = 0, type, lineHeight = 0 } = line;
+ const { divides, asc = 0, type, lineHeight = 0, paddingTop } = line;
const maxLineAsc = asc;
@@ -360,7 +360,7 @@ export class Documents extends DocComponent {
const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
const spanStartPoint = calculateRectRotate(
- originTranslate.addByPoint(spanLeft, 0),
+ originTranslate.addByPoint(spanLeft, paddingTop),
centerPoint,
centerAngle,
vertexAngle,
@@ -392,7 +392,7 @@ export class Documents extends DocComponent {
const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
const spanStartPoint = calculateRectRotate(
- originTranslate.addByPoint(spanLeft + xOffset, 0),
+ originTranslate.addByPoint(spanLeft + xOffset, paddingTop),
centerPoint,
centerAngle,
vertexAngle,
@@ -402,7 +402,7 @@ export class Documents extends DocComponent {
const spanPointWithFont = calculateRectRotate(
originTranslate.addByPoint(
spanLeft + maxLineAscSin + xOffset,
- maxLineAscCos
+ maxLineAscCos + paddingTop
),
centerPoint,
centerAngle,
@@ -571,7 +571,7 @@ export class Documents extends DocComponent {
for (let i = 0; i < linesCount; i++) {
const line = lines[i];
- const { divides, asc = 0, type, lineHeight = 0 } = line;
+ const { divides, asc = 0, type, lineHeight = 0, paddingTop } = line;
const maxLineAsc = asc;
@@ -616,7 +616,7 @@ export class Documents extends DocComponent {
const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
const spanStartPoint = calculateRectRotate(
- originTranslate.addByPoint(spanLeft, 0),
+ originTranslate.addByPoint(spanLeft, paddingTop),
centerPoint,
centerAngle,
vertexAngle,
@@ -648,7 +648,7 @@ export class Documents extends DocComponent {
const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
const spanStartPoint = calculateRectRotate(
- originTranslate.addByPoint(spanLeft + xOffset, 0),
+ originTranslate.addByPoint(spanLeft + xOffset, paddingTop),
centerPoint,
centerAngle,
vertexAngle,
@@ -658,7 +658,7 @@ export class Documents extends DocComponent {
const spanPointWithFont = calculateRectRotate(
originTranslate.addByPoint(
spanLeft + maxLineAscSin + xOffset,
- maxLineAscCos
+ maxLineAscCos + paddingTop
),
centerPoint,
centerAngle,
@@ -777,7 +777,7 @@ export class Documents extends DocComponent {
for (let i = 0; i < linesCount; i++) {
const line = lines[i];
- const { divides, asc = 0, type, lineHeight = 0 } = line;
+ const { divides, asc = 0, type, lineHeight = 0, paddingTop } = line;
const maxLineAsc = asc;
@@ -835,7 +835,7 @@ export class Documents extends DocComponent {
const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
const spanStartPoint = calculateRectRotate(
- originTranslate.addByPoint(spanLeft, 0),
+ originTranslate.addByPoint(spanLeft, paddingTop),
centerPoint,
centerAngle,
vertexAngle,
@@ -867,7 +867,7 @@ export class Documents extends DocComponent {
const centerPoint = Vector2.create(spanWidth / 2, lineHeight / 2);
const spanStartPoint = calculateRectRotate(
- originTranslate.addByPoint(spanLeft + xOffset, 0),
+ originTranslate.addByPoint(spanLeft + xOffset, paddingTop),
centerPoint,
centerAngle,
vertexAngle,
@@ -877,7 +877,7 @@ export class Documents extends DocComponent {
const spanPointWithFont = calculateRectRotate(
originTranslate.addByPoint(
spanLeft + maxLineAscSin + xOffset,
- maxLineAscCos
+ maxLineAscCos + paddingTop
),
centerPoint,
centerAngle,
diff --git a/packages/engine-render/src/components/docs/extensions/line.ts b/packages/engine-render/src/components/docs/extensions/line.ts
index f66c28b751..1c6fd68dcc 100644
--- a/packages/engine-render/src/components/docs/extensions/line.ts
+++ b/packages/engine-render/src/components/docs/extensions/line.ts
@@ -45,25 +45,25 @@ export class Line extends docExtension {
return;
}
- const { asc, dsc } = line;
+ const { asc, dsc, paddingTop } = line;
const { sp: strikeoutPosition, spo, sbo, bd } = bBox;
const scale = getScale(parentScale);
const DELTA = 0.5;
const { ul: underline, st: strikethrough, ol: overline, va: baselineOffset, bbl: bottomBorderLine } = textStyle;
if (underline) {
- const startY = asc + dsc;
+ const startY = asc + dsc + paddingTop;
this._drawLine(ctx, glyph, underline, startY, scale);
}
if (bottomBorderLine) {
- const startY = asc + dsc + 3;
+ const startY = asc + dsc + 3 + paddingTop;
this._drawLine(ctx, glyph, bottomBorderLine, startY, scale, 2);
}
if (strikethrough) {
// strikethrough position is the middle of bounding box ascent and descent.
- let startY = asc + bd - strikeoutPosition - DELTA;
+ let startY = asc + bd - strikeoutPosition - DELTA + paddingTop;
/**
* --------- superscript strikethrough position -------
@@ -82,7 +82,7 @@ export class Line extends docExtension {
}
if (overline) {
- const startY = -DEFAULT_OFFSET_SPACING - DELTA;
+ const startY = -DEFAULT_OFFSET_SPACING - DELTA + paddingTop;
this._drawLine(ctx, glyph, overline, startY, scale);
}
diff --git a/packages/engine-render/src/components/docs/text-selection/convert-text-range.ts b/packages/engine-render/src/components/docs/text-selection/convert-text-range.ts
index 2ca2256d86..6765d8b3fa 100644
--- a/packages/engine-render/src/components/docs/text-selection/convert-text-range.ts
+++ b/packages/engine-render/src/components/docs/text-selection/convert-text-range.ts
@@ -281,13 +281,16 @@ export class NodePositionConvertToCursor {
const isValid = this._isValidPosition(startOrigin, endOrigin);
if (!isValid) {
- throw new Error('Invalid positions in NodePositionConvertToCursor, they are not in the same segment page when in header or footer.');
+ throw new Error(`
+ Invalid positions in NodePositionConvertToCursor,
+ they are not in the same segment page when in header or footer.`
+ );
}
const { start, end } = compareNodePosition(startOrigin, endOrigin);
this._selectionIterator(start, end, (start_sp, end_sp, isFirst, isLast, divide, line) => {
- const { lineHeight, marginTop, asc } = line;
+ const { lineHeight, marginTop, asc, paddingTop } = line;
const { glyphGroup, st } = divide;
if (glyphGroup.length === 0) {
// The divide is empty, and no need to set selection.
@@ -330,9 +333,9 @@ export class NodePositionConvertToCursor {
contentBoxPosition = {
startX: startX + firstGlyphLeft + (isCurrentList ? firstGlyphWidth : 0),
- startY: startY + marginTop + asc - anchorGlyph.bBox.ba,
+ startY: startY + marginTop + paddingTop + asc - anchorGlyph.bBox.ba,
endX: startX + lastGlyphLeft + lastGlyphWidth,
- endY: startY + marginTop + asc + anchorGlyph.bBox.bd,
+ endY: startY + marginTop + paddingTop + asc + anchorGlyph.bBox.bd,
};
} else {
const isStartBackFin = isStartBack && !isCurrentList;
@@ -346,9 +349,9 @@ export class NodePositionConvertToCursor {
contentBoxPosition = {
startX: startX + firstGlyphLeft + (isStartBackFin ? 0 : firstGlyphWidth),
- startY: startY + marginTop + asc - anchorGlyph.bBox.ba,
+ startY: startY + marginTop + paddingTop + asc - anchorGlyph.bBox.ba,
endX: startX + lastGlyphLeft + (isEndBack ? 0 : lastGlyphWidth),
- endY: startY + marginTop + asc + anchorGlyph.bBox.bd,
+ endY: startY + marginTop + paddingTop + asc + anchorGlyph.bBox.bd,
};
}