Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::svg::RendererSkia Class Reference

Rendering backend using Skia, https://github.com/google/skia. More...

#include "donner/svg/renderer/RendererSkia.h"

Classes

class  Impl
 Implementation class for RendererSkia. More...
 

Public Member Functions

 RendererSkia (bool verbose=false)
 Create the Skia renderer.
 
 ~RendererSkia ()
 Destructor.
 
 RendererSkia (RendererSkia &&) noexcept
 Move constructor.
 
RendererSkiaoperator= (RendererSkia &&) noexcept
 Move assignment operator.
 
 RendererSkia (const RendererSkia &)=delete
 
RendererSkiaoperator= (const RendererSkia &)=delete
 
void draw (SVGDocument &document)
 Draw the SVG document using the renderer.
 
std::string drawIntoAscii (SVGDocument &document)
 Render the given SVGDocument into ASCII art.
 
sk_sp< SkPicture > drawIntoSkPicture (SVGDocument &document)
 Draw the given SVGDocument into a SkPicture, for offscreen rendering or debugging purposes.
 
bool save (const char *filename)
 Save the rendered image to a PNG file.
 
std::span< const uint8_t > pixelData () const
 Get the pixel data of the rendered image.
 
int width () const
 Get the width of the rendered image in pixels.
 
int height () const
 Get the height of the rendered image in pixels.
 
const SkBitmap & bitmap () const
 Get the SkBitmap of the rendered image.
 
void setAntialias (bool antialias)
 Enable or disable antialiasing.
 

Detailed Description

Rendering backend using Skia, https://github.com/google/skia.

Skia is a 2D graphics library that powers Chrome, Firefox, Android, and many other projects, and supports all functionality required to implement SVG (as many of these projects also support SVG).

Skia is used as the reference renderer while implementing Donner, but long-term Donner would like to support other rendering backends, so dependencies on Skia should be kept to a minimum and isolated to RendererSkia.

This is a prototype-quality implementation, and is subject to refactoring in the future to provide a cleaner API boundary between Donner and the rendering backend.

Examples
svg_to_png.cc.

Constructor & Destructor Documentation

◆ RendererSkia()

donner::svg::RendererSkia::RendererSkia ( bool verbose = false)
explicit

Create the Skia renderer.

Parameters
verboseIf true, print verbose logging.

Member Function Documentation

◆ draw()

void donner::svg::RendererSkia::draw ( SVGDocument & document)

Draw the SVG document using the renderer.

Writes to an internal bitmap, which can be retrieved using the bitmap() method.

Parameters
documentThe SVG document to render.
Examples
svg_to_png.cc.

◆ drawIntoAscii()

std::string donner::svg::RendererSkia::drawIntoAscii ( SVGDocument & document)

Render the given SVGDocument into ASCII art.

The generated image is of given size, and has a black background.

Colors will be mapped to ASCII characters, with @ white all the way to . black, with ten shades of gray.

For example:

<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
<rect width="8" height="8" fill="white" />
</svg>
int height() const
Get the height of the rendered image in pixels.
Definition RendererSkia.h:119
int width() const
Get the width of the rendered image in pixels.
Definition RendererSkia.h:116

Renders as:

@@@@@@@@........
@@@@@@@@........
@@@@@@@@........
@@@@@@@@........
@@@@@@@@........
@@@@@@@@........
@@@@@@@@........
@@@@@@@@........
................
................
................
................
................
................
................
................
Parameters
documentSVG document to render, of max size 64x64.

◆ drawIntoSkPicture()

sk_sp< SkPicture > donner::svg::RendererSkia::drawIntoSkPicture ( SVGDocument & document)

Draw the given SVGDocument into a SkPicture, for offscreen rendering or debugging purposes.

Parameters
documentThe SVG document to render.

◆ pixelData()

std::span< const uint8_t > donner::svg::RendererSkia::pixelData ( ) const

Get the pixel data of the rendered image.

Returns
A span of the pixel data, in RGBA format of size width() * height() * 4.

◆ save()

bool donner::svg::RendererSkia::save ( const char * filename)

Save the rendered image to a PNG file.

Parameters
filenameThe filename to save the PNG to.
Returns
True if the save was successful.
Examples
svg_to_png.cc.

◆ setAntialias()

void donner::svg::RendererSkia::setAntialias ( bool antialias)
inline

Enable or disable antialiasing.

On by default.

Parameters
antialiasWhether to enable antialiasing.

The documentation for this class was generated from the following files: