[librsvg/rustification] Use a new rsvg_drawing_ctx_get_normalized_font_size(); make the computation in a helper function



commit b55970ae21f2f773e98ede77cba7f8ce5b86fefe
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Nov 16 15:08:07 2016 -0600

    Use a new rsvg_drawing_ctx_get_normalized_font_size(); make the computation in a helper function
    
    The public rsvg_drawing_ctx_get_normalized_font_size() just takes an
    RsvgDrawingCtx and operates on the current state.  The
    actual (recursive) computation is now done in a helper function, which
    is also of use for computing the baseline_shift.

 rsvg-css.c     |   16 +++++++++++-----
 rsvg-private.h |    3 ++-
 rsvg-text.c    |    2 +-
 3 files changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/rsvg-css.c b/rsvg-css.c
index 00d5674..a601fff 100644
--- a/rsvg-css.c
+++ b/rsvg-css.c
@@ -92,8 +92,8 @@ rsvg_css_parse_vbox (const char *vbox)
 }
 
 /* Recursive evaluation of all parent elements regarding absolute font size */
-double
-_rsvg_css_normalize_font_size (RsvgState * state, RsvgDrawingCtx * ctx)
+static double
+normalize_font_size (RsvgState * state, RsvgDrawingCtx * ctx)
 {
     RsvgState *parent;
 
@@ -104,7 +104,7 @@ _rsvg_css_normalize_font_size (RsvgState * state, RsvgDrawingCtx * ctx)
         parent = rsvg_state_parent (state);
         if (parent) {
             double parent_size;
-            parent_size = _rsvg_css_normalize_font_size (parent, ctx);
+            parent_size = normalize_font_size (parent, ctx);
             return state->font_size.length * parent_size;
         }
         break;
@@ -117,6 +117,12 @@ _rsvg_css_normalize_font_size (RsvgState * state, RsvgDrawingCtx * ctx)
 }
 
 double
+rsvg_drawing_ctx_get_normalized_font_size (RsvgDrawingCtx *ctx)
+{
+    return normalize_font_size (rsvg_current_state (ctx), ctx);
+}
+
+double
 _rsvg_css_normalize_length (const RsvgLength * in, RsvgDrawingCtx * ctx)
 {
     if (in->unit == LENGTH_UNIT_DEFAULT)
@@ -137,7 +143,7 @@ _rsvg_css_normalize_length (const RsvgLength * in, RsvgDrawingCtx * ctx)
             return in->length * rsvg_viewport_percentage (w, h);
         }
     } else if (in->unit == LENGTH_UNIT_FONT_EM || in->unit == LENGTH_UNIT_FONT_EX) {
-        double font = _rsvg_css_normalize_font_size (rsvg_current_state (ctx), ctx);
+        double font = rsvg_drawing_ctx_get_normalized_font_size (ctx);
         if (in->unit == LENGTH_UNIT_FONT_EM)
             return in->length * font;
         else
@@ -177,7 +183,7 @@ _rsvg_css_accumulate_baseline_shift (RsvgState * state, RsvgDrawingCtx * ctx)
     if (parent) {
         if (state->has_baseline_shift) {
             double parent_font_size;
-            parent_font_size = _rsvg_css_normalize_font_size (parent, ctx); /* font size from here */
+            parent_font_size = normalize_font_size (parent, ctx); /* font size from here */
             shift = parent_font_size * state->baseline_shift;
         }
         shift += _rsvg_css_accumulate_baseline_shift (parent, ctx); /* baseline-shift for parent element */
diff --git a/rsvg-private.h b/rsvg-private.h
index 1e8c8a6..bc58bb2 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -431,7 +431,8 @@ double rsvg_length_hand_normalize (const RsvgLength *length,
                                    double font_size);
 
 G_GNUC_INTERNAL
-double _rsvg_css_normalize_font_size    (RsvgState * state, RsvgDrawingCtx * ctx);
+double rsvg_drawing_ctx_get_normalized_font_size (RsvgDrawingCtx * ctx);
+
 G_GNUC_INTERNAL
 double _rsvg_css_accumulate_baseline_shift (RsvgState * state, RsvgDrawingCtx * ctx);
 
diff --git a/rsvg-text.c b/rsvg-text.c
index c50e2fb..1bb7eed 100644
--- a/rsvg-text.c
+++ b/rsvg-text.c
@@ -538,7 +538,7 @@ rsvg_text_create_layout (RsvgDrawingCtx * ctx, const char *text, PangoContext *
 
     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 / dpi_y * 72);
+                                     rsvg_drawing_ctx_get_normalized_font_size (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]