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: punctuation adjustment in the middle of line (#1686)

Ran Luo2382e3bdb092
diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts
index 33b89f1753..734b9b5da2 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts
@@ -18,7 +18,7 @@ import type { IParagraph } from '@univerjs/core';
import { HorizontalAlign } from '@univerjs/core';
import type { IDocumentSkeletonDivide, IDocumentSkeletonLine, IDocumentSkeletonPage } from '../../../../../basics/i-document-skeleton-cached';
import { getGlyphGroupWidth, lineIterator } from '../../tools';
-import { setGlyphGroupLeft } from '../../model/glyph';
+import { glyphShrinkLeft, glyphShrinkRight, setGlyphGroupLeft } from '../../model/glyph';
import { hasCJK, hasCJKText, isCjkLeftAlignedPunctuation, isCjkRightAlignedPunctuation } from '../../../../../basics/tools';
// How much a character should hang into the end margin.
@@ -219,16 +219,13 @@ function shrinkStartAndEndCJKPunctuation(line: IDocumentSkeletonLine) {
if (isCjkRightAlignedPunctuation(firstGlyph.content)) {
const shrinkAmount = firstGlyph.adjustability.shrinkability[0];
- firstGlyph.width -= shrinkAmount;
- firstGlyph.adjustability.shrinkability[0] -= shrinkAmount;
- firstGlyph.xOffset -= shrinkAmount;
+ glyphShrinkLeft(firstGlyph, shrinkAmount);
}
if (isCjkLeftAlignedPunctuation(lastGlyph.content)) {
const shrinkAmount = lastGlyph.adjustability.shrinkability[1];
- lastGlyph.width -= shrinkAmount;
- lastGlyph.adjustability.shrinkability[1] -= shrinkAmount;
+ glyphShrinkRight(lastGlyph, shrinkAmount);
}
}
}
diff --git a/packages/engine-render/src/components/docs/layout/model/__test__/glyph.spec.ts b/packages/engine-render/src/components/docs/layout/model/__test__/glyph.spec.ts
index 0e3e9094d6..7de4fbf509 100644
--- a/packages/engine-render/src/components/docs/layout/model/__test__/glyph.spec.ts
+++ b/packages/engine-render/src/components/docs/layout/model/__test__/glyph.spec.ts
@@ -113,7 +113,6 @@ describe('Glyph utils test cases', () => {
} as IDocumentSkeletonGlyph;
glyphShrinkRight(glyph, 5);
expect(glyph.adjustability.shrinkability).toEqual([10, 5]);
- expect(glyph.adjustability.stretchability).toEqual([10, 15]);
expect(glyph.width).toBe(15);
});
});
@@ -130,7 +129,6 @@ describe('Glyph utils test cases', () => {
} as IDocumentSkeletonGlyph;
glyphShrinkLeft(glyph, 5);
expect(glyph.adjustability.shrinkability).toEqual([5, 10]);
- expect(glyph.adjustability.stretchability).toEqual([15, 10]);
expect(glyph.width).toBe(15);
expect(glyph.xOffset).toBe(-5);
});
diff --git a/packages/engine-render/src/components/docs/layout/model/glyph.ts b/packages/engine-render/src/components/docs/layout/model/glyph.ts
index 3139c30e42..f40b443211 100644
--- a/packages/engine-render/src/components/docs/layout/model/glyph.ts
+++ b/packages/engine-render/src/components/docs/layout/model/glyph.ts
@@ -278,12 +278,10 @@ function _getMaxBoundingBox(glyph: IDocumentSkeletonGlyph, bulletSkeleton: IDocu
export function glyphShrinkRight(glyph: IDocumentSkeletonGlyph, amount: number) {
glyph.width -= amount;
glyph.adjustability.shrinkability[1] -= amount;
- glyph.adjustability.stretchability[1] += amount;
}
export function glyphShrinkLeft(glyph: IDocumentSkeletonGlyph, amount: number) {
glyph.width -= amount;
glyph.xOffset -= amount;
glyph.adjustability.shrinkability[0] -= amount;
- glyph.adjustability.stretchability[0] += amount;
}