~alcinnz/fontconfig-pure

ref: 58463bff4ead31b6b58f5e6b181914c856a33537 fontconfig-pure/lib/Graphics/Text/Font/Choose/Config.hs -rw-r--r-- 1.7 KiB
58463bff — Adrian Cochrane Fuzz test roundtrip conversions between C & Haskell datastructures! 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE CApiFFI #-}
module Graphics.Text.Font.Choose.Config(Config', fini, version,
        initLoadConfig, initLoadConfigAndFonts, initFonts, reinit, bringUptoDate,
        -- For the sake of Graphics.Font.Choose.Config.Accessors
        Config, fcConfigDestroy) where

import Foreign.Ptr (Ptr, FunPtr)
import Foreign.ForeignPtr (ForeignPtr, newForeignPtr)

import Graphics.Text.Font.Choose.Result (throwBool, throwNull)

data Config'
type Config = ForeignPtr Config'



initLoadConfig :: IO Config
initLoadConfig = newForeignPtr fcConfigDestroy =<< throwNull =<< fcInitLoadConfig -- FIXME: What's proper memory-management here?

initLoadConfigAndFonts :: IO Config
initLoadConfigAndFonts = newForeignPtr fcConfigDestroy =<< throwNull =<< fcInitLoadConfigAndFonts -- FIXME: What's proper memory-management here?

initFonts :: IO ()
initFonts = throwBool =<< fcInit
foreign import capi "fontconfig/fontconfig.h FcFini" fini :: IO ()
foreign import capi "fontconfig/fontconfig.h FcGetVersion" version :: Int
reinit :: IO ()
reinit = throwBool =<< fcInitReinitialize
bringUptoDate :: IO ()
bringUptoDate = throwBool =<< fcInitBringUptoDate

foreign import capi "fontconfig/fontconfig.h FcInitLoadConfig" fcInitLoadConfig :: IO (Ptr Config')
foreign import capi "fontconfig/fontconfig.h FcInitLoadConfigAndFonts" fcInitLoadConfigAndFonts :: IO (Ptr Config')
foreign import capi "fontconfig/fontconfig.h FcInit" fcInit :: IO Bool
foreign import capi "fontconfig/fontconfig.h &FcConfigDestroy" fcConfigDestroy :: FunPtr (Ptr Config' -> IO ())

foreign import capi "fontconfig/fontconfig.h FcInitReinitialize" fcInitReinitialize :: IO Bool
foreign import capi "fontconfig/fontconfig.h FcInitBringUptoDate" fcInitBringUptoDate :: IO Bool