module Graphics.Text.Font.Choose.FontSet.API where
import Graphics.Text.Font.Choose.FontSet
import Graphics.Text.Font.Choose.Pattern
import Graphics.Text.Font.Choose.Config
import Graphics.Text.Font.Choose.ObjectSet
import Graphics.Text.Font.Choose.CharSet
import Graphics.Text.Font.Choose.Result (Word8, throwPtr)
import Foreign.Ptr (Ptr, castPtr, nullPtr)
import Foreign.ForeignPtr (withForeignPtr)
import Foreign.Marshal.Alloc (alloca)
import System.IO.Unsafe (unsafePerformIO)
fontSetList :: Config -> [FontSet] -> Pattern -> ObjectSet -> FontSet
fontSetList :: Config -> [FontSet] -> Pattern -> ObjectSet -> FontSet
fontSetList Config
config [FontSet]
fontss Pattern
pattern ObjectSet
objs = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config forall a b. (a -> b) -> a -> b
$ \Ptr Config'
config' ->
forall a. [FontSet] -> (Ptr FontSet_ -> Int -> IO a) -> IO a
withFontSets [FontSet]
fontss forall a b. (a -> b) -> a -> b
$ \Ptr FontSet_
fontss' Int
n -> forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pattern forall a b. (a -> b) -> a -> b
$ \Pattern_
pattern' ->
forall a. ObjectSet -> (ObjectSet_ -> IO a) -> IO a
withObjectSet ObjectSet
objs forall a b. (a -> b) -> a -> b
$ \ObjectSet_
objs' ->
IO FontSet_ -> IO FontSet
thawFontSet_ forall a b. (a -> b) -> a -> b
$ Ptr Config'
-> Ptr FontSet_ -> Int -> Pattern_ -> ObjectSet_ -> IO FontSet_
fcFontSetList Ptr Config'
config' Ptr FontSet_
fontss' Int
n Pattern_
pattern' ObjectSet_
objs'
fontSetList' :: [FontSet] -> Pattern -> ObjectSet -> FontSet
fontSetList' :: [FontSet] -> Pattern -> ObjectSet -> FontSet
fontSetList' [FontSet]
fontss Pattern
pattern ObjectSet
objs = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ forall a. [FontSet] -> (Ptr FontSet_ -> Int -> IO a) -> IO a
withFontSets [FontSet]
fontss forall a b. (a -> b) -> a -> b
$ \Ptr FontSet_
fontss' Int
n ->
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pattern forall a b. (a -> b) -> a -> b
$ \Pattern_
pattern' -> forall a. ObjectSet -> (ObjectSet_ -> IO a) -> IO a
withObjectSet ObjectSet
objs forall a b. (a -> b) -> a -> b
$ \ObjectSet_
objs' ->
IO FontSet_ -> IO FontSet
thawFontSet_ forall a b. (a -> b) -> a -> b
$ Ptr Config'
-> Ptr FontSet_ -> Int -> Pattern_ -> ObjectSet_ -> IO FontSet_
fcFontSetList forall a. Ptr a
nullPtr Ptr FontSet_
fontss' Int
n Pattern_
pattern' ObjectSet_
objs'
foreign import ccall "FcFontSetList" fcFontSetList ::
Config_ -> Ptr FontSet_ -> Int -> Pattern_ -> ObjectSet_ -> IO FontSet_
fontSetMatch :: Config -> [FontSet] -> Pattern -> Maybe Pattern
fontSetMatch :: Config -> [FontSet] -> Pattern -> Maybe Pattern
fontSetMatch Config
config [FontSet]
fontss Pattern
pattern = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config forall a b. (a -> b) -> a -> b
$ \Ptr Config'
config' ->
forall a. [FontSet] -> (Ptr FontSet_ -> Int -> IO a) -> IO a
withFontSets [FontSet]
fontss forall a b. (a -> b) -> a -> b
$ \Ptr FontSet_
fontss' Int
n -> forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pattern forall a b. (a -> b) -> a -> b
$ \Pattern_
pattern' ->
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
res' -> do
Pattern_
ret <- Ptr Config'
-> Ptr FontSet_ -> Int -> Pattern_ -> Ptr Word8 -> IO Pattern_
fcFontSetMatch Ptr Config'
config' Ptr FontSet_
fontss' Int
n Pattern_
pattern' Ptr Word8
res'
forall a. Ptr Word8 -> IO a -> IO (Maybe a)
throwPtr Ptr Word8
res' forall a b. (a -> b) -> a -> b
$ IO Pattern_ -> IO Pattern
thawPattern_ forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure Pattern_
ret
fontSetMatch' :: [FontSet] -> Pattern -> Maybe Pattern
fontSetMatch' :: [FontSet] -> Pattern -> Maybe Pattern
fontSetMatch' [FontSet]
fontss Pattern
pattern = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ forall a. [FontSet] -> (Ptr FontSet_ -> Int -> IO a) -> IO a
withFontSets [FontSet]
fontss forall a b. (a -> b) -> a -> b
$ \Ptr FontSet_
fontss' Int
n ->
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pattern forall a b. (a -> b) -> a -> b
$ \Pattern_
pattern' -> forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
res' -> do
Pattern_
ret <- Ptr Config'
-> Ptr FontSet_ -> Int -> Pattern_ -> Ptr Word8 -> IO Pattern_
fcFontSetMatch forall a. Ptr a
nullPtr Ptr FontSet_
fontss' Int
n Pattern_
pattern' Ptr Word8
res'
forall a. Ptr Word8 -> IO a -> IO (Maybe a)
throwPtr Ptr Word8
res' forall a b. (a -> b) -> a -> b
$ IO Pattern_ -> IO Pattern
thawPattern_ forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure Pattern_
ret
foreign import ccall "FcFontSetMatch" fcFontSetMatch ::
Config_ -> Ptr FontSet_ -> Int -> Pattern_ -> Ptr Word8 -> IO Pattern_
fontSetSort :: Config -> [FontSet] -> Pattern -> Bool -> Maybe (FontSet, CharSet)
fontSetSort :: Config -> [FontSet] -> Pattern -> Bool -> Maybe (FontSet, CharSet)
fontSetSort Config
config [FontSet]
fontss Pattern
pattern Bool
trim = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Config
config forall a b. (a -> b) -> a -> b
$ \Ptr Config'
config' -> forall a. [FontSet] -> (Ptr FontSet_ -> Int -> IO a) -> IO a
withFontSets [FontSet]
fontss forall a b. (a -> b) -> a -> b
$ \Ptr FontSet_
fontss' Int
n ->
forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pattern forall a b. (a -> b) -> a -> b
$ \Pattern_
pattern' -> forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CharSet_
csp' -> forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
res' -> do
FontSet_
ret' <- Ptr Config'
-> Ptr FontSet_
-> Int
-> Pattern_
-> Bool
-> Ptr CharSet_
-> Ptr Word8
-> IO FontSet_
fcFontSetSort Ptr Config'
config' Ptr FontSet_
fontss' Int
n Pattern_
pattern' Bool
trim Ptr CharSet_
csp' Ptr Word8
res'
forall a. Ptr Word8 -> IO a -> IO (Maybe a)
throwPtr Ptr Word8
res' forall a b. (a -> b) -> a -> b
$ do
FontSet
x <- IO FontSet_ -> IO FontSet
thawFontSet_ forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure FontSet_
ret'
CharSet
y <- Ptr CharSet_ -> IO CharSet
thawCharSet' Ptr CharSet_
csp'
forall (m :: * -> *) a. Monad m => a -> m a
return (FontSet
x, CharSet
y)
fontSetSort' :: [FontSet] -> Pattern -> Bool -> Maybe (FontSet, CharSet)
fontSetSort' :: [FontSet] -> Pattern -> Bool -> Maybe (FontSet, CharSet)
fontSetSort' [FontSet]
fontss Pattern
pattern Bool
trim = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$
forall a. [FontSet] -> (Ptr FontSet_ -> Int -> IO a) -> IO a
withFontSets [FontSet]
fontss forall a b. (a -> b) -> a -> b
$ \Ptr FontSet_
fontss' Int
n -> forall a. Pattern -> (Pattern_ -> IO a) -> IO a
withPattern Pattern
pattern forall a b. (a -> b) -> a -> b
$ \Pattern_
pattern' ->
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CharSet_
csp' -> forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
res' -> do
FontSet_
ret' <- Ptr Config'
-> Ptr FontSet_
-> Int
-> Pattern_
-> Bool
-> Ptr CharSet_
-> Ptr Word8
-> IO FontSet_
fcFontSetSort forall a. Ptr a
nullPtr Ptr FontSet_
fontss' Int
n Pattern_
pattern' Bool
trim Ptr CharSet_
csp' Ptr Word8
res'
forall a. Ptr Word8 -> IO a -> IO (Maybe a)
throwPtr Ptr Word8
res' forall a b. (a -> b) -> a -> b
$ do
FontSet
x <- IO FontSet_ -> IO FontSet
thawFontSet_ forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure FontSet_
ret'
CharSet
y <- Ptr CharSet_ -> IO CharSet
thawCharSet' Ptr CharSet_
csp'
forall (m :: * -> *) a. Monad m => a -> m a
return (FontSet
x, CharSet
y)
foreign import ccall "FcFontSetSort" fcFontSetSort :: Config_ -> Ptr FontSet_
-> Int -> Pattern_ -> Bool -> Ptr CharSet_ -> Ptr Word8 -> IO FontSet_