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

Antonio Ospite <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
On Thu, 12 Oct 2017 21:59:08 +1030
Adrian Johnson <[email protected]> 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?
-- 
cairo mailing list
[email protected]
https://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.