NetSurf
Data Structures | Macros | Typedefs | Functions | Variables
svg.c File Reference

implementation of content for image/svg using libsvgtiny. More...

#include <assert.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <svgtiny.h>
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/nsurl.h"
#include "netsurf/plotters.h"
#include "netsurf/content.h"
#include "content/content_protected.h"
#include "content/content_factory.h"
#include "image/svg.h"
Include dependency graph for svg.c:

Go to the source code of this file.

Data Structures

struct  svg_content
 

Macros

#define BGR(c)
 

Typedefs

typedef struct svg_content svg_content
 

Functions

static nserror svg_create_svg_data (svg_content *c)
 
static nserror svg_create (const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, struct llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
 Create a CONTENT_SVG. More...
 
static bool svg_convert (struct content *c)
 Convert a CONTENT_SVG for display. More...
 
static void svg_reformat (struct content *c, int width, int height)
 Reformat a CONTENT_SVG. More...
 
static bool svg_redraw_internal (struct content *c, int x, int y, int width, int height, const struct rect *clip, const struct redraw_context *ctx, float scale, colour background_colour)
 Redraw a CONTENT_SVG. More...
 
static bool svg_redraw (struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
 Redraw a CONTENT_SVG. More...
 
static void svg_destroy (struct content *c)
 Destroy a CONTENT_SVG and free all resources it owns. More...
 
static nserror svg_clone (const struct content *old, struct content **newc)
 
static content_type svg_content_type (void)
 
 CONTENT_FACTORY_REGISTER_TYPES (svg, svg_types, svg_content_handler)
 

Variables

static const content_handler svg_content_handler
 
static const char * svg_types []
 

Detailed Description

implementation of content for image/svg using libsvgtiny.

Definition in file svg.c.

Macro Definition Documentation

◆ BGR

#define BGR (   c)
Value:
((c) == svgtiny_TRANSPARENT ? NS_TRANSPARENT : \
((svgtiny_RED((c))) | \
(svgtiny_GREEN((c)) << 8) | \
(svgtiny_BLUE((c)) << 16)))
#define NS_TRANSPARENT
Transparent colour value.
Definition: plot_style.h:39

Typedef Documentation

◆ svg_content

typedef struct svg_content svg_content

Function Documentation

◆ CONTENT_FACTORY_REGISTER_TYPES()

CONTENT_FACTORY_REGISTER_TYPES ( svg  ,
svg_types  ,
svg_content_handler   
)

◆ svg_clone()

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

Definition at line 311 of file svg.c.

References svg_content::base, content__clone(), content_destroy(), CONTENT_STATUS_DONE, CONTENT_STATUS_READY, NSERROR_CLONE_FAILED, NSERROR_NOMEM, NSERROR_OK, content::status, svg_convert(), and svg_create_svg_data().

Here is the call graph for this function:

◆ svg_content_type()

static content_type svg_content_type ( void  )
static

Definition at line 346 of file svg.c.

References CONTENT_IMAGE.

◆ svg_convert()

static bool svg_convert ( struct content c)
static

Convert a CONTENT_SVG for display.

Definition at line 109 of file svg.c.

References content_set_done(), content_set_ready(), and content_set_status().

Referenced by svg_clone().

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

◆ svg_create()

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

Create a CONTENT_SVG.

Definition at line 73 of file svg.c.

References svg_content::base, content__init(), llcache, NSERROR_NOMEM, NSERROR_OK, and svg_create_svg_data().

Here is the call graph for this function:

◆ svg_create_svg_data()

static nserror svg_create_svg_data ( svg_content c)
static

Definition at line 52 of file svg.c.

References svg_content::base, content_broadcast_error(), svg_content::current_height, svg_content::current_width, svg_content::diagram, NSERROR_NOMEM, and NSERROR_OK.

Referenced by svg_clone(), and svg_create().

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

◆ svg_destroy()

static void svg_destroy ( struct content c)
static

Destroy a CONTENT_SVG and free all resources it owns.

Definition at line 302 of file svg.c.

References svg_content::diagram.

◆ svg_redraw()

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

Redraw a CONTENT_SVG.

Definition at line 242 of file svg.c.

References content_redraw_data::background_colour, clip(), content_redraw_data::height, content_redraw_data::repeat_x, content_redraw_data::repeat_y, content_redraw_data::scale, svg_redraw_internal(), content_redraw_data::width, content_redraw_data::x, and content_redraw_data::y.

Here is the call graph for this function:

◆ svg_redraw_internal()

static bool svg_redraw_internal ( struct content c,
int  x,
int  y,
int  width,
int  height,
const struct rect clip,
const struct redraw_context ctx,
float  scale,
colour  background_colour 
)
static

Redraw a CONTENT_SVG.

Definition at line 161 of file svg.c.

References plot_font_style::background, BGR, svg_content::diagram, plot_style_s::fill_colour, plot_font_style::foreground, content::height, height, NSERROR_OK, plotter_table::path, redraw_context::plot, plot_style_font, plot_style_int_to_fixed, PLOT_STYLE_SCALE, plot_font_style::size, plot_style_s::stroke_colour, plot_style_s::stroke_width, plotter_table::text, content::width, and width.

Referenced by svg_redraw().

Here is the caller graph for this function:

◆ svg_reformat()

static void svg_reformat ( struct content c,
int  width,
int  height 
)
static

Reformat a CONTENT_SVG.

Definition at line 128 of file svg.c.

References content__get_source_data(), content_get_url(), svg_content::current_height, svg_content::current_width, svg_content::diagram, content::height, height, nsurl_access(), content::width, and width.

Here is the call graph for this function:

Variable Documentation

◆ svg_content_handler

const content_handler svg_content_handler
static
Initial value:
= {
.create = svg_create,
.data_complete = svg_convert,
.reformat = svg_reformat,
.destroy = svg_destroy,
.redraw = svg_redraw,
.clone = svg_clone,
.no_share = true
}
static void svg_destroy(struct content *c)
Destroy a CONTENT_SVG and free all resources it owns.
Definition: svg.c:302
static bool svg_convert(struct content *c)
Convert a CONTENT_SVG for display.
Definition: svg.c:109
static bool svg_redraw(struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
Redraw a CONTENT_SVG.
Definition: svg.c:242
static void svg_reformat(struct content *c, int width, int height)
Reformat a CONTENT_SVG.
Definition: svg.c:128
static nserror svg_clone(const struct content *old, struct content **newc)
Definition: svg.c:311
static nserror svg_create(const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, struct llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
Create a CONTENT_SVG.
Definition: svg.c:73
static content_type svg_content_type(void)
Definition: svg.c:346

Definition at line 351 of file svg.c.

◆ svg_types

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

Definition at line 362 of file svg.c.