From 9e1e5029f66325c1391a658c39c4573e74aafe03 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 25 Nov 2022 11:42:30 +1300 Subject: [PATCH] Commit FontSet API (seperated out to break import loop). --- Graphics/Text/Font/Choose/FontSet/API.hs | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Graphics/Text/Font/Choose/FontSet/API.hs diff --git a/Graphics/Text/Font/Choose/FontSet/API.hs b/Graphics/Text/Font/Choose/FontSet/API.hs new file mode 100644 index 0000000..0eaa611 --- /dev/null +++ b/Graphics/Text/Font/Choose/FontSet/API.hs @@ -0,0 +1,55 @@ +-- Here to break recursive imports... +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 (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 fontss pattern objs = unsafePerformIO $ withForeignPtr config $ \config' -> + withFontSets fontss $ \fontss' n -> withPattern pattern $ \pattern' -> + withObjectSet objs $ \objs' -> + thawFontSet_ $ fcFontSetList config' fontss' n pattern' objs' +fontSetList' :: [FontSet] -> Pattern -> ObjectSet -> FontSet +fontSetList' fontss pattern objs = unsafePerformIO $ withFontSets fontss $ \fontss' n -> + withPattern pattern $ \pattern' -> withObjectSet objs $ \objs' -> + thawFontSet_ $ fcFontSetList nullPtr fontss' n pattern' objs' +foreign import ccall "FcFontSetList" fcFontSetList :: + Config_ -> Ptr FontSet_ -> Int -> Pattern_ -> ObjectSet_ -> IO FontSet_ + +fontSetMatch :: Config -> [FontSet] -> Pattern -> Maybe Pattern +fontSetMatch config fontss pattern = unsafePerformIO $ withForeignPtr config $ \config' -> + withFontSets fontss $ \fontss' n -> withPattern pattern $ \pattern' -> + alloca $ \res' -> do + ret <- fcFontSetMatch config' fontss' n pattern' res' + throwPtr res' $ thawPattern_ $ pure ret +fontSetMatch' :: [FontSet] -> Pattern -> Maybe Pattern +fontSetMatch' fontss pattern = unsafePerformIO $ withFontSets fontss $ \fontss' n -> + withPattern pattern $ \pattern' -> alloca $ \res' -> do + ret <- fcFontSetMatch nullPtr fontss' n pattern' res' + throwPtr res' $ thawPattern_ $ pure ret +foreign import ccall "FcFontSetMatch" fcFontSetMatch :: + Config_ -> Ptr FontSet_ -> Int -> Pattern_ -> Ptr Int -> IO Pattern_ + +fontSetSort :: Config -> [FontSet] -> Pattern -> Bool -> CharSet -> Maybe FontSet +fontSetSort config fontss pattern trim csp = unsafePerformIO $ + withForeignPtr config $ \config' -> withFontSets fontss $ \fontss' n -> + withPattern pattern $ \pattern' -> withCharSet csp $ \csp' -> alloca $ \res' -> do + ret' <- fcFontSetSort config' fontss' n pattern' trim csp' res' + throwPtr res' $ thawFontSet_ $ pure ret' +fontSetSort' :: [FontSet] -> Pattern -> Bool -> CharSet -> Maybe FontSet +fontSetSort' fontss pattern trim csp = unsafePerformIO $ + withFontSets fontss $ \fontss' n -> withPattern pattern $ \pattern' -> + withCharSet csp $ \csp' -> alloca $ \res' -> do + ret' <- fcFontSetSort nullPtr fontss' n pattern' trim csp' res' + throwPtr res' $ thawFontSet_ $ pure ret' +foreign import ccall "FcFontSetSort" fcFontSetSort :: Config_ -> Ptr FontSet_ + -> Int -> Pattern_ -> Bool -> CharSet_ -> Ptr Int -> IO FontSet_ -- 2.30.2