manpagez: man pages & more
html files: rsvg-2.0
Home | html | info | man

Migrating to the geometry APIs

Until librsvg 2.44, the available APIs to query the geometry of a layer or element were these:

struct _RsvgPositionData {
    int x;
    int y;
};

gboolean rsvg_handle_get_position_sub (RsvgHandle       *handle,
                                       RsvgPositionData *position_data,
                                       const char       *id);

struct _RsvgDimensionData {
    int width;
    int height;
    gdouble em;
    gdouble ex;
};

gboolean rsvg_handle_get_dimensions_sub (RsvgHandle        *handle,
                                         RsvgDimensionData *dimension_data,
                                         const char        *id);
    

These functions are inconvenient — separate calls to get the position and dimensions —, and also inexact, since they only return integer values, while SVG uses floating-point units.

Since librsvg 2.46, you can use these functions instead:

typedef struct {
    double x;
    double y;
    double width;
    double height;
} RsvgRectangle;

gboolean rsvg_handle_get_geometry_for_layer (RsvgHandle           *handle,
                                             const char           *id,
                                             const RsvgRectangle  *viewport,
                                             RsvgRectangle        *out_ink_rect,
                                             RsvgRectangle        *out_logical_rect,
                                             GError              **error);

gboolean rsvg_handle_get_geometry_for_element (RsvgHandle     *handle,
                                               const char     *id,
                                               RsvgRectangle  *out_ink_rect,
                                               RsvgRectangle  *out_logical_rect,
                                               GError        **error);
    

These functions return exact floating-point values. They also give you the ink rectangle, or area covered by paint, as well as the logical rectangle, which is the extents of unstroked paths (i.e. just the outlines).

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.