Skip to content

Commit

Permalink
fix(docs): line space (#3082)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs authored Aug 16, 2024
1 parent 3a5635f commit f5dcea0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
24 changes: 12 additions & 12 deletions packages/engine-render/src/components/docs/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -402,7 +402,7 @@ export class Documents extends DocComponent {
const spanPointWithFont = calculateRectRotate(
originTranslate.addByPoint(
spanLeft + maxLineAscSin + xOffset,
maxLineAscCos
maxLineAscCos + paddingTop
),
centerPoint,
centerAngle,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -658,7 +658,7 @@ export class Documents extends DocComponent {
const spanPointWithFont = calculateRectRotate(
originTranslate.addByPoint(
spanLeft + maxLineAscSin + xOffset,
maxLineAscCos
maxLineAscCos + paddingTop
),
centerPoint,
centerAngle,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -877,7 +877,7 @@ export class Documents extends DocComponent {
const spanPointWithFont = calculateRectRotate(
originTranslate.addByPoint(
spanLeft + maxLineAscSin + xOffset,
maxLineAscCos
maxLineAscCos + paddingTop
),
centerPoint,
centerAngle,
Expand Down
10 changes: 5 additions & 5 deletions packages/engine-render/src/components/docs/extensions/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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,
};
}

Expand Down

0 comments on commit f5dcea0

Please sign in to comment.