[librsvg] build: Check for PangoFT2/FontConfig availability



commit 46c8688aa1795958fb1308c2bf5ea29295fe6c23
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Mar 3 15:19:42 2017 +0800

    build: Check for PangoFT2/FontConfig availability
    
    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        |   19 ++++++++++++++++++-
 rsvg-cairo-clip.c   |    2 ++
 rsvg-cairo-draw.c   |   12 +++++++++++-
 rsvg-cairo-render.c |    7 +++++++
 rsvg-cairo-render.h |    5 +++++
 6 files changed, 46 insertions(+), 2 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 822baec..fd471be 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,7 +42,7 @@ GLIB_REQUIRED=2.12.0
 GIO_REQUIRED=2.24.0
 LIBXML_REQUIRED=2.7.0
 CAIRO_REQUIRED=1.2.0
-PANGO_REQUIRED=1.32.6
+PANGO_REQUIRED=1.38.0
 GDK_PIXBUF_REQUIRED=2.20
 GTK3_REQUIRED=3.10.0
 CROCO_REQUIRED=0.6.1
@@ -296,6 +296,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])
diff --git a/rsvg-cairo-clip.c b/rsvg-cairo-clip.c
index 0a09f84..8cb956b 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 76abbb3..ed32639 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"
@@ -130,6 +132,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)
 {
@@ -181,6 +184,7 @@ get_font_map_for_testing (RsvgCairoRender *render)
 
     return render->font_map_for_testing;
 }
+#endif
 
 PangoContext *
 rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
@@ -190,11 +194,15 @@ rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
     RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
     double dpi_y;
 
+#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);
@@ -202,9 +210,11 @@ rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
     rsvg_drawing_ctx_get_dpi (ctx, NULL, &dpi_y);
     pango_cairo_context_set_resolution (context, dpi_y);
 
+#ifdef HAVE_PANGOFT2
     if (ctx->is_testing) {
         set_font_options_for_testing (context);
     }
+#endif
 
     return context;
 }
@@ -230,7 +240,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 b4d5a2f..c94a97d 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>
@@ -48,6 +50,7 @@ rsvg_cairo_render_free (RsvgRender * self)
     g_assert (me->bb_stack == NULL);
     g_assert (me->surfaces_stack == NULL);
 
+#ifdef HAVE_PANGOFT2
     if (me->font_config_for_testing) {
         FcConfigDestroy (me->font_config_for_testing);
         me->font_config_for_testing = NULL;
@@ -57,6 +60,7 @@ rsvg_cairo_render_free (RsvgRender * self)
         g_object_unref (me->font_map_for_testing);
         me->font_map_for_testing = NULL;
     }
+#endif
 
     g_free (me);
 }
@@ -86,8 +90,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
 
     cairo_matrix_init_identity (&matrix);
     rsvg_bbox_init (&cairo_render->bbox, &matrix);
diff --git a/rsvg-cairo-render.h b/rsvg-cairo-render.h
index ddd92ac..ada9179 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,8 +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]