From 75dbf79c9c324947f479a2c785d2e629644d0f15 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Tue, 29 Nov 2022 14:53:54 +1300 Subject: [PATCH] Bind CSS 'font-variation-settings' to FontConfig 'variable' property. --- Graphics/Text/Font/Choose/Pattern.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Graphics/Text/Font/Choose/Pattern.hs b/Graphics/Text/Font/Choose/Pattern.hs index c26de01..3d17b35 100644 --- a/Graphics/Text/Font/Choose/Pattern.hs +++ b/Graphics/Text/Font/Choose/Pattern.hs @@ -190,6 +190,13 @@ parseFontFeatures (String feat:toks) | feature@(_:_:_:_:[]) <- unpack feat = cas Number _ (NVInteger x):tail -> ([(feature, fromEnum x)], True, tail) parseFontFeatures toks = ([], False, toks) +parseFontVars :: [Token] -> ([(String, NumericValue)], Bool, [Token]) +parseFontVars (String var':Number _ x:Comma:tail) | var@(_:_:_:_:[]) <- unpack var' = + let (vars, b, tail') = parseFontVars tail in ((var, x):vars, b, tail') +parseFontVars (String var':Number _ x:tail) | var@(_:_:_:_:[]) <- unpack var' = + ([(var, x)], True, tail) +parseFontVars toks = ([], False, toks) + parseLength :: Double -> NumericValue -> Text -> Double parseLength super length unit = convert (nv2double length) unit where @@ -211,6 +218,7 @@ parseLength super length unit = convert (nv2double length) unit sets a b c d = Just $ setValues a b c d set a b c d = Just $ setValue a b c d seti a b c d = Just $ setValue a b (c :: Int) d +unset' a b = Just $ unset a b getSize pat | ValueDouble x <- getValue "size" pat = x | otherwise = 10 @@ -262,9 +270,15 @@ instance PropertyParser Pattern where | ValueInt _ <- getValue "weight" self = Just self -- As bold as it goes... | otherwise = seti "weight" Strong 200 self - longhand _ self "font-feature-settings" [Ident k] | k `elem` ["initial", "normal"] = Just self + longhand _ self "font-feature-settings" [Ident k] + | k `elem` ["initial", "normal"] = unset' "fontfeatures" self longhand _ self "font-feature-settings" toks | (features, True, []) <- parseFontFeatures toks = set "fontfeatures" Strong (intercalate "," $ map fst features) self + longhand _ self "font-variation-settings" [Ident k] + | k `elem` ["initial", "normal"] = unset' "variable" self + longhand _ self "font-variation-settings" toks + | (_, True, []) <- parseFontVars toks = set "variable" Strong True self + longhand _ _ _ _ = Nothing -- 2.30.2