Re: errors during fo:external-graphic processing

Tony Graham <[email protected]> Sun, 11 Sep 2005 11:43:25 +0100
Newsgroups gmane.text.xml.xmlroff.general
Message-ID <[email protected]>
Stefan Seefeld <[email protected]> writes:
> Stefan Seefeld wrote:
>
>> Now that looks like something I can contribute (as opposed to
>> things such as how to split areas), so if you hold on a bit
>> I may come up with a patch.
>
> What about this one ?

It looks pretty good, though I have yet to try it.

My quibbles are:

 - I don't want to introduce a dependency on xmlChar (and the libxml2 header
   files) in an FO's header file. (You can probably find where there already
   is one amongst the FOs and properties, but if there is, I'd like to remove
   it, too.)

   The xmlChar* should be translated to gchar*.

 - I think we still need fo_external_graphic_new() (i.e., with no arguments)
   for GObject compatibility.

   There probably should either be a
   fo_external_graphic_new_with_base_uri(gchar*) or a
   fo_external_graphic_set_base_uri(gchar*) in addition to
   fo_external_graphic_new().

And after thinking about it for a while, I can dredge up:

 - The base URI property should be declared as a GObject-style property as
   well, which means stuff in fo_external_graphic_class_init(),
   fo_external_graphic_set_property(), fo_external_graphic_get_property(), and
   the base_url should be freed in fo_external_graphic_finalize().

   I can take care of those aspects.

 - The base URI string should be copied to make the FoExternalGraphic property
   value just so it's safer to free either the XmlDoc or the FO.

 - The base URI should be passed to fo_image_new_from_url(gchar* base_uri,
   gchar* uri) since the same URI resolution will be required for
   background-image and possibly other properties.

   (In time, there will be an FoImageManager or similar that you use to get an
   FoImage.  The manager will keep a map of URIs and images so you don't
   create duplicate FoImage objects for the same image, and it can do the URI
   resolution.)

Thank you for doing this.  I will incorporate your ideas before the next
release.

Regards,


Tony.

> Regards,
> 		Stefan
> Index: result-to-fo.c
> ===================================================================
> RCS file: /cvsroot/xmlroff/xmlroff/result-to-fo.c,v
> retrieving revision 1.25
> diff -u -r1.25 result-to-fo.c
> --- result-to-fo.c	13 Jun 2005 22:22:41 -0000	1.25
> +++ result-to-fo.c	10 Sep 2005 14:54:33 -0000
> @@ -216,7 +216,8 @@
>      break; /* end 'd' */
>    case 'e':
>      if (strcmp (name, "external-graphic") == 0) {
> -      fo_node = fo_external_graphic_new ();
> +      xmlChar *base_uri = xmlNodeGetBase(node->doc, node);
> +      fo_node = fo_external_graphic_new (base_uri);
>        ok = TRUE;
>      }
>      break; /* end 'e' */
> Index: fo/fo-external-graphic-private.h
> ===================================================================
> RCS file: /cvsroot/xmlroff/xmlroff/fo/fo-external-graphic-private.h,v
> retrieving revision 1.7
> diff -u -r1.7 fo-external-graphic-private.h
> --- fo/fo-external-graphic-private.h	9 Sep 2005 11:00:57 -0000	1.7
> +++ fo/fo-external-graphic-private.h	10 Sep 2005 14:54:34 -0000
> @@ -23,6 +23,7 @@
>    FoFo        parent_instance;
>  
>    FoDoc      *fo_doc;
> +  xmlChar    *base_url;
>    FoImage    *fo_image;
>    gdouble     area_width;
>    gdouble     area_height;
> Index: fo/fo-external-graphic.c
> ===================================================================
> RCS file: /cvsroot/xmlroff/xmlroff/fo/fo-external-graphic.c,v
> retrieving revision 1.19
> diff -u -r1.19 fo-external-graphic.c
> --- fo/fo-external-graphic.c	9 Sep 2005 11:00:57 -0000	1.19
> +++ fo/fo-external-graphic.c	10 Sep 2005 14:54:36 -0000
> @@ -84,6 +84,7 @@
>  #include "fo-property-src.h"
>  #include "fo-property-text-align.h"
>  #include "fo-property-width.h"
> +#include "libxml/uri.h"
>  
>  /* ORC = U+FFFC
>   *     = 1111 1111 1111 1100 (UTF-16)
> @@ -1290,9 +1291,17 @@
>   * Return value: the new #FoExternalGraphic.
>   **/
>  FoFo*
> -fo_external_graphic_new (void)
> +fo_external_graphic_new (xmlChar *base_url)
>  {
> -  return FO_FO (g_object_new (fo_external_graphic_get_type (), NULL));
> +  FoFo *fo_fo = FO_FO(g_object_new (fo_external_graphic_get_type (), NULL));
> +  FO_EXTERNAL_GRAPHIC(fo_fo)->base_url = base_url;
> +  return fo_fo;
> +}
> +
> +xmlChar*
> +fo_external_graphic_get_base_url (FoFo *fo_fo)
> +{
> +  return FO_EXTERNAL_GRAPHIC(fo_fo)->base_url;
>  }
>  
>  /**
> @@ -1403,7 +1412,8 @@
>                                GError   **error)
>  {
>    FoExternalGraphic *fo_external_graphic;
> -
> +  gchar *src, *url;
> +  
>    g_return_if_fail (fo != NULL);
>    g_return_if_fail (FO_IS_EXTERNAL_GRAPHIC (fo));
>    g_return_if_fail (FO_IS_CONTEXT (current_context));
> @@ -1419,8 +1429,9 @@
>    fo_external_graphic_set_line_height (fo,
>  				       fo_property_line_height_resolve (fo_external_graphic->line_height,
>  									fo_context_get_font_size (fo->context)));
> -  fo_external_graphic->fo_image =
> -    fo_image_new_from_url (fo_uri_specification_get_value (fo_property_get_value (fo_external_graphic->src)));
> +  src = fo_uri_specification_get_value (fo_property_get_value (fo_external_graphic->src));
> +  url = xmlBuildURI(fo_external_graphic->base_url, src);
> +  fo_external_graphic->fo_image = fo_image_new_from_url (url);
>    fo_external_graphic_layout_resolve (fo_external_graphic);
>  }
>  
> Index: fo/fo-external-graphic.h
> ===================================================================
> RCS file: /cvsroot/xmlroff/xmlroff/fo/fo-external-graphic.h,v
> retrieving revision 1.4
> diff -u -r1.4 fo-external-graphic.h
> --- fo/fo-external-graphic.h	30 Mar 2004 22:45:41 -0000	1.4
> +++ fo/fo-external-graphic.h	10 Sep 2005 14:54:36 -0000
> @@ -28,7 +28,9 @@
>  
>  
>  GType         fo_external_graphic_get_type      (void) G_GNUC_CONST;
> -FoFo *fo_external_graphic_new (void);
> +FoFo *fo_external_graphic_new (xmlChar *base_uri);
> +
> +xmlChar*    fo_external_graphic_get_base_url (FoFo       *fo_fo);
>  
>  FoProperty* fo_external_graphic_get_alignment_adjust (FoFo       *fo_fo);
>  void        fo_external_graphic_set_alignment_adjust (FoFo       *fo_fo,



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf