From 18b29da8fa2cc23650f2fd33c0917bcc2289a7b6 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Mon, 22 Apr 2024 17:17:19 +1200 Subject: [PATCH] Expose font weight adjustments & correct current-config refcount. --- fontconfig-pure.cabal | 2 +- lib/Graphics/Text/Font/Choose/Config/Accessors.hs | 6 +++--- lib/Graphics/Text/Font/Choose/Weight.hs | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 lib/Graphics/Text/Font/Choose/Weight.hs diff --git a/fontconfig-pure.cabal b/fontconfig-pure.cabal index 1d5223c..987813c 100644 --- a/fontconfig-pure.cabal +++ b/fontconfig-pure.cabal @@ -69,7 +69,7 @@ library Graphics.Text.Font.Choose.Pattern, Graphics.Text.Font.Choose.FontSet, Graphics.Text.Font.Choose.Config, Graphics.Text.Font.Choose.Result, Graphics.Text.Font.Choose.Internal.FFI, FreeType.FontConfig, - Graphics.Text.Font.Choose.Config.Accessors + Graphics.Text.Font.Choose.Config.Accessors, Graphics.Text.Font.Choose.Weight c-sources: cbits/cmp.c, cbits/transcode.c, cbits/fontconfig-wrap.c include-dirs: cbits diff --git a/lib/Graphics/Text/Font/Choose/Config/Accessors.hs b/lib/Graphics/Text/Font/Choose/Config/Accessors.hs index 653610c..aa84f75 100644 --- a/lib/Graphics/Text/Font/Choose/Config/Accessors.hs +++ b/lib/Graphics/Text/Font/Choose/Config/Accessors.hs @@ -7,7 +7,7 @@ import Graphics.Text.Font.Choose.Pattern import Graphics.Text.Font.Choose.CharSet import Graphics.Text.Font.Choose.ObjectSet -import Foreign.Ptr (Ptr) +import Foreign.Ptr (Ptr, nullPtr) import Foreign.ForeignPtr (newForeignPtr, withForeignPtr) import Foreign.C.String (CString, withCString, peekCString) --import Foreign.C.ConstPtr (ConstPtr) @@ -26,8 +26,8 @@ setCurrent conf = throwBool =<< withForeignPtr conf fcConfigSetCurrent foreign import capi "fontconfig/fontconfig.h FcConfigSetCurrent" fcConfigSetCurrent :: Ptr Config' -> IO Bool current :: IO Config -current = newForeignPtr fcConfigDestroy =<< throwNull =<< fcConfigGetCurrent -foreign import capi "fontconfig/fontconfig.h FcConfigGetCurrent" fcConfigGetCurrent :: IO (Ptr Config') +current = newForeignPtr fcConfigDestroy =<< throwNull =<< fcConfigReference nullPtr +foreign import capi "fontconfig/fontconfig.h FcConfigReference" fcConfigReference :: Ptr Config' -> IO (Ptr Config') uptodate :: Config -> IO Bool uptodate conf = withForeignPtr conf fcConfigUptoDate diff --git a/lib/Graphics/Text/Font/Choose/Weight.hs b/lib/Graphics/Text/Font/Choose/Weight.hs new file mode 100644 index 0000000..89f22b4 --- /dev/null +++ b/lib/Graphics/Text/Font/Choose/Weight.hs @@ -0,0 +1,11 @@ +{-# LANGUAGE CApiFFI #-} +module Graphics.Text.Font.Choose.Weight where + +foreign import capi "fontconfig/fontconfig.h FcWeightFromOpenTypeDouble" + weightFromOpenTypeDouble :: Double -> Double +foreign import capi "fontconfig/fontconfig.h FcWeightToOpenTypeDouble" + weightToOpenTypeDouble :: Double -> Double +foreign import capi "fontconfig/fontconfig.h FcWeightFromOpenType" + weightFromOpenType :: Int -> Int +foreign import capi "fontconfig/fontconfig.h FcWeightToOpenType" + weightToOpenType :: Int -> Int -- 2.30.2