M Graphics/Text/Font/Choose/Config.hs => Graphics/Text/Font/Choose/Config.hs +3 -3
@@ 15,7 15,7 @@ import System.IO.Unsafe (unsafePerformIO)
import Data.Set (empty) -- For testing segfault source.
import Control.Exception (bracket)
-import Graphics.Text.Font.Choose.Result (throwNull, throwFalse, throwPtr)
+import Graphics.Text.Font.Choose.Result (Word8, throwNull, throwFalse, throwPtr)
-- | System configuration regarding available fonts.
type Config = ForeignPtr Config'
@@ 233,7 233,7 @@ fontMatch' pattern = unsafePerformIO $ withPattern pattern $ \pattern' -> alloca
ret <- fcFontMatch nullPtr pattern' res'
throwPtr res' $ thawPattern_ $ pure ret
foreign import ccall "FcFontMatch" fcFontMatch ::
- Config_ -> Pattern_ -> Ptr Int -> IO Pattern_
+ Config_ -> Pattern_ -> Ptr Word8 -> IO Pattern_
-- | Returns the list of fonts sorted by closeness to p. If trim is `True`,
-- elements in the list which don't include Unicode coverage not provided by
@@ 259,7 259,7 @@ fontSort' pattern trim = unsafePerformIO $ withPattern pattern $ \pattern' ->
y <- thawCharSet $ throwNull csp'
return (x, y)
foreign import ccall "FcFontSort" fcFontSort ::
- Config_ -> Pattern_ -> Bool -> CharSet_ -> Ptr Int -> IO FontSet_
+ Config_ -> Pattern_ -> Bool -> CharSet_ -> Ptr Word8 -> IO FontSet_
-- | Creates a new pattern consisting of elements of font not appearing in pat,
-- elements of pat not appearing in font and the best matching value from pat
M Graphics/Text/Font/Choose/FontSet/API.hs => Graphics/Text/Font/Choose/FontSet/API.hs +3 -3
@@ 6,7 6,7 @@ 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 Graphics.Text.Font.Choose.Result (Word8, throwPtr)
import Foreign.Ptr (Ptr, castPtr, nullPtr)
import Foreign.ForeignPtr (withForeignPtr)
@@ 47,7 47,7 @@ fontSetMatch' fontss pattern = unsafePerformIO $ withFontSets fontss $ \fontss'
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_
+ Config_ -> Ptr FontSet_ -> Int -> Pattern_ -> Ptr Word8 -> IO Pattern_
-- | Returns the list of fonts from sets sorted by closeness to pattern.
-- If trim is `True`, elements in the list which don't include Unicode coverage
@@ 74,4 74,4 @@ fontSetSort' fontss pattern trim csp = unsafePerformIO $
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_
+ -> Int -> Pattern_ -> Bool -> CharSet_ -> Ptr Word8 -> IO FontSet_
M Graphics/Text/Font/Choose/Result.hs => Graphics/Text/Font/Choose/Result.hs +8 -8
@@ 1,19 1,19 @@
-module Graphics.Text.Font.Choose.Result (Result(..), resultFromPointer,
+module Graphics.Text.Font.Choose.Result (Result(..), Word8, resultFromPointer,
Error(..), throwResult, throwInt, throwPtr, throwFalse, throwNull) where
import Foreign.Storable (peek)
import Foreign.Ptr (Ptr, nullPtr)
import Control.Exception (throwIO, throw, Exception)
+import Data.Word (Word8)
data Result = Match | NoMatch | TypeMismatch | ResultNoId | OutOfMemory | Other
deriving (Eq, Show, Read, Enum, Bounded)
-resultFromPointer :: Ptr Int -> IO Result
-resultFromPointer res = do
- ret <- peek res
- if ret > fromEnum (maxBound :: Result) || ret < fromEnum (minBound :: Result)
- then return Match -- FIXME: Why these erroneous exceptions thrown?
- else return $ toEnum ret
+resultFromPointer :: Ptr Word8 -> IO Result
+resultFromPointer res = toEnum8 <$> peek res
+
+toEnum8 :: Enum a => Word8 -> a
+toEnum8 = toEnum . fromEnum
data Error = ErrTypeMismatch | ErrResultNoId | ErrOutOfMemory deriving (Eq, Show, Read)
instance Exception Error
@@ 29,7 29,7 @@ throwInt :: Int -> IO a -> IO (Maybe a)
throwInt x
| x >= 0 && x <= 4 = throwResult $ toEnum x
| otherwise = throwResult $ Other
-throwPtr :: Ptr Int -> IO a -> IO (Maybe a)
+throwPtr :: Ptr Word8 -> IO a -> IO (Maybe a)
throwPtr a b = resultFromPointer a >>= flip throwResult b
throwFalse :: Bool -> IO ()
M fontconfig-harfbuzz/fontconfig-harfbuzz.cabal => fontconfig-harfbuzz/fontconfig-harfbuzz.cabal +2 -2
@@ 57,7 57,7 @@ library
-- other-extensions:
-- Other library packages from which modules are imported.
- build-depends: base >=4.12 && <4.16, fontconfig-pure, harfbuzz-pure, bytestring
+ build-depends: base >=4.12 && <5, fontconfig-pure, harfbuzz-pure, bytestring
-- Directories containing source files.
hs-source-dirs: .
@@ 77,7 77,7 @@ executable fontconfig-harfbuzz
-- other-extensions:
-- Other library packages from which modules are imported.
- build-depends: base >=4.12 && <4.13, typograffiti>=0.2, text,
+ build-depends: base >=4.12 && <5, typograffiti>=0.2, text,
harfbuzz-pure, GLUT >= 2.7, gl, mtl, fontconfig-pure,
freetype2, fontconfig-harfbuzz, linear
M fontconfig-pure.cabal => fontconfig-pure.cabal +3 -3
@@ 68,7 68,7 @@ library
-- other-extensions:
-- Other library packages from which modules are imported.
- build-depends: base >=4.12 && <4.16, containers >= 0.1 && <1,
+ build-depends: base >=4.12 && <5, containers >= 0.1 && <1,
linear >= 1.0.1 && <2, freetype2 >= 0.2 && < 0.3,
hashable >= 1.3 && <2,
css-syntax, text, stylist-traits >= 0.1.1 && < 1, scientific
@@ 93,7 93,7 @@ executable fontconfig-pure
-- other-extensions:
-- Other library packages from which modules are imported.
- build-depends: base >=4.12 && <4.16, fontconfig-pure
+ build-depends: base >=4.12 && <5, fontconfig-pure
-- Directories containing source files.
-- hs-source-dirs:
@@ 106,4 106,4 @@ test-suite test-fontconfig
default-language: Haskell2010
type: exitcode-stdio-1.0
main-is: Test.hs
- build-depends: base >= 4.12 && <4.16, fontconfig-pure, hspec, QuickCheck
+ build-depends: base >= 4.12 && <5, fontconfig-pure, hspec, QuickCheck