RED-3988: update document viewer service
This commit is contained in:
parent
0ae4729b8a
commit
576f6ec6e3
@ -405,17 +405,16 @@ export class AnnotationActionsService {
|
||||
if (annotationWrapper.rectangle || annotationWrapper.imported || annotationWrapper.isImage) {
|
||||
this._annotationManager.delete(annotationWrapper);
|
||||
const rectangleAnnotation = this.#generateRectangle(annotationWrapper);
|
||||
this._pdf.annotationManager.addAnnotation(rectangleAnnotation, { imported: true });
|
||||
await this._pdf.annotationManager.drawAnnotationsFromList([rectangleAnnotation]);
|
||||
this._pdf.annotationManager.selectAnnotation(rectangleAnnotation);
|
||||
await this._annotationManager.add(rectangleAnnotation);
|
||||
this._annotationManager.select(rectangleAnnotation);
|
||||
return;
|
||||
}
|
||||
|
||||
viewerAnnotation.ReadOnly = false;
|
||||
viewerAnnotation.Hidden = false;
|
||||
viewerAnnotation.disableRotationControl();
|
||||
this._pdf.annotationManager.redrawAnnotation(viewerAnnotation);
|
||||
this._pdf.annotationManager.selectAnnotation(viewerAnnotation);
|
||||
this._annotationManager.redraw(viewerAnnotation);
|
||||
this._annotationManager.select(viewerAnnotation);
|
||||
}
|
||||
|
||||
async acceptResize($event: MouseEvent, annotation: AnnotationWrapper): Promise<void> {
|
||||
@ -468,7 +467,7 @@ export class AnnotationActionsService {
|
||||
|
||||
#generateRectangle(annotationWrapper: AnnotationWrapper) {
|
||||
const annotation = this._pdf.rectangle();
|
||||
const pageHeight = this._pdf.documentViewer.getPageHeight(annotationWrapper.pageNumber);
|
||||
const pageHeight = this._documentViewer.getHeight(annotationWrapper.pageNumber);
|
||||
const rectangle: IRectangle = annotationWrapper.positions[0];
|
||||
annotation.PageNumber = annotationWrapper.pageNumber;
|
||||
annotation.X = rectangle.topLeft.x;
|
||||
@ -576,7 +575,7 @@ export class AnnotationActionsService {
|
||||
} else {
|
||||
const rect = toPosition(
|
||||
viewerAnnotation.getPageNumber(),
|
||||
this._pdf.documentViewer.getPageHeight(viewerAnnotation.getPageNumber()),
|
||||
this._documentViewer.getHeight(viewerAnnotation.getPageNumber()),
|
||||
this._annotationDrawService.annotationToQuads(viewerAnnotation),
|
||||
);
|
||||
return {
|
||||
|
||||
@ -257,7 +257,7 @@ export class PdfProxyService {
|
||||
|
||||
private _addManualRedactionOfType(type: ManualRedactionEntryType) {
|
||||
const selectedQuads: Record<string, Quad[]> = this._pdf.documentViewer.getSelectedTextQuads();
|
||||
const text = this._pdf.documentViewer.getSelectedText();
|
||||
const text = this._documentViewer.selectedText;
|
||||
const manualRedactionEntry = this._getManualRedaction(selectedQuads, text, true);
|
||||
this.manualAnnotationRequested$.next({ manualRedactionEntry, type });
|
||||
}
|
||||
|
||||
@ -48,9 +48,7 @@ export class StampService {
|
||||
await this._stampExcludedPages(pdfDoc, file.excludedPages);
|
||||
}
|
||||
|
||||
this._pdf.documentViewer.refreshAll();
|
||||
const currentPage = this._pdf.currentPage;
|
||||
this._pdf.documentViewer.updateView([currentPage], currentPage);
|
||||
this._documentViewer.refreshAndUpdateView();
|
||||
}
|
||||
|
||||
private async _stampExcludedPages(document: PDFNet.PDFDoc, excludedPages: number[]): Promise<void> {
|
||||
|
||||
@ -90,8 +90,7 @@ export class AnnotationDrawService {
|
||||
const annotations = annotationWrappers
|
||||
.map(annotation => this._computeAnnotation(annotation, dossierTemplateId, hideSkipped))
|
||||
.filter(a => !!a);
|
||||
this._pdf.annotationManager.addAnnotations(annotations, { imported: true });
|
||||
await this._pdf.annotationManager.drawAnnotationsFromList(annotations);
|
||||
await this._annotationManager.add(annotations);
|
||||
|
||||
if (this._userPreferenceService.areDevFeaturesEnabled) {
|
||||
const { dossierId, fileId } = this._pdf;
|
||||
@ -107,13 +106,9 @@ export class AnnotationDrawService {
|
||||
const sectionRectangles = sectionGrid.rectanglesPerPage[page];
|
||||
sectionRectangles.forEach(sectionRectangle => {
|
||||
sections.push(this._computeSection(dossierTemplateId, parseInt(page, 10), sectionRectangle));
|
||||
// sectionRectangle.tableCells?.forEach(cell =>{
|
||||
// sections.push(this.computeSection(activeViewer, parseInt(page, 10), cell));
|
||||
// })
|
||||
});
|
||||
}
|
||||
this._pdf.annotationManager.addAnnotations(sections, { imported: true });
|
||||
await this._pdf.annotationManager.drawAnnotationsFromList(sections);
|
||||
await this._annotationManager.add(sections);
|
||||
}
|
||||
|
||||
private _computeSection(dossierTemplateId: string, pageNumber: number, sectionRectangle: ISectionRectangle) {
|
||||
|
||||
@ -2,10 +2,10 @@ import { Injectable } from '@angular/core';
|
||||
import { Core } from '@pdftron/webviewer';
|
||||
import type { List } from '@iqser/common-ui';
|
||||
import { AnnotationPredicate, DeleteAnnotationsOptions } from '../utils/types';
|
||||
import { AnnotationWrapper } from '../../../models/file/annotation.wrapper';
|
||||
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
|
||||
import { fromEvent, Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { getId, isStringOrWrapper } from '../utils/functions';
|
||||
import { asList, getId, isStringOrWrapper } from '../utils/functions';
|
||||
import AnnotationManager = Core.AnnotationManager;
|
||||
import Annotation = Core.Annotations.Annotation;
|
||||
|
||||
@ -83,6 +83,21 @@ export class REDAnnotationManager {
|
||||
this.#manager.selectAnnotations(annotationsFromViewer);
|
||||
}
|
||||
|
||||
select(annotations: Annotation | Annotation[]) {
|
||||
this.#manager.selectAnnotations(asList(annotations));
|
||||
}
|
||||
|
||||
redraw(annotations: Annotation | Annotation[]) {
|
||||
annotations = asList(annotations);
|
||||
annotations.forEach(annotation => this.#manager.redrawAnnotation(annotation));
|
||||
}
|
||||
|
||||
add(annotations: Annotation | Annotation[]) {
|
||||
annotations = asList(annotations);
|
||||
this.#manager.addAnnotations(annotations, { imported: true });
|
||||
return this.#manager.drawAnnotationsFromList(annotations);
|
||||
}
|
||||
|
||||
#getById(annotation: AnnotationWrapper | string) {
|
||||
return this.#manager.getAnnotationById(getId(annotation));
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import { PdfViewer } from './pdf-viewer.service';
|
||||
import { UserPreferenceService } from '@services/user-preference.service';
|
||||
import { log, shareLast } from '@iqser/common-ui';
|
||||
import { stopAndPrevent, stopAndPreventIfNotAllowed } from '../utils/functions';
|
||||
import { RotationType, RotationTypes } from '@red/domain';
|
||||
import DocumentViewer = Core.DocumentViewer;
|
||||
import Color = Core.Annotations.Color;
|
||||
import Quad = Core.Math.Quad;
|
||||
@ -148,6 +149,28 @@ export class REDDocumentViewer {
|
||||
}
|
||||
}
|
||||
|
||||
refreshAndUpdateView() {
|
||||
this.#document.refreshAll();
|
||||
const currentPage = this._pdf.currentPage;
|
||||
this.#document.updateView([currentPage], currentPage);
|
||||
}
|
||||
|
||||
resetRotation(pages: number | number[] | string | string[]) {
|
||||
if (!(pages instanceof Array)) {
|
||||
pages = [Number(pages)];
|
||||
}
|
||||
|
||||
pages.forEach(page => this.#document.setRotation(0, Number(page)));
|
||||
}
|
||||
|
||||
rotate(rotation: RotationType, page = this._pdf.currentPage) {
|
||||
if (rotation === RotationTypes.LEFT) {
|
||||
this.#document.rotateCounterClockwise(page);
|
||||
} else {
|
||||
this.#document.rotateClockwise(page);
|
||||
}
|
||||
}
|
||||
|
||||
#setCurrentPage() {
|
||||
const currentDocPage = this._activatedRoute.snapshot.queryParamMap.get('page');
|
||||
this.#document.setCurrentPage(Number(currentDocPage ?? '1'));
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { BehaviorSubject, firstValueFrom, of } from 'rxjs';
|
||||
import { RotationType, RotationTypes } from '@red/domain';
|
||||
import { RotationType } from '@red/domain';
|
||||
import { FileManagementService } from '../../../services/files/file-management.service';
|
||||
import { distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators';
|
||||
import {
|
||||
@ -16,8 +16,7 @@ import { FilesService } from '../../../services/files/files.service';
|
||||
import { PdfViewer } from './pdf-viewer.service';
|
||||
import { FilesMapService } from '../../../services/files/files-map.service';
|
||||
import { NGXLogger } from 'ngx-logger';
|
||||
|
||||
const ONE_ROTATION_DEGREE = 90;
|
||||
import { REDDocumentViewer } from './document-viewer.service';
|
||||
|
||||
@Injectable()
|
||||
export class PageRotationService {
|
||||
@ -31,6 +30,7 @@ export class PageRotationService {
|
||||
private readonly _fileManagementService: FileManagementService,
|
||||
private readonly _filesService: FilesService,
|
||||
private readonly _filesMapService: FilesMapService,
|
||||
private readonly _documentViewer: REDDocumentViewer,
|
||||
) {}
|
||||
|
||||
get hasRotations() {
|
||||
@ -68,15 +68,7 @@ export class PageRotationService {
|
||||
}
|
||||
|
||||
discardRotation() {
|
||||
const rotations = this.#rotations$.value;
|
||||
|
||||
for (const page of Object.keys(rotations)) {
|
||||
const times = rotations[page] / ONE_ROTATION_DEGREE;
|
||||
for (let i = 1; i <= times; i++) {
|
||||
this._pdf.documentViewer.rotateCounterClockwise(Number(page));
|
||||
}
|
||||
}
|
||||
|
||||
this._documentViewer.resetRotation(Object.keys(this.#rotations$.value));
|
||||
this.clearRotations();
|
||||
}
|
||||
|
||||
@ -87,11 +79,7 @@ export class PageRotationService {
|
||||
|
||||
this.#rotations$.next({ ...this.#rotations$.value, [pageNumber]: rotationValue });
|
||||
|
||||
if (rotation === RotationTypes.LEFT) {
|
||||
this._pdf.documentViewer.rotateCounterClockwise(pageNumber);
|
||||
} else {
|
||||
this._pdf.documentViewer.rotateClockwise(pageNumber);
|
||||
}
|
||||
this._documentViewer.rotate(rotation);
|
||||
}
|
||||
|
||||
clearRotations() {
|
||||
|
||||
@ -14,7 +14,6 @@ import { Rgb } from '../utils/types';
|
||||
import { asList } from '../utils/functions';
|
||||
import { REDAnnotationManager } from './annotation-manager.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import AnnotationManager = Core.AnnotationManager;
|
||||
import TextTool = Core.Tools.TextTool;
|
||||
import Annotation = Core.Annotations.Annotation;
|
||||
import TextHighlightAnnotation = Core.Annotations.TextHighlightAnnotation;
|
||||
@ -32,10 +31,7 @@ export class PdfViewer {
|
||||
* @deprecated Use REDDocumentViewer service instead
|
||||
*/
|
||||
documentViewer: DocumentViewer;
|
||||
/**
|
||||
* @deprecated Use REDAnnotationManager service instead
|
||||
*/
|
||||
annotationManager: AnnotationManager;
|
||||
|
||||
fileId: string;
|
||||
dossierId: string;
|
||||
|
||||
@ -144,7 +140,6 @@ export class PdfViewer {
|
||||
this._logger.info('[PDF] Initialized');
|
||||
|
||||
this.documentViewer = this.#instance.Core.documentViewer;
|
||||
this.annotationManager = this.#instance.Core.annotationManager;
|
||||
|
||||
this.compareMode$ = this.#compareMode$.asObservable();
|
||||
this.pageChanged$ = this.#pageChanged$.pipe(shareLast());
|
||||
|
||||
@ -25,9 +25,12 @@ export function isStringOrWrapper(value: unknown): value is string | AnnotationW
|
||||
return typeof value === 'string' || value instanceof AnnotationWrapper;
|
||||
}
|
||||
|
||||
export function asList<T>(items: T[] | T): T[];
|
||||
export function asList(items: string[] | string): string[];
|
||||
export function asList(items: AnnotationWrapper[] | AnnotationWrapper): AnnotationWrapper[];
|
||||
export function asList(items: string[] | string | AnnotationWrapper[] | AnnotationWrapper): string[] | AnnotationWrapper[] {
|
||||
export function asList<T>(
|
||||
items: string[] | string | AnnotationWrapper[] | AnnotationWrapper | T | T[],
|
||||
): string[] | AnnotationWrapper[] | T[] {
|
||||
if (typeof items === 'string') {
|
||||
return [items];
|
||||
}
|
||||
@ -36,5 +39,10 @@ export function asList(items: string[] | string | AnnotationWrapper[] | Annotati
|
||||
return [items];
|
||||
}
|
||||
|
||||
const isArray = items instanceof Array;
|
||||
if (!isArray) {
|
||||
return [items];
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user