[librsvg: 2/14] handle: move the whole fontmap hack to tests



commit 2cb8f6ba58df7f4686231084a9692295b2f22532
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Jan 5 19:24:37 2019 +0100

    handle: move the whole fontmap hack to tests
    
    There is no reason to set the default fontmap from within handle.
    Setting the default fontmap is part of setting up the text fixture
    and can live in test-utils. Beside we do not need to hold on to
    the fontmap pointer, since setting by the default pango keeps its
    own reference.

 librsvg/rsvg-handle.c  | 72 --------------------------------------------------
 librsvg/rsvg-private.h |  6 -----
 tests/rsvg-test.c      |  2 ++
 tests/test-utils.c     | 50 +++++++++++++++++++++++++++++++++++
 tests/test-utils.h     |  3 +++
 5 files changed, 55 insertions(+), 78 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index 707cd052..ba962389 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -123,7 +123,6 @@
 #include <string.h>
 #include <limits.h>
 #include <stdlib.h>
-
 #include <glib/gprintf.h>
 #include "rsvg-private.h"
 
@@ -181,11 +180,6 @@ struct RsvgHandlePrivate {
 
     gboolean in_loop;          /* see get_dimension() */
 
-#ifdef HAVE_PANGOFT2
-    FcConfig *font_config_for_testing;
-    PangoFontMap *font_map_for_testing;
-#endif
-
     RsvgHandleRust *rust_handle;
 };
 
@@ -215,11 +209,6 @@ rsvg_handle_init (RsvgHandle * self)
 
     self->priv->in_loop = FALSE;
 
-#ifdef HAVE_PANGOFT2
-    self->priv->font_config_for_testing = NULL;
-    self->priv->font_map_for_testing = NULL;
-#endif
-
     self->priv->rust_handle = rsvg_handle_rust_new();
 }
 
@@ -234,12 +223,6 @@ rsvg_handle_dispose (GObject *instance)
     }
 
     g_clear_pointer (&self->priv->base_uri, g_free);
-
-#ifdef HAVE_PANGOFT2
-    g_clear_pointer (&self->priv->font_config_for_testing, FcConfigDestroy);
-    g_clear_object (&self->priv->font_map_for_testing);
-#endif
-
     g_clear_pointer (&self->priv->rust_handle, rsvg_handle_rust_free);
 
     G_OBJECT_CLASS (rsvg_handle_parent_class)->dispose (instance);
@@ -1315,60 +1298,6 @@ rsvg_handle_set_size_callback (RsvgHandle * handle,
     handle->priv->user_data_destroy = user_data_destroy;
 }
 
