Commit fa49e24b authored by Carlos Martín Nieto's avatar Carlos Martín Nieto

Port default DPI tracking to Rust

It's the only place from where we're accessing it already.
parent 575a8091
Pipeline #49203 failed with stages
in 25 minutes and 3 seconds
......@@ -29,14 +29,7 @@
#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;
extern void rsvg_rust_set_default_dpi_x_y(float dpi_x, float dpi_y);
/**
* rsvg_error_quark:
......@@ -70,7 +63,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 +84,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);
}
/**
......
......@@ -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);
......
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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment