adjusts canvas backend size by dpr
@@ -74,8 +74,10 @@ impl DrawingBackend for CanvasBackend {
fn get_size(&self) -> (u32, u32) {
// Getting just canvas.width gives poor results on HighDPI screens.
- let rect = self.canvas.get_bounding_client_rect();
- (rect.width() as u32, rect.height() as u32)
+ let window = window()?;
+ let mut dpr = window.device_pixel_ratio();
+ dpr = if dpr == 0 { 1 } else { dpr };
+ ((canvas.width() as f64 / dpr) as u32, (canvas.height() as f64 / dpr) as u32)
}
fn ensure_prepared(&mut self) -> Result<(), DrawingErrorKind<CanvasError>> {
