fontconfig-pure 0.5.0.2 → 0.5.1.0
raw patch · 9 files changed
+29/−6 lines, 9 filesdep ~QuickCheckPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: QuickCheck
API changes (from Hackage documentation)
+ Graphics.Text.Font.Choose.Config.Accessors: current' :: Config
Files
- CHANGELOG.md +4/−0
- fontconfig-pure.cabal +3/−3
- lib/FreeType/FontConfig.hs +1/−0
- lib/Graphics/Text/Font/Choose/CharSet.hs +1/−0
- lib/Graphics/Text/Font/Choose/Config.hs +1/−0
- lib/Graphics/Text/Font/Choose/Config/Accessors.hs +11/−2
- lib/Graphics/Text/Font/Choose/LangSet.hs +2/−1
- lib/Graphics/Text/Font/Choose/Result.hs +4/−0
- lib/Graphics/Text/Font/Choose/StrSet.hs +2/−0
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for fontconfig-pure +## 0.5.1.0 -- 2025-02-04++* Expose a pure accessor for the current config (for API ergonomics, meant to earlier)+ ## 0.5.0.3 -- 2025-01-17 * Better descriptions for Hackage
fontconfig-pure.cabal view
@@ -20,7 +20,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.5.0.2+version: 0.5.1.0 -- A short (one-line) description of the package. synopsis:@@ -95,7 +95,7 @@ scientific >= 0.3.8 && < 1, text >= 2.0.2 && < 3, msgpack >= 1.0 && <2, vector >= 0.13 && <1, bytestring >= 0.11.5 && < 1, stylist-traits >=0.1.1 && <1, css-syntax >= 0.1.0 && < 0.2,- QuickCheck+ QuickCheck >= 2.15.0 && < 2.16 -- Directories containing source files. hs-source-dirs: lib@@ -153,5 +153,5 @@ build-depends: base ^>=4.17.0.0, fontconfig-pure,- hspec, QuickCheck >= 2.15.0 && < 2.16,+ hspec, QuickCheck, msgpack, containers, text, css-syntax, stylist-traits
lib/FreeType/FontConfig.hs view
@@ -307,6 +307,7 @@ glyphMetrics = gsrMetrics glyph2' } +-- | Convience API around `glyphForIndex` to retrieve the image & metrics of the font's glyph. bmpAndMetricsForIndex :: FTFC_Instance -> FTFC_Subpixel -> Word32 -> IO (FT_Bitmap, FT_Glyph_Metrics) bmpAndMetricsForIndex inst subpixel index = do
lib/Graphics/Text/Font/Choose/CharSet.hs view
@@ -54,6 +54,7 @@ diffDecompress prev (x:xs) = let y = prev + x in y:diffDecompress y xs diffDecompress _ [] = [] +-- | Wrapper around `CharSet` which can implement typeclasses. newtype CharSet' = CharSet' { unCharSet :: CharSet } deriving (Eq, Read, Show) instance MessagePack CharSet' where toObject = toObject . diffCompress 0 . IntSet.toAscList . unCharSet
lib/Graphics/Text/Font/Choose/Config.hs view
@@ -28,6 +28,7 @@ -- Returns whether this process succeeded or not. If the default configuration has already been loaded, this routine does nothing and returns True. initFonts :: IO () initFonts = throwBool =<< fcInit+-- | Closes FontConfig's database connection. foreign import capi "fontconfig/fontconfig.h FcFini" fini :: IO () -- | Returns the version number of the library.
lib/Graphics/Text/Font/Choose/Config/Accessors.hs view
@@ -2,7 +2,7 @@ -- | APIs for retrieving configuration -- This is seperate from Graphics.Text.Font.Choose.Config to avoid cyclic dependencies. module Graphics.Text.Font.Choose.Config.Accessors(- configCreate, setCurrent, current, uptodate, home, enableHome, buildFonts,+ configCreate, setCurrent, current, current', uptodate, home, enableHome, buildFonts, configDirs, fontDirs, configFiles, cacheDirs, fonts, rescanInterval, setRescanInterval, appFontAddFile, appFontAddDir, appFontClear, substitute, fontMatch, fontSort, fontRenderPrepare, fontList, filename, parseAndLoad,@@ -25,6 +25,8 @@ import Graphics.Text.Font.Choose.Internal.FFI (peekCString', fromMessageIO0, withMessage, withForeignPtr', fromMessage0, fromMessage) +import System.IO.Unsafe (unsafePerformIO) -- For current'+ -- | Creates an empty configuration. configCreate :: IO Config configCreate = newForeignPtr fcConfigDestroy =<< throwNull =<< fcConfigCreate@@ -36,10 +38,17 @@ setCurrent conf = throwBool =<< withForeignPtr conf fcConfigSetCurrent foreign import capi "fontconfig/fontconfig.h FcConfigSetCurrent" fcConfigSetCurrent :: Ptr Config' -> IO Bool --- | Returns the current default configuration.+-- | Returns the current default configuration, legacy impure function! current :: IO Config current = newForeignPtr fcConfigDestroy =<< throwNull =<< fcConfigReference nullPtr foreign import capi "fontconfig/fontconfig.h FcConfigReference" fcConfigReference :: Ptr Config' -> IO (Ptr Config')++-- | Returns the current default configuration.+-- WARNING: Might not behave correctly around calls to `setCurrent`,+-- but given how many APIs expect a config this makes pure code easier to write.+{-# NOINLINE current' #-} -- To be double-safe.+current' :: Config+current' = unsafePerformIO current -- If I want to initialize a ForeignPtr, must unfortunately use impure code. -- | Checks all of the files related to config and returns whether any of them has -- been modified since the configuration was created.
lib/Graphics/Text/Font/Choose/LangSet.hs view
@@ -56,11 +56,12 @@ i2cmp 2 = DifferentTerritory i2cmp _ = throw ErrOOM --- | Compares language coverage for the 2 given LangSets.+-- | Variation of `cmp` which operates on `LangSet'`. cmp' :: LangSet' -> LangSet' -> LangComparison cmp' a b | valid a && valid b = i2cmp $ withMessage fcLangSetCompare [a, b] | otherwise = DifferentLang where valid = validLangSet'+-- | Compares language coverage for the 2 given LangSets. cmp :: LangSet -> LangSet -> LangComparison cmp a b = LangSet' a `cmp'` LangSet' b
lib/Graphics/Text/Font/Choose/Result.hs view
@@ -5,17 +5,21 @@ import Text.Read (readMaybe) import Control.Exception (Exception, throwIO) +-- | Exceptions which can be thrown by FontConfig. data FcException = ErrType | ErrNoId | ErrOOM | ErrOther deriving (Read, Show, Eq, Enum) instance Exception FcException +-- | Converts a pass|failure return value into a Haskell exception. throwBool :: Bool -> IO () throwBool False = throwIO ErrOOM throwBool True = return () +-- | Turns a failed allocation into a Haskell exception. throwNull :: Ptr a -> IO (Ptr a) throwNull a | a == nullPtr = throwIO ErrOOM | otherwise = return a +-- | Turns a serialized string into a Haskell exception. throwString :: String -> IO () throwString a | Just b <- readMaybe a :: Maybe FcException = throwIO b | otherwise = return ()
lib/Graphics/Text/Font/Choose/StrSet.hs view
@@ -7,6 +7,7 @@ import Data.MessagePack (MessagePack(..)) import Test.QuickCheck (Arbitrary(..)) +-- | A set of strings to match. newtype StrSet = StrSet { unStrSet :: Set String } deriving (Eq, Show, Read) instance MessagePack StrSet where@@ -15,5 +16,6 @@ instance Arbitrary StrSet where arbitrary = StrSet <$> S.map (filter (/= '\0')) <$> arbitrary +-- | Whether the StrSet can be processed by FontConfig. validStrSet :: StrSet -> Bool validStrSet (StrSet self) = notElem '\0' `all` self