Skip to content

Commit

Permalink
add magnFactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zxhd863943427 committed Aug 29, 2023
1 parent 3618a58 commit cc2cc04
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/src/asset/anno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,15 @@ async function getRectImgData(pdfObj: any) {
return;
}
const cavasElement = pageElement.querySelector(".canvasWrapper canvas") as HTMLCanvasElement;
let magnFactor = 1;
let scale;
const trueWith = cavasElement.getBoundingClientRect().width;
if (trueWith <= 0) {
scale = window.devicePixelRatio || 1;
} else {
scale = cavasElement.width / trueWith;
}
scale += magnFactor;
const rectStyle = (rectElement.firstElementChild as HTMLElement).style;
const captureLocation = {
width: scale * parseFloat(rectStyle.width),
Expand All @@ -690,7 +692,7 @@ async function getRectImgData(pdfObj: any) {
};

const pdfPage = await pdfObj.pdfDocument.getPage(parseInt(pageElement.getAttribute("data-page-number")));
const captureCanvas = await getCaptureCanvas(pdfPage, pdfObj.pdfViewer.currentScale);
const captureCanvas = await getCaptureCanvas(pdfPage, scale * pdfObj.pdfViewer.currentScale/(scale - magnFactor));
const captureImageData = captureCanvas.getContext("2d").getImageData(captureLocation.left, captureLocation.top, captureLocation.width, captureLocation.height);

const tempCanvas = document.createElement("canvas");
Expand Down

0 comments on commit cc2cc04

Please sign in to comment.