module Graphics.Rendering.Pango.Cairo (
cairoFontMapGetDefault,
cairoFontMapSetResolution,
cairoFontMapGetResolution,
cairoCreateContext,
cairoContextSetResolution,
cairoContextGetResolution,
cairoContextSetFontOptions,
cairoContextGetFontOptions,
setSourceColor,
updateContext,
createLayout,
updateLayout,
showGlyphString,
showLayoutLine,
showLayout,
glyphStringPath,
layoutLinePath,
layoutPath
) where
import Control.Exception (bracket)
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.GObject (wrapNewGObject, makeNewGObject,
objectRef, objectUnref)
import Graphics.Rendering.Pango.Types
import Graphics.Rendering.Pango.BasicTypes
import Graphics.Rendering.Pango.Structs ( pangoItemGetFont, Color(..) )
import Graphics.Rendering.Pango.Layout ( layoutSetText )
import Data.IORef
import Graphics.Rendering.Cairo.Types as Cairo
import qualified Graphics.Rendering.Cairo.Internal as Cairo.Internal
import qualified Graphics.Rendering.Cairo as Cairo
import Graphics.Rendering.Cairo.Internal (Render(Render))
import Control.Monad.Reader
setSourceColor :: Color -> Render ()
setSourceColor (Color red green blue) =
Cairo.setSourceRGB
(realToFrac red / 65535.0)
(realToFrac green / 65535.0)
(realToFrac blue / 65535.0)
cairoFontMapGetDefault :: IO FontMap
cairoFontMapGetDefault =
makeNewGObject mkFontMap $ pango_cairo_font_map_get_default
cairoFontMapSetResolution :: FontMap -> Double -> IO ()
cairoFontMapSetResolution (FontMap fm) dpi =
withForeignPtr fm $ \fmPtr ->
pango_cairo_font_map_set_resolution
(castPtr fmPtr) (realToFrac dpi)
cairoFontMapGetResolution :: FontMap -> IO Double
cairoFontMapGetResolution (FontMap fm) = liftM realToFrac $
withForeignPtr fm $ \fmPtr ->
pango_cairo_font_map_get_resolution (castPtr fmPtr)
cairoCreateContext :: Maybe FontMap -> IO PangoContext
cairoCreateContext (Just (FontMap fm)) = wrapNewGObject mkPangoContext $
withForeignPtr fm $ \fmPtr ->
pango_cairo_font_map_create_context (castPtr fmPtr)
cairoCreateContext Nothing = do
fmPtr <- pango_cairo_font_map_get_default
wrapNewGObject mkPangoContext $
pango_cairo_font_map_create_context (castPtr fmPtr)
cairoContextSetResolution :: PangoContext -> Double -> IO ()
cairoContextSetResolution pc dpi =
(\(PangoContext arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->pango_cairo_context_set_resolution argPtr1 arg2) pc (realToFrac dpi)
cairoContextGetResolution :: PangoContext -> IO Double
cairoContextGetResolution pc = liftM realToFrac $
(\(PangoContext arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_cairo_context_get_resolution argPtr1) pc
cairoContextSetFontOptions :: PangoContext -> FontOptions -> IO ()
cairoContextSetFontOptions pc fo =
(\(PangoContext arg1) (FontOptions arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->pango_cairo_context_set_font_options argPtr1 argPtr2) pc fo
cairoContextResetFontOptions :: PangoContext -> IO ()
cairoContextResetFontOptions pc =
(\(PangoContext arg1) (FontOptions arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->pango_cairo_context_set_font_options argPtr1 argPtr2) pc
(Cairo.Internal.FontOptions nullForeignPtr)
cairoContextGetFontOptions :: PangoContext -> IO FontOptions
cairoContextGetFontOptions pc = do
foPtr <- (\(PangoContext arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_cairo_context_get_font_options argPtr1) pc
Cairo.Internal.mkFontOptions foPtr
updateContext :: PangoContext -> Render ()
updateContext pc = Render $ do
cr <- ask
liftIO $ (\(Cairo arg1) (PangoContext arg2) -> withForeignPtr arg2 $ \argPtr2 ->pango_cairo_update_context arg1 argPtr2) cr pc
createLayout :: GlibString string => string -> Render PangoLayout
createLayout text = Render $ do
cr <- ask
liftIO $ do
layRaw <- wrapNewGObject mkPangoLayoutRaw $
(\(Cairo arg1) -> pango_cairo_create_layout arg1) cr
textRef <- newIORef undefined
let pl = (PangoLayout textRef layRaw)
layoutSetText pl text
return pl
updateLayout :: PangoLayout -> Render ()
updateLayout (PangoLayout _ lay) = Render $ do
cr <- ask
liftIO $ (\(Cairo arg1) (PangoLayoutRaw arg2) -> withForeignPtr arg2 $ \argPtr2 ->pango_cairo_update_layout arg1 argPtr2) cr lay
showGlyphString :: GlyphItem -> Render ()
showGlyphString (GlyphItem pi gs) = Render $ do
cr <- ask
font <- liftIO $ pangoItemGetFont pi
liftIO $ (\(Cairo arg1) (Font arg2) (GlyphStringRaw arg3) -> withForeignPtr arg2 $ \argPtr2 ->withForeignPtr arg3 $ \argPtr3 ->pango_cairo_show_glyph_string arg1 argPtr2 argPtr3) cr font gs
showLayoutLine :: LayoutLine -> Render ()
showLayoutLine (LayoutLine _ ll) = Render $ do
cr <- ask
liftIO $ (\(Cairo arg1) (LayoutLineRaw arg2) -> withForeignPtr arg2 $ \argPtr2 ->pango_cairo_show_layout_line arg1 argPtr2) cr ll
showLayout :: PangoLayout -> Render ()
showLayout (PangoLayout _ lay) = Render $ do
cr <- ask
liftIO $ (\(Cairo arg1) (PangoLayoutRaw arg2) -> withForeignPtr arg2 $ \argPtr2 ->pango_cairo_show_layout arg1 argPtr2) cr lay
glyphStringPath :: GlyphItem -> Render ()
glyphStringPath (GlyphItem pi gs) = Render $ do
cr <- ask
font <- liftIO $ pangoItemGetFont pi
liftIO $ (\(Cairo arg1) (Font arg2) (GlyphStringRaw arg3) -> withForeignPtr arg2 $ \argPtr2 ->withForeignPtr arg3 $ \argPtr3 ->pango_cairo_glyph_string_path arg1 argPtr2 argPtr3) cr font gs
layoutLinePath :: LayoutLine -> Render ()
layoutLinePath (LayoutLine _ ll) = Render $ do
cr <- ask
liftIO $ (\(Cairo arg1) (LayoutLineRaw arg2) -> withForeignPtr arg2 $ \argPtr2 ->pango_cairo_layout_line_path arg1 argPtr2) cr ll
layoutPath :: PangoLayout -> Render ()
layoutPath (PangoLayout _ lay) = Render $ do
cr <- ask
liftIO $ (\(Cairo arg1) (PangoLayoutRaw arg2) -> withForeignPtr arg2 $ \argPtr2 ->pango_cairo_layout_path arg1 argPtr2) cr lay
foreign import ccall unsafe "pango_cairo_font_map_get_default"
pango_cairo_font_map_get_default :: (IO (Ptr FontMap))
foreign import ccall unsafe "pango_cairo_font_map_set_resolution"
pango_cairo_font_map_set_resolution :: ((Ptr ()) -> (CDouble -> (IO ())))
foreign import ccall unsafe "pango_cairo_font_map_get_resolution"
pango_cairo_font_map_get_resolution :: ((Ptr ()) -> (IO CDouble))
foreign import ccall unsafe "pango_cairo_font_map_create_context"
pango_cairo_font_map_create_context :: ((Ptr ()) -> (IO (Ptr PangoContext)))
foreign import ccall unsafe "pango_cairo_context_set_resolution"
pango_cairo_context_set_resolution :: ((Ptr PangoContext) -> (CDouble -> (IO ())))
foreign import ccall unsafe "pango_cairo_context_get_resolution"
pango_cairo_context_get_resolution :: ((Ptr PangoContext) -> (IO CDouble))
foreign import ccall unsafe "pango_cairo_context_set_font_options"
pango_cairo_context_set_font_options :: ((Ptr PangoContext) -> ((Ptr FontOptions) -> (IO ())))
foreign import ccall unsafe "pango_cairo_context_get_font_options"
pango_cairo_context_get_font_options :: ((Ptr PangoContext) -> (IO (Ptr FontOptions)))
foreign import ccall unsafe "pango_cairo_update_context"
pango_cairo_update_context :: ((Ptr Cairo) -> ((Ptr PangoContext) -> (IO ())))
foreign import ccall unsafe "pango_cairo_create_layout"
pango_cairo_create_layout :: ((Ptr Cairo) -> (IO (Ptr PangoLayoutRaw)))
foreign import ccall unsafe "pango_cairo_update_layout"
pango_cairo_update_layout :: ((Ptr Cairo) -> ((Ptr PangoLayoutRaw) -> (IO ())))
foreign import ccall unsafe "pango_cairo_show_glyph_string"
pango_cairo_show_glyph_string :: ((Ptr Cairo) -> ((Ptr Font) -> ((Ptr GlyphStringRaw) -> (IO ()))))
foreign import ccall unsafe "pango_cairo_show_layout_line"
pango_cairo_show_layout_line :: ((Ptr Cairo) -> ((Ptr LayoutLineRaw) -> (IO ())))
foreign import ccall unsafe "pango_cairo_show_layout"
pango_cairo_show_layout :: ((Ptr Cairo) -> ((Ptr PangoLayoutRaw) -> (IO ())))
foreign import ccall unsafe "pango_cairo_glyph_string_path"
pango_cairo_glyph_string_path :: ((Ptr Cairo) -> ((Ptr Font) -> ((Ptr GlyphStringRaw) -> (IO ()))))
foreign import ccall unsafe "pango_cairo_layout_line_path"
pango_cairo_layout_line_path :: ((Ptr Cairo) -> ((Ptr LayoutLineRaw) -> (IO ())))
foreign import ccall unsafe "pango_cairo_layout_path"
pango_cairo_layout_path :: ((Ptr Cairo) -> ((Ptr PangoLayoutRaw) -> (IO ())))