rasterific-svg-0.2.2: SVG renderer based on Rasterific.

Safe HaskellNone
LanguageHaskell2010

Graphics.Rasterific.Svg

Contents

Description

Svg renderer based on Rasterific.

Here is a simple example of loading a SVG file (using svg-tree) rendering it to a picture, and saving it to a PNG (using Juicy.Pixels)

import Codec.Picture( writePng )
import Graphics.Svg( loadSvgFile )
import Graphics.Rasterific.Svg( loadCreateFontCache
                              , renderSvgDocument
                              )
loadRender :: FilePath -> FilePath -> IO ()
loadRender svgfilename pngfilename = do
  f <- loadSvgFile svgfilename
  case f of
    Nothing -> putStrLn "Error while loading SVG"
    Just doc -> do
      cache <- loadCreateFontCache "fonty-texture-cache"
      (finalImage, _) <- renderSvgDocument cache Nothing 96 doc
      writePng pngfilename finalImage

Synopsis

Main functions

drawingOfSvgDocument Source

Arguments

:: FontCache

Structure used to access fonts

-> Maybe (Int, Int)

Optional document size

-> Dpi

Current resolution for text and elements

-> Document

Svg document

-> IO (DrawResult, LoadedElements) 

Render an svg document to a Rasterific Drawing. If you provide a size, the document will be stretched to match the provided size.

The DPI parameter really should depend of your screen, but a good default value is 96

The use of the IO Monad is there to allow loading of fonts and referenced images.

renderSvgDocument Source

Arguments

:: FontCache

Structure used to access fonts

-> Maybe (Int, Int)

Optional document size

-> Dpi

Current resolution for text and elements

-> Document

Svg document

-> IO (Image PixelRGBA8, LoadedElements) 

Render an svg document to an image. If you provide a size, the document will be stretched to match the provided size.

The DPI parameter really should depend of your screen, but a good default value is 96

The use of the IO Monad is there to allow loading of fonts and referenced images.

loadCreateFontCache :: FilePath -> IO FontCache Source

This function will create a font cache, a structure allowing to quickly match a font family name and style to a specific true type font on disk.

The cache is saved on disk at the filepath given as parameter. If a cache is found it is automatically loaded from the file.

Creating the cache is a rather long operation (especially on Windows), that's why you may want to keep the cache around.

Types

data Result Source

Rendering status.

Constructors

ResultSuccess

No problem found

ResultError String

Error with message

data DrawResult Source

Represent a Rasterific drawing with the associated image size.

Constructors

DrawResult 

Fields

_drawAction :: Drawing PixelRGBA8 ()

Rasterific drawing, can be reused and composed with other elements for scene drawing.

_drawWidth :: !Int

Supposed drawing width of the drawing, ideally represent the final image width.

_drawHeight :: !Int

Supposed drawing height of the drawing, ideally represent the final image height.

type Dpi = Int

Express device resolution in dot per inch.

Other helper functions

renderSvgFile :: FilePath -> FilePath -> IO Result Source

Convert an SVG file to a PNG file, return True if the operation went without problems.

This function will call loadCreateFontCache with the filename "fonty-texture-cache"