module Graphics.Text.Font.Choose.Config where

import Graphics.Text.Font.Choose.Strings
import Graphics.Text.Font.Choose.FontSet
import Graphics.Text.Font.Choose.CharSet
import Graphics.Text.Font.Choose.Pattern
import Graphics.Text.Font.Choose.ObjectSet

import Foreign.ForeignPtr
import Foreign.Ptr (Ptr, nullPtr, FunPtr)
import Foreign.Marshal.Alloc (alloca, allocaBytes, free)
import Foreign.Storable (Storable(..))
import Foreign.C.String (CString, peekCString, withCString)
import System.IO.Unsafe (unsafePerformIO)
import Data.Set (empty) -- For testing segfault source.

import Control.Exception (bracket)
import Graphics.Text.Font.Choose.Result (Word8, throwNull, throwFalse, throwPtr)

-- | System configuration regarding available fonts.
type Config = ForeignPtr Config'
data Config'
type Config_ = Ptr Config'

-- | Creates an empty configuration.
configCreate :: IO Config
configCreate :: IO Config
configCreate = FinalizerPtr Config' -> Ptr Config' -> IO Config
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr Config'
fcConfigDestroy (Ptr Config' -> IO Config) -> IO (Ptr Config') -> IO Config
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Config' -> Ptr Config'
forall a. Ptr a -> Ptr a
throwNull (Ptr Config' -> Ptr Config')
-> IO (Ptr Config') -> IO (Ptr Config')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO (Ptr Config')
fcConfigCreate
foreign import ccall "FcConfigCreate" fcConfigCreate :: IO Config_
ptr2config :: Ptr Config' -> IO Config
ptr2config = FinalizerPtr Config' -> Ptr Config' -> IO Config
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr Config'
fcConfigDestroy
foreign import ccall "&FcConfigDestroy" fcConfigDestroy :: FunPtr (Config_ -> IO ())

-- | Sets the current default configuration to config.
-- Implicitly calls `configBuildFonts` if necessary.
configSetCurrent :: Config -> IO ()
configSetCurrent :: Config -> IO ()
configSetCurrent config :: Config
config = Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Config -> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Bool) -> IO Bool)
-> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> IO Bool
fcConfigSetCurrent)
foreign import ccall "FcConfigSetCurrent" fcConfigSetCurrent :: Config_ -> IO Bool

-- | Returns the current default configuration.
configGetCurrent :: IO Config
configGetCurrent :: IO Config
configGetCurrent = (Ptr Config' -> Ptr Config'
forall a. Ptr a -> Ptr a
throwNull (Ptr Config' -> Ptr Config')
-> IO (Ptr Config') -> IO (Ptr Config')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Config' -> IO (Ptr Config')
fcConfigReference Ptr Config'
forall a. Ptr a
nullPtr) IO (Ptr Config') -> (Ptr Config' -> IO Config) -> IO Config
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
    FinalizerPtr Config' -> Ptr Config' -> IO Config
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr Config'
fcConfigDestroy
foreign import ccall "FcConfigReference" fcConfigReference :: Config_ -> IO Config_

-- | Checks all of the files related to config and returns whether any of them
-- has been modified since the configuration was created.
configUptoDate :: Config -> IO Bool
configUptoDate :: Config -> IO Bool
configUptoDate config :: Config
config = Config -> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Bool) -> IO Bool)
-> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> IO Bool
fcConfigUptoDate
foreign import ccall "FcConfigUptoDate" fcConfigUptoDate :: Config_ -> IO Bool

-- | Return the current user's home directory, if it is available,
-- and if using it is enabled, and NULL otherwise. (See also `configEnableHome`).
configHome :: IO (Maybe String)
configHome :: IO (Maybe String)
configHome = do
    CString
ret <- IO CString
fcConfigHome
    if CString
ret CString -> CString -> Bool
forall a. Eq a => a -> a -> Bool
== CString
forall a. Ptr a
nullPtr then Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
forall a. Maybe a
Nothing else String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> IO String -> IO (Maybe String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CString -> IO String
peekCString CString
ret
foreign import ccall "FcConfigHome" fcConfigHome :: IO CString

-- | If enable is `True`, then Fontconfig will use various files which are
-- specified relative to the user's home directory (using the ~ notation in
-- the configuration). When enable is `False`, then all use of the home
-- directory in these contexts will be disabled. The previous setting of
-- the value is returned.
foreign import ccall "FcConfigEnableHome" configEnableHome :: Bool -> IO Bool

-- | Returns the list of font directories specified in the configuration files
-- for config. Does not include any subdirectories.
configBuildFonts :: Config -> IO ()
configBuildFonts :: Config -> IO ()
configBuildFonts config :: Config
config = Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Config -> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Bool) -> IO Bool)
-> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> IO Bool
fcConfigBuildFonts)
-- | Variant of `configBuildFonts` operating on the current configuration.
configBuildFonts' :: IO ()
configBuildFonts' :: IO ()
configBuildFonts' = Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Config' -> IO Bool
fcConfigBuildFonts Ptr Config'
forall a. Ptr a
nullPtr
foreign import ccall "FcConfigBuildFonts" fcConfigBuildFonts :: Config_ -> IO Bool

-- | Returns the list of font directories specified in the configuration files
-- for config. Does not include any subdirectories.
configGetConfigDirs :: Config -> IO StrList
configGetConfigDirs :: Config -> IO StrList
configGetConfigDirs = (Ptr Config' -> IO StrList_) -> Config -> IO StrList
configStrsFunc Ptr Config' -> IO StrList_
fcConfigGetConfigDirs
-- | Variant of `configGetConfigDirs` which operates on the current configuration.
configGetConfigDirs' :: IO StrList
configGetConfigDirs' :: IO StrList
configGetConfigDirs' = StrList_ -> IO StrList
thawStrList (StrList_ -> IO StrList) -> IO StrList_ -> IO StrList
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Config' -> IO StrList_
fcConfigGetConfigDirs Ptr Config'
forall a. Ptr a
nullPtr
foreign import ccall "FcConfigGetConfigDirs" fcConfigGetConfigDirs :: Config_ -> IO StrList_

-- | Returns the list of font directories in config.
-- This includes the configured font directories along with any directories
-- below those in the filesystem.
configGetFontDirs :: Config -> IO StrList
configGetFontDirs :: Config -> IO StrList
configGetFontDirs = (Ptr Config' -> IO StrList_) -> Config -> IO StrList
configStrsFunc Ptr Config' -> IO StrList_
fcConfigGetFontDirs
-- | Variant of `configGetFontDirs` which operates on the current config.
configGetFontDirs' :: IO StrList
configGetFontDirs' :: IO StrList
configGetFontDirs' = IO StrList_ -> IO StrList
thawStrList_ (IO StrList_ -> IO StrList) -> IO StrList_ -> IO StrList
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> IO StrList_
fcConfigGetFontDirs Ptr Config'
forall a. Ptr a
nullPtr
foreign import ccall "FcConfigGetFontDirs" fcConfigGetFontDirs :: Config_ -> IO StrList_

-- | Returns the list of known configuration files used to generate config.
configGetConfigFiles :: Config -> IO StrList
configGetConfigFiles :: Config -> IO StrList
configGetConfigFiles = (Ptr Config' -> IO StrList_) -> Config -> IO StrList
configStrsFunc Ptr Config' -> IO StrList_
fcConfigGetConfigFiles
-- | Variant of `configGetConfigFiles` which operates upon current configuration.
configGetConfigFiles' :: IO StrList
configGetConfigFiles' :: IO StrList
configGetConfigFiles' = IO StrList_ -> IO StrList
thawStrList_ (IO StrList_ -> IO StrList) -> IO StrList_ -> IO StrList
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> IO StrList_
fcConfigGetConfigFiles Ptr Config'
forall a. Ptr a
nullPtr
foreign import ccall "FcConfigGetConfigFiles" fcConfigGetConfigFiles :: Config_ -> IO StrList_

-- | Returns a string list containing all of the directories that fontconfig
-- will search when attempting to load a cache file for a font directory.
configGetCacheDirs :: Config -> IO StrList
configGetCacheDirs :: Config -> IO StrList
configGetCacheDirs = (Ptr Config' -> IO StrList_) -> Config -> IO StrList
configStrsFunc Ptr Config' -> IO StrList_
fcConfigGetCacheDirs
-- | Variant of `configGetCacheDirs` which operates upon current configuration.
configGetCacheDirs' :: IO StrList
configGetCacheDirs' :: IO StrList
configGetCacheDirs' = IO StrList_ -> IO StrList
thawStrList_ (IO StrList_ -> IO StrList) -> IO StrList_ -> IO StrList
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> IO StrList_
fcConfigGetCacheDirs Ptr Config'
forall a. Ptr a
nullPtr
foreign import ccall "FcConfigGetCacheDirs" fcConfigGetCacheDirs :: Config_ -> IO StrList_

-- | Whether to operate upon system or application fontlists.
data SetName = SetSystem | SetApplication deriving (Int -> SetName
SetName -> Int
SetName -> [SetName]
SetName -> SetName
SetName -> SetName -> [SetName]
SetName -> SetName -> SetName -> [SetName]
(SetName -> SetName)
-> (SetName -> SetName)
-> (Int -> SetName)
-> (SetName -> Int)
-> (SetName -> [SetName])
-> (SetName -> SetName -> [SetName])
-> (SetName -> SetName -> [SetName])
-> (SetName -> SetName -> SetName -> [SetName])
-> Enum SetName
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: SetName -> SetName -> SetName -> [SetName]
$cenumFromThenTo :: SetName -> SetName -> SetName -> [SetName]
enumFromTo :: SetName -> SetName -> [SetName]
$cenumFromTo :: SetName -> SetName -> [SetName]
enumFromThen :: SetName -> SetName -> [SetName]
$cenumFromThen :: SetName -> SetName -> [SetName]
enumFrom :: SetName -> [SetName]
$cenumFrom :: SetName -> [SetName]
fromEnum :: SetName -> Int
$cfromEnum :: SetName -> Int
toEnum :: Int -> SetName
$ctoEnum :: Int -> SetName
pred :: SetName -> SetName
$cpred :: SetName -> SetName
succ :: SetName -> SetName
$csucc :: SetName -> SetName
Enum, SetName -> SetName -> Bool
(SetName -> SetName -> Bool)
-> (SetName -> SetName -> Bool) -> Eq SetName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetName -> SetName -> Bool
$c/= :: SetName -> SetName -> Bool
== :: SetName -> SetName -> Bool
$c== :: SetName -> SetName -> Bool
Eq, Int -> SetName -> ShowS
[SetName] -> ShowS
SetName -> String
(Int -> SetName -> ShowS)
-> (SetName -> String) -> ([SetName] -> ShowS) -> Show SetName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetName] -> ShowS
$cshowList :: [SetName] -> ShowS
show :: SetName -> String
$cshow :: SetName -> String
showsPrec :: Int -> SetName -> ShowS
$cshowsPrec :: Int -> SetName -> ShowS
Show, ReadPrec [SetName]
ReadPrec SetName
Int -> ReadS SetName
ReadS [SetName]
(Int -> ReadS SetName)
-> ReadS [SetName]
-> ReadPrec SetName
-> ReadPrec [SetName]
-> Read SetName
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SetName]
$creadListPrec :: ReadPrec [SetName]
readPrec :: ReadPrec SetName
$creadPrec :: ReadPrec SetName
readList :: ReadS [SetName]
$creadList :: ReadS [SetName]
readsPrec :: Int -> ReadS SetName
$creadsPrec :: Int -> ReadS SetName
Read)
-- | Returns one of the two sets of fonts from the configuration as specified
-- by set. This font set is owned by the library and must not be modified or
-- freed. If config is NULL, the current configuration is used.
-- This function isn't MT-safe.
configGetFonts :: Config -> SetName -> IO FontSet
configGetFonts :: Config -> SetName -> IO FontSet
configGetFonts config :: Config
config set :: SetName
set = do
    FontSet_
ret <- Config -> (Ptr Config' -> IO FontSet_) -> IO FontSet_
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO FontSet_) -> IO FontSet_)
-> (Ptr Config' -> IO FontSet_) -> IO FontSet_
forall a b. (a -> b) -> a -> b
$ (Ptr Config' -> Int -> IO FontSet_)
-> Int -> Ptr Config' -> IO FontSet_
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr Config' -> Int -> IO FontSet_
fcConfigGetFonts (Int -> Ptr Config' -> IO FontSet_)
-> Int -> Ptr Config' -> IO FontSet_
forall a b. (a -> b) -> a -> b
$ SetName -> Int
forall a. Enum a => a -> Int
fromEnum SetName
set
    FontSet_ -> IO FontSet
thawFontSet (FontSet_ -> IO FontSet) -> FontSet_ -> IO FontSet
forall a b. (a -> b) -> a -> b
$ FontSet_ -> FontSet_
forall a. Ptr a -> Ptr a
throwNull FontSet_
ret
-- | Variant of `configGetFonts` which operates upon current configuration.
configGetFonts' :: SetName -> IO FontSet
configGetFonts' :: SetName -> IO FontSet
configGetFonts' set :: SetName
set = do
    FontSet_
ret <- Ptr Config' -> Int -> IO FontSet_
fcConfigGetFonts Ptr Config'
forall a. Ptr a
nullPtr (Int -> IO FontSet_) -> Int -> IO FontSet_
forall a b. (a -> b) -> a -> b
$ SetName -> Int
forall a. Enum a => a -> Int
fromEnum SetName
set
    FontSet_ -> IO FontSet
thawFontSet (FontSet_ -> IO FontSet) -> FontSet_ -> IO FontSet
forall a b. (a -> b) -> a -> b
$ FontSet_ -> FontSet_
forall a. Ptr a -> Ptr a
throwNull FontSet_
ret
foreign import ccall "FcConfigGetFonts" fcConfigGetFonts :: Config_ -> Int -> IO FontSet_

-- | Returns the interval between automatic checks of the configuration
-- (in seconds) specified in config. The configuration is checked during
-- a call to FcFontList when this interval has passed since the last check.
-- An interval setting of zero disables automatic checks.
configGetRescanInterval :: Config -> IO Int
configGetRescanInterval :: Config -> IO Int
configGetRescanInterval = (Config -> (Ptr Config' -> IO Int) -> IO Int)
-> (Ptr Config' -> IO Int) -> Config -> IO Int
forall a b c. (a -> b -> c) -> b -> a -> c
flip Config -> (Ptr Config' -> IO Int) -> IO Int
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ((Ptr Config' -> IO Int) -> Config -> IO Int)
-> (Ptr Config' -> IO Int) -> Config -> IO Int
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> IO Int
fcConfigGetRescanInterval
-- | Variant of `configGetRescanInterval` which operates upon current configuration.
configGetRescanInterval' :: IO Int
configGetRescanInterval' :: IO Int
configGetRescanInterval' = Ptr Config' -> IO Int
fcConfigGetRescanInterval Ptr Config'
forall a. Ptr a
nullPtr
foreign import ccall "FcConfigGetRescanInterval" fcConfigGetRescanInterval ::
    Config_ -> IO Int

-- | Sets the rescan interval.
-- An interval setting of zero disables automatic checks.
configSetRescanInterval :: Config -> Int -> IO ()
configSetRescanInterval :: Config -> Int -> IO ()
configSetRescanInterval config :: Config
config val :: Int
val =
    Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Config -> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Bool) -> IO Bool)
-> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ (Ptr Config' -> Int -> IO Bool) -> Int -> Ptr Config' -> IO Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr Config' -> Int -> IO Bool
fcConfigSetRescanInterval Int
val)
-- | Variant of `configSetRescanInterval` which operates upon current configuration.
configSetRescanInterval' :: Int -> IO ()
configSetRescanInterval' :: Int -> IO ()
configSetRescanInterval' v :: Int
v = Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Config' -> Int -> IO Bool
fcConfigSetRescanInterval Ptr Config'
forall a. Ptr a
nullPtr Int
v
foreign import ccall "FcConfigSetRescanInterval" fcConfigSetRescanInterval ::
    Config_ -> Int -> IO Bool

-- | Adds an application-specific font to the configuration.
configAppFontAddFile :: Config -> String -> IO ()
configAppFontAddFile :: Config -> String -> IO ()
configAppFontAddFile config :: Config
config file :: String
file = Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
    (Config -> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Bool) -> IO Bool)
-> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' -> String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withCString String
file ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \file' :: CString
file' ->
        Ptr Config' -> CString -> IO Bool
fcConfigAppFontAddFile Ptr Config'
config' CString
file')
-- | Variant of `configAppFontAddFile` which operates upon current configuration.
configAppFontAddFile' :: String -> IO ()
configAppFontAddFile' :: String -> IO ()
configAppFontAddFile' file :: String
file =
    Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withCString String
file ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> CString -> IO Bool
fcConfigAppFontAddFile Ptr Config'
forall a. Ptr a
nullPtr)
foreign import ccall "FcConfigAppFontAddFile" fcConfigAppFontAddFile ::
    Config_ -> CString -> IO Bool

-- | Scans the specified directory for fonts,
-- adding each one found to the application-specific set of fonts.
configAppFontAddDir :: Config -> String -> IO ()
configAppFontAddDir :: Config -> String -> IO ()
configAppFontAddDir config :: Config
config file :: String
file = Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
    (Config -> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Bool) -> IO Bool)
-> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' -> String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withCString String
file ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> CString -> IO Bool
fcConfigAppFontAddDir Ptr Config'
config')
-- | Variant of `configAppFontAddDir` which operates upon current configuration.
configAppFontAddDir' :: String -> IO ()
configAppFontAddDir' :: String -> IO ()
configAppFontAddDir' v :: String
v = Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withCString String
v ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> CString -> IO Bool
fcConfigAppFontAddDir Ptr Config'
forall a. Ptr a
nullPtr)
foreign import ccall "FcConfigAppFontAddDir" fcConfigAppFontAddDir ::
    Config_ -> CString -> IO Bool

-- | Clears the set of application-specific fonts.
configAppFontClear :: Config -> IO ()
configAppFontClear :: Config -> IO ()
configAppFontClear config :: Config
config = Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Config -> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config Ptr Config' -> IO Bool
fcConfigAppFontClear
-- | Variant of `configAppFontClear` which operates upon current configuration.
configAppFontClear' :: IO ()
configAppFontClear' :: IO ()
configAppFontClear' = Bool -> IO ()
throwFalse (Bool -> IO ()) -> IO Bool -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Config' -> IO Bool
fcConfigAppFontClear Ptr Config'
forall a. Ptr a
nullPtr
foreign import ccall "FcConfigAppFontClear" fcConfigAppFontClear :: Config_ -> IO Bool

-- | What purpose does the given pattern serve?
data MatchKind = MatchPattern | MatchFont | MatchScan deriving Int -> MatchKind
MatchKind -> Int
MatchKind -> [MatchKind]
MatchKind -> MatchKind
MatchKind -> MatchKind -> [MatchKind]
MatchKind -> MatchKind -> MatchKind -> [MatchKind]
(MatchKind -> MatchKind)
-> (MatchKind -> MatchKind)
-> (Int -> MatchKind)
-> (MatchKind -> Int)
-> (MatchKind -> [MatchKind])
-> (MatchKind -> MatchKind -> [MatchKind])
-> (MatchKind -> MatchKind -> [MatchKind])
-> (MatchKind -> MatchKind -> MatchKind -> [MatchKind])
-> Enum MatchKind
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: MatchKind -> MatchKind -> MatchKind -> [MatchKind]
$cenumFromThenTo :: MatchKind -> MatchKind -> MatchKind -> [MatchKind]
enumFromTo :: MatchKind -> MatchKind -> [MatchKind]
$cenumFromTo :: MatchKind -> MatchKind -> [MatchKind]
enumFromThen :: MatchKind -> MatchKind -> [MatchKind]
$cenumFromThen :: MatchKind -> MatchKind -> [MatchKind]
enumFrom :: MatchKind -> [MatchKind]
$cenumFrom :: MatchKind -> [MatchKind]
fromEnum :: MatchKind -> Int
$cfromEnum :: MatchKind -> Int
toEnum :: Int -> MatchKind
$ctoEnum :: Int -> MatchKind
pred :: MatchKind -> MatchKind
$cpred :: MatchKind -> MatchKind
succ :: MatchKind -> MatchKind
$csucc :: MatchKind -> MatchKind
Enum
-- | Performs the sequence of pattern modification operations,
-- if kind is `MatchPattern`, then those tagged as pattern operations are applied,
-- else if kind is `MatchFont`, those tagged as font operations are applied and
-- p_pat is used for <test> elements with target=pattern.
configSubstituteWithPat :: Config -> Pattern -> Pattern -> MatchKind -> Pattern
configSubstituteWithPat :: Config -> Pattern -> Pattern -> MatchKind -> Pattern
configSubstituteWithPat config :: Config
config p :: Pattern
p p_pat :: Pattern
p_pat kind :: MatchKind
kind = IO Pattern -> Pattern
forall a. IO a -> a
unsafePerformIO (IO Pattern -> Pattern) -> IO Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$
    Config -> (Ptr Config' -> IO Pattern) -> IO Pattern
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Pattern) -> IO Pattern)
-> (Ptr Config' -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' -> Pattern -> (Pattern_ -> IO Pattern) -> IO Pattern
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
p ((Pattern_ -> IO Pattern) -> IO Pattern)
-> (Pattern_ -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \p' :: Pattern_
p' ->
        Pattern -> (Pattern_ -> IO Pattern) -> IO Pattern
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
p_pat ((Pattern_ -> IO Pattern) -> IO Pattern)
-> (Pattern_ -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \p_pat' :: Pattern_
p_pat' -> do
            Bool
ok <- Ptr Config' -> Pattern_ -> Pattern_ -> Int -> IO Bool
fcConfigSubstituteWithPat Ptr Config'
config' Pattern_
p' Pattern_
p_pat' (Int -> IO Bool) -> Int -> IO Bool
forall a b. (a -> b) -> a -> b
$ MatchKind -> Int
forall a. Enum a => a -> Int
fromEnum MatchKind
kind
            Bool -> IO ()
throwFalse Bool
ok
            Pattern_ -> IO Pattern
thawPattern Pattern_
p'
-- | Variant of `configSubstituteWithPat` which operates upon current configuration.
configSubstituteWithPat' :: Pattern -> Pattern -> MatchKind -> Pattern
configSubstituteWithPat' :: Pattern -> Pattern -> MatchKind -> Pattern
configSubstituteWithPat' p :: Pattern
p p_pat :: Pattern
p_pat kind :: MatchKind
kind = IO Pattern -> Pattern
forall a. IO a -> a
unsafePerformIO (IO Pattern -> Pattern) -> IO Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$
    Pattern -> (Pattern_ -> IO Pattern) -> IO Pattern
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
p ((Pattern_ -> IO Pattern) -> IO Pattern)
-> (Pattern_ -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \p' :: Pattern_
p' -> Pattern -> (Pattern_ -> IO Pattern) -> IO Pattern
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
p_pat ((Pattern_ -> IO Pattern) -> IO Pattern)
-> (Pattern_ -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \p_pat' :: Pattern_
p_pat' -> do
        Bool
ok <- Ptr Config' -> Pattern_ -> Pattern_ -> Int -> IO Bool
fcConfigSubstituteWithPat Ptr Config'
forall a. Ptr a
nullPtr Pattern_
p' Pattern_
p_pat' (Int -> IO Bool) -> Int -> IO Bool
forall a b. (a -> b) -> a -> b
$ MatchKind -> Int
forall a. Enum a => a -> Int
fromEnum MatchKind
kind
        Bool -> IO ()
throwFalse Bool
ok
        Pattern_ -> IO Pattern
thawPattern Pattern_
p'
foreign import ccall "FcConfigSubstituteWithPat" fcConfigSubstituteWithPat ::
    Config_ -> Pattern_ -> Pattern_ -> Int -> IO Bool

-- | Calls FcConfigSubstituteWithPat without setting p_pat.
configSubstitute :: Config -> Pattern -> MatchKind -> Pattern
configSubstitute :: Config -> Pattern -> MatchKind -> Pattern
configSubstitute config :: Config
config p :: Pattern
p kind :: MatchKind
kind = IO Pattern -> Pattern
forall a. IO a -> a
unsafePerformIO (IO Pattern -> Pattern) -> IO Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$
    Config -> (Ptr Config' -> IO Pattern) -> IO Pattern
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Pattern) -> IO Pattern)
-> (Ptr Config' -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' -> Pattern -> (Pattern_ -> IO Pattern) -> IO Pattern
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
p ((Pattern_ -> IO Pattern) -> IO Pattern)
-> (Pattern_ -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \p' :: Pattern_
p' -> do
        Bool
ok <- Ptr Config' -> Pattern_ -> Int -> IO Bool
fcConfigSubstitute Ptr Config'
config' Pattern_
p' (Int -> IO Bool) -> Int -> IO Bool
forall a b. (a -> b) -> a -> b
$ MatchKind -> Int
forall a. Enum a => a -> Int
fromEnum MatchKind
kind
        Bool -> IO ()
throwFalse Bool
ok
        Pattern_ -> IO Pattern
thawPattern Pattern_
p'
-- | Variant `configSubstitute` which operates upon current configuration.
configSubstitute' :: Pattern -> MatchKind -> Pattern
configSubstitute' :: Pattern -> MatchKind -> Pattern
configSubstitute' p :: Pattern
p kind :: MatchKind
kind = IO Pattern -> Pattern
forall a. IO a -> a
unsafePerformIO (IO Pattern -> Pattern) -> IO Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern -> (Pattern_ -> IO Pattern) -> IO Pattern
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
p ((Pattern_ -> IO Pattern) -> IO Pattern)
-> (Pattern_ -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \p' :: Pattern_
p' -> do
    Bool
ok <- Ptr Config' -> Pattern_ -> Int -> IO Bool
fcConfigSubstitute Ptr Config'
forall a. Ptr a
nullPtr Pattern_
p' (Int -> IO Bool) -> Int -> IO Bool
forall a b. (a -> b) -> a -> b
$ MatchKind -> Int
forall a. Enum a => a -> Int
fromEnum MatchKind
kind
    Bool -> IO ()
throwFalse Bool
ok
    Pattern_ -> IO Pattern
thawPattern Pattern_
p'
foreign import ccall "FcConfigSubstitute" fcConfigSubstitute ::
    Config_ -> Pattern_ -> Int -> IO Bool

-- | Finds the font in sets most closely matching pattern and returns
-- the result of `fontRenderPrepare` for that font and the provided pattern.
-- This function should be called only after `configSubstitute` and
-- `defaultSubstitute` have been called for p;
-- otherwise the results will not be correct.
fontMatch :: Config -> Pattern -> Maybe Pattern
fontMatch :: Config -> Pattern -> Maybe Pattern
fontMatch config :: Config
config pattern :: Pattern
pattern = IO (Maybe Pattern) -> Maybe Pattern
forall a. IO a -> a
unsafePerformIO (IO (Maybe Pattern) -> Maybe Pattern)
-> IO (Maybe Pattern) -> Maybe Pattern
forall a b. (a -> b) -> a -> b
$ Config -> (Ptr Config' -> IO (Maybe Pattern)) -> IO (Maybe Pattern)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO (Maybe Pattern)) -> IO (Maybe Pattern))
-> (Ptr Config' -> IO (Maybe Pattern)) -> IO (Maybe Pattern)
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' ->
    Pattern -> (Pattern_ -> IO (Maybe Pattern)) -> IO (Maybe Pattern)
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pattern ((Pattern_ -> IO (Maybe Pattern)) -> IO (Maybe Pattern))
-> (Pattern_ -> IO (Maybe Pattern)) -> IO (Maybe Pattern)
forall a b. (a -> b) -> a -> b
$ \pattern' :: Pattern_
pattern' -> (Ptr Word8 -> IO (Maybe Pattern)) -> IO (Maybe Pattern)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (Maybe Pattern)) -> IO (Maybe Pattern))
-> (Ptr Word8 -> IO (Maybe Pattern)) -> IO (Maybe Pattern)
forall a b. (a -> b) -> a -> b
$ \res' :: Ptr Word8
res' -> do
        Pattern_
ret <- Ptr Config' -> Pattern_ -> Ptr Word8 -> IO Pattern_
fcFontMatch Ptr Config'
config' Pattern_
pattern' Ptr Word8
res'
        Ptr Word8 -> IO Pattern -> IO (Maybe Pattern)
forall a. Ptr Word8 -> IO a -> IO (Maybe a)
throwPtr Ptr Word8
res' (IO Pattern -> IO (Maybe Pattern))
-> IO Pattern -> IO (Maybe Pattern)
forall a b. (a -> b) -> a -> b
$ IO Pattern_ -> IO Pattern
thawPattern_ (IO Pattern_ -> IO Pattern) -> IO Pattern_ -> IO Pattern
forall a b. (a -> b) -> a -> b
$ Pattern_ -> IO Pattern_
forall (f :: * -> *) a. Applicative f => a -> f a
pure Pattern_
ret
-- | Variant of `fontMatch` which operates upon current configuration.
fontMatch' :: Pattern -> Maybe Pattern
fontMatch' :: Pattern -> Maybe Pattern
fontMatch' pattern :: Pattern
pattern = IO (Maybe Pattern) -> Maybe Pattern
forall a. IO a -> a
unsafePerformIO (IO (Maybe Pattern) -> Maybe Pattern)
-> IO (Maybe Pattern) -> Maybe Pattern
forall a b. (a -> b) -> a -> b
$ Pattern -> (Pattern_ -> IO (Maybe Pattern)) -> IO (Maybe Pattern)
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pattern ((Pattern_ -> IO (Maybe Pattern)) -> IO (Maybe Pattern))
-> (Pattern_ -> IO (Maybe Pattern)) -> IO (Maybe Pattern)
forall a b. (a -> b) -> a -> b
$ \pattern' :: Pattern_
pattern' -> (Ptr Word8 -> IO (Maybe Pattern)) -> IO (Maybe Pattern)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (Maybe Pattern)) -> IO (Maybe Pattern))
-> (Ptr Word8 -> IO (Maybe Pattern)) -> IO (Maybe Pattern)
forall a b. (a -> b) -> a -> b
$ \res' :: Ptr Word8
res' -> do
    Pattern_
ret <- Ptr Config' -> Pattern_ -> Ptr Word8 -> IO Pattern_
fcFontMatch Ptr Config'
forall a. Ptr a
nullPtr Pattern_
pattern' Ptr Word8
res'
    Ptr Word8 -> IO Pattern -> IO (Maybe Pattern)
forall a. Ptr Word8 -> IO a -> IO (Maybe a)
throwPtr Ptr Word8
res' (IO Pattern -> IO (Maybe Pattern))
-> IO Pattern -> IO (Maybe Pattern)
forall a b. (a -> b) -> a -> b
$ IO Pattern_ -> IO Pattern
thawPattern_ (IO Pattern_ -> IO Pattern) -> IO Pattern_ -> IO Pattern
forall a b. (a -> b) -> a -> b
$ Pattern_ -> IO Pattern_
forall (f :: * -> *) a. Applicative f => a -> f a
pure Pattern_
ret
foreign import ccall "FcFontMatch" fcFontMatch ::
    Config_ -> Pattern_ -> Ptr Word8 -> IO Pattern_

-- | Returns the list of fonts sorted by closeness to p. If trim is `True`,
-- elements in the list which don't include Unicode coverage not provided by
-- earlier elements in the list are elided. The union of Unicode coverage of
-- all of the fonts is returned in `snd`. This function should be called only
-- after `configSubstitute` and `defaultSubstitute` have been called for p;
-- otherwise the results will not be correct.
fontSort :: Config -> Pattern -> Bool -> Maybe (FontSet, CharSet)
fontSort :: Config -> Pattern -> Bool -> Maybe (FontSet, CharSet)
fontSort config :: Config
config pattern :: Pattern
pattern trim :: Bool
trim = IO (Maybe (FontSet, CharSet)) -> Maybe (FontSet, CharSet)
forall a. IO a -> a
unsafePerformIO (IO (Maybe (FontSet, CharSet)) -> Maybe (FontSet, CharSet))
-> IO (Maybe (FontSet, CharSet)) -> Maybe (FontSet, CharSet)
forall a b. (a -> b) -> a -> b
$ Config
-> (Ptr Config' -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO (Maybe (FontSet, CharSet)))
 -> IO (Maybe (FontSet, CharSet)))
-> (Ptr Config' -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' ->
    Pattern
-> (Pattern_ -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pattern ((Pattern_ -> IO (Maybe (FontSet, CharSet)))
 -> IO (Maybe (FontSet, CharSet)))
-> (Pattern_ -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a b. (a -> b) -> a -> b
$ \pattern' :: Pattern_
pattern' -> (CharSet_ -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a. (CharSet_ -> IO a) -> IO a
withNewCharSet ((CharSet_ -> IO (Maybe (FontSet, CharSet)))
 -> IO (Maybe (FontSet, CharSet)))
-> (CharSet_ -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a b. (a -> b) -> a -> b
$ \csp' :: CharSet_
csp' -> (Ptr Word8 -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (Maybe (FontSet, CharSet)))
 -> IO (Maybe (FontSet, CharSet)))
-> (Ptr Word8 -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a b. (a -> b) -> a -> b
$ \res' :: Ptr Word8
res' -> do
        FontSet_
ret <- Ptr Config'
-> Pattern_ -> Bool -> CharSet_ -> Ptr Word8 -> IO FontSet_
fcFontSort Ptr Config'
config' Pattern_
pattern' Bool
trim CharSet_
csp' Ptr Word8
res'
        Ptr Word8 -> IO (FontSet, CharSet) -> IO (Maybe (FontSet, CharSet))
forall a. Ptr Word8 -> IO a -> IO (Maybe a)
throwPtr Ptr Word8
res' (IO (FontSet, CharSet) -> IO (Maybe (FontSet, CharSet)))
-> IO (FontSet, CharSet) -> IO (Maybe (FontSet, CharSet))
forall a b. (a -> b) -> a -> b
$ do
            FontSet
x <- IO FontSet_ -> IO FontSet
thawFontSet_ (IO FontSet_ -> IO FontSet) -> IO FontSet_ -> IO FontSet
forall a b. (a -> b) -> a -> b
$ FontSet_ -> IO FontSet_
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FontSet_ -> IO FontSet_) -> FontSet_ -> IO FontSet_
forall a b. (a -> b) -> a -> b
$ FontSet_ -> FontSet_
forall a. Ptr a -> Ptr a
throwNull FontSet_
ret
            CharSet
y <- CharSet_ -> IO CharSet
thawCharSet (CharSet_ -> IO CharSet) -> CharSet_ -> IO CharSet
forall a b. (a -> b) -> a -> b
$ CharSet_ -> CharSet_
forall a. Ptr a -> Ptr a
throwNull CharSet_
csp'
            (FontSet, CharSet) -> IO (FontSet, CharSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (FontSet
x, CharSet
y)
-- | Variant of `fontSort` which operates upon current configuration.
fontSort' :: Pattern -> Bool -> Maybe (FontSet, CharSet)
fontSort' :: Pattern -> Bool -> Maybe (FontSet, CharSet)
fontSort' pattern :: Pattern
pattern trim :: Bool
trim = IO (Maybe (FontSet, CharSet)) -> Maybe (FontSet, CharSet)
forall a. IO a -> a
unsafePerformIO (IO (Maybe (FontSet, CharSet)) -> Maybe (FontSet, CharSet))
-> IO (Maybe (FontSet, CharSet)) -> Maybe (FontSet, CharSet)
forall a b. (a -> b) -> a -> b
$ Pattern
-> (Pattern_ -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pattern ((Pattern_ -> IO (Maybe (FontSet, CharSet)))
 -> IO (Maybe (FontSet, CharSet)))
-> (Pattern_ -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a b. (a -> b) -> a -> b
$ \pattern' :: Pattern_
pattern' ->
    (CharSet_ -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a. (CharSet_ -> IO a) -> IO a
withNewCharSet ((CharSet_ -> IO (Maybe (FontSet, CharSet)))
 -> IO (Maybe (FontSet, CharSet)))
-> (CharSet_ -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a b. (a -> b) -> a -> b
$ \csp' :: CharSet_
csp' -> (Ptr Word8 -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (Maybe (FontSet, CharSet)))
 -> IO (Maybe (FontSet, CharSet)))
-> (Ptr Word8 -> IO (Maybe (FontSet, CharSet)))
-> IO (Maybe (FontSet, CharSet))
forall a b. (a -> b) -> a -> b
$ \res' :: Ptr Word8
res' -> do
        FontSet_
ret <- Ptr Config'
-> Pattern_ -> Bool -> CharSet_ -> Ptr Word8 -> IO FontSet_
fcFontSort Ptr Config'
forall a. Ptr a
nullPtr Pattern_
pattern' Bool
trim CharSet_
csp' Ptr Word8
res'
        Ptr Word8 -> IO (FontSet, CharSet) -> IO (Maybe (FontSet, CharSet))
forall a. Ptr Word8 -> IO a -> IO (Maybe a)
throwPtr Ptr Word8
res' (IO (FontSet, CharSet) -> IO (Maybe (FontSet, CharSet)))
-> IO (FontSet, CharSet) -> IO (Maybe (FontSet, CharSet))
forall a b. (a -> b) -> a -> b
$ do
            FontSet
x <- IO FontSet_ -> IO FontSet
thawFontSet_ (IO FontSet_ -> IO FontSet) -> IO FontSet_ -> IO FontSet
forall a b. (a -> b) -> a -> b
$ FontSet_ -> IO FontSet_
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FontSet_ -> IO FontSet_) -> FontSet_ -> IO FontSet_
forall a b. (a -> b) -> a -> b
$ FontSet_ -> FontSet_
forall a. Ptr a -> Ptr a
throwNull FontSet_
ret
            CharSet
y <- CharSet_ -> IO CharSet
thawCharSet (CharSet_ -> IO CharSet) -> CharSet_ -> IO CharSet
forall a b. (a -> b) -> a -> b
$ CharSet_ -> CharSet_
forall a. Ptr a -> Ptr a
throwNull CharSet_
csp'
            (FontSet, CharSet) -> IO (FontSet, CharSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (FontSet
x, CharSet
y)
foreign import ccall "FcFontSort" fcFontSort ::
    Config_ -> Pattern_ -> Bool -> CharSet_ -> Ptr Word8 -> IO FontSet_

-- | Creates a new pattern consisting of elements of font not appearing in pat,
-- elements of pat not appearing in font and the best matching value from pat
-- for elements appearing in both. The result is passed to
--`configSubstituteWithPat` with kind `matchFont` and then returned.
fontRenderPrepare :: Config -> Pattern -> Pattern -> Pattern
fontRenderPrepare :: Config -> Pattern -> Pattern -> Pattern
fontRenderPrepare config :: Config
config pat :: Pattern
pat font :: Pattern
font = IO Pattern -> Pattern
forall a. IO a -> a
unsafePerformIO (IO Pattern -> Pattern) -> IO Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Config -> (Ptr Config' -> IO Pattern) -> IO Pattern
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Pattern) -> IO Pattern)
-> (Ptr Config' -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' ->
    Pattern -> (Pattern_ -> IO Pattern) -> IO Pattern
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pat ((Pattern_ -> IO Pattern) -> IO Pattern)
-> (Pattern_ -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \pat' :: Pattern_
pat' -> Pattern -> (Pattern_ -> IO Pattern) -> IO Pattern
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
font ((Pattern_ -> IO Pattern) -> IO Pattern)
-> (Pattern_ -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \font' :: Pattern_
font' -> do
        Pattern_
ret <- Ptr Config' -> Pattern_ -> Pattern_ -> IO Pattern_
fcFontRenderPrepare Ptr Config'
config' Pattern_
pat' Pattern_
font'
        IO Pattern_ -> IO Pattern
thawPattern_ (IO Pattern_ -> IO Pattern) -> IO Pattern_ -> IO Pattern
forall a b. (a -> b) -> a -> b
$ Pattern_ -> IO Pattern_
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pattern_ -> IO Pattern_) -> Pattern_ -> IO Pattern_
forall a b. (a -> b) -> a -> b
$ Pattern_ -> Pattern_
forall a. Ptr a -> Ptr a
throwNull Pattern_
ret
-- | Variant of `fontRenderPrepare` which operates upon current configuration.
fontRenderPrepare' :: Pattern -> Pattern -> Pattern
fontRenderPrepare' :: Pattern -> Pattern -> Pattern
fontRenderPrepare' pat :: Pattern
pat font :: Pattern
font = IO Pattern -> Pattern
forall a. IO a -> a
unsafePerformIO (IO Pattern -> Pattern) -> IO Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern -> (Pattern_ -> IO Pattern) -> IO Pattern
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pat ((Pattern_ -> IO Pattern) -> IO Pattern)
-> (Pattern_ -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \pat' :: Pattern_
pat' ->
    Pattern -> (Pattern_ -> IO Pattern) -> IO Pattern
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
font ((Pattern_ -> IO Pattern) -> IO Pattern)
-> (Pattern_ -> IO Pattern) -> IO Pattern
forall a b. (a -> b) -> a -> b
$ \font' :: Pattern_
font' -> do
        Pattern_
ret <- Ptr Config' -> Pattern_ -> Pattern_ -> IO Pattern_
fcFontRenderPrepare Ptr Config'
forall a. Ptr a
nullPtr Pattern_
pat' Pattern_
font'
        IO Pattern_ -> IO Pattern
thawPattern_ (IO Pattern_ -> IO Pattern) -> IO Pattern_ -> IO Pattern
forall a b. (a -> b) -> a -> b
$ Pattern_ -> IO Pattern_
forall (f :: * -> *) a. Applicative f => a -> f a
pure Pattern_
ret
foreign import ccall "FcFontRenderPrepare" fcFontRenderPrepare ::
    Config_ -> Pattern_ -> Pattern_ -> IO Pattern_

-- | Selects fonts matching p, creates patterns from those fonts containing only
-- the objects in os and returns the set of unique such patterns.
fontList :: Config -> Pattern -> ObjectSet -> FontSet
fontList :: Config -> Pattern -> StrList -> FontSet
fontList config :: Config
config p :: Pattern
p os :: StrList
os = IO FontSet -> FontSet
forall a. IO a -> a
unsafePerformIO (IO FontSet -> FontSet) -> IO FontSet -> FontSet
forall a b. (a -> b) -> a -> b
$ Config -> (Ptr Config' -> IO FontSet) -> IO FontSet
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO FontSet) -> IO FontSet)
-> (Ptr Config' -> IO FontSet) -> IO FontSet
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' ->
    Pattern -> (Pattern_ -> IO FontSet) -> IO FontSet
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
p ((Pattern_ -> IO FontSet) -> IO FontSet)
-> (Pattern_ -> IO FontSet) -> IO FontSet
forall a b. (a -> b) -> a -> b
$ \p' :: Pattern_
p' -> StrList -> (ObjectSet_ -> IO FontSet) -> IO FontSet
forall a. StrList -> (ObjectSet_ -> IO a) -> IO a
withObjectSet StrList
os ((ObjectSet_ -> IO FontSet) -> IO FontSet)
-> (ObjectSet_ -> IO FontSet) -> IO FontSet
forall a b. (a -> b) -> a -> b
$ \os' :: ObjectSet_
os' -> do
        FontSet_
ret <- Ptr Config' -> Pattern_ -> ObjectSet_ -> IO FontSet_
fcFontList Ptr Config'
config' Pattern_
p' ObjectSet_
os'
        IO FontSet_ -> IO FontSet
thawFontSet_ (IO FontSet_ -> IO FontSet) -> IO FontSet_ -> IO FontSet
forall a b. (a -> b) -> a -> b
$ FontSet_ -> IO FontSet_
forall (f :: * -> *) a. Applicative f => a -> f a
pure FontSet_
ret
-- | Variant of `fontList` which operates upon current configuration.
fontList' :: Pattern -> ObjectSet -> FontSet
fontList' :: Pattern -> StrList -> FontSet
fontList' p :: Pattern
p os :: StrList
os = IO FontSet -> FontSet
forall a. IO a -> a
unsafePerformIO (IO FontSet -> FontSet) -> IO FontSet -> FontSet
forall a b. (a -> b) -> a -> b
$ Pattern -> (Pattern_ -> IO FontSet) -> IO FontSet
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
p ((Pattern_ -> IO FontSet) -> IO FontSet)
-> (Pattern_ -> IO FontSet) -> IO FontSet
forall a b. (a -> b) -> a -> b
$ \p' :: Pattern_
p' -> StrList -> (ObjectSet_ -> IO FontSet) -> IO FontSet
forall a. StrList -> (ObjectSet_ -> IO a) -> IO a
withObjectSet StrList
os ((ObjectSet_ -> IO FontSet) -> IO FontSet)
-> (ObjectSet_ -> IO FontSet) -> IO FontSet
forall a b. (a -> b) -> a -> b
$ \os' :: ObjectSet_
os' -> do
    FontSet_
ret <- Ptr Config' -> Pattern_ -> ObjectSet_ -> IO FontSet_
fcFontList Ptr Config'
forall a. Ptr a
nullPtr Pattern_
p' ObjectSet_
os'
    IO FontSet_ -> IO FontSet
thawFontSet_ (IO FontSet_ -> IO FontSet) -> IO FontSet_ -> IO FontSet
forall a b. (a -> b) -> a -> b
$ FontSet_ -> IO FontSet_
forall (f :: * -> *) a. Applicative f => a -> f a
pure FontSet_
ret
foreign import ccall "FcFontList" fcFontList ::
    Config_ -> Pattern_ -> ObjectSet_ -> IO FontSet_

{-configGetFilename :: Config -> String -> String
configGetFilename config name = unsafePerformIO $ withForeignPtr config $ \config' ->
    withCString name $ \name' -> do
        ret <- fcConfigGetFilename config' name'
        peekCString' ret
configGetFilename' :: String -> String
configGetFilename' name = unsafePerformIO $ withCString name $ \name' -> do
    ret <- fcConfigGetFilename nullPtr name'
    peekCString' ret
foreign import ccall "FcConfigGetFilename" fcConfigGetFilename :: Config_ -> CString -> IO CString
peekCString' txt = bracket (pure $ throwNull txt) free peekCString-}

-- | Walks the configuration in 'file' and constructs the internal representation
-- in 'config'. Any include files referenced from within 'file' will be loaded
-- and parsed. If 'complain' is `False`, no warning will be displayed if 'file'
-- does not exist. Error and warning messages will be output to stderr. 
configParseAndLoad :: Config -> String -> Bool -> IO Bool
configParseAndLoad :: Config -> String -> Bool -> IO Bool
configParseAndLoad config :: Config
config name :: String
name complain :: Bool
complain = Config -> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Bool) -> IO Bool)
-> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' ->
    String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withCString String
name ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \name' :: CString
name' -> Ptr Config' -> CString -> Bool -> IO Bool
fcConfigParseAndLoad Ptr Config'
config' CString
name' Bool
complain
-- Variant of `configParseAndLoad` which operates upon current configuration.
configParseAndLoad' :: String -> Bool -> IO Bool
configParseAndLoad' :: String -> Bool -> IO Bool
configParseAndLoad' name :: String
name complain :: Bool
complain =
    String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withCString String
name ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \name' :: CString
name' -> Ptr Config' -> CString -> Bool -> IO Bool
fcConfigParseAndLoad Ptr Config'
forall a. Ptr a
nullPtr CString
name' Bool
complain
foreign import ccall "FcConfigParseAndLoad" fcConfigParseAndLoad ::
    Config_ -> CString -> Bool -> IO Bool

-- | Walks the configuration in 'memory' and constructs the internal representation
-- in 'config'. Any includes files referenced from within 'memory' will be loaded
-- and dparsed. If 'complain' is `False`, no warning will be displayed if 'file'
-- does not exist. Error and warning messages will be output to stderr.
configParseAndLoadFromMemory :: Config -> String -> Bool -> IO Bool
configParseAndLoadFromMemory :: Config -> String -> Bool -> IO Bool
configParseAndLoadFromMemory config :: Config
config buffer :: String
buffer complain :: Bool
complain = Config -> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO Bool) -> IO Bool)
-> (Ptr Config' -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' ->
    String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withCString String
buffer ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \buffer' :: CString
buffer' ->
        Ptr Config' -> CString -> Bool -> IO Bool
fcConfigParseAndLoadFromMemory Ptr Config'
config' CString
buffer' Bool
complain
-- | Variant of `configParseAndLoadFromMemory` which operates upon current
-- configuration.
configParseAndLoadFromMemory' :: String -> Bool -> IO Bool
configParseAndLoadFromMemory' :: String -> Bool -> IO Bool
configParseAndLoadFromMemory' buffer :: String
buffer complain :: Bool
complain = String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withCString String
buffer ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \buffer' :: CString
buffer' ->
    Ptr Config' -> CString -> Bool -> IO Bool
fcConfigParseAndLoadFromMemory Ptr Config'
forall a. Ptr a
nullPtr CString
buffer' Bool
complain
foreign import ccall "FcConfigParseAndLoadFromMemory" fcConfigParseAndLoadFromMemory ::
    Config_ -> CString -> Bool -> IO Bool

-- | Obtains the system root directory in 'config' if available.
-- All files (including file properties in patterns) obtained from this 'config'
-- are relative to this system root directory.
-- This function isn't MT-safe. 
configGetSysRoot :: Config -> IO String
configGetSysRoot :: Config -> IO String
configGetSysRoot = (Config -> (Ptr Config' -> IO String) -> IO String)
-> (Ptr Config' -> IO String) -> Config -> IO String
forall a b c. (a -> b -> c) -> b -> a -> c
flip Config -> (Ptr Config' -> IO String) -> IO String
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ((Ptr Config' -> IO String) -> Config -> IO String)
-> (Ptr Config' -> IO String) -> Config -> IO String
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' -> do
    CString
ret <- Ptr Config' -> IO CString
fcConfigGetSysRoot Ptr Config'
config'
    CString -> IO String
peekCString (CString -> IO String) -> CString -> IO String
forall a b. (a -> b) -> a -> b
$ CString -> CString
forall a. Ptr a -> Ptr a
throwNull CString
ret
-- | Variant of `configGetSysRoot` which operates upon current configuration.
configGetSysRoot' :: IO String
configGetSysRoot' :: IO String
configGetSysRoot' = (CString -> IO String
peekCString (CString -> IO String)
-> (CString -> CString) -> CString -> IO String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.CString -> CString
forall a. Ptr a -> Ptr a
throwNull) (CString -> IO String) -> IO CString -> IO String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Config' -> IO CString
fcConfigGetSysRoot Ptr Config'
forall a. Ptr a
nullPtr
foreign import ccall "FcConfigGetSysRoot" fcConfigGetSysRoot :: Config_ -> IO CString

-- | Set 'sysroot' as the system root directory. All file paths used or created
-- with this 'config' (including file properties in patterns) will be considered
-- or made relative to this 'sysroot'. This allows a host to generate caches for
-- targets at build time. This also allows a cache to be re-targeted to a
-- different base directory if 'configGetSysRoot' is used to resolve file paths.
-- When setting this on the current config this causes changing current config.
configSetSysRoot :: Config -> String -> IO ()
configSetSysRoot :: Config -> String -> IO ()
configSetSysRoot config :: Config
config val :: String
val = Config -> (Ptr Config' -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO ()) -> IO ())
-> (Ptr Config' -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' -> String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withCString String
val ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$
    Ptr Config' -> CString -> IO ()
fcConfigSetSysRoot Ptr Config'
config'
-- | Variant of `configSetSysRoot` which operates upon current configuration.
configSetSysRoot' :: String -> IO ()
configSetSysRoot' :: String -> IO ()
configSetSysRoot' val :: String
val = String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withCString String
val ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ Ptr Config' -> CString -> IO ()
fcConfigSetSysRoot Ptr Config'
forall a. Ptr a
nullPtr
foreign import ccall "FcConfigSetSysRoot" fcConfigSetSysRoot :: Config_ -> CString -> IO ()

-- | Retrieves a list of all filepaths & descriptions for all fonts in this
-- configuration alongside whether each is enabled.
-- Not thread-safe.
configGetFileInfo :: Config -> IO [(FilePath, String, Bool)]
configGetFileInfo :: Config -> IO [(String, String, Bool)]
configGetFileInfo config :: Config
config =
  Config
-> (Ptr Config' -> IO [(String, String, Bool)])
-> IO [(String, String, Bool)]
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config ((Ptr Config' -> IO [(String, String, Bool)])
 -> IO [(String, String, Bool)])
-> (Ptr Config' -> IO [(String, String, Bool)])
-> IO [(String, String, Bool)]
forall a b. (a -> b) -> a -> b
$ \config' :: Ptr Config'
config' -> Int
-> (Ptr ConfigFileInfoIter' -> IO [(String, String, Bool)])
-> IO [(String, String, Bool)]
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes Int
configFileInfoIter'Size ((Ptr ConfigFileInfoIter' -> IO [(String, String, Bool)])
 -> IO [(String, String, Bool)])
-> (Ptr ConfigFileInfoIter' -> IO [(String, String, Bool)])
-> IO [(String, String, Bool)]
forall a b. (a -> b) -> a -> b
$ \iter' :: Ptr ConfigFileInfoIter'
iter' -> do
    Ptr Config' -> Ptr ConfigFileInfoIter' -> IO ()
fcConfigFileInfoIterInit Ptr Config'
config' Ptr ConfigFileInfoIter'
iter'
    let readEnt :: IO (Maybe (String, String, Bool))
readEnt = (Ptr CString -> IO (Maybe (String, String, Bool)))
-> IO (Maybe (String, String, Bool))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CString -> IO (Maybe (String, String, Bool)))
 -> IO (Maybe (String, String, Bool)))
-> (Ptr CString -> IO (Maybe (String, String, Bool)))
-> IO (Maybe (String, String, Bool))
forall a b. (a -> b) -> a -> b
$ \name' :: Ptr CString
name' -> (Ptr CString -> IO (Maybe (String, String, Bool)))
-> IO (Maybe (String, String, Bool))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CString -> IO (Maybe (String, String, Bool)))
 -> IO (Maybe (String, String, Bool)))
-> (Ptr CString -> IO (Maybe (String, String, Bool)))
-> IO (Maybe (String, String, Bool))
forall a b. (a -> b) -> a -> b
$ \description' :: Ptr CString
description' -> (Ptr Bool -> IO (Maybe (String, String, Bool)))
-> IO (Maybe (String, String, Bool))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Bool -> IO (Maybe (String, String, Bool)))
 -> IO (Maybe (String, String, Bool)))
-> (Ptr Bool -> IO (Maybe (String, String, Bool)))
-> IO (Maybe (String, String, Bool))
forall a b. (a -> b) -> a -> b
$ \enabled' :: Ptr Bool
enabled' -> do {
        Bool
ok <- Ptr Config'
-> Ptr ConfigFileInfoIter'
-> Ptr CString
-> Ptr CString
-> Ptr Bool
-> IO Bool
fcConfigFileInfoIterGet Ptr Config'
config' Ptr ConfigFileInfoIter'
iter' Ptr CString
name' Ptr CString
description' Ptr Bool
enabled';
        if Bool
ok then do
            String
name <- CString -> IO String
peekCString (CString -> IO String) -> IO CString -> IO String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek Ptr CString
name'
            String
description <- CString -> IO String
peekCString (CString -> IO String) -> IO CString -> IO String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek Ptr CString
description'
            Bool
enabled <- Ptr Bool -> IO Bool
forall a. Storable a => Ptr a -> IO a
peek Ptr Bool
enabled'
            Maybe (String, String, Bool) -> IO (Maybe (String, String, Bool))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (String, String, Bool) -> IO (Maybe (String, String, Bool)))
-> Maybe (String, String, Bool)
-> IO (Maybe (String, String, Bool))
forall a b. (a -> b) -> a -> b
$ (String, String, Bool) -> Maybe (String, String, Bool)
forall a. a -> Maybe a
Just (String
name, String
description, Bool
enabled)
        else Maybe (String, String, Bool) -> IO (Maybe (String, String, Bool))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (String, String, Bool)
forall a. Maybe a
Nothing}
    let go :: IO [(String, String, Bool)]
go = do {
        Maybe (String, String, Bool)
ent' <- IO (Maybe (String, String, Bool))
readEnt;
        case Maybe (String, String, Bool)
ent' of
            Just ent :: (String, String, Bool)
ent -> do
                Bool
ok <- Ptr Config' -> Ptr ConfigFileInfoIter' -> IO Bool
fcConfigFileInfoIterNext Ptr Config'
config' Ptr ConfigFileInfoIter'
iter'
                [(String, String, Bool)]
ents <- if Bool
ok then IO [(String, String, Bool)]
go else [(String, String, Bool)] -> IO [(String, String, Bool)]
forall (m :: * -> *) a. Monad m => a -> m a
return []
                [(String, String, Bool)] -> IO [(String, String, Bool)]
forall (m :: * -> *) a. Monad m => a -> m a
return ((String, String, Bool)
ent (String, String, Bool)
-> [(String, String, Bool)] -> [(String, String, Bool)]
forall a. a -> [a] -> [a]
: [(String, String, Bool)]
ents)
            Nothing -> [(String, String, Bool)] -> IO [(String, String, Bool)]
forall (m :: * -> *) a. Monad m => a -> m a
return []}
    IO [(String, String, Bool)]
go
-- | Variant `configGetFileInfo` which operates upon current configuration.
configGetFileInfo' :: IO [(FilePath, String, Bool)]
configGetFileInfo' :: IO [(String, String, Bool)]
configGetFileInfo' = IO Config
configGetCurrent IO Config
-> (Config -> IO [(String, String, Bool)])
-> IO [(String, String, Bool)]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Config -> IO [(String, String, Bool)]
configGetFileInfo
data ConfigFileInfoIter'
foreign import ccall "size_ConfigFileInfoIter" configFileInfoIter'Size :: Int
type ConfigFileInfoIter_ = Ptr ConfigFileInfoIter'
foreign import ccall "FcConfigFileInfoIterInit" fcConfigFileInfoIterInit ::
    Config_ -> ConfigFileInfoIter_ -> IO ()
foreign import ccall "FcConfigFileInfoIterNext" fcConfigFileInfoIterNext ::
    Config_ -> ConfigFileInfoIter_ -> IO Bool
foreign import ccall "FcConfigFileInfoIterGet" fcConfigFileInfoIterGet ::
    Config_ -> ConfigFileInfoIter_ -> Ptr CString -> Ptr CString -> Ptr Bool -> IO Bool

------

configStrsFunc :: (Config_ -> IO StrList_) -> Config -> IO StrList
configStrsFunc :: (Ptr Config' -> IO StrList_) -> Config -> IO StrList
configStrsFunc cb :: Ptr Config' -> IO StrList_
cb config :: Config
config = IO StrList_ -> IO StrList
thawStrList_ (IO StrList_ -> IO StrList) -> IO StrList_ -> IO StrList
forall a b. (a -> b) -> a -> b
$ Config -> (Ptr Config' -> IO StrList_) -> IO StrList_
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config Ptr Config' -> IO StrList_
cb