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

Antonio Ospite ao2 at ao2.it
Mon Oct 23 21:54:15 UTC 2017


On Mon, 23 Oct 2017 10:29:16 -0700
Bill Spitzak <spitzak at gmail.com> wrote:

> If I understand that right, "percent" is not allowed in the style attribute.
>

The focus here are the "width" and "height" attributes of the root
<svg/>, IIUC they are presentation attributes which allow percent as a
unit, to back up this argument I verified that files with percent as
unit in there do validate according to the "unofficial" XML schemas
available online:
https://github.com/oreillymedia/HTMLBook/tree/master/schema/svg
https://github.com/ao2/HTMLBook/tree/svg-schema-add-version-attribute/schema/svg

See also one of my previous messages.

> Also it seems like the default is "user". By default I mean what svg
> does if you don't specify the unit at all. If cairo has been forcing
> that value to pt then I think Cairo is wrong.
>

It may very well be wrong, but that's the current behavior and
that's what users (either human or not) might expect, so I don't think
it'd be wise to change the default unit cairo uses for the generated
SVGs.

However having as CAIRO_SVG_UNIT_USER as first in the enum definition
makes sense following this rationale:

  1. The enum lists all the units allowed by the specification,
     regardless of where they are used in cairo.

  2. It's only the new API call cairo_svg_surface_set_document_unit()
     that refers specifically to the root <svg/> element.

So following to 1. this enum might be OK:

typedef enum _cairo_svg_unit {
    CAIRO_SVG_UNIT_USER = 0,
    CAIRO_SVG_UNIT_EM,
    CAIRO_SVG_UNIT_EX,
    CAIRO_SVG_UNIT_PX,
    CAIRO_SVG_UNIT_IN,
    CAIRO_SVG_UNIT_CM,
    CAIRO_SVG_UNIT_MM,
    CAIRO_SVG_UNIT_PT,
    CAIRO_SVG_UNIT_PC,
    CAIRO_SVG_UNIT_PERCENT
} cairo_svg_unit_t;

This also seems to follow the specification[1] more naturally, i.e.:
explicit units match the optional pattern ("em" | "ex" | ... )?

I can add a comment when initializing the default document->unit to
CAIRO_SVG_UNIT_PT to stress out that this value is used for backward
compatibility.

Thanks,
   Antonio

[1] https://www.w3.org/TR/SVG/types.html#DataTypeLength

-- 
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