svgcairo-0.12.1: Binding to the libsvg-cairo library.

Portability | portable
Stability | experimental
Maintainer | gtk2hs-devel@lists.sourceforge.net
Safe Haskell | None

Graphics.Rendering.Cairo.SVG

Contents

- Convenience API
- Standard API
  - Block scoped versions
  - GC-managed versions

Description

The SVG extension to the Cairo 2D graphics library.

Synopsis

- svgRenderFromFile :: FilePath -> Render Bool
- svgRenderFromHandle :: Handle -> Render Bool
- svgRenderFromString :: String -> Render Bool
- data SVG
- svgRender :: SVG -> Render Bool
- svgGetSize :: SVG -> (Int, Int)
- withSvgFromFile :: FilePath -> (SVG -> Render a) -> Render a
- withSvgFromHandle :: Handle -> (SVG -> Render a) -> Render a
- withSvgFromString :: String -> (SVG -> Render a) -> Render a
- svgNewFromFile :: FilePath -> IO SVG
- svgNewFromHandle :: Handle -> IO SVG
- svgNewFromString :: String -> IO SVG

# Convenience API

These operations render an SVG image directly in the current `Render` contect. Because they operate in the cairo `Render` monad they are affected by the current transformation matrix. So it is possible, for example, to scale or rotate an SVG image.

In the following example we scale an SVG image to a unit square:

     let (width, height) = svgGetSize in
     do scale (1/width) (1/height)
     svgRender svg

svgRenderFromFile :: FilePath -> Render Bool Source

svgRenderFromHandle :: Handle -> Render Bool Source

svgRenderFromString :: String -> Render Bool Source

# Standard API

With this API there are seperate functions for loading the SVG and rendering it. This allows us to be more effecient in the case that an SVG image is used many times - since it can be loaded just once and rendered many times. With the convenience API above the SVG would be parsed and processed each time it is drawn.

data SVG Source

Instances

GObjectClass SVG |

svgRender :: SVG -> Render Bool Source

render an SVG file

Returns `False` if an error was detected. On librsvg before 2.22.3, `svgRender` always returns `True`.

svgGetSize Source

Arguments

:: SVG |

-> (Int, Int)

    (width, height)

Get the width and height of the SVG image.

## Block scoped versions

These versions of the SVG loading operations give temporary access to the `SVG` object within the scope of the handler function. These operations guarantee that the resources for the SVG object are deallocated at the end of the handler block. If this form of resource allocation is too restrictive you can use the GC-managed versions below.

These versions are ofen used in the following style:

     withSvgFromFile "foo.svg" $ \svg -> do
     ...
     svgRender svg
     ...

withSvgFromFile :: FilePath -> (SVG -> Render a) -> Render aSource

withSvgFromHandle :: Handle -> (SVG -> Render a) -> Render aSource

withSvgFromString :: String -> (SVG -> Render a) -> Render aSource

## GC-managed versions

These versions of the SVG loading operations use the standard Haskell garbage collector to manage the resources associated with the `SVG` object. As such they are more convenient to use but the GC cannot give strong guarantees about when the resources associated with the `SVG` object will be released. In most circumstances this is not a problem, especially if the SVG files being used are not very big.

svgNewFromFile :: FilePath -> IO SVG Source

svgNewFromHandle :: Handle -> IO SVG Source

svgNewFromString :: String -> IO SVG Source