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.

feat(sheets-ui): support drawing print (#2418)

zhangwf24cacef51e6
diff --git a/packages/drawing-ui/src/controllers/image-update.controller.ts b/packages/drawing-ui/src/controllers/image-update.controller.ts
index 8c89c57aaf..f35ad00670 100644
--- a/packages/drawing-ui/src/controllers/image-update.controller.ts
+++ b/packages/drawing-ui/src/controllers/image-update.controller.ts
@@ -15,21 +15,24 @@
*/
import type { ICommandInfo, Nullable } from '@univerjs/core';
-import { Disposable,
+import {
+ Disposable,
ICommandService,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
toDisposable,
} from '@univerjs/core';
-import type { IImageProps, Scene } from '@univerjs/engine-render';
-import { CURSOR_TYPE, DRAWING_OBJECT_LAYER_INDEX, Image, IRenderManagerService } from '@univerjs/engine-render';
+import type { Image, Scene } from '@univerjs/engine-render';
+import { CURSOR_TYPE, IRenderManagerService } from '@univerjs/engine-render';
import type { IDrawingSearch, IImageData } from '@univerjs/drawing';
-import { DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, IDrawingManagerService, IImageIoService, ImageSourceType } from '@univerjs/drawing';
+import { DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, IDrawingManagerService, IImageIoService } from '@univerjs/drawing';
import { IDialogService } from '@univerjs/ui';
+import { Inject } from '@wendellhu/redi';
import { COMPONENT_IMAGE_VIEWER } from '../views/image-viewer/component-name';
import { ImageResetSizeOperation } from '../commands/operations/image-reset-size.operation';
-import { getCurrentUnitInfo, insertGroupObject } from './utils';
+import { DrawingRenderService } from '../services/drawing-render.service';
+import { getCurrentUnitInfo } from './utils';
const IMAGE_VIEWER_DROPDOWN_PADDING = 50;
@@ -41,7 +44,8 @@ export class ImageUpdateController extends Disposable {
@IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,
@IDialogService private readonly _dialogService: IDialogService,
@IImageIoService private readonly _imageIoService: IImageIoService,
- @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService
+ @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
+ @Inject(DrawingRenderService) private readonly _drawingRenderService: DrawingRenderService
) {
super();
@@ -193,72 +197,21 @@ export class ImageUpdateController extends Disposable {
private _insertImages(params: IDrawingSearch[]) {
(params).forEach(async (param) => {
const { unitId, subUnitId, drawingId } = param;
- const imageParam = this._drawingManagerService.getDrawingByParam(param) as IImageData;
- if (imageParam == null) {
- return;
- }
-
- const { transform, drawingType, source, imageSourceType, srcRect, prstGeom, groupId } = imageParam;
- if (drawingType !== DrawingTypeEnum.DRAWING_IMAGE) {
- return;
- }
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
if (renderObject == null) {
return;
}
- const { scene, transformer } = renderObject;
- if (transform == null) {
- return true;
- }
- const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
- const imageShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId });
- const imageShape = scene.getObject(imageShapeKey);
-
- if (imageShape != null) {
- imageShape.transformByState({ left, top, width, height, angle, flipX, flipY, skewX, skewY });
+ const imageParam = this._drawingManagerService.getDrawingByParam(param) as IImageData;
+ if (imageParam == null) {
return;
}
- const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
- const zIndex = orders.indexOf(drawingId);
- const imageConfig: IImageProps = { ...transform, zIndex: zIndex === -1 ? (orders.length - 1) : zIndex };
- const imageNativeCache = this._imageIoService.getImageSourceCache(source, imageSourceType);
-
- let shouldBeCache = false;
- if (imageNativeCache != null) {
- imageConfig.image = imageNativeCache;
- } else {
- if (imageSourceType === ImageSourceType.UUID) {
- try {
- imageConfig.url = await this._imageIoService.getImage(source);
- } catch (error) {
- console.error(error);
- return;
- }
- } else {
- imageConfig.url = source;
- }
- shouldBeCache = true;
- }
-
- const image = new Image(imageShapeKey, imageConfig);
- if (shouldBeCache) {
- this._imageIoService.addImageSourceCache(source, imageSourceType, image.getNative());
- }
-
- scene.addObject(image, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(image);
-
- groupId && insertGroupObject({ drawingId: groupId, unitId, subUnitId }, image, scene, this._drawingManagerService);
-
- if (prstGeom != null) {
- image.setPrstGeom(prstGeom);
- }
- if (srcRect != null) {
- image.setSrcRect(srcRect);
+ const image = await this._drawingRenderService.renderImage(imageParam, renderObject.scene);
+ if (!image) {
+ return;
}
-
this._addHoverForImage(image);
this._addDialogForImage(image);
});
diff --git a/packages/drawing-ui/src/index.ts b/packages/drawing-ui/src/index.ts
index 622037425f..99647180c5 100644
--- a/packages/drawing-ui/src/index.ts
+++ b/packages/drawing-ui/src/index.ts
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+export { DrawingRenderService } from './services/drawing-render.service';
export { getUpdateParams } from './utils/get-update-params';
export { ImageResetSizeOperation } from './commands/operations/image-reset-size.operation';
export { CloseImageCropOperation, OpenImageCropOperation } from './commands/operations/image-crop.operation';
diff --git a/packages/drawing-ui/src/plugin.ts b/packages/drawing-ui/src/plugin.ts
index 7aafa88585..6d4f40ee8f 100644
--- a/packages/drawing-ui/src/plugin.ts
+++ b/packages/drawing-ui/src/plugin.ts
@@ -21,6 +21,7 @@ import { DrawingUpdateController } from './controllers/drawing-update.controller
import { DrawingUIController } from './controllers/drawing-ui.controller';
import { ImageCropperController } from './controllers/image-cropper.controller';
import { ImageUpdateController } from './controllers/image-update.controller';
+import { DrawingRenderService } from './services/drawing-render.service';
const PLUGIN_NAME = 'DRAWING_UI_PLUGIN';
@@ -43,7 +44,7 @@ export class UniverDrawingUIPlugin extends Plugin {
const dependencies: Dependency[] = [
// services
-
+ [DrawingRenderService],
// controllers
[DrawingUpdateController],
[DrawingUIController],
diff --git a/packages/drawing-ui/src/services/drawing-render.service.ts b/packages/drawing-ui/src/services/drawing-render.service.ts
new file mode 100644
index 0000000000..2dd14dd9d0
--- /dev/null
+++ b/packages/drawing-ui/src/services/drawing-render.service.ts
@@ -0,0 +1,102 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { IDrawingSearch, IImageData } from '@univerjs/drawing';
+import { DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, IDrawingManagerService, IImageIoService, ImageSourceType } from '@univerjs/drawing';
+import type { IImageProps, Scene } from '@univerjs/engine-render';
+import { DRAWING_OBJECT_LAYER_INDEX, Image } from '@univerjs/engine-render';
+import { insertGroupObject } from '../controllers/utils';
+
+export class DrawingRenderService {
+ constructor(
+ @IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,
+ @IImageIoService private readonly _imageIoService: IImageIoService
+ ) { }
+
+ async renderImage(imageParam: IImageData, scene: Scene) {
+ const { transform, drawingType, source, imageSourceType, srcRect, prstGeom, groupId, unitId, subUnitId, drawingId } = imageParam;
+ if (drawingType !== DrawingTypeEnum.DRAWING_IMAGE) {
+ return;
+ }
+
+ if (transform == null) {
+ return;
+ }
+
+ const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
+ const imageShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId });
+ const imageShape = scene.getObject(imageShapeKey);
+
+ if (imageShape != null) {
+ imageShape.transformByState({ left, top, width, height, angle, flipX, flipY, skewX, skewY });
+ return;
+ }
+
+ const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
+ const zIndex = orders.indexOf(drawingId);
+ const imageConfig: IImageProps = { ...transform, zIndex: zIndex === -1 ? (orders.length - 1) : zIndex };
+ const imageNativeCache = this._imageIoService.getImageSourceCache(source, imageSourceType);
+
+ let shouldBeCache = false;
+ if (imageNativeCache != null) {
+ imageConfig.image = imageNativeCache;
+ } else {
+ if (imageSourceType === ImageSourceType.UUID) {
+ try {
+ imageConfig.url = await this._imageIoService.getImage(source);
+ } catch (error) {
+ console.error(error);
+ return;
+ }
+ } else {
+ imageConfig.url = source;
+ }
+ shouldBeCache = true;
+ }
+
+ imageConfig.printable = true;
+ const image = new Image(imageShapeKey, imageConfig);
+ if (shouldBeCache) {
+ this._imageIoService.addImageSourceCache(source, imageSourceType, image.getNative());
+ }
+
+ scene.addObject(image, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(image);
+
+ groupId && insertGroupObject({ drawingId: groupId, unitId, subUnitId }, image, scene, this._drawingManagerService);
+
+ if (prstGeom != null) {
+ image.setPrstGeom(prstGeom);
+ }
+ if (srcRect != null) {
+ image.setSrcRect(srcRect);
+ }
+
+ return image;
+ }
+
+ renderDrawing(param: IDrawingSearch, scene: Scene) {
+ const drawingParam = this._drawingManagerService.getDrawingByParam(param);
+ if (drawingParam == null) {
+ return;
+ }
+
+ switch (drawingParam.drawingType) {
+ case DrawingTypeEnum.DRAWING_IMAGE:
+ return this.renderImage(drawingParam as IImageData, scene);
+ default:
+ }
+ }
+}
diff --git a/packages/engine-render/src/base-object.ts b/packages/engine-render/src/base-object.ts
index 49a979294a..4a7c371c87 100644
--- a/packages/engine-render/src/base-object.ts
+++ b/packages/engine-render/src/base-object.ts
@@ -79,6 +79,8 @@ export abstract class BaseObject extends Disposable {
protected _dirty: boolean = true;
protected _forceDirty: boolean = true;
+ private _printable: boolean = false;
+
private _top: number = 0;
private _topOrigin: number | string = 0;
@@ -155,6 +157,10 @@ export abstract class BaseObject extends Disposable {
return transform;
}
+ get printable() {
+ return this._printable;
+ }
+
get topOrigin() {
return this._topOrigin;
}
diff --git a/packages/engine-render/src/basics/interfaces.ts b/packages/engine-render/src/basics/interfaces.ts
index bb5b053250..635dd916a9 100644
--- a/packages/engine-render/src/basics/interfaces.ts
+++ b/packages/engine-render/src/basics/interfaces.ts
@@ -49,6 +49,7 @@ export interface IObjectFullState extends ITransformState {
forceRender?: boolean;
debounceParentDirty?: boolean;
transformerConfig?: ITransformerConfig;
+ printable?: boolean;
}
export interface IRect extends ISize, IOffset {
diff --git a/packages/engine-render/src/components/sheets/extensions/marker.ts b/packages/engine-render/src/components/sheets/extensions/marker.ts
index 8d5447281d..9bcc72db16 100644
--- a/packages/engine-render/src/components/sheets/extensions/marker.ts
+++ b/packages/engine-render/src/components/sheets/extensions/marker.ts
@@ -37,6 +37,10 @@ export class Marker extends SheetExtension {
// eslint-disable-next-line max-lines-per-function
override draw(ctx: UniverRenderingContext, parentScale: IScale, skeleton: SpreadsheetSkeleton, diffRanges: IRange[]): void {
+ if (ctx.__mode === 'printing') {
+ return;
+ }
+
const { worksheet, rowColumnSegment } = skeleton;
if (!worksheet) {
return;
diff --git a/packages/engine-render/src/context.ts b/packages/engine-render/src/context.ts
index baf6b0e0a5..669223e1cc 100644
--- a/packages/engine-render/src/context.ts
+++ b/packages/engine-render/src/context.ts
@@ -965,9 +965,13 @@ export class UniverRenderingContextWebGL { }
*/
export class UniverRenderingContextWebGPU { }
-export class UniverRenderingContext extends UniverRenderingContext2D { }
+export class UniverRenderingContext extends UniverRenderingContext2D {
+ __mode = 'rendering';
+}
export class UniverPrintingContext extends UniverRenderingContext2D {
+ __mode = 'printing';
+
private __getScale() {
const m = this.getTransform();
return {
diff --git a/packages/sheets-data-validation/src/widgets/dropdown-widget.ts b/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
index 07ee3935f9..4b50f56e22 100644
--- a/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
+++ b/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
@@ -17,7 +17,7 @@
import { BooleanNumber, DataValidationRenderMode, DEFAULT_EMPTY_DOCUMENT_VALUE, DocumentDataModel, HorizontalAlign, ICommandService, LocaleService, Tools, VerticalAlign, WrapStrategy } from '@univerjs/core';
import type { ICellRenderContext, IDocumentData, IPaddingData, IStyleData, Nullable } from '@univerjs/core';
import { Documents, DocumentSkeleton, DocumentViewModel, getDocsSkeletonPageSize, Rect } from '@univerjs/engine-render';
-import type { IMouseEvent, IPointerEvent, ISheetFontRenderExtension, SpreadsheetSkeleton, UniverRenderingContext2D } from '@univerjs/engine-render';
+import type { IMouseEvent, IPointerEvent, ISheetFontRenderExtension, SpreadsheetSkeleton, UniverRenderingContext, UniverRenderingContext2D } from '@univerjs/engine-render';
import { Inject } from '@wendellhu/redi';
import type { IBaseDataValidationWidget } from '@univerjs/data-validation';
import { getCellValueOrigin } from '../utils/get-cell-data-origin';
@@ -270,7 +270,7 @@ export class DropdownWidget implements IBaseDataValidationWidget {
ctx.beginPath();
ctx.rect(0, 0, realWidth, fontHeight);
ctx.clip();
- documents.render(ctx);
+ documents.render(ctx as UniverRenderingContext);
ctx.translateWithPrecision(paddingLeft, 0);
ctx.restore();
@@ -330,7 +330,7 @@ export class DropdownWidget implements IBaseDataValidationWidget {
ctx.translate(MARGIN_H, paddingTop);
const rectWidth = Math.max(cellWidth - MARGIN_H * 2, 1);
const rectHeight = fontHeight;
- Rect.drawWith(ctx, {
+ Rect.drawWith(ctx as UniverRenderingContext, {
width: rectWidth,
height: rectHeight,
fill: activeItem?.color || DROP_DOWN_DEFAULT_COLOR,
@@ -342,7 +342,7 @@ export class DropdownWidget implements IBaseDataValidationWidget {
ctx.rect(0, 0, realWidth, fontHeight);
ctx.clip();
ctx.translateWithPrecision(paddingLeft, 0);
- documents.render(ctx);
+ documents.render(ctx as UniverRenderingContext);
ctx.restore();
ctx.translate(realWidth + PADDING_H + 4, (fontHeight - ICON_SIZE) / 2);
ctx.fillStyle = DROP_DOWN_ICON_COLOR;
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-printing.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-printing.controller.ts
new file mode 100644
index 0000000000..aa32634433
--- /dev/null
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-printing.controller.ts
@@ -0,0 +1,114 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { IRange } from '@univerjs/core';
+import { Disposable, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
+import { DrawingTypeEnum, IDrawingManagerService } from '@univerjs/drawing';
+import { DrawingRenderService } from '@univerjs/drawing-ui';
+import { IRenderManagerService } from '@univerjs/engine-render';
+import { SheetPrintInterceptorService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
+import { Inject } from '@wendellhu/redi';
+
+@OnLifecycle(LifecycleStages.Rendered, SheetDrawingPrintingController)
+export class SheetDrawingPrintingController extends Disposable {
+ constructor(
+ @Inject(SheetPrintInterceptorService) private readonly _sheetPrintInterceptorService: SheetPrintInterceptorService,
+ @Inject(DrawingRenderService) private readonly _drawingRenderService: DrawingRenderService,
+ @IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,
+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService
+ ) {
+ super();
+
+ this._initPrinting();
+ }
+
+ private _initPrinting() {
+ this.disposeWithMe(
+ this._sheetPrintInterceptorService.interceptor.intercept(
+ this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,
+ {
+ handler: (_param, pos, next) => {
+ const { unitId, scene, subUnitId } = pos;
+ const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId);
+ const subUnitData = unitData?.[subUnitId];
+ if (subUnitData) {
+ subUnitData.order.forEach((id) => {
+ this._drawingRenderService.renderDrawing(subUnitData.data[id], scene);
+ });
+ }
+
+ return next();
+ },
+ }
+ )
+ );
+
+ this.disposeWithMe(
+ this._sheetPrintInterceptorService.interceptor.intercept(
+ this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,
+ {
+ handler: (range, pos, next) => {
+ const { unitId, subUnitId } = pos;
+ const renderer = this._renderManagerService.getRenderById(unitId);
+ if (!renderer) {
+ return next(range);
+ }
+
+ const skeleton = renderer.with(SheetSkeletonManagerService).getUnitSkeleton(unitId, subUnitId);
+ if (!skeleton) {
+ return next(range);
+ }
+ const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId);
+ const subUnitData = unitData?.[pos.subUnitId];
+ if (!subUnitData) {
+ return next(range);
+ }
+
+ const { scaleX, scaleY } = renderer.scene;
+ const newRange: IRange = range ? { ...range } : { startColumn: 0, endColumn: 0, endRow: 0, startRow: 0 };
+ const data = subUnitData.order.map((key) => subUnitData.data[key]).filter((item) => item.drawingType !== DrawingTypeEnum.DRAWING_DOM);
+ if (data.length) {
+ data.forEach((param) => {
+ if (!param.groupId && param.transform && Tools.isDefine(param.transform.left) && Tools.isDefine(param.transform.top) && Tools.isDefine(param.transform.width) && Tools.isDefine(param.transform.height)) {
+ const start = skeleton.skeleton.getCellPositionByOffset(param.transform.left, param.transform.top, scaleX, scaleY, { x: 0, y: 0 });
+ const end = skeleton.skeleton.getCellPositionByOffset(param.transform.left + param.transform.width, param.transform.top + param.transform.height, scaleX, scaleY, { x: 0, y: 0 });
+ if (start.column < newRange.startColumn) {
+ newRange.startColumn = start.column;
+ }
+
+ if (start.row < newRange.startRow) {
+ newRange.startRow = start.row;
+ }
+
+ if (newRange.endRow < end.row) {
+ newRange.endRow = end.row;
+ }
+
+ if (newRange.endColumn < end.column) {
+ newRange.endColumn = end.column;
+ }
+ }
+ });
+ return next(newRange);
+ }
+
+ return next(range);
+ },
+ }
+ )
+ );
+ }
+}
diff --git a/packages/sheets-drawing-ui/src/plugin.ts b/packages/sheets-drawing-ui/src/plugin.ts
index 4adc8c6e79..6d66e8e958 100644
--- a/packages/sheets-drawing-ui/src/plugin.ts
+++ b/packages/sheets-drawing-ui/src/plugin.ts
@@ -26,6 +26,7 @@ import type { IUniverSheetsDrawingConfig } from './controllers/sheet-drawing.con
import { DefaultSheetsDrawingConfig, SheetDrawingUIController } from './controllers/sheet-drawing.controller';
import { SheetDrawingTransformAffectedController } from './controllers/sheet-drawing-transform-affected.controller';
import { SheetCanvasFloatDomManagerService } from './services/canvas-float-dom-manager.service';
+import { SheetDrawingPrintingController } from './controllers/sheet-drawing-printing.controller';
const PLUGIN_NAME = 'SHEET_IMAGE_UI_PLUGIN';
@@ -66,6 +67,7 @@ export class UniverSheetsDrawingUIPlugin extends Plugin {
[SheetDrawingUpdateController],
[DrawingPopupMenuController],
[SheetDrawingTransformAffectedController],
+ [SheetDrawingPrintingController],
];
diff --git a/packages/sheets-ui/src/index.ts b/packages/sheets-ui/src/index.ts
index 8ef7c5faf2..4d6eab6607 100644
--- a/packages/sheets-ui/src/index.ts
+++ b/packages/sheets-ui/src/index.ts
@@ -105,3 +105,4 @@ export { FormulaEditorController } from './controllers/editor/formula-editor.con
export { StatusBarController } from './controllers/status-bar.controller';
export { SheetPermissionInterceptorBaseController } from './controllers/permission/sheet-permission-interceptor-base.controller';
export type { IRangeProtectionRenderCellData } from './views/permission/extensions/range-protection.render';
+export { SheetPrintInterceptorService } from './services/print-interceptor.service';
diff --git a/packages/sheets-ui/src/services/print-interceptor.service.ts b/packages/sheets-ui/src/services/print-interceptor.service.ts
new file mode 100644
index 0000000000..7dbedbe9ee
--- /dev/null
+++ b/packages/sheets-ui/src/services/print-interceptor.service.ts
@@ -0,0 +1,47 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { IRange } from '@univerjs/core';
+import { createInterceptorKey, Disposable, InterceptorManager } from '@univerjs/core';
+import type { Scene } from '@univerjs/engine-render';
+
+interface ISheetPos {
+ unitId: string;
+ subUnitId: string;
+}
+
+const PRINTING_RANGE = createInterceptorKey<IRange, ISheetPos>('PRINTING_RANGE');
+const PRINTING_COMPONENT_COLLECT = createInterceptorKey<undefined, ISheetPos & { scene: Scene }>('PRINTING_COMPONENT_COLLECT');
+
+export class SheetPrintInterceptorService extends Disposable {
+ readonly interceptor = new InterceptorManager({
+ PRINTING_RANGE,
+ PRINTING_COMPONENT_COLLECT,
+ });
+
+ constructor() {
+ super();
+ this.disposeWithMe(this.interceptor.intercept(this.interceptor.getInterceptPoints().PRINTING_RANGE, {
+ priority: -1,
+ handler: (_value) => _value,
+ }));
+
+ this.disposeWithMe(this.interceptor.intercept(this.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT, {
+ priority: -1,
+ handler: (_value) => _value,
+ }));
+ }
+}
diff --git a/packages/sheets-ui/src/sheets-ui-plugin.ts b/packages/sheets-ui/src/sheets-ui-plugin.ts
index b114355456..e78d0c8778 100644
--- a/packages/sheets-ui/src/sheets-ui-plugin.ts
+++ b/packages/sheets-ui/src/sheets-ui-plugin.ts
@@ -84,6 +84,7 @@ import { SheetPermissionInterceptorFormulaRenderController } from './controllers
import { SheetPermissionPanelModel } from './services/permission/sheet-permission-panel.model';
import { SheetPermissionUserManagerService } from './services/permission/sheet-permission-user-list.service';
import { WorksheetProtectionRenderService } from './services/permission/worksheet-permission-render.service';
+import { SheetPrintInterceptorService } from './services/print-interceptor.service';
@DependentOn(UniverSheetsPlugin, UniverUIPlugin)
export class UniverSheetsUIPlugin extends Plugin {
@@ -114,6 +115,7 @@ export class UniverSheetsUIPlugin extends Plugin {
[ICellEditorManagerService, { useClass: CellEditorManagerService }],
[IFormulaEditorManagerService, { useClass: FormulaEditorManagerService }],
[IAutoFillService, { useClass: AutoFillService }],
+ [SheetPrintInterceptorService],
[ScrollManagerService],
// This would be removed from global injector and moved into RenderUnit provider.