Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- drawingOfSvgDocument :: FontCache -> Maybe (Int, Int) -> Dpi -> Document -> IO (DrawResult, LoadedElements)
- renderSvgDocument :: FontCache -> Maybe (Int, Int) -> Dpi -> Document -> IO (Image PixelRGBA8, LoadedElements)
- pdfOfSvgDocument :: FontCache -> Maybe (Int, Int) -> Dpi -> Document -> IO (ByteString, LoadedElements)
- loadCreateFontCache :: FilePath -> IO FontCache
- data LoadedElements = LoadedElements {}
- data Result
- data DrawResult = DrawResult {
- _drawAction :: Drawing PixelRGBA8 ()
- _drawWidth :: !Int
- _drawHeight :: !Int
- type Dpi = Int
- renderSvgFile :: FilePath -> FilePath -> IO Result
Main functions
:: 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.
:: 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.
pdfOfSvgDocument :: FontCache -> Maybe (Int, Int) -> Dpi -> Document -> IO (ByteString, LoadedElements) Source
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 LoadedElements Source
Rendering status.
ResultSuccess | No problem found |
ResultError String | Error with message |
data DrawResult Source
Represent a Rasterific drawing with the associated image size.
DrawResult | |
|