Skip to content

Commit

Permalink
[QuickSignPDF] Fix Fabric canvas scale bug (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhatib authored Dec 15, 2022
1 parent 303020a commit 71f99c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
15 changes: 10 additions & 5 deletions src/PDFViewer/FabricPagePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ const FabricPagePreview = forwardRef<FabricJSEditor, Props>(function (

const onFabricReady = useCallback(
(canvas) => {
canvas.width = viewport!.width;
canvas.height = viewport!.height;
if (viewport) {
canvas.width = viewport.width;
canvas.height = viewport.height;
}
canvas.setZoom(scale || 1);
onReady(canvas);
},
Expand All @@ -67,8 +69,11 @@ const FabricPagePreview = forwardRef<FabricJSEditor, Props>(function (
}, [load]);

useEffect(() => {
editor?.canvas.setZoom(scale || 1);
}, [editor?.canvas, scale]);
if (!viewport || !editor) return;
editor.canvas.setZoom(scale || 1);
editor.canvas.setWidth(viewport.width);
editor.canvas.setHeight(viewport.height);
}, [editor, scale, viewport]);

return (
<div className="relative">
Expand All @@ -80,7 +85,7 @@ const FabricPagePreview = forwardRef<FabricJSEditor, Props>(function (
height={viewport?.height}
></canvas>
{/* Drawing Canvas */}
{viewport && (
{scale && (
<FabricJSCanvas
className="absolute top-0 right-0 left-0 bottom-0"
onReady={onFabricReady}
Expand Down
8 changes: 0 additions & 8 deletions src/QuickSignPDF/QuickSignPDF.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
/**
* To implement this, the DrawablePagePreview implements a double canvas
* mechanism that overlay a drawable canvas over the PDF renderer canvas.
*
* Limitations:
* - Once the user hits download the drawings are BURNED into the PDF pages and
* humans can no longer draw on top of it. Not sure why this happens but it seems
* it seems we can only burn onto the PDF once. Need investigation.
* - We can't currently control the scale of the PDF preview because it affects
* the scale the paths are affected in scaled and position.
*/

import {
ArrowLeftCircleIcon,
ArrowRightCircleIcon,
Expand Down

0 comments on commit 71f99c5

Please sign in to comment.