From 6e336e5ee4797190f83be2b381234980c7b680f5 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 1 Dec 2022 14:19:27 +1300 Subject: [PATCH] Define skeleton for parsing @font-face. --- Graphics/Text/Font/Choose/FontSet.hs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Graphics/Text/Font/Choose/FontSet.hs b/Graphics/Text/Font/Choose/FontSet.hs index fe7d717..102d7a0 100644 --- a/Graphics/Text/Font/Choose/FontSet.hs +++ b/Graphics/Text/Font/Choose/FontSet.hs @@ -1,4 +1,4 @@ --- NOTE: Untested! +{-# LANGUAGE OverloadedStrings #-} module Graphics.Text.Font.Choose.FontSet where import Graphics.Text.Font.Choose.Pattern @@ -11,6 +11,9 @@ import Foreign.Marshal.Array (peekArray) import Control.Monad (forM) import Control.Exception (bracket) +-- For CSS bindings +import Stylist.Parse (StyleSheet(..), parseProperties) + type FontSet = [Pattern] ------ @@ -56,3 +59,18 @@ foreign import ccall "get_fontSet_fonts" get_fontSet_fonts :: FontSet_ -> IO (Pt thawFontSet_ :: IO FontSet_ -> IO FontSet thawFontSet_ cb = bracket (throwNull <$> cb) fcFontSetDestroy thawFontSet + +------ +--- CSS Bindings +------ + +data FontFaceParser a = FontFaceParser { cssFonts :: FontSet, cssInner :: a} + +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 x self) key toks = + let (a, b) = addAtRule self key toks in (FontFaceParser x a, b) -- 2.30.2