From 92f6f9bf377a92e9ba582750de1daab38f503d78 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Tue, 22 Nov 2022 13:51:56 +1300 Subject: [PATCH] Expose more weight APIs & the FcAtomic APIs. --- Graphics/Text/Font/Choose/File/Atomic.hs | 45 ++++++++++++++++++++++++ Graphics/Text/Font/Choose/Weight.hs | 3 +- fontconfig-pure.cabal | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Graphics/Text/Font/Choose/File/Atomic.hs diff --git a/Graphics/Text/Font/Choose/File/Atomic.hs b/Graphics/Text/Font/Choose/File/Atomic.hs new file mode 100644 index 0000000..cb2d55a --- /dev/null +++ b/Graphics/Text/Font/Choose/File/Atomic.hs @@ -0,0 +1,45 @@ +module Graphics.Text.Font.Choose.File.Atomic where + +import Foreign.ForeignPtr +import Foreign.Ptr (Ptr, FunPtr) +import Foreign.C.String (CString, peekCString, withCString) +import Control.Exception (bracket) + +data Atomic' +type Atomic = ForeignPtr Atomic' +type Atomic_ = Ptr Atomic' + +create :: String -> IO Atomic +create filename = withCString filename fcAtomicCreate >>= newForeignPtr fcAtomicDestroy +foreign import ccall "FcAtomicCreate" fcAtomicCreate :: CString -> IO Atomic_ +foreign import ccall "&FcAtomicDestroy" fcAtomicDestroy :: FunPtr (Atomic_ -> IO ()) + +lock :: Atomic -> IO Bool +lock = flip withForeignPtr fcAtomicLock +foreign import ccall "FcAtomicLock" fcAtomicLock :: Atomic_ -> IO Bool + +newFile :: Atomic -> IO String +newFile atomic = withForeignPtr atomic fcAtomicNewFile >>= peekCString +foreign import ccall "FcAtomicNewFile" fcAtomicNewFile :: Atomic_ -> IO CString + +origFile :: Atomic -> IO String +origFile atomic = withForeignPtr atomic fcAtomicOrigFile >>= peekCString +foreign import ccall "FcAtomicOrigFile" fcAtomicOrigFile :: Atomic_ -> IO CString + +replaceOrig :: Atomic -> IO Bool +replaceOrig = flip withForeignPtr fcAtomicReplaceOrig +foreign import ccall "FcAtomicReplaceOrig" fcAtomicReplaceOrig :: Atomic_ -> IO Bool + +deleteNew :: Atomic -> IO () +deleteNew = flip withForeignPtr fcAtomicDeleteNew +foreign import ccall "FcAtomicDeleteNew" fcAtomicDeleteNew :: Atomic_ -> IO () + +unlock :: Atomic -> IO () +unlock = flip withForeignPtr fcAtomicUnlock +foreign import ccall "FcAtomicUnlock" fcAtomicUnlock :: Atomic_ -> IO () + +withLock :: Atomic -> IO () -> IO () +withLock atomic cb = bracket (lock atomic) (const $ unlock atomic) inner + where + inner True = cb + inner False = return () diff --git a/Graphics/Text/Font/Choose/Weight.hs b/Graphics/Text/Font/Choose/Weight.hs index 411d248..04dec54 100644 --- a/Graphics/Text/Font/Choose/Weight.hs +++ b/Graphics/Text/Font/Choose/Weight.hs @@ -4,4 +4,5 @@ foreign import ccall "FcWeightFromOpenTypeDouble" weightFromOpenTypeDouble :: Double -> Double foreign import ccall "FcWeightToOpenTypeDouble" weightToOpenTypeDouble :: Double -> Double - +foreign import ccall "FcWeightFromOpenType" weightFromOpenType :: Int -> Int +foreign import ccall "FcWeightToOpenType" weightToOpenType :: Int -> Int diff --git a/fontconfig-pure.cabal b/fontconfig-pure.cabal index ab21c07..fe5f51f 100644 --- a/fontconfig-pure.cabal +++ b/fontconfig-pure.cabal @@ -56,7 +56,7 @@ library Graphics.Text.Font.Choose.Strings, Graphics.Text.Font.Choose.Range, Graphics.Text.Font.Choose.LangSet, Graphics.Text.Font.Choose.Value, Graphics.Text.Font.Choose.Pattern, Graphics.Text.Font.Choose.FontSet, - Graphics.Text.Font.Choose.Config + Graphics.Text.Font.Choose.Config, Graphics.Text.Font.Choose.File.Atomic c-sources: cbits/pattern.c -- 2.30.2