From e6ec3c2630997b271042fddc8fdcc4d124e4866a Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 24 May 2023 23:48:57 +0100 Subject: [PATCH 2/2] * src/rsvg-port.c: Fix out-of-memory conditions with newer librsvg * src/rsvg-port.c (rsvg_port_preset_slot): Adjust for change of behavior of `rsvg_handle_get_intrinsic_dimensions' in librsvg 2.53+. The compile-time macro `LIBRSVG_CHECK_VERSION` is not used, as it is possible to build against one version but run against another version. Excerpts from `rsvg_handle_get_intrinsic_dimensions' section in `librsvg/rsvg.h': ``` * Before librsvg 2.54.0, the `out_has_width` and `out_has_height` arguments would be set to true or false * depending on whether the SVG document actually had `width` and `height` attributes, respectively. * * However, since librsvg 2.54.0, `width` and `height` are now [geometry * properties](https://www.w3.org/TR/SVG2/geometry.html) per the SVG2 specification; they * are not plain attributes. SVG2 made it so that the initial value of those properties * is `auto`, which is equivalent to specifing a value of `100%`. In this sense, even SVG * documents which lack `width` or `height` attributes semantically have to make them * default to `100%`. This is why since librsvg 2.54.0, `out_has_width` and * `out_has_heigth` are always returned as `TRUE`, since with SVG2 all documents *have* a * default width and height of `100%`. * ``` Signed-off-by: Hin-Tak Leung --- src/rsvg-port.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/rsvg-port.c b/src/rsvg-port.c index d446861..07f65ec 100644 --- a/src/rsvg-port.c +++ b/src/rsvg-port.c @@ -241,12 +241,27 @@ { dimension_svg.width = (int)out_width.length; /* XXX rounding? */ dimension_svg.height = (int)out_height.length; + + /* + * librsvg 2.53+ behavior, on svg doc without explicit width/height. + * See `rsvg_handle_get_intrinsic_dimensions' section in + * the "librsvg/rsvg.h" header. + */ + if (((int)out_width.length == 1) && ((int)out_height.length == 1)) { + dimension_svg.width = units_per_EM; + dimension_svg.height = units_per_EM; + } } else { - /* If neither `ViewBox` nor `width`/`height` are present, the */ - /* `units_per_EM` in SVG coordinates must be the same as */ - /* `units_per_EM` of the TTF/CFF outlines. */ + /* + * If neither `ViewBox` nor `width`/`height` are present, the + * `units_per_EM` in SVG coordinates must be the same as + * `units_per_EM` of the TTF/CFF outlines. + * + * librsvg up to 2.52 behavior, on svg doc without explicit + * width/height. + */ dimension_svg.width = units_per_EM; dimension_svg.height = units_per_EM; } -- 2.40.1