~alcinnz/fontconfig-pure

ref: db90fbd0f2143c28aaa9d49f91e6376109518b57 fontconfig-pure/Graphics/Text/Font/Choose/ObjectSet.hs -rw-r--r-- 855 bytes
db90fbd0 — Adrian Cochrane Get FontSet module compiling (need to review memory management responsibilities). 2 years 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
module Graphics.Text.Font.Choose.ObjectSet where

import Foreign.Ptr (Ptr)
import Foreign.C.String (CString, withCString)

import Control.Monad (forM)
import Control.Exception (bracket)

type ObjectSet = [String]

------
--- LowLevel
------
data ObjectSet'
type ObjectSet_ = Ptr ObjectSet'

withObjectSet :: ObjectSet -> (ObjectSet_ -> IO a) -> IO a
withObjectSet objs cb = withNewObjectSet $ \objs' -> do
    forM objs $ \obj -> withCString obj $ fcObjectSetAdd objs'
    cb objs'
foreign import ccall "FcObjectSetAdd" fcObjectSetAdd ::
    ObjectSet_ -> CString -> IO Bool

withNewObjectSet :: (ObjectSet_ -> IO a) -> IO a
withNewObjectSet cb = bracket fcObjectSetCreate fcObjectSetDestroy cb
foreign import ccall "FcObjectSetCreate" fcObjectSetCreate :: IO ObjectSet_
foreign import ccall "FcObjectSetDestroy" fcObjectSetDestroy :: ObjectSet_ -> IO ()