From 384d73c610a33f1b09a4dbb16b7e855f05eb631f Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 18 Nov 2022 12:35:17 +1300 Subject: [PATCH] Draft implicit-config versions of fontset APIs. --- Graphics/Text/Font/Choose/FontSet.hs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Graphics/Text/Font/Choose/FontSet.hs b/Graphics/Text/Font/Choose/FontSet.hs index 542858e..8a25825 100644 --- a/Graphics/Text/Font/Choose/FontSet.hs +++ b/Graphics/Text/Font/Choose/FontSet.hs @@ -28,21 +28,32 @@ foreign import ccall "FcFontSetList" fcFontSetList :: Config_ -> Ptr FontSet_ -> Int -> Pattern_ -> ObjectSet_ -> IO FontSet_ fontSetMatch :: Config -> [FontSet] -> Pattern -> Maybe Pattern -fontSetMatch config fontss pattern = withConfig config $ \config' -> +fontSetMatch config fontss pattern = unsafePerformIO $ withConfig config $ \config' -> withFontSets fontss $ \fontss' -> withPattern $ \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' -> + withPattern $ \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_ -> IO Pattern_ fontSetSort :: Config -> [FontSet] -> Pattern -> Bool -> CharSet -> Maybe FontSet -fontSetSort config fontss pattern trim csp cb = withConfig config $ \config' -> - withFontSets fontss $ \fontss' withPattern $ \pattern' -> - withCharSet csp $ \csp' -> alloca $ \res' -> do - ret' <- fcFontSetSort config' 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_ -} +fontSetSort config fontss pattern trim csp = unsafePerformIO $ + withConfig config $ \config' -> withFontSets fontss $ \fontss' n -> + withPattern $ \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 $ withConfig $ \config' -> + withFontSets fontss $ \fontss' n -> withPattern $ \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_ -} ------ --- Low-level -- 2.30.2