@@ 17,8 17,8 @@ foreign import capi "fontconfig/fontconfig.h FcWeightFromOpenTypeDouble"
foreign import capi "fontconfig/fontconfig.h FcWeightToOpenTypeDouble"
weightToOpenTypeDouble :: Double -> Double
-- | Like weightFromOpenTypeDouble but with integer arguments. Use the other function instead.
-foreign import capi "fontconfig/fontconfig.h FcWeightFromOpenType"
- weightFromOpenType :: Int -> Int
+weightFromOpenType :: Int -> Int
+weightFromOpenType = fromEnum . weightFromOpenTypeDouble . toEnum
-- | Like weightToOpenTypeDouble but with integer arguments. Use the other function instead.
-foreign import capi "fontconfig/fontconfig.h FcWeightToOpenType"
- weightToOpenType :: Int -> Int
+weightToOpenType :: Int -> Int
+weightToOpenType = fromEnum . weightToOpenTypeDouble . toEnum
@@ 11,6 11,7 @@ import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Text as Txt
import Data.Maybe (isJust)
+import GHC.Real (infinity)
import Graphics.Text.Font.Choose
import Graphics.Text.Font.Choose.Internal.Test
@@ 96,3 97,37 @@ main = hspec $ do
-- A couple additional ones so we know its not always responding with DifferentTerritory!
S.singleton "mn-mn" `cmp` S.singleton "mn-mn" `shouldBe` SameLang
S.singleton "mn-mn" `cmp` S.singleton "pap-an" `shouldBe` DifferentLang
+ it "Font weights" $ do
+ weightFromOpenTypeDouble (fromRational infinity) `shouldBe` 215
+ weightFromOpenType maxBound `shouldBe` 215
+ it "Name parsing" $ do
+ nameParse "sans\\-serif" `shouldBe` M.fromList [
+ ("family", [(Strong, ValueString "sans-serif")])
+ ]
+ nameParse "Foo-10" `shouldBe` M.fromList [
+ ("family", [(Strong, ValueString "Foo")]),
+ -- NOTE: Equality derived from the pure-Haskell type is stricter than FontConfig's.
+ -- This subtest might fail in the future, not sure what to do about that.
+ ("size", [(Strong, ValueDouble 10)])
+ ]
+ nameParse "Foo,Bar-10" `shouldBe` M.fromList [
+ ("family", [(Strong, ValueString "Foo"), (Strong, ValueString "Bar")]),
+ ("size", [(Strong, ValueDouble 10)])
+ ]
+ nameParse "Foo:weight=medium" `shouldBe` M.fromList [
+ ("family", [(Strong, ValueString "Foo")]),
+ ("weight", [(Strong, ValueDouble 100)])
+ ]
+ nameParse "Foo:weight_medium" `shouldBe` M.fromList [
+ ("family", [(Strong, ValueString "Foo")]),
+ ("weight", [(Strong, ValueDouble 100)])
+ ]
+ nameParse ":medium" `shouldBe` M.fromList [
+ ("weight", [(Strong, ValueInt 100)])
+ ]
+ nameParse ":normal" `shouldBe` M.fromList [
+ ("width", [(Strong, ValueInt 100)])
+ ]
+ nameParse ":weight=[medium bold]" `shouldBe` M.fromList [
+ ("weight", [(Strong, ValueRange $ Range 100 200)])
+ ]