NetSurf
Data Structures | Typedefs | Functions | Variables
rsvg.c File Reference

implementation of content handler for image/svg using librsvg. More...

#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include <sys/types.h>
#include <librsvg/rsvg.h>
#include <librsvg/rsvg-cairo.h>
#include <nsutils/endian.h>
#include "utils/log.h"
#include "utils/utils.h"
#include "utils/messages.h"
#include "netsurf/plotters.h"
#include "netsurf/bitmap.h"
#include "netsurf/content.h"
#include "content/llcache.h"
#include "content/content_protected.h"
#include "content/content_factory.h"
#include "desktop/gui_internal.h"
#include "desktop/bitmap.h"
#include "image/rsvg.h"
Include dependency graph for rsvg.c:

Go to the source code of this file.

Data Structures

struct  rsvg_content
 

Typedefs

typedef struct rsvg_content rsvg_content
 

Functions

static nserror rsvg_create_svg_data (rsvg_content *c)
 
static nserror rsvg_create (const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
 
static bool rsvg_process_data (struct content *c, const char *data, unsigned int size)
 
static bool rsvg_convert (struct content *c)
 
static bool rsvg_redraw (struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
 
static void rsvg_destroy (struct content *c)
 
static nserror rsvg_clone (const struct content *old, struct content **newc)
 
static void * rsvg_get_internal (const struct content *c, void *context)
 
static content_type rsvg_content_type (void)
 
static bool rsvg_content_is_opaque (struct content *c)
 
 CONTENT_FACTORY_REGISTER_TYPES (nsrsvg, rsvg_types, rsvg_content_handler)
 

Variables

static const content_handler rsvg_content_handler
 
static const char * rsvg_types []
 

Detailed Description

implementation of content handler for image/svg using librsvg.

SVG files are rendered to a NetSurf bitmap by creating a Cairo rendering surface (content_rsvg_data.cs) over the bitmap's data, creating a Cairo drawing context using that surface, and then passing that drawing context to librsvg which then uses Cairo calls to plot the graphic to the bitmap. We store this in content->bitmap, and then use the usual bitmap plotter function to render it for redraw requests.

Definition in file rsvg.c.

Typedef Documentation

◆ rsvg_content

typedef struct rsvg_content rsvg_content

Function Documentation

◆ CONTENT_FACTORY_REGISTER_TYPES()

CONTENT_FACTORY_REGISTER_TYPES ( nsrsvg  ,
rsvg_types  ,
rsvg_content_handler   
)

◆ rsvg_clone()

static nserror rsvg_clone ( const struct content old,
struct content **  newc 
)
static

Definition at line 228 of file rsvg.c.

References rsvg_content::base, content__clone(), content__get_source_data(), content_destroy(), CONTENT_STATUS_DONE, CONTENT_STATUS_READY, NSERROR_CLONE_FAILED, NSERROR_NOMEM, NSERROR_OK, rsvg_convert(), rsvg_create_svg_data(), rsvg_process_data(), content::size, and content::status.

Here is the call graph for this function:

◆ rsvg_content_is_opaque()

static bool rsvg_content_is_opaque ( struct content c)
static

◆ rsvg_content_type()

static content_type rsvg_content_type ( void  )
static

Definition at line 280 of file rsvg.c.

References CONTENT_IMAGE.

◆ rsvg_convert()

static bool rsvg_convert ( struct content c)
static

Definition at line 132 of file rsvg.c.

References rsvg_content::bitmap, netsurf_table::bitmap, bitmap_format_to_client(), BITMAP_NONE, content_broadcast_error(), content_set_done(), content_set_ready(), content_set_status(), gui_bitmap_table::create, rsvg_content::cs, rsvg_content::ct, gui_bitmap_table::get_buffer, gui_bitmap_table::get_rowstride, guit, content::height, gui_bitmap_table::modified, NSERROR_NOMEM, NSERROR_SVG_ERROR, NSLOG, rsvg_content::rsvgh, and content::width.

Referenced by rsvg_clone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rsvg_create()

static nserror rsvg_create ( const content_handler handler,
lwc_string *  imime_type,
const struct http_parameter params,
llcache_handle llcache,
const char *  fallback_charset,
bool  quirks,
struct content **  c 
)
static

Definition at line 84 of file rsvg.c.

References rsvg_content::base, content__init(), llcache, NSERROR_NOMEM, NSERROR_OK, and rsvg_create_svg_data().

Here is the call graph for this function:

◆ rsvg_create_svg_data()

static nserror rsvg_create_svg_data ( rsvg_content c)
static

Definition at line 67 of file rsvg.c.

References rsvg_content::base, rsvg_content::bitmap, content_broadcast_error(), rsvg_content::cs, rsvg_content::ct, NSERROR_NOMEM, NSERROR_OK, NSLOG, and rsvg_content::rsvgh.

Referenced by rsvg_clone(), and rsvg_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rsvg_destroy()

static void rsvg_destroy ( struct content c)
static

◆ rsvg_get_internal()

static void * rsvg_get_internal ( const struct content c,
void *  context 
)
static

Definition at line 273 of file rsvg.c.

References rsvg_content::bitmap.

◆ rsvg_process_data()

static bool rsvg_process_data ( struct content c,
const char *  data,
unsigned int  size 
)
static

Definition at line 115 of file rsvg.c.

References content_broadcast_error(), NSERROR_SVG_ERROR, NSLOG, rsvg_content::rsvgh, and content::size.

Referenced by rsvg_clone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rsvg_redraw()

static bool rsvg_redraw ( struct content c,
struct content_redraw_data data,
const struct rect clip,
const struct redraw_context ctx 
)
static

Variable Documentation

◆ rsvg_content_handler

const content_handler rsvg_content_handler
static
Initial value:
= {
.create = rsvg_create,
.process_data = rsvg_process_data,
.data_complete = rsvg_convert,
.destroy = rsvg_destroy,
.redraw = rsvg_redraw,
.clone = rsvg_clone,
.get_internal = rsvg_get_internal,
.is_opaque = rsvg_content_is_opaque,
.no_share = false,
}
static bool rsvg_redraw(struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
Definition: rsvg.c:195
static bool rsvg_content_is_opaque(struct content *c)
Definition: rsvg.c:286
static nserror rsvg_create(const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
Definition: rsvg.c:84
static void * rsvg_get_internal(const struct content *c, void *context)
Definition: rsvg.c:273
static bool rsvg_convert(struct content *c)
Definition: rsvg.c:132
static bool rsvg_process_data(struct content *c, const char *data, unsigned int size)
Definition: rsvg.c:115
static void rsvg_destroy(struct content *c)
Definition: rsvg.c:216
static nserror rsvg_clone(const struct content *old, struct content **newc)
Definition: rsvg.c:228
static content_type rsvg_content_type(void)
Definition: rsvg.c:280

Definition at line 298 of file rsvg.c.

◆ rsvg_types

const char* rsvg_types[]
static
Initial value:
= {
"image/svg",
"image/svg+xml"
}

Definition at line 311 of file rsvg.c.