-#ifdef HAVE_PANGOFT2
-
-static FcConfig *
-create_font_config_for_testing (void)
-{
-    const char *font_paths[] = {
-        "resources/Roboto-Regular.ttf",
-        "resources/Roboto-Italic.ttf",
-        "resources/Roboto-Bold.ttf",
-        "resources/Roboto-BoldItalic.ttf",
-    };
-
-    FcConfig *config = FcConfigCreate ();
-    int i;
-
-    for (i = 0; i < G_N_ELEMENTS(font_paths); i++) {
-        char *font_path = g_test_build_filename (G_TEST_DIST, font_paths[i], NULL);
-
-        if (!FcConfigAppFontAddFile (config, (const FcChar8 *) font_path)) {
-            g_error ("Could not load font file \"%s\" for tests; aborting", font_path);
-        }
-
-        g_free (font_path);
-    }
-
-    return config;
-}
-
-#endif
-
-static void
-rsvg_handle_update_font_map_for_testing (RsvgHandle *handle, gboolean testing)
-{
-#ifdef HAVE_PANGOFT2
-    PangoCairoFontMap *font_map = NULL;
-
-    if (testing) {
-        if (handle->priv->font_config_for_testing == NULL) {
-            handle->priv->font_config_for_testing = create_font_config_for_testing ();
-        }
-
-        if (handle->priv->font_map_for_testing == NULL) {
-            handle->priv->font_map_for_testing = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
-            pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (handle->priv->font_map_for_testing),
-                                          handle->priv->font_config_for_testing);
-        }
-
-        font_map = PANGO_CAIRO_FONT_MAP (handle->priv->font_map_for_testing);
-    }
-
-    pango_cairo_font_map_set_default (font_map);
-#endif
-}
-
 /**
  * rsvg_handle_internal_set_testing:
  * @handle: a #RsvgHandle
@@ -1383,7 +1312,6 @@ rsvg_handle_internal_set_testing (RsvgHandle *handle, gboolean testing)
     g_return_if_fail (RSVG_IS_HANDLE (handle));
 
     rsvg_handle_rust_set_testing (handle->priv->rust_handle, testing);
-    rsvg_handle_update_font_map_for_testing (handle, testing);
 }
 
 /* This one is defined in the C code, because the prototype has varargs
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index 05c5cca7..d1f658d2 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -31,7 +31,6 @@
 
 #include "rsvg.h"
 
-#include <pango/pango.h>
 #include <glib.h>
 #include <glib-object.h>
 #include <math.h>
@@ -40,11 +39,6 @@
 # include <float.h>
 #endif
 
-#include <pango/pangocairo.h>
-#ifdef HAVE_PANGOFT2
-#include <pango/pangofc-fontmap.h>
-#endif
-
 G_BEGIN_DECLS 
 
 typedef struct RsvgDrawingCtx RsvgDrawingCtx;
diff --git a/tests/rsvg-test.c b/tests/rsvg-test.c
index dc4a99a3..348fd81c 100644
--- a/tests/rsvg-test.c
+++ b/tests/rsvg-test.c
@@ -320,6 +320,8 @@ main (int argc, char **argv)
 
     g_test_init (&argc, &argv, NULL);
 
+    test_utils_setup_font_map ();
+
     if (argc < 2) {
         GFile *base, *tests;
 
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 5b637ad0..a5dc7313 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -5,6 +5,11 @@
 #include "test-utils.h"
 
 #include <string.h>
+#include <pango/pango.h>
+#include <pango/pangocairo.h>
+#ifdef HAVE_PANGOFT2
+#include <pango/pangofc-fontmap.h>
+#endif
 
 /* Compare two buffers, returning the number of pixels that are
  * different and the maximum difference of any single color channel in
@@ -307,3 +312,48 @@ test_utils_add_test_for_all_files (const gchar   *prefix,
 
   g_list_free_full (files, g_object_unref);
 }
+
+#ifdef HAVE_PANGOFT2
+static FcConfig *
+create_font_config_for_testing (void)
+{
+    const char *font_paths[] = {
+        "resources/Roboto-Regular.ttf",
+        "resources/Roboto-Italic.ttf",
+        "resources/Roboto-Bold.ttf",
+        "resources/Roboto-BoldItalic.ttf",
+    };
+
+    FcConfig *config = FcConfigCreate ();
+    int i;
+
+    for (i = 0; i < G_N_ELEMENTS(font_paths); i++) {
+        char *font_path = g_test_build_filename (G_TEST_DIST, font_paths[i], NULL);
+
+        if (!FcConfigAppFontAddFile (config, (const FcChar8 *) font_path)) {
+            g_error ("Could not load font file \"%s\" for tests; aborting", font_path);
+        }
+
+        g_free (font_path);
+    }
+
+    return config;
+}
+#endif
+
+void
+test_utils_setup_font_map (void)
+{
+#ifdef HAVE_PANGOFT2
+    FcConfig *config = create_font_config_for_testing ();
+    PangoFontMap *font_map = NULL;
+
+    font_map = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
+    pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (font_map), config);
+    FcConfigDestroy (config);
+
+    pango_cairo_font_map_set_default (PANGO_CAIRO_FONT_MAP (font_map));
+
+    g_object_unref (font_map);
+#endif
+}
diff --git a/tests/test-utils.h b/tests/test-utils.h
index fdbf3b66..c974210a 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -31,6 +31,9 @@ void         test_utils_add_test_for_all_files  (const gchar    *prefix,
                                                  GFile          *file,
                                                  GTestDataFunc   test_func,
                                                  AddTestFunc     add_test_func);
+
+void test_utils_setup_font_map (void);
+
 G_END_DECLS
 
 #endif /* TEST_UTILS_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]