~alcinnz/fontconfig-pure

b1d288334ace6a1942c9be0145152a474191dcc7 — Adrian Cochrane 1 year, 4 months ago 427cb12
Document FontConfig Strings & Weights bindings, utilize weight bindings for CSS bindings.
M Graphics/Text/Font/Choose/Pattern.hs => Graphics/Text/Font/Choose/Pattern.hs +2 -13
@@ 33,6 33,7 @@ import Data.Text (unpack, Text)
import Stylist (PropertyParser(..))
import Data.Scientific (toRealFloat)
import Data.List (intercalate)
import Graphics.Text.Font.Choose.Weight (weightFromOpenType)

-- | An `Pattern`` holds a set of names with associated value lists;
-- each name refers to a property of a font.


@@ 273,19 274,7 @@ parseFontStretch _ = Nothing
parseFontWeight :: Token -> Maybe Int
parseFontWeight (Ident k) | k `elem` ["initial", "normal"] = Just 80
parseFontWeight (Ident "bold") = Just 200
parseFontWeight (Number _ (NVInteger 100)) = Just 0
parseFontWeight (Number _ (NVInteger 200)) = Just 40
parseFontWeight (Number _ (NVInteger 300)) = Just 50
parseFontWeight (Number _ (NVInteger 400)) = Just 80
parseFontWeight (Number _ (NVInteger 500)) = Just 100
parseFontWeight (Number _ (NVInteger 600)) = Just 180
parseFontWeight (Number _ (NVInteger 700)) = Just 200
parseFontWeight (Number _ (NVInteger 800)) = Just 205
parseFontWeight (Number _ (NVInteger 900)) = Just 210
parseFontWeight (Number _ (NVInteger 950)) = Just 215
parseFontWeight (Number _ (NVInteger x))
    | x > 920 = parseFontWeight $ Number "" $ NVInteger 950
    | otherwise = parseFontWeight $ Number "" $ NVInteger $ (x `div` 100) * 100
parseFontWeight (Number _ (NVInteger x)) = Just $ weightFromOpenType $ fromEnum x
parseFontWeight _ = Nothing

nv2double (NVInteger x) = fromInteger x

M Graphics/Text/Font/Choose/Strings.hs => Graphics/Text/Font/Choose/Strings.hs +2 -0
@@ 11,6 11,7 @@ import Foreign.C.String (CString, withCString, peekCString)
import Control.Exception (bracket)
import Control.Monad (forM)

-- | Set of strings, as exposed by other FreeType APIs.
type StrSet = Set String

data StrSet'


@@ 44,6 45,7 @@ thawStrSet_ cb = bracket (throwNull <$> cb) fcStrSetDestroy thawStrSet

------------

-- | Output string lists from FontConfig.
type StrList = [String]

data StrList'

M Graphics/Text/Font/Choose/Weight.hs => Graphics/Text/Font/Choose/Weight.hs +12 -0
@@ 1,8 1,20 @@
module Graphics.Text.Font.Choose.Weight where

-- | Returns an double value to use with "weight", from an double in the
-- 1..1000 range, resembling the numbers from OpenType specification's OS2
-- usWeight numbers, which are also similar to CSS font-weight numbers.
-- If input is negative, zero, or greater than 1000, returns -1.
-- This function linearly interpolates between various FC_WEIGHT_* constants.
-- As such, the returned value does not necessarily match any of the predefined
-- constants.
foreign import ccall "FcWeightFromOpenTypeDouble" weightFromOpenTypeDouble ::
    Double -> Double
-- | `weightToOpenTypeDouble` is the inverse of `weightFromOpenType`.
-- If the input is less than FC_WEIGHT_THIN or greater than FC_WEIGHT_EXTRABLACK,
-- returns -1. Otherwise returns a number in the range 1 to 1000.
foreign import ccall "FcWeightToOpenTypeDouble" weightToOpenTypeDouble ::
    Double -> Double
-- | Variant of `weightFromOpenTypeDouble` taking ints.
foreign import ccall "FcWeightFromOpenType" weightFromOpenType :: Int -> Int
-- | Variant of `weightToOpenTypeDouble` taking ints.
foreign import ccall "FcWeightToOpenType" weightToOpenType :: Int -> Int