~alcinnz/fontconfig-pure

878b65cdbdd47160658408033f718109267f0c57 — Adrian Cochrane 2 years ago 6e336e5
Implement @font-face 'font-family' property.
2 files changed, 17 insertions(+), 3 deletions(-)

M Graphics/Text/Font/Choose/FontSet.hs
M Graphics/Text/Font/Choose/Pattern.hs
M Graphics/Text/Font/Choose/FontSet.hs => Graphics/Text/Font/Choose/FontSet.hs +14 -2
@@ 13,6 13,8 @@ import Control.Exception (bracket)

-- For CSS bindings
import Stylist.Parse (StyleSheet(..), parseProperties)
import Data.CSS.Syntax.Tokens (Token(..))
import Data.Text (unpack, Text)

type FontSet = [Pattern]



@@ 66,11 68,21 @@ thawFontSet_ cb = bracket (throwNull <$> cb) fcFontSetDestroy thawFontSet

data FontFaceParser a = FontFaceParser { cssFonts :: FontSet, cssInner :: a}

properties2font :: [(Text, [Token])] -> Pattern
properties2font (("font-family", [String font]):props) =
    setValue "family" Strong (unpack font) $ properties2font props
properties2font (("font-family", [Ident font]):props) =
    setValue "family" Strong (unpack font) $ properties2font props

properties2font (_:props) = properties2font props
properties2font [] = []

instance StyleSheet a => StyleSheet (FontFaceParser a) where
    setPriorities v (FontFaceParser x self) = FontFaceParser x $ setPriorities v self
    addRule (FontFaceParser x self) rule = FontFaceParser x $ addRule self rule

    addAtRule self "font-face" toks =
        let (props, toks') = parseProperties toks in (self, toks')
    addAtRule (FontFaceParser fonts self) "font-face" toks =
        let ((props, _), toks') = parseProperties toks
        in (FontFaceParser (properties2font props:fonts) self, toks')
    addAtRule (FontFaceParser x self) key toks =
        let (a, b) = addAtRule self key toks in (FontFaceParser x a, b)

M Graphics/Text/Font/Choose/Pattern.hs => Graphics/Text/Font/Choose/Pattern.hs +3 -1
@@ 1,7 1,9 @@
{-# LANGUAGE DeriveGeneric, OverloadedStrings, TypeSynonymInstances, FlexibleInstances #-}
module Graphics.Text.Font.Choose.Pattern (Pattern(..), Binding(..), equalSubset,
    normalizePattern, filter, defaultSubstitute, nameParse, nameUnparse, format,
    Pattern_, withPattern, thawPattern, thawPattern_, patternAsPointer) where
    Pattern_, withPattern, thawPattern, thawPattern_, patternAsPointer,

    setValue, setValues, unset) where

import Prelude hiding (filter)
import Data.List (nub)