[pinpoint] Handle relative paths fully



commit 99d155acc0a3789d309863defc2f98ad354f0237
Author: Chris Lord <chris linux intel com>
Date:   Tue Mar 8 14:49:05 2011 -0800

    Handle relative paths fully
    
    Change the relative path handling so that it applies to all background
    types and add the same code in the cairo renderer as well. Fixes videos
    and SVGs not working when loading a presentation outside of its directory.

 pp-cairo.c   |   29 +++++++++++++++++++++++------
 pp-clutter.c |   25 +++++++++++++++++++------
 2 files changed, 42 insertions(+), 12 deletions(-)
---
diff --git a/pp-cairo.c b/pp-cairo.c
index d1cf2d6..3c91094 100644
--- a/pp-cairo.c
+++ b/pp-cairo.c
@@ -41,6 +41,7 @@
 typedef struct _CairoRenderer
 {
   PinPointRenderer renderer;
+  gchar      *path;
   GHashTable *surfaces;         /* keep cairo_surface_t around for source
                                    images as we wantt to only include one
                                    instance of the image when using it in
@@ -77,10 +78,11 @@ cairo_renderer_init (PinPointRenderer *pp_renderer,
   /* A4, landscape */
   renderer->surface = cairo_pdf_surface_create (pp_output_filename,
                                                 A4_LS_WIDTH, A4_LS_HEIGHT);
+  renderer->path = g_strdup (pinpoint_file);
 
   renderer->ctx = cairo_create (renderer->surface);
   renderer->surfaces = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                              NULL, _destroy_surface);
+                                              g_free, _destroy_surface);
   renderer->svgs = g_hash_table_new_full (g_str_hash, g_str_equal,
                                           NULL,
                                           g_object_unref);
@@ -225,7 +227,7 @@ _cairo_get_surface (CairoRenderer *renderer,
     }
 
   surface = _cairo_new_surface_from_pixbuf (pixbuf);
-  g_hash_table_insert (renderer->surfaces, (char *) file, surface);
+  g_hash_table_insert (renderer->surfaces, g_strdup (file), surface);
 
   /* If we embed a JPEG, we can actually insert the coded data into the PDF in
    * a lossless fashion (no recompression of the JPEG) */
@@ -279,6 +281,18 @@ static void
 _cairo_render_background (CairoRenderer *renderer,
                           PinPointPoint *point)
 {
+  gchar *full_path = NULL;
+  const gchar *file = point->bg;
+
+  if (point->bg_type != PP_BG_COLOR && renderer->path && file)
+    {
+      gchar *dir = g_path_get_dirname (renderer->path);
+      full_path = g_build_filename (dir, file, NULL);
+      g_free (dir);
+
+      file = full_path;
+    }
+
   if (point->stage_color)
     {
       ClutterColor color;
@@ -312,7 +326,7 @@ _cairo_render_background (CairoRenderer *renderer,
         cairo_surface_t *surface;
         float bg_x, bg_y, bg_width, bg_height, bg_scale_x, bg_scale_y;
 
-        surface = _cairo_get_surface (renderer, point->bg);
+        surface = _cairo_get_surface (renderer, file);
         if (surface == NULL)
           break;
 
@@ -342,12 +356,12 @@ _cairo_render_background (CairoRenderer *renderer,
         float bg_x, bg_y, bg_width, bg_height, bg_scale_x, bg_scale_y;
         GCancellable* cancellable = g_cancellable_new ();
 
-        pixbuf = gst_video_thumbnailer_get_shot (point->bg, cancellable);
+        pixbuf = gst_video_thumbnailer_get_shot (file, cancellable);
         if (pixbuf == NULL)
           break;
 
         surface = _cairo_new_surface_from_pixbuf (pixbuf);
-        g_hash_table_insert (renderer->surfaces, (char *) point->bg, surface);
+        g_hash_table_insert (renderer->surfaces, g_strdup (file), surface);
 
         bg_width = cairo_image_surface_get_width (surface);
         bg_height = cairo_image_surface_get_height (surface);
@@ -370,7 +384,7 @@ _cairo_render_background (CairoRenderer *renderer,
     case PP_BG_SVG:
 #ifdef HAVE_RSVG
       {
-        RsvgHandle *svg = _cairo_get_svg (renderer, point->bg);
+        RsvgHandle *svg = _cairo_get_svg (renderer, file);
         RsvgDimensionData dim;
         float bg_x, bg_y, bg_scale_x, bg_scale_y;
 
@@ -397,6 +411,8 @@ _cairo_render_background (CairoRenderer *renderer,
     default:
       g_assert_not_reached();
     }
+
+  g_free (full_path);
 }
 
 static void
@@ -491,6 +507,7 @@ cairo_renderer_finalize (PinPointRenderer *pp_renderer)
 {
   CairoRenderer *renderer = CAIRO_RENDERER (pp_renderer);
 
+  g_free (renderer->path);
   cairo_surface_destroy (renderer->surface);
   g_hash_table_unref (renderer->surfaces);
   g_hash_table_unref (renderer->svgs);
diff --git a/pp-clutter.c b/pp-clutter.c
index 7de1c65..7051d96 100644
--- a/pp-clutter.c
+++ b/pp-clutter.c
@@ -162,7 +162,7 @@ static gboolean pp_get_fullscreen (ClutterStage *stage)
 static void
 _destroy_surface (gpointer data)
 {
-  /* not destroying background, since it would be destoryed with
+  /* not destroying background, since it would be destroyed with
    * the stage itself.
    */
 }
@@ -400,7 +400,7 @@ _clutter_get_texture (ClutterRenderer *renderer,
   clutter_container_add_actor (CLUTTER_CONTAINER (renderer->stage), source);
   clutter_actor_hide (source);
 
-  g_hash_table_insert (renderer->bg_cache, (char *) file, source);
+  g_hash_table_insert (renderer->bg_cache, (char *) g_strdup (file), source);
 
   return clutter_clone_new (source);
 }
@@ -412,9 +412,20 @@ clutter_renderer_make_point (PinPointRenderer *pp_renderer,
 {
   ClutterRenderer *renderer = CLUTTER_RENDERER (pp_renderer);
   ClutterPointData *data = point->data;
+  const gchar *file = point->bg;
+  gchar *full_path = NULL;
   ClutterColor color;
   gboolean ret;
 
+  if (point->bg_type != PP_BG_COLOR && renderer->path && file)
+    {
+      gchar *dir = g_path_get_dirname (renderer->path);
+      full_path = g_build_filename (dir, file, NULL);
+      g_free (dir);
+
+      file = full_path;
+    }
+
   switch (point->bg_type)
     {
     case PP_BG_COLOR:
@@ -429,13 +440,13 @@ clutter_renderer_make_point (PinPointRenderer *pp_renderer,
       }
       break;
     case PP_BG_IMAGE:
-      data->background = _clutter_get_texture (renderer, point->bg);
+      data->background = _clutter_get_texture (renderer, file);
       ret = TRUE;
       break;
     case PP_BG_VIDEO:
 #ifdef USE_CLUTTER_GST
       data->background = clutter_gst_video_texture_new ();
-      clutter_media_set_filename (CLUTTER_MEDIA (data->background), point->bg);
+      clutter_media_set_filename (CLUTTER_MEDIA (data->background), file);
       /* should pre-roll the video and set the size */
       clutter_actor_set_size (data->background, 400, 300);
       ret = TRUE;
@@ -449,7 +460,7 @@ clutter_renderer_make_point (PinPointRenderer *pp_renderer,
 
         aa = pp_super_aa_new ();
         pp_super_aa_set_resolution (PP_SUPER_AA (aa), 2, 2);
-        svg = dax_actor_new_from_file (point->bg, &error);
+        svg = dax_actor_new_from_file (file, &error);
         mx_offscreen_set_pick_child (MX_OFFSCREEN (aa), TRUE);
         clutter_container_add_actor (CLUTTER_CONTAINER (aa),
                                      svg);
@@ -459,7 +470,7 @@ clutter_renderer_make_point (PinPointRenderer *pp_renderer,
         if (data->background == NULL)
           {
             g_warning ("Could not open SVG file %s: %s",
-                       point->bg, error->message);
+                       file, error->message);
             g_clear_error (&error);
           }
         ret = data->background != NULL;
@@ -470,6 +481,8 @@ clutter_renderer_make_point (PinPointRenderer *pp_renderer,
       g_assert_not_reached();
     }
 
+  g_free (full_path);
+
   if (data->background)
     {
       clutter_container_add_actor (CLUTTER_CONTAINER (renderer->background),



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