Skip to content

Commit

Permalink
Revert width change code
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-reflectivity committed Mar 28, 2020
1 parent 662f19a commit 795df7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/app/pdf-viewer/pdf-viewer.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ describe('AppComponent', () => {
});

describe('getScale', () => {
it('should get scale 1 with viewportWidth = 0 or viewerContainerWidth = 0', function() {
pdfViewerFixture.detectChanges();
it('should get scale 1 with offsetWidth = 0', function () {
let spy = spyOnProperty(
(pdfViewer as any).pdfViewerContainer.nativeElement,
'clientWidth',
(pdfViewer as any).element.nativeElement,
'offsetWidth',
'get'
).and.returnValue(0);

Expand Down
22 changes: 10 additions & 12 deletions src/app/pdf-viewer/pdf-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,21 @@ export class PdfViewerComponent
.getPage(currentViewer.currentPageNumber)
.then((page: PDFPageProxy) => {
const rotation = this._rotation || page.rotate;
const viewportWidth =
(page as any).getViewport({
scale: this._zoom,
rotation
}).width * PdfViewerComponent.CSS_UNITS;
const viewport = (page as any).getViewport({
scale: this._zoom,
rotation
});
let scale = this._zoom;
let stickToPage = true;

// Scale the document when it shouldn't be in original size or doesn't fit into the viewport
if (
!this._originalSize ||
(this._fitToPage &&
viewportWidth > this.pdfViewerContainer.nativeElement.clientWidth)
viewport.width > this.element.nativeElement.offsetWidth)
) {
scale = this.getScale(
(page as any).getViewport({ scale: 1, rotation })
.width
(page as any).getViewport({ scale: 1, rotation }).width
);
stickToPage = !this._stickToPage;
}
Expand Down Expand Up @@ -590,16 +588,16 @@ export class PdfViewerComponent
}

private getScale(viewportWidth: number) {
const pdfContainerWidth =
this.pdfViewerContainer.nativeElement.clientWidth -
const offsetWidth =
this.element.nativeElement.offsetWidth -
(this._showBorders ? 2 * PdfViewerComponent.BORDER_WIDTH : 0);

if (pdfContainerWidth === 0 || viewportWidth === 0) {
if (offsetWidth === 0) {
return 1;
}

return (
(this._zoom * (pdfContainerWidth / viewportWidth)) /
(this._zoom * (offsetWidth / viewportWidth)) /
PdfViewerComponent.CSS_UNITS
);
}
Expand Down

0 comments on commit 795df7c

Please sign in to comment.