~alcinnz/fontconfig-pure

ref: 32350eb896fa7c3579f8b1ea6f6d16cb738c5e5d fontconfig-pure/Graphics/Text/Font/Choose/ObjectSet.hs -rw-r--r-- 1.1 KiB
32350eb8 — Adrian Cochrane Add initial README. 1 year, 10 months ago
                                                                                
e21707cb Adrian Cochrane
9942f874 Adrian Cochrane
e21707cb Adrian Cochrane
f238fc9c Adrian Cochrane
e21707cb Adrian Cochrane
9942f874 Adrian Cochrane
e21707cb Adrian Cochrane
9942f874 Adrian Cochrane
e21707cb Adrian Cochrane
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
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)
import Graphics.Text.Font.Choose.Result (throwFalse, throwNull)

-- | An `ObjectSet` holds a list of pattern property names;
-- it is used to indicate which properties are to be returned in the patterns
-- from `FontList`.
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 $ \obj' ->
        throwFalse <$> fcObjectSetAdd objs' obj'
    cb objs'
foreign import ccall "FcObjectSetAdd" fcObjectSetAdd ::
    ObjectSet_ -> CString -> IO Bool

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