~alcinnz/fontconfig-pure

ref: 47cc098450b726d49471eab75b08df89c5c75b6c fontconfig-pure/lib/Graphics/Text/Font/Choose/Result.hs -rw-r--r-- 705 bytes
47cc0984 — Adrian Cochrane Commit missing support module. 4 months ago
                                                                                
dbefdc06 Adrian Cochrane
bea597e7 Adrian Cochrane
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- | Exceptions which can be thrown by FontConfig.
module Graphics.Text.Font.Choose.Result (FcException(..), throwBool, throwNull, throwString) where

import Foreign.Ptr (Ptr, nullPtr)
import Text.Read (readMaybe)
import Control.Exception (Exception, throwIO)

data FcException = ErrType | ErrNoId | ErrOOM | ErrOther deriving (Read, Show, Eq, Enum)
instance Exception FcException

throwBool :: Bool -> IO ()
throwBool False = throwIO ErrOOM
throwBool True = return ()

throwNull :: Ptr a -> IO (Ptr a)
throwNull a | a == nullPtr = throwIO ErrOOM
    | otherwise = return a

throwString :: String -> IO ()
throwString a | Just b <- readMaybe a :: Maybe FcException = throwIO b
    | otherwise = return ()