mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2438] fixed thumbnails height (#3407)
* [ADF-2438] calculate thumbnail height * [ADF-2438] send height to parent element * [ADF-2438] add width to css * [ADF-2438] moved height and width logic to parent component * [ADF-2438] added height and width logic to parent component * [ADF-2438] fixed failing test
This commit is contained in:
committed by
Eugenio Romano
parent
2f51b9f2b8
commit
1266acc4ab
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, Input, OnInit, ElementRef, ViewEncapsulation } from '@angular/core';
|
||||
import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
@@ -30,16 +30,17 @@ export class PdfThumbComponent implements OnInit {
|
||||
|
||||
image$: Promise<string>;
|
||||
|
||||
constructor(
|
||||
private element: ElementRef, private sanitizer: DomSanitizer) {}
|
||||
constructor(private sanitizer: DomSanitizer) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.image$ = this.page.getPage().then((page) => this.getThumb(page));
|
||||
}
|
||||
|
||||
private getThumb(page): Promise<string> {
|
||||
const canvas = this.getCanvas();
|
||||
const viewport = page.getViewport(1);
|
||||
|
||||
const pageRatio = viewport.width / viewport.height;
|
||||
const canvas = this.getCanvas(pageRatio);
|
||||
const scale = Math.min((canvas.height / viewport.height), (canvas.width / viewport.width));
|
||||
|
||||
return page.render({
|
||||
@@ -52,13 +53,10 @@ export class PdfThumbComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
private getCanvas(): HTMLCanvasElement {
|
||||
const elementRect = this.element.nativeElement.getBoundingClientRect();
|
||||
private getCanvas(pageRatio): HTMLCanvasElement {
|
||||
const canvas = document.createElement('canvas');
|
||||
|
||||
canvas.width = elementRect.width;
|
||||
canvas.height = elementRect.height;
|
||||
|
||||
canvas.width = this.page.getWidth();
|
||||
canvas.height = this.page.getHeight();
|
||||
return canvas;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user