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): resolve theme colors when printing (#7537)
Univer603016f6af3c
diff --git a/packages/engine-render/src/__tests__/canvas.spec.ts b/packages/engine-render/src/__tests__/canvas.spec.tsindex 45d6dfa185..6f1e7cf24d 100644--- a/packages/engine-render/src/__tests__/canvas.spec.ts+++ b/packages/engine-render/src/__tests__/canvas.spec.ts@@ -14,6 +14,7 @@* limitations under the License.*/+import type { ICanvasColorService } from '../services/canvas-color.service';import { afterEach, describe, expect, it, vi } from 'vitest';import { Canvas, CanvasRenderMode, HitCanvas, SceneCanvas } from '../canvas';@@ -23,12 +24,13 @@ describe('canvas wrapper', () => {});it('initializes rendering and printing contexts with sizing and ids', () => {+ const colorService: ICanvasColorService = { getRenderColor: (color: string) => color };const canvas = new Canvas({id: 'ignored-by-constructor',width: 120,height: 80,pixelRatio: 2,- colorService: { getRenderColor: (color: string) => color } as any,+ colorService,});canvas.setId('render-canvas');@@ -53,6 +55,23 @@ describe('canvas wrapper', () => {printing.dispose();});+ it('resolves theme colors in printing contexts', () => {+ const getRenderColor = vi.fn((color: string) => color === 'primary.500' ? '#dfe5ff' : color);+ const colorService: ICanvasColorService = { getRenderColor };+ const printing = new Canvas({+ mode: CanvasRenderMode.Printing,+ width: 20,+ height: 10,+ colorService,+ });++ printing.getContext().fillStyle = 'primary.500';++ expect(getRenderColor).toHaveBeenCalledWith('primary.500');+ expect(printing.getContext().fillStyle).toBe('#dfe5ff');+ printing.dispose();+ });+it('keeps zero-sized canvases from changing pixel ratio and supports scene/hit subclasses', () => {const canvas = new Canvas();canvas.setPixelRatio(3);diff --git a/packages/engine-render/src/canvas.ts b/packages/engine-render/src/canvas.tsindex f8fc202d66..19554255d8 100644--- a/packages/engine-render/src/canvas.ts+++ b/packages/engine-render/src/canvas.ts@@ -91,7 +91,9 @@ export class Canvas {}if (props.mode === CanvasRenderMode.Printing) {- this._context = new UniverPrintingContext(context);+ this._context = new UniverPrintingContext(context, {+ canvasColorService: props.colorService,+ });} else {this._context = new UniverRenderingContext(context, {canvasColorService: props.colorService,