Fix create/destroy/set/get Lua Rsvg functions.

We need an interface to be able to create/destroy/set/get the
RsvgRectangle and RsvgDimensionData structs via Lua, which were missing
or incomplete.

Documentation was also missing, which has been updated.
This commit is contained in:
Brenden Matthews
2022-10-16 11:30:05 -05:00
committed by Brenden Matthews
parent e99a555097
commit 589b240360
3 changed files with 121 additions and 11 deletions

View File

@@ -29,12 +29,16 @@
#include <librsvg/rsvg.h>
#include <stdlib.h>
RsvgDimensionData *rsvgDimensionDataCreate(void) {
RsvgDimensionData *rsvg_dimension_data_create(void) {
return (RsvgDimensionData *)calloc(1, sizeof(RsvgDimensionData));
}
void rsvgDimensionDataGet(RsvgDimensionData *dd, int *width, int *height,
double *em, double *ex) {
void rsvg_dimension_data_destroy(RsvgDimensionData *pointer) {
if (pointer) { free(pointer); }
}
void rsvg_dimension_data_get(RsvgDimensionData *dd, int *width, int *height,
double *em, double *ex) {
if (dd) {
*width = dd->width;
*height = dd->height;
@@ -43,6 +47,16 @@ void rsvgDimensionDataGet(RsvgDimensionData *dd, int *width, int *height,
}
}
void rsvg_dimension_data_set(RsvgDimensionData *dd, int width, int height,
double em, double ex) {
if (dd) {
dd->width = width;
dd->height = height;
dd->em = em;
dd->ex = ex;
}
}
RsvgPositionData *rsvgPositionDataCreate(void) {
return (RsvgPositionData *)calloc(1, sizeof(RsvgPositionData));
}
@@ -78,4 +92,30 @@ int rsvg_destroy_handle(RsvgHandle *handle) {
return 0;
}
RsvgRectangle *rsvg_rectangle_create(void) {
return calloc(1, sizeof(RsvgRectangle));
}
void rsvg_rectangle_destroy(RsvgRectangle *rect) { free(rect); }
void rsvg_rectangle_set(RsvgRectangle *rect, double x, double y, double width,
double height) {
if (rect) {
rect->x = x;
rect->y = y;
rect->width = width;
rect->height = height;
}
}
void rsvg_rectangle_get(RsvgRectangle *rect, double *x, double *y,
double *width, double *height) {
if (rect) {
*x = rect->x;
*y = rect->y;
*width = rect->width;
*height = rect->height;
}
}
#endif /* _LIBRSVG_HELPER_H_ */

View File

@@ -61,9 +61,12 @@ typedef struct _RsvgDimensionData {
int height;
double em;
double ex;
static tolua_outside RsvgDimensionData * rsvgDimensionDataCreate @ create();
tolua_outside void rsvgDimensionDataGet @ get(int * width, int * height,
static tolua_outside RsvgDimensionData* rsvg_dimension_data_create @ create();
static tolua_outside void rsvg_dimension_data_destroy @ destroy(RsvgDimensionData *);
tolua_outside void rsvg_dimension_data_get @ get(int * width, int * height,
double * em, double * ex);
tolua_outside void rsvg_dimension_data_set @ get(int width, int height,
double em, double ex);
} RsvgDimensionData;
/**
@@ -82,6 +85,11 @@ typedef struct _RsvgRectangle {
double y;
double width;
double height;
static tolua_outside RsvgRectangle* rsvg_rectangle_create @ create();
static tolua_outside void rsvg_rectangle_destroy @ destroy(RsvgRectangle *pointer);
tolua_outside void rsvg_rectangle_set @ set(double x, double y, double width, double height);
tolua_outside void rsvg_rectangle_get @ get(double *x, double *y, double *width, double *height);
} RsvgRectangle;
const char *rsvg_handle_get_base_uri (RsvgHandle * handle);