mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[AAE-4009] Fix horizontal scroll issue for pdf-viewer (#7023)
* [AAE-4009] Fix horizontal scroll issue for pdf-viewer * [AAE-4009] Rewrite method with single exit
This commit is contained in:
parent
f3ada4ef85
commit
f7ec24d1bb
@ -625,6 +625,16 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
}, 25000);
|
||||
|
||||
it('should check if page fits to documentContainer', (done) => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent, 'checkPageFitInContainer');
|
||||
componentUrlTestComponent.pdfViewerComponent.scalePage(1);
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.checkPageFitInContainer).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Zoom', () => {
|
||||
|
@ -306,6 +306,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
}
|
||||
horizontalScale = Math.round(horizontalScale);
|
||||
scale = Math.min(this.MAX_AUTO_SCALE, horizontalScale);
|
||||
scale = this.checkPageFitInContainer(scale);
|
||||
|
||||
break;
|
||||
default:
|
||||
@ -316,6 +317,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
this.setScaleUpdatePages(scale);
|
||||
} else {
|
||||
this.currentScale = 0;
|
||||
scale = this.checkPageFitInContainer(scale);
|
||||
this.setScaleUpdatePages(scale);
|
||||
}
|
||||
}
|
||||
@ -329,6 +331,20 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
return document.getElementById(`${this.randomPdfId}-viewer-viewerPdf`);
|
||||
}
|
||||
|
||||
checkPageFitInContainer(scale: number): number {
|
||||
const documentContainerSize = this.getDocumentContainer();
|
||||
const page = this.pdfViewer._pages[this.pdfViewer._currentPageNumber - 1];
|
||||
|
||||
if (page.width > documentContainerSize.clientWidth) {
|
||||
scale = Math.fround((documentContainerSize.clientWidth - 20) / page.width);
|
||||
if (scale < this.MIN_SCALE) {
|
||||
scale = this.MIN_SCALE;
|
||||
}
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all the pages with the newScale scale
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user