[cairo] [Bug 90166] Add a way to specify units (in SVG output)

Antonio Ospite ao2 at ao2.it
Mon Oct 30 22:20:15 UTC 2017


On Thu, 12 Oct 2017 21:59:08 +1030
Adrian Johnson <ajohnson at redneon.com> wrote:

[...]
> The enum in the patch is:
> 
> typedef enum _cairo_svg_unit {

[...]

> } cairo_svg_unit_t;
> 
> This looks good to me. It just needs a getter.
>

About the getter function, what do you prefer?

1. A function which returns the unit in the return value.

   This seems the more natural approach, but what to return if the
   surface is not a SVG surface? In this case I could set the error code
   and return the default SVG unit, and document this behavior in the
   API doc.
   
   This was my first version:

    cairo_svg_unit_t
    cairo_svg_surface_get_document_unit (cairo_surface_t *abstract_surface) +{
        cairo_svg_surface_t *surface = NULL; /* hide compiler warning */

        if (! _extract_svg_surface (abstract_surface, &surface)) {
           _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
           return CAIRO_SVG_UNIT_USER;
        }

        return surface->document->unit;
    }

2. A function which returns the unit in an output parameter and returns
   a status in the return value.
   
   This seems more robust; is it cairo-style?

    cairo_status_t
    cairo_svg_surface_get_document_unit (cairo_surface_t	*abstract_surface,
                                         cairo_svg_unit_t	*unit)
    {
        cairo_svg_surface_t *surface = NULL; /* hide compiler warning */

        if (! _extract_svg_surface (abstract_surface, &surface))
            return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);

        *unit = surface->document->unit;
        return CAIRO_STATUS_SUCCESS;
    }

> Are all the units in SVG 1.1? If not the minimum version will need to
> be documented.
>

All the units are in SVG 1.0 already, so nothing to add about that.

> The default unit will also need to be documented.
>

I'll mention that the default unit for *cairo* is "pt".

Ciao,
   Antonio


-- 
Antonio Ospite
https://ao2.it
https://twitter.com/ao2it

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?


More information about the cairo mailing list