[librsvg/librsvg-2.40] Backport: build: Check for PangoFT2/FontConfig availability



commit 892a29c2b5010bfd4a952d842fc690425a258690
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Oct 4 09:33:01 2017 -0500

    Backport: build: Check for PangoFT2/FontConfig availability
    
    From commit 46c8688aa1795958fb1308c2bf5ea29295fe6c23
    
    On Windows the GTK+ stack does not hard depend on PangoFT2 (thus
    Fontconfig--GTK+ uses PangoWin32 to do the Font discovery and
    configuration stuff by default, unless one uses an envvar to force
    PangoFT2 usage), unlike *NIX platforms, so we need to check for
    it by doing:
    
    -On Windows, enable the test code that uses PangoFT2/FontConfig if
     PangoFT2 and FontConfig is found during configure.  On Visual Studio
     builds, this is set to be disabled in config.h.win32(.in), and can be
     manually enabled by uncommenting #define HAVE_PANGOFT2 1 in
     config.h.win32 prior to the build (or rebuild).  This continues to have
     FontConfig and PangoFT2 to act as an optional dependency.
    
    -On non-Windows platforms, make PangoFT2 and FontConfig a hard dependency,
     which is what the current code assumes.
    
    We might probably need to make the custom TTF load via PangoWin32 and/or
    the native Windows API to run the tests when PangoFT2 and FontConfig are
    not found on Windows.
    
    Also bump the Pango dependency to 1.38 as the test code uses API that is
    introduced in 1.38.x.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779405

 config.h.win32.in   |    3 +++
 configure.ac        |   22 ++++++++++++++++++++--
 rsvg-cairo-clip.c   |    2 ++
 rsvg-cairo-draw.c   |   23 +++++++++++++++++------
 rsvg-cairo-render.c |   13 +++++++++++++
 rsvg-cairo-render.h |    6 ++++++
 6 files changed, 61 insertions(+), 8 deletions(-)
---
diff --git a/config.h.win32.in b/config.h.win32.in
index 8e298dc..7d4ee6b 100644
--- a/config.h.win32.in
+++ b/config.h.win32.in
@@ -20,6 +20,9 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #define HAVE_MEMORY_H 1
 
+/* Have the pangoft2 library */
+/* #define HAVE_PANGOFT2 1 */
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #if !defined (_MSC_VER) || (_MSC_VER >= 1600)
 #define HAVE_STDINT_H 1
diff --git a/configure.ac b/configure.ac
index c6582b4..0ffe74d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,7 +35,7 @@ GLIB_REQUIRED=2.12.0
 GIO_REQUIRED=2.24.0
 LIBXML_REQUIRED=2.9.0
 CAIRO_REQUIRED=1.2.0
-PANGOCAIRO_REQUIRED=1.32.6
+PANGO_REQUIRED=1.38.0
 GDK_PIXBUF_REQUIRED=2.20
 GTK3_REQUIRED=3.10.0
 CROCO_REQUIRED=0.6.1
@@ -102,7 +102,8 @@ PKG_CHECK_MODULES(LIBRSVG, \
        glib-2.0 >= $GLIB_REQUIRED \
        gio-2.0 >= $GIO_REQUIRED \
        libxml-2.0 >= $LIBXML_REQUIRED \
-       pangocairo >= $PANGOCAIRO_REQUIRED \
+       pangocairo >= $PANGO_REQUIRED \
+       pangoft2 >= $PANGO_REQUIRED \
        cairo >= $CAIRO_REQUIRED \
        cairo-png >= $CAIRO_REQUIRED
         libcroco-0.6 >= $CROCO_REQUIRED)
@@ -260,6 +261,23 @@ GLIB_LC_MESSAGES
 
 dnl ===========================================================================
 
+# Check for pangoft2 and fontconfig, which is optional on Windows
+
+PKG_CHECK_MODULES([PANGOFT2],[pangoft2 >= $PANGO_REQUIRED],[have_pangoft2=yes],[have_pangoft2=no])
+PKG_CHECK_MODULES([FONTCONFIG],[fontconfig],[have_fontconfig=yes],[have_fontconfig=no])
+
+if test "x$native_win32" != "xyes"; then
+  if test "x$have_pangoft2" != "xyes" -o "x$have_fontconfig" != "xyes"; then
+    AC_MSG_ERROR([pangoft2 and fontconfig are required for non-Windows platforms.])
+  fi
+fi
+
+if test "x$have_pangoft2" = "xyes" -a "x$have_fontconfig" = "xyes"; then
+  AC_DEFINE(HAVE_PANGOFT2, 1, [Have the pangoft2 library])
+fi
+
+dnl ===========================================================================
+
 # Check whether MSVC toolset is explicitly set
 AM_CONDITIONAL(MSVC_BASE_NO_TOOLSET_SET, [test x$MSVC_BASE_TOOLSET = x])
 AM_CONDITIONAL(MSVC_NO_TOOLSET_SET, [test x$MSVC_TOOLSET = x])
diff --git a/rsvg-cairo-clip.c b/rsvg-cairo-clip.c
index 909a89f..bea1e04 100644
--- a/rsvg-cairo-clip.c
+++ b/rsvg-cairo-clip.c
@@ -27,6 +27,8 @@
             Carl Worth <cworth cworth org>
 */
 
+#include "config.h"
+
 #include "rsvg-cairo-draw.h"
 #include "rsvg-cairo-clip.h"
 #include "rsvg-cairo-render.h"
diff --git a/rsvg-cairo-draw.c b/rsvg-cairo-draw.c
index 0a50255..71a981e 100644
--- a/rsvg-cairo-draw.c
+++ b/rsvg-cairo-draw.c
@@ -27,6 +27,8 @@
             Carl Worth <cworth cworth org>
 */
 
+#include "config.h"
+
 #include "rsvg-cairo-draw.h"
 #include "rsvg-cairo-render.h"
 #include "rsvg-cairo-clip.h"
@@ -364,6 +366,7 @@ _set_rsvg_affine (RsvgCairoRender * render, cairo_matrix_t *affine)
     cairo_set_matrix (cr, &matrix);
 }
 
+#ifdef HAVE_PANGOFT2
 static cairo_font_options_t *
 get_font_options_for_testing (void)
 {
@@ -405,15 +408,17 @@ create_font_config_for_testing (RsvgCairoRender *render)
 static PangoFontMap *
 get_font_map_for_testing (RsvgCairoRender *render)
 {
-    PangoFontMap *font_map;
-
     create_font_config_for_testing (render);
 
-    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), render->font_config_for_testing);
+    if (!render->font_map_for_testing) {
+        render->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 (render->font_map_for_testing),
+                                      render->font_config_for_testing);
+    }
 
-    return font_map;
+    return render->font_map_for_testing;
 }
+#endif
 
 PangoContext *
 rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
@@ -422,20 +427,26 @@ rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
     PangoContext *context;
     RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
 
+#ifdef HAVE_PANGOFT2
     if (ctx->is_testing) {
         fontmap = get_font_map_for_testing (render);
     } else {
+#endif
         fontmap = pango_cairo_font_map_get_default ();
+#ifdef HAVE_PANGOFT2
     }
+#endif
 
     context = pango_font_map_create_context (fontmap);
     pango_cairo_update_context (render->cr, context);
 
     pango_cairo_context_set_resolution (context, ctx->dpi_y);
 
+#ifdef HAVE_PANGOFT2
     if (ctx->is_testing) {
         set_font_options_for_testing (context);
     }
+#endif
 
     return context;
 }
@@ -450,7 +461,7 @@ rsvg_cairo_render_pango_layout (RsvgDrawingCtx * ctx, PangoLayout * layout, doub
     PangoGravity gravity = pango_context_get_gravity (pango_layout_get_context (layout));
     double rotation;
 
-    pango_layout_get_extents (layout, &ink, NULL);
+    pango_layout_get_extents(layout, &ink, NULL);
 
     if (ink.width == 0 || ink.height == 0) {
         return;
diff --git a/rsvg-cairo-render.c b/rsvg-cairo-render.c
index 546336b..f958ba3 100644
--- a/rsvg-cairo-render.c
+++ b/rsvg-cairo-render.c
@@ -25,6 +25,8 @@
    Caleb Moore <c moore student unsw edu au>
 */
 
+#include "config.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <glib.h>
@@ -46,11 +48,18 @@ rsvg_cairo_render_free (RsvgRender * self)
 
     /* TODO */
 
+#ifdef HAVE_PANGOFT2
     if (me->font_config_for_testing) {
         FcConfigDestroy (me->font_config_for_testing);
         me->font_config_for_testing = NULL;
     }
 
+    if (me->font_map_for_testing) {
+        g_object_unref (me->font_map_for_testing);
+        me->font_map_for_testing = NULL;
+    }
+#endif
+
     g_free (me);
 }
 
@@ -78,7 +87,11 @@ rsvg_cairo_render_new (cairo_t * cr, double width, double height)
     cairo_render->cr_stack = NULL;
     cairo_render->bb_stack = NULL;
     cairo_render->surfaces_stack = NULL;
+
+#ifdef HAVE_PANGOFT2
     cairo_render->font_config_for_testing = NULL;
+    cairo_render->font_map_for_testing = NULL;
+#endif
 
     return cairo_render;
 }
diff --git a/rsvg-cairo-render.h b/rsvg-cairo-render.h
index d3bd6a7..291c779 100644
--- a/rsvg-cairo-render.h
+++ b/rsvg-cairo-render.h
@@ -30,7 +30,10 @@
 
 #include "rsvg-private.h"
 #include <cairo.h>
+
+#ifdef HAVE_PANGOFT2
 #include <pango/pangofc-fontmap.h>
+#endif
 
 G_BEGIN_DECLS typedef struct _RsvgCairoRender RsvgCairoRender;
 
@@ -50,7 +53,10 @@ struct _RsvgCairoRender {
     GList *bb_stack;
     GList *surfaces_stack;
 
+#ifdef HAVE_PANGOFT2
     FcConfig *font_config_for_testing;
+    PangoFontMap *font_map_for_testing;
+#endif
 };
 
 #define RSVG_CAIRO_RENDER(render) (_RSVG_RENDER_CIC ((render), RSVG_RENDER_TYPE_CAIRO, RsvgCairoRender))


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