[librsvg/rustification] Use a new rsvg_drawing_ctx_get_dpi() accessor throughout
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustification] Use a new rsvg_drawing_ctx_get_dpi() accessor throughout
- Date: Thu, 17 Nov 2016 00:28:48 +0000 (UTC)
commit 11282a185a9723b75bd5f8e53b26a3afddcaca3a
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Nov 16 14:49:20 2016 -0600
Use a new rsvg_drawing_ctx_get_dpi() accessor throughout
Instead of accessing ctx->{dpi_x,dpi_y} directly.
rsvg-base.c | 17 +++++++++++++++--
rsvg-cairo-draw.c | 6 +++++-
rsvg-css.c | 10 +++++++---
rsvg-private.h | 3 +++
rsvg-text.c | 6 ++++--
5 files changed, 34 insertions(+), 8 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index 302c117..eda5934 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -2381,8 +2381,21 @@ rsvg_drawing_ctx_pop_view_box (RsvgDrawingCtx * ctx)
void
rsvg_drawing_ctx_get_view_box_size (RsvgDrawingCtx *ctx, double *out_width, double *out_height)
{
- *out_width = ctx->vb.rect.width;
- *out_height = ctx->vb.rect.height;
+ if (out_width)
+ *out_width = ctx->vb.rect.width;
+
+ if (out_height)
+ *out_height = ctx->vb.rect.height;
+}
+
+void
+rsvg_drawing_ctx_get_dpi (RsvgDrawingCtx *ctx, double *out_dpi_x, double *out_dpi_y)
+{
+ if (out_dpi_x)
+ *out_dpi_x = ctx->dpi_x;
+
+ if (out_dpi_y)
+ *out_dpi_y = ctx->dpi_y;
}
void
diff --git a/rsvg-cairo-draw.c b/rsvg-cairo-draw.c
index 17cdd8d..070b76a 100644
--- a/rsvg-cairo-draw.c
+++ b/rsvg-cairo-draw.c
@@ -464,11 +464,15 @@ rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
PangoFontMap *fontmap;
PangoContext *context;
RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
+ double dpi_y;
fontmap = pango_cairo_font_map_get_default ();
context = pango_font_map_create_context (fontmap);
pango_cairo_update_context (render->cr, context);
- pango_cairo_context_set_resolution (context, ctx->dpi_y);
+
+ rsvg_drawing_ctx_get_dpi (ctx, NULL, &dpi_y);
+ pango_cairo_context_set_resolution (context, dpi_y);
+
return context;
}
diff --git a/rsvg-css.c b/rsvg-css.c
index 12c721d..00d5674 100644
--- a/rsvg-css.c
+++ b/rsvg-css.c
@@ -143,15 +143,19 @@ _rsvg_css_normalize_length (const RsvgLength * in, RsvgDrawingCtx * ctx)
else
return in->length * font / 2.;
} else if (in->unit == LENGTH_UNIT_INCH) {
+ double dpi_x, dpi_y;
+
+ rsvg_drawing_ctx_get_dpi (ctx, &dpi_x, &dpi_y);
+
switch (in->dir) {
case LENGTH_DIR_HORIZONTAL:
- return in->length * ctx->dpi_x;
+ return in->length * dpi_x;
case LENGTH_DIR_VERTICAL:
- return in->length * ctx->dpi_y;
+ return in->length * dpi_y;
case LENGTH_DIR_BOTH:
- return in->length * rsvg_viewport_percentage (ctx->dpi_x, ctx->dpi_y);
+ return in->length * rsvg_viewport_percentage (dpi_x, dpi_y);
}
} else if (in->unit == LENGTH_UNIT_RELATIVE_LARGER) {
/* todo: "larger" */
diff --git a/rsvg-private.h b/rsvg-private.h
index 059ea23..1e8c8a6 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -447,6 +447,9 @@ G_GNUC_INTERNAL
void rsvg_drawing_ctx_get_view_box_size (RsvgDrawingCtx *ctx, double *out_width, double *out_height);
G_GNUC_INTERNAL
+void rsvg_drawing_ctx_get_dpi (RsvgDrawingCtx *ctx, double *out_dpi_x, double *out_dpi_y);
+
+G_GNUC_INTERNAL
void rsvg_SAX_handler_struct_init (void);
G_GNUC_INTERNAL
char *rsvg_get_url_string (const char *str);
diff --git a/rsvg-text.c b/rsvg-text.c
index a807d90..e2950d3 100644
--- a/rsvg-text.c
+++ b/rsvg-text.c
@@ -513,6 +513,7 @@ rsvg_text_create_layout (RsvgDrawingCtx * ctx,
PangoLayout *layout;
PangoAttrList *attr_list;
PangoAttribute *attribute;
+ double dpi_y;
if (state->lang)
pango_context_set_language (context, pango_language_from_string (state->lang));
@@ -532,9 +533,10 @@ rsvg_text_create_layout (RsvgDrawingCtx * ctx,
pango_font_description_set_variant (font_desc, state->font_variant);
pango_font_description_set_weight (font_desc, state->font_weight);
pango_font_description_set_stretch (font_desc, state->font_stretch);
+
+ rsvg_drawing_ctx_get_dpi (ctx, NULL, &dpi_y);
pango_font_description_set_size (font_desc,
- _rsvg_css_normalize_font_size (state, ctx) *
- PANGO_SCALE / ctx->dpi_y * 72);
+ _rsvg_css_normalize_font_size (state, ctx) * PANGO_SCALE / dpi_y * 72);
layout = pango_layout_new (context);
pango_layout_set_font_description (layout, font_desc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]