@@ 28,6 28,7 @@ import Data.CSS.Syntax.Tokens (Token(..), NumericValue(..))
import Data.Text (unpack, Text)
import Stylist (PropertyParser(..))
import Data.Scientific (toRealFloat)
+import Data.List (intercalate)
type Pattern = [(String, [(Binding, Value)])]
data Binding = Strong | Weak | Same deriving (Eq, Ord, Enum, Show, Generic)
@@ 177,6 178,18 @@ parseFontFamily (String font:tail) = ([unpack font], True, tail)
parseFontFamily (Ident font:tail) = ([unpack font], True, tail)
parseFontFamily toks = ([], False, toks) -- Invalid syntax!
+parseFontFeatures :: [Token] -> ([(String, Int)], Bool, [Token])
+parseFontFeatures (String feat:toks) | feature@(_:_:_:_:[]) <- unpack feat = case toks of
+ Comma:tail -> let (feats, b, tail') = parseFontFeatures tail in ((feature, 1):feats, b, tail')
+ Ident "on":Comma:tail -> let (f, b, t) = parseFontFeatures tail in ((feature, 1):f, b, t)
+ Ident "on":tail -> ([(feature, 1)], True, tail)
+ Ident "off":Comma:tail -> let (f, b, t) = parseFontFeatures tail in ((feature, 1):f, b, t)
+ Ident "off":tail -> ([(feature, 1)], True, tail)
+ Number _ (NVInteger x):Comma:tail ->
+ let (feats, b, tail') = parseFontFeatures tail in ((feature, fromEnum x):feats, b, tail')
+ Number _ (NVInteger x):tail -> ([(feature, fromEnum x)], True, tail)
+parseFontFeatures toks = ([], False, toks)
+
parseLength :: Double -> NumericValue -> Text -> Double
parseLength super length unit = convert (nv2double length) unit
where
@@ 249,4 262,9 @@ 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" toks
+ | (features, True, []) <- parseFontFeatures toks =
+ set "fontfeatures" Strong (intercalate "," $ map fst features) self
+
longhand _ _ _ _ = Nothing