Method

RsvgHandleget_intrinsic_size_in_pixels

since: 2.52

Declaration [src]

gboolean
rsvg_handle_get_intrinsic_size_in_pixels (
  RsvgHandle* handle,
  gdouble* out_width,
  gdouble* out_height
)

Description [src]

Converts an SVG document’s intrinsic dimensions to pixels, and returns the result.

This function is able to extract the size in pixels from an SVG document if the document has both width and height attributes with physical units (px, in, cm, mm, pt, pc) or font-based units (em, ex). For physical units, the dimensions are normalized to pixels using the dots-per-inch (DPI) value set previously with rsvg_handle_set_dpi(). For font-based units, this function uses the computed value of the font-size property for the toplevel <svg> element. In those cases, this function returns TRUE.

For historical reasons, the default DPI is 90. Current CSS assumes a default DPI of 96, so you may want to set the DPI of a RsvgHandle immediately after creating it with rsvg_handle_set_dpi().

This function is not able to extract the size in pixels directly from the intrinsic dimensions of the SVG document if the width or height are in percentage units (or if they do not exist, in which case the SVG spec mandates that they default to 100%), as these require a viewport to be resolved to a final size. In this case, the function returns FALSE.

For example, the following document fragment has intrinsic dimensions that will resolve to 20x30 pixels.

<svg xmlns="http://www.w3.org/2000/svg" width="20" height="30"/>

Similarly, if the DPI is set to 96, this document will resolve to 192×288 pixels (i.e. 96×2 × 96×3).

<svg xmlns="http://www.w3.org/2000/svg" width="2in" height="3in"/>

The dimensions of the following documents cannot be resolved to pixels directly, and this function would return FALSE for them:

<!-- Needs a viewport against which to compute the percentages. -->
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"/>

<!-- Does not have intrinsic width/height, just a 1:2 aspect ratio which
     needs to be fitted within a viewport. -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 200"/>

Instead of querying an SVG document’s size, applications are encouraged to render SVG documents to a size chosen by the application, by passing a suitably-sized viewport to rsvg_handle_render_document().

Available since: 2.52

Parameters

out_width

Type: gdouble*

Will be set to the computed width; you should round this up to get integer pixels.

The argument will be set by the function.
The argument can be NULL.
out_height

Type: gdouble*

Will be set to the computed height; you should round this up to get integer pixels.

The argument will be set by the function.
The argument can be NULL.

Return value

Type: gboolean

TRUE if the dimensions could be converted directly to pixels; in this case out_width and out_height will be set accordingly. Note that the dimensions are floating-point numbers, so your application can know the exact size of an SVG document. To get integer dimensions, you should use ceil() to round up to the nearest integer (just using round(), may may chop off pixels with fractional coverage). If the dimensions cannot be converted to pixels, returns FALSE and puts 0.0 in both out_width and out_height.