-----------------------------------------------------------------------------
-- |
-- Module      :  PNGOutput
-- Copyright   :  (c)2011, Texas Instruments France
-- License     :  BSD-style (see the file LICENSE)
-- 
-- Maintainer  :  c-favergeon-borgialli@ti.com
-- Stability   :  provisional
-- Portability :  portable
--
-- PNG Implementation of the graphic code (require the Haskell cairo bindings)

module PNGOutput(
 drawPNG
 ) where






import Graphics
import Graphics.Rendering.Cairo


instance GraphicOutput Render where
  fillColor r g b = setSourceRGB r g b
  fillColorA r g b a = setSourceRGBA r g b a
  strokeLine xa ya xb yb = do
      moveTo xa ya
      lineTo xb yb
      stroke
  text  fontSz xa ya str = do
     selectFontFace "Times-Roman" FontSlantNormal FontWeightNormal
     setFontSize (fromIntegral fontSz)
     save
     moveTo xa ya
     scale 1.0 (-1.0)
     showText str
     restore

  fillRectangle xa ya xb yb = do
    rectangle xa ya (xb-xa) (yb-ya)
    fill


drawPNG :: PictSettings -> String -> [(Int,Double)] -> IO ()
drawPNG settings filename samples =  do
      withImageSurface  FormatARGB32 (width settings) (height settings) $ \surface -> do
        renderWith surface $ do
             setSourceRGB 1.0 1.0 1.0
             rectangle 0.0 0.0 (fromIntegral $ width settings) (fromIntegral $ height settings)
             fill
             scale 1.0 (-1.0)
             translate 0.0 (fromIntegral $ -(height settings))
             drawCurve settings samples
        surfaceWriteToPNG surface filename 



