@@ -98,9 +98,7 @@ import { aspectRatioToNumber } from "./tools/frame";
98
98
99
99
import Cursors from "./cursors" ;
100
100
101
- // I can't get this to work! :-(
102
- // When I can, this should be window.devicePixelRatio
103
- const penDPIFactor = 1 ;
101
+ const penDPIFactor = window . devicePixelRatio ;
104
102
105
103
const MIDDLE_MOUSE_BUTTON = 1 ;
106
104
@@ -183,12 +181,6 @@ export default function Canvas({
183
181
} | null > ( null ) ;
184
182
185
183
const penCanvasRef = useRef < any > ( null ) ;
186
- useEffect ( ( ) => {
187
- const canvas = penCanvasRef . current ;
188
- if ( canvas == null ) return ;
189
- const ctx = canvas . getContext ( "2d" ) ;
190
- ctx . scale ( penDPIFactor , penDPIFactor ) ;
191
- } , [ ] ) ;
192
184
193
185
// Whenever the data <--> window transform params change,
194
186
// ensure the current center of the viewport is preserved,
@@ -864,9 +856,12 @@ export default function Canvas({
864
856
if ( canvas == null ) return ;
865
857
const ctx = canvas . getContext ( "2d" ) ;
866
858
if ( ctx == null ) return ;
859
+ ctx . restore ( ) ;
860
+ ctx . save ( ) ;
861
+ ctx . scale ( penDPIFactor , penDPIFactor ) ;
867
862
const path : Point [ ] = [ ] ;
868
863
for ( const point of mousePath . current . slice (
869
- mousePath . current . length - 3
864
+ mousePath . current . length - 2
870
865
) ) {
871
866
path . push ( {
872
867
x : point . x * canvasScaleRef . current ,
0 commit comments