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(engine-render): clip sheet header labels to cells (#7694)
wpxp1234564298456dd20a
diff --git a/packages/engine-render/src/components/sheets/extensions/__tests__/column-header-layout.spec.ts b/packages/engine-render/src/components/sheets/extensions/__tests__/column-header-layout.spec.tsindex 858c120ed7..ab5a25d808 100644--- a/packages/engine-render/src/components/sheets/extensions/__tests__/column-header-layout.spec.ts+++ b/packages/engine-render/src/components/sheets/extensions/__tests__/column-header-layout.spec.ts@@ -149,6 +149,34 @@ describe('column header layout extension', () => {expect(ctx.fillText).toHaveBeenCalledTimes(compressedColumnCount + 1);});+ it('clips default column labels to their header cells', () => {+ const layout = new ColumnHeaderLayout({+ columnsCfg: {+ 0: 'AA',+ 1: 'AB',+ },+ });+ const ctx = createCtx();+ const skeleton = {+ rowColumnSegment: { startRow: 0, endRow: 0, startColumn: 0, endColumn: 1 },+ columnHeaderHeight: 20,+ rowHeightAccumulation: [20],+ columnWidthAccumulation: [8, 16],+ columnTotalWidth: 16,+ rowTotalHeight: 20,+ worksheet: {+ getSheetId: vi.fn(() => 'sheet-main'),+ },+ } as any;++ layout.draw(ctx, { scaleX: 1, scaleY: 1 } as any, skeleton);++ expect(ctx.fillText).toHaveBeenCalledTimes(2);+ expect(ctx.rectByPrecision).toHaveBeenNthCalledWith(1, 0, 0, 8, 20);+ expect(ctx.rectByPrecision).toHaveBeenNthCalledWith(2, 8, 0, 8, 20);+ expect(ctx.clip).toHaveBeenCalledTimes(2);+ });+it('uses gapConfig default colors when drawing column gaps', () => {const layout = new ColumnHeaderLayout();const ctx = createCtx();diff --git a/packages/engine-render/src/components/sheets/extensions/__tests__/row-header-layout.spec.ts b/packages/engine-render/src/components/sheets/extensions/__tests__/row-header-layout.spec.tsindex 2eae1e7b8a..f38034b4fd 100644--- a/packages/engine-render/src/components/sheets/extensions/__tests__/row-header-layout.spec.ts+++ b/packages/engine-render/src/components/sheets/extensions/__tests__/row-header-layout.spec.ts@@ -150,6 +150,34 @@ describe('row header layout extension', () => {expect(ctx.fillText).toHaveBeenCalledTimes(compressedRowCount + 1);});+ it('clips default row labels to their header cells', () => {+ const layout = new RowHeaderLayout({+ rowsCfg: {+ 0: '10',+ 1: '11',+ },+ });+ const ctx = createCtx();+ const skeleton = {+ rowColumnSegment: { startRow: 0, endRow: 1, startColumn: 0, endColumn: 0 },+ rowHeaderWidth: 30,+ rowHeightAccumulation: [8, 16],+ columnWidthAccumulation: [30],+ columnTotalWidth: 30,+ rowTotalHeight: 16,+ worksheet: {+ getSheetId: vi.fn(() => 'sheet-main'),+ },+ } as any;++ layout.draw(ctx, { scaleX: 1, scaleY: 1 } as any, skeleton);++ expect(ctx.fillText).toHaveBeenCalledTimes(2);+ expect(ctx.rectByPrecision).toHaveBeenNthCalledWith(1, 0, 0, 30, 8);+ expect(ctx.rectByPrecision).toHaveBeenNthCalledWith(2, 0, 8, 30, 8);+ expect(ctx.clip).toHaveBeenCalledTimes(2);+ });+it('uses gapConfig default colors when drawing row gaps', () => {const layout = new RowHeaderLayout();const ctx = createCtx();diff --git a/packages/engine-render/src/components/sheets/extensions/column-header-layout.ts b/packages/engine-render/src/components/sheets/extensions/column-header-layout.tsindex 3c73f87e5b..1e34023129 100644--- a/packages/engine-render/src/components/sheets/extensions/column-header-layout.ts+++ b/packages/engine-render/src/components/sheets/extensions/column-header-layout.ts@@ -242,18 +242,16 @@ export class ColumnHeaderLayout extends SheetExtension {})();const middleYCellRect = cellBound.height / 2 + MIDDLE_CELL_POS_MAGIC_NUMBER; // Magic number 1, because the vertical alignment appears to be off by 1 pixel+ ctx.save();+ ctx.beginPath();if (specStyle) {- ctx.save();- ctx.beginPath();this.setStyleToCtx(ctx, curColumnCfg);- ctx.rectByPrecision(cellBound.left, cellBound.top, cellBound.width, cellBound.height);- ctx.clip();}+ ctx.rectByPrecision(cellBound.left, cellBound.top, cellBound.width, cellBound.height);+ ctx.clip();ctx.fillText(curColumnCfg.text, textX, middleYCellRect);- if (specStyle) {- ctx.restore();- }+ ctx.restore();preColumnPosition = columnEndPosition;}diff --git a/packages/engine-render/src/components/sheets/extensions/row-header-layout.ts b/packages/engine-render/src/components/sheets/extensions/row-header-layout.tsindex ab86100766..42d2dea929 100644--- a/packages/engine-render/src/components/sheets/extensions/row-header-layout.ts+++ b/packages/engine-render/src/components/sheets/extensions/row-header-layout.ts@@ -245,18 +245,16 @@ export class RowHeaderLayout extends SheetExtension {})();const middleYCellRect = preRowPosition + (rowEndPosition - preRowPosition) / 2 + MIDDLE_CELL_POS_MAGIC_NUMBER; // Magic number 1, because the vertical alignment appears to be off by 1 pixel+ ctx.save();+ ctx.beginPath();if (specStyle) {- ctx.save();- ctx.beginPath();this.setStyleToCtx(ctx, curRowCfg);- ctx.rectByPrecision(cellBound.left, cellBound.top, cellBound.width, cellBound.height);- ctx.clip();}+ ctx.rectByPrecision(cellBound.left, cellBound.top, cellBound.width, cellBound.height);+ ctx.clip();ctx.fillText(curRowCfg.text, textX, middleYCellRect);- if (specStyle) {- ctx.restore();- }+ ctx.restore();preRowPosition = rowEndPosition;}