~alcinnz/fontconfig-pure

ref: 47cc098450b726d49471eab75b08df89c5c75b6c fontconfig-pure/lib/Graphics/Text/Font/Choose/Config.hs -rw-r--r-- 3.0 KiB
47cc0984 — Adrian Cochrane Commit missing support module. 4 months ago
                                                                                
bea597e7 Adrian Cochrane
dbefdc06 Adrian Cochrane
94860b2e Adrian Cochrane
1abac8a1 Adrian Cochrane
94860b2e Adrian Cochrane
bea597e7 Adrian Cochrane
94860b2e Adrian Cochrane
bea597e7 Adrian Cochrane
94860b2e Adrian Cochrane
bea597e7 Adrian Cochrane
94860b2e Adrian Cochrane
bea597e7 Adrian Cochrane
94860b2e Adrian Cochrane
bea597e7 Adrian Cochrane
94860b2e Adrian Cochrane
1abac8a1 Adrian Cochrane
bea597e7 Adrian Cochrane
94860b2e Adrian Cochrane
bea597e7 Adrian Cochrane
94860b2e Adrian Cochrane
bea597e7 Adrian Cochrane
94860b2e Adrian Cochrane
bea597e7 Adrian Cochrane
94860b2e 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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{-# LANGUAGE CApiFFI #-}
-- | Load system fonts configuration.
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)

-- | Internal placeholder underlying `Config`.
data Config'
-- | holds the internal representation of a configuration.
type Config = ForeignPtr Config'


-- | Loads the default configuration file and returns the resulting configuration. Does not load any font information.
initLoadConfig :: IO Config
initLoadConfig = newForeignPtr fcConfigDestroy =<< throwNull =<< fcInitLoadConfig -- FIXME: What's proper memory-management here?

-- | Loads the default configuration file and builds information about the available fonts. Returns the resulting configuration.
initLoadConfigAndFonts :: IO Config
initLoadConfigAndFonts = newForeignPtr fcConfigDestroy =<< throwNull =<< fcInitLoadConfigAndFonts -- FIXME: What's proper memory-management here?

-- | Loads the default configuration file and the fonts referenced therein and sets the default configuration to that result.
-- Returns whether this process succeeded or not. If the default configuration has already been loaded, this routine does nothing and returns True.
initFonts :: IO ()
initFonts = throwBool =<< fcInit
foreign import capi "fontconfig/fontconfig.h FcFini" fini :: IO ()

-- | Returns the version number of the library.
foreign import capi "fontconfig/fontconfig.h FcGetVersion" version :: Int

-- | Forces the default configuration file to be reloaded and resets the default configuration.
-- Returns False if the configuration cannot be reloaded (due to configuration file errors,
-- allocation failures or other issues) and leaves the existing configuration unchanged. Otherwise returns True.
reinit :: IO ()
reinit = throwBool =<< fcInitReinitialize

-- | Checks the rescan interval in the default configuration, checking the configuration
-- if the interval has passed and reloading the configuration if when any changes are detected.
-- Returns False if the configuration cannot be reloaded (see `reinit`). Otherwise returns True.
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
-- | Internal ForeignPtr destructor for `Config`.
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