Skip to content

Commit

Permalink
fix(drawing): doc drawing same to sheet drawing (#2372)
Browse files Browse the repository at this point in the history
* fix(drawing): doc drawing same to sheet drawing

* fix(drawing): type error

* fix(drawing): user input angle invalid
  • Loading branch information
DR-Univer authored May 31, 2024
1 parent dbf643e commit e3f6654
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
4 changes: 4 additions & 0 deletions examples/src/data/sheets/demo/default-workbook-data-demo.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class DocDrawingUpdateController extends Disposable {
if (type === ImageUploadStatusType.ERROR_EXCEED_SIZE) {
this._messageService.show({
type: MessageType.Error,
content: this._localeService.t('update-status.exceedMaxSize', String(DRAWING_IMAGE_ALLOW_SIZE / 1024 * 1024)),
content: this._localeService.t('update-status.exceedMaxSize', String(DRAWING_IMAGE_ALLOW_SIZE / (1024 * 1024))),
});
} else if (type === ImageUploadStatusType.ERROR_IMAGE_TYPE) {
this._messageService.show({
Expand All @@ -136,6 +136,14 @@ export class DocDrawingUpdateController extends Disposable {
const { imageId, imageSourceType, source, base64Cache } = imageParam;
const { width, height, image } = await getImageSize(base64Cache || '');

const renderObject = this._renderManagerService.getRenderById(unitId);

if (renderObject == null) {
return;
}

const { width: sceneWidth, height: sceneHeight } = renderObject.scene;

this._imageIoService.addImageSourceCache(imageId, imageSourceType, image);

let scale = 1;
Expand All @@ -145,7 +153,7 @@ export class DocDrawingUpdateController extends Disposable {
scale = Math.max(scaleWidth, scaleHeight);
}

const docTransform = this._getImagePosition(width, height, scale);
const docTransform = this._getImagePosition(width * scale, height * scale, sceneWidth, sceneHeight);

if (docTransform == null) {
return;
Expand Down Expand Up @@ -186,7 +194,7 @@ export class DocDrawingUpdateController extends Disposable {
};
}

private _getImagePosition(imageWidth: number, imageHeight: number, scale: number): Nullable<IDocDrawingPosition> {
private _getImagePosition(imageWidth: number, imageHeight: number, sceneWidth: number, sceneHeight: number): Nullable<IDocDrawingPosition> {
const activeTextRange = this._textSelectionManagerService.getActiveTextRange();
const position = activeTextRange?.getAbsolutePosition() || {
left: 0,
Expand All @@ -196,8 +204,8 @@ export class DocDrawingUpdateController extends Disposable {
// TODO:@Jocs calculate the position of the image in doc
return {
size: {
width: imageWidth * scale,
height: imageHeight * scale,
width: imageWidth,
height: imageHeight,
},
positionH: {
relativeFrom: ObjectRelativeFromH.MARGIN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { DocumentDataModel, Nullable } from '@univerjs/core';
import { ICommandService, IDrawingManagerService, IUniverInstanceService, LifecycleStages, LocaleService, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
import { FOCUSING_COMMON_DRAWINGS, IContextService, IDrawingManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
import type { IDisposable } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import type { BaseObject, Scene } from '@univerjs/engine-render';
Expand All @@ -36,8 +36,7 @@ export class DocDrawingPopupMenuController extends RxDisposable {
@Inject(DocCanvasPopManagerService) private readonly _canvasPopManagerService: DocCanvasPopManagerService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@ICommandService private readonly _commandService: ICommandService
@IContextService private readonly _contextService: IContextService

) {
super();
Expand Down Expand Up @@ -126,18 +125,29 @@ export class DocDrawingPopupMenuController extends RxDisposable {
menuItems: this._getImageMenuItems(unitId, subUnitId, drawingId),
},
})));

this._drawingManagerService.focusDrawing([{
unitId,
subUnitId,
drawingId,
}]);
})
)
);

this.disposeWithMe(
toDisposable(
transformer.onClearControlObservable.add((changeSelf) => {
transformer.onClearControlObservable.add(() => {
disposePopups.forEach((dispose) => dispose.dispose());
this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, false);
this._drawingManagerService.focusDrawing(null);
})
)
);
this.disposeWithMe(
toDisposable(
transformer.onChangingObservable.add(() => {
disposePopups.forEach((dispose) => dispose.dispose());

// if (changeSelf === true) {
// this._commandService.executeCommand(SidebarSheetDrawingOperation.id, { value: 'close' });
// }
})
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { Nullable, Workbook } from '@univerjs/core';
import { FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, IDrawingManagerService, IUniverInstanceService, LifecycleStages, LocaleService, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
import { FOCUSING_COMMON_DRAWINGS, IContextService, IDrawingManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
import type { IDisposable } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import type { BaseObject, Scene } from '@univerjs/engine-render';
Expand All @@ -36,9 +36,7 @@ export class DrawingPopupMenuController extends RxDisposable {
@Inject(SheetCanvasPopManagerService) private readonly _canvasPopManagerService: SheetCanvasPopManagerService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@IContextService private readonly _contextService: IContextService,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@ICommandService private readonly _commandService: ICommandService
@IContextService private readonly _contextService: IContextService

) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ export class SheetDrawingUpdateController extends Disposable {
return;
}
const { unitId, subUnitId } = info;

const { imageId, imageSourceType, source, base64Cache } = imageParam;

const { width, height, image } = await getImageSize(base64Cache || '');

const renderObject = this._renderManagerService.getRenderById(unitId);
Expand Down Expand Up @@ -334,7 +332,7 @@ export class SheetDrawingUpdateController extends Disposable {

const newDrawing: Partial<ISheetDrawing> = {
...param,
transform: { ...transform, ...drawingPositionToTransform(sheetTransform, this._selectionRenderService) },
transform: { ...sheetDrawing.transform, ...transform, ...drawingPositionToTransform(sheetTransform, this._selectionRenderService) },
sheetTransform: { ...sheetTransform },
};

Expand Down

0 comments on commit e3f6654

Please sign in to comment.