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

Antonio Ospite ao2 at ao2.it
Thu Oct 12 10:25:41 UTC 2017

On Wed, 11 Oct 2017 16:19:18 -0700
spitzak at gmail.com (Bill Spitzak) wrote:

> Proposed api:
> void cairo_svg_surface_set_document_unit (cairo_surface_t*, const char*)
> The string pointer must point at a valid svg unit type, such as "pt"
> or "em". NULL is the same as "" (which means "user" units). The
> function should do some basic sanity checks (maximum length, and only
> printing ASCII) and is a no-op if it fails.

The API addition I originally proposed[1,2] looks like this:

void cairo_svg_surface_set_document_unit (cairo_surface_t*, cairo_svg_unit_t)

Where cairo_svg_unit_t is an enum type representing all the possible

The function signature is modeled after
cairo_svg_surface_restrict_to_version() which also uses an enum, so
cairo users are already familiar with this approach, and I think it's OK
for a few more reasons:

  1. IMHO it's a little more robust, it allows to produce only valid
     documents (after we discuss if relative units are safe to use).

  2. The implementation is simple, hence easy to validate, for instance
     there is no need to handle special characters like " to assure that
     the XML is well formed.

  3. The event of new units being added to the SVG spec seems quite
     rare, so having cairo react to that (even in a minor release) seems
     acceptable to me considering the benefits of 1. and 2.

Sanitizing user strings is a bother, when possible I prefer avoiding
a problem rather than having to solve it.

That said I am obviously open to suggestions, since I am not the one who
is going to maintain the codebase I will be OK with what the cairo
developers decide.

After we decide on the API I will bring up some more questions.


[1] https://bugs.freedesktop.org/show_bug.cgi?id=90166
[2] https://bugs.freedesktop.org/attachment.cgi?id=134799

Antonio Ospite

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