diff --git a/.gitignore b/.gitignore index 0f28dff..cbcd806 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ backup/* examples/wasm-demo/www/pkg examples/.ipynb_checkpoints/ tarpaulin-report.html -.vscode/* \ No newline at end of file +.vscode/* +.idea/ diff --git a/Cargo.toml b/Cargo.toml index 53952f7..25f847b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ wasm-bindgen = "0.2.55" [dependencies.web-sys] version = "0.3.32" -features = ['Document', 'DomRect', 'Element', 'HtmlElement', 'Node', 'Window', 'HtmlCanvasElement', 'CanvasRenderingContext2d'] +features = ['Document', 'DomRect', 'Element', 'HtmlElement', 'Node', 'Window', 'HtmlCanvasElement', 'CanvasRenderingContext2d', 'CssStyleDeclaration'] [dev-dependencies] plotters = "^0.3.0" diff --git a/src/canvas.rs b/src/canvas.rs index 216e8fa..0924906 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -1,3 +1,4 @@ +use std::str::FromStr; use js_sys::JSON; use wasm_bindgen::{JsCast, JsValue}; use web_sys::{window, CanvasRenderingContext2d, HtmlCanvasElement}; @@ -80,7 +81,13 @@ impl DrawingBackend for CanvasBackend { type ErrorType = CanvasError; fn get_size(&self) -> (u32, u32) { - (self.canvas.width(), self.canvas.height()) + let style = window().unwrap() + .get_computed_style(&self.canvas) + .unwrap().unwrap(); + let width = style.get_property_value("width").unwrap().replace("px", ""); + let height = style.get_property_value("height").unwrap().replace("px", ""); + (u32::from_str(&width).unwrap(), + u32::from_str(&height).unwrap()) } fn ensure_prepared(&mut self) -> Result<(), DrawingErrorKind> {