I'm trying to develop a C program based on https://github.com/songulabuzar/librsvg-minimal-example, which reads and renders and SVG file, using both librsvg and cairo libraries.
I have noticed, that both libraries contain enums that define length units.
In (lib)cairo, in https://github.com/freedesktop/cairo/blob/7bf3a78/src/cairo-svg.h there is:
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;
... which is most obviously used with cairo_svg_surface_set_document_unit
function (declared in the same header file).
On the other hand, (lib)rsvg in https://github.com/GNOME/librsvg/blob/d158d11/include/librsvg/rsvg.h defines:
typedef enum {
RSVG_UNIT_PERCENT,
RSVG_UNIT_PX,
RSVG_UNIT_EM,
RSVG_UNIT_EX,
RSVG_UNIT_IN,
RSVG_UNIT_CM,
RSVG_UNIT_MM,
RSVG_UNIT_PT,
RSVG_UNIT_PC
} RsvgUnit;
... and specifically, it also defines a length with a unit:
typedef struct {
double length;
RsvgUnit unit;
} RsvgLength;
So, what I'd like to know, is: is there a function in either of these APIs, that converts one length with units to another unit?
Say, I have a defined length of 1.5 inches (in librsvg
, that would be a RsvgLength
with { .length = 1.5, .unit = RSVG_UNIT_IN }
) - is there a built-in function (in either of these APIs) to convert this kind of length to centimeters?
( as a reminder, for this example, 1.5 in = 3.81 cm ... I am aware that not all conversions would be a-priori possible, that is, converting cm to px (pixels) would also require the document DPI (dots-per-inch) ).