libxputty 0.1
Loading...
Searching...
No Matches
Functions
xsvgloader.h File Reference

Go to the source code of this file.

Functions

void widget_get_svg (Widget_t *w, const char *name)
 widget_get_svg - read svg into Widget_t xlib surface
 
void widget_get_scaled_svg (Widget_t *w, const char *name)
 widget_get_scaled_svg - read svg scaled into Widget_t xlib surface
 
void widget_get_svg_from_file (Widget_t *w, const char *filename)
 widget_get_svg_from_file - read svg into Widget_t xlib surface
 
void widget_get_scaled_svg_from_file (Widget_t *w, const char *filename, int width_t, int height_t)
 widget_get_scaled_svg_from_file - read svg into Widget_t xlib surface
 
cairo_surface_t * cairo_image_surface_create_from_svg (const char *name)
 

Function Documentation

◆ cairo_image_surface_create_from_svg()

cairo_surface_t * cairo_image_surface_create_from_svg ( const char *  name)

Definition at line 336 of file xsvgloader.c.

336 {
337 struct NSVGimage* const image = nsvgParseFromFile(filename, "px", 96);
338
339 if (!image) return NULL;
340 int width_t = image->width;
341 int height_t = image->height;
342
343 cairo_surface_t *getsvg = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, width_t, height_t);
344 cairo_t *cri = cairo_create (getsvg);
345 draw_svg_image(cri, image, width_t, height_t);
346 nsvgDelete(image);
347 return getsvg;
348}
NSVGimage * nsvgParseFromFile(const char *filename, const char *units, float dpi)
Definition nanosvg.h:2934
void nsvgDelete(NSVGimage *image)
Definition nanosvg.h:2993
float height
Definition nanosvg.h:162
float width
Definition nanosvg.h:161

References NSVGimage::height, nsvgDelete(), nsvgParseFromFile(), and NSVGimage::width.

◆ widget_get_scaled_svg()

void widget_get_scaled_svg ( Widget_t w,
const char *  name 
)

widget_get_scaled_svg - read svg scaled into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the svg
*name- pointer to the base64 image data

Definition at line 269 of file xsvgloader.c.

269 {
270 char* b64dst;
271 b64dst = (char*)malloc((strlen(name)+1) * sizeof(char));
272 b64_decode((char*)name, b64dst);
273 struct NSVGimage* const image = nsvgParse(b64dst, "px", 96);
274
275 if (!image) return;
276 int width = image->width;
277 int height = image->height;
278 int width_t = w->scale.init_width;
279 int height_t = w->scale.init_height;
280 double x = (double)width_t/(double)width;
281 double y = (double)height_t/(double)height;
282
283 cairo_surface_t *getsvg = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, width, height);
284 cairo_t *cris = cairo_create (getsvg);
285 draw_svg_image(cris, image, width, height);
286
287 cairo_surface_destroy(w->image);
288 w->image = NULL;
289 w->image = cairo_surface_create_similar (w->surface,
290 CAIRO_CONTENT_COLOR_ALPHA, width_t, height_t);
291 cairo_t *cri = cairo_create (w->image);
292
293 cairo_scale(cri, x,y);
294 cairo_set_source_surface (cri, getsvg,0,0);
295 cairo_paint (cri);
296
297 cairo_destroy(cris);
298 cairo_surface_destroy(getsvg);
299 nsvgDelete(image);
300 free(b64dst);
301 cairo_destroy(cri);
302}
void b64_decode(char *b64src, char *clrdst)
b64_decode - decode to a b64 based char
Definition b64_encode.c:26
NSVGimage * nsvgParse(char *input, const char *units, float dpi)
Definition nanosvg.h:2910
int init_height
Definition xwidget.h:355
int init_width
Definition xwidget.h:353
Resize_t scale
Definition xwidget.h:525
cairo_surface_t * image
Definition xwidget.h:491
cairo_surface_t * surface
Definition xwidget.h:483

References b64_decode(), NSVGimage::height, Widget_t::image, Resize_t::init_height, Resize_t::init_width, nsvgDelete(), nsvgParse(), Widget_t::scale, Widget_t::surface, and NSVGimage::width.

◆ widget_get_scaled_svg_from_file()

void widget_get_scaled_svg_from_file ( Widget_t w,
const char *  filename,
int  width_t,
int  height_t 
)

widget_get_scaled_svg_from_file - read svg into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the svg
*filename- pointer to the image data file
width_t- the requested width
height_t- the requested height

Definition at line 321 of file xsvgloader.c.

321 {
322 struct NSVGimage* const image = nsvgParseFromFile(filename, "px", 96);
323
324 if (!image) return;
325 cairo_surface_destroy(w->image);
326 w->image = NULL;
327
328 w->image = cairo_surface_create_similar (w->surface,
329 CAIRO_CONTENT_COLOR_ALPHA, width_t, height_t);
330 cairo_t *cri = cairo_create (w->image);
331 draw_svg_image(cri, image, width_t, height_t);
332 nsvgDelete(image);
333 cairo_destroy(cri);
334}

References Widget_t::image, nsvgDelete(), nsvgParseFromFile(), and Widget_t::surface.

◆ widget_get_svg()

void widget_get_svg ( Widget_t w,
const char *  name 
)

widget_get_svg - read svg into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the svg
*name- pointer to the base64 image data

Definition at line 248 of file xsvgloader.c.

248 {
249 char* b64dst;
250 b64dst = (char*)malloc((strlen(name)+1) * sizeof(char));
251 b64_decode((char*)name, b64dst);
252 struct NSVGimage* const image = nsvgParse(b64dst, "px", 96);
253
254 if (!image) return;
255 int width_t = image->width;
256 int height_t = image->height;
257 cairo_surface_destroy(w->image);
258 w->image = NULL;
259
260 w->image = cairo_surface_create_similar (w->surface,
261 CAIRO_CONTENT_COLOR_ALPHA, width_t, height_t);
262 cairo_t *cri = cairo_create (w->image);
263 draw_svg_image(cri, image, width_t, height_t);
264 nsvgDelete(image);
265 free(b64dst);
266 cairo_destroy(cri);
267}

References b64_decode(), NSVGimage::height, Widget_t::image, nsvgDelete(), nsvgParse(), Widget_t::surface, and NSVGimage::width.

◆ widget_get_svg_from_file()

void widget_get_svg_from_file ( Widget_t w,
const char *  filename 
)

widget_get_svg_from_file - read svg into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the svg
*filename- pointer to the image data file

Definition at line 304 of file xsvgloader.c.

304 {
305 struct NSVGimage* const image = nsvgParseFromFile(filename, "px", 96);
306
307 if (!image) return;
308 int width_t = w->scale.init_width;
309 int height_t = w->scale.init_height;
310 cairo_surface_destroy(w->image);
311 w->image = NULL;
312
313 w->image = cairo_surface_create_similar (w->surface,
314 CAIRO_CONTENT_COLOR_ALPHA, width_t, height_t);
315 cairo_t *cri = cairo_create (w->image);
316 draw_svg_image(cri, image, width_t, height_t);
317 nsvgDelete(image);
318 cairo_destroy(cri);
319}

References Widget_t::image, Resize_t::init_height, Resize_t::init_width, nsvgDelete(), nsvgParseFromFile(), Widget_t::scale, and Widget_t::surface.