summaryrefslogtreecommitdiff
path: root/rsvg_internals
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2019-01-03 23:24:06 +0000
committerFederico Mena Quintero <federico@gnome.org>2019-01-05 20:50:52 -0600
commitd7ca2a9daf988e7efe7c88d04c70edb360b7f6b2 (patch)
tree0a4a0b4b6ddc3819c4e7547efc575494855d9d29 /rsvg_internals
parent575a809111b78eea8ee59753360ccecb254da786 (diff)
downloadlibrsvg-d7ca2a9daf988e7efe7c88d04c70edb360b7f6b2.tar.gz
Port default DPI tracking to Rust
It's the only place from where we're accessing it already.
Diffstat (limited to 'rsvg_internals')
-rw-r--r--rsvg_internals/src/dpi.rs29
1 files changed, 23 insertions, 6 deletions
diff --git a/rsvg_internals/src/dpi.rs b/rsvg_internals/src/dpi.rs
index 6d4693ba..fcbe13cb 100644
--- a/rsvg_internals/src/dpi.rs
+++ b/rsvg_internals/src/dpi.rs
@@ -1,9 +1,11 @@
use std::cell::Cell;
-extern "C" {
- fn rsvg_get_default_dpi_y() -> f64;
- fn rsvg_get_default_dpi_x() -> f64;
-}
+// This is configurable at runtime
+const DEFAULT_DPI_X: f64 = 90.0;
+const DEFAULT_DPI_Y: f64 = 90.0;
+
+static mut DPI_X: f64 = DEFAULT_DPI_X;
+static mut DPI_Y: f64 = DEFAULT_DPI_Y;
#[derive(Debug, Clone, Default)]
pub struct Dpi {
@@ -14,7 +16,7 @@ pub struct Dpi {
impl Dpi {
pub fn x(&self) -> f64 {
if self.x.get() <= 0.0 {
- unsafe { rsvg_get_default_dpi_x() }
+ unsafe { DPI_X }
} else {
self.x.get()
}
@@ -26,7 +28,7 @@ impl Dpi {
pub fn y(&self) -> f64 {
if self.y.get() <= 0.0 {
- unsafe { rsvg_get_default_dpi_y() }
+ unsafe { DPI_Y }
} else {
self.y.get()
}
@@ -36,3 +38,18 @@ impl Dpi {
self.y.set(dpi_y)
}
}
+
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_rust_set_default_dpi_x_y(dpi_x: f64, dpi_y: f64) {
+ if dpi_x <= 0.0 {
+ DPI_X = DEFAULT_DPI_X;
+ } else {
+ DPI_X = dpi_x;
+ }
+
+ if dpi_y <= 0.0 {
+ DPI_Y = DEFAULT_DPI_Y;
+ } else {
+ DPI_Y = dpi_y;
+ }
+}