[librsvg: 1/2] Port default DPI tracking to Rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/2] Port default DPI tracking to Rust
- Date: Sun, 6 Jan 2019 02:54:41 +0000 (UTC)
commit d7ca2a9daf988e7efe7c88d04c70edb360b7f6b2
Author: Carlos MartÃn Nieto <cmn dwim me>
Date: Thu Jan 3 23:24:06 2019 +0000
Port default DPI tracking to Rust
It's the only place from where we're accessing it already.
librsvg/rsvg-base.c | 34 ++++------------------------------
librsvg/rsvg-private.h | 6 ------
rsvg_internals/src/dpi.rs | 29 +++++++++++++++++++++++------
3 files changed, 27 insertions(+), 42 deletions(-)
---
diff --git a/librsvg/rsvg-base.c b/librsvg/rsvg-base.c
index 54d0601e..caf1453b 100644
--- a/librsvg/rsvg-base.c
+++ b/librsvg/rsvg-base.c
@@ -29,14 +29,8 @@
#include "rsvg-private.h"
#include "rsvg-css.h"
-/*
- * This is configurable at runtime
- */
-#define RSVG_DEFAULT_DPI_X 90.0
-#define RSVG_DEFAULT_DPI_Y 90.0
-
-static double rsvg_internal_dpi_x = RSVG_DEFAULT_DPI_X;
-static double rsvg_internal_dpi_y = RSVG_DEFAULT_DPI_Y;
+/* Implemented in rsvg_internals/src/dpi.rs */
+extern void rsvg_rust_set_default_dpi_x_y(double dpi_x, double dpi_y);
/**
* rsvg_error_quark:
@@ -70,7 +64,7 @@ rsvg_error_quark (void)
void
rsvg_set_default_dpi (double dpi)
{
- rsvg_set_default_dpi_x_y (dpi, dpi);
+ rsvg_rust_set_default_dpi_x_y (dpi, dpi);
}
/**
@@ -91,27 +85,7 @@ rsvg_set_default_dpi (double dpi)
void
rsvg_set_default_dpi_x_y (double dpi_x, double dpi_y)
{
- if (dpi_x <= 0.)
- rsvg_internal_dpi_x = RSVG_DEFAULT_DPI_X;
- else
- rsvg_internal_dpi_x = dpi_x;
-
- if (dpi_y <= 0.)
- rsvg_internal_dpi_y = RSVG_DEFAULT_DPI_Y;
- else
- rsvg_internal_dpi_y = dpi_y;
-}
-
-double
-rsvg_get_default_dpi_x (void)
-{
- return rsvg_internal_dpi_x;
-}
-
-double
-rsvg_get_default_dpi_y (void)
-{
- return rsvg_internal_dpi_y;
+ rsvg_rust_set_default_dpi_x_y (dpi_x, dpi_y);
}
/**
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index 05c5cca7..add5f31c 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -60,12 +60,6 @@ typedef struct _RsvgNode RsvgNode;
#define N_(X) X
#endif
-G_GNUC_INTERNAL
-double rsvg_get_default_dpi_x (void);
-
-G_GNUC_INTERNAL
-double rsvg_get_default_dpi_y (void);
-
G_GNUC_INTERNAL
void rsvg_return_if_fail_warning (const char *pretty_function,
const char *expression, GError ** error);
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;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]