From 6fb750efc5f52cf06504ba562f4005fba695572c Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 6 Apr 2023 20:55:47 +1200 Subject: [PATCH] Parse text-pagination properties. --- Graphics/Layout/CSS.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Graphics/Layout/CSS.hs b/Graphics/Layout/CSS.hs index 889bb06..6aef096 100644 --- a/Graphics/Layout/CSS.hs +++ b/Graphics/Layout/CSS.hs @@ -2,10 +2,11 @@ module Graphics.Layout.CSS(CSSBox(..), BoxSizing(..), Display(..), finalizeCSS, finalizeCSS') where -import Data.CSS.Syntax.Tokens (Token(..)) +import Data.CSS.Syntax.Tokens (Token(..), NumericValue(..)) import qualified Data.Text as Txt import Stylist (PropertyParser(..), TrivialPropertyParser) import Stylist.Tree (StyleTree(..)) +import Data.Text.ParagraphLayout (PageOptions(..)) import Graphics.Layout.Box as B import Graphics.Layout @@ -25,7 +26,8 @@ data CSSBox a = CSSBox { gridStyles :: CSSGrid, cellStyles :: CSSCell, inlineStyles :: CSSInline, - captionBelow :: Bool + captionBelow :: Bool, + pageOptions :: PageOptions } data BoxSizing = BorderBox | ContentBox noborder = Border (0,"px") (0,"px") (0,"px") (0,"px") @@ -54,7 +56,8 @@ instance PropertyParser a => PropertyParser (CSSBox a) where gridStyles = temp, cellStyles = temp, inlineStyles = temp, - captionBelow = False + captionBelow = False, + pageOptions = PageOptions 0 0 2 2 } inherit parent = CSSBox { boxSizing = boxSizing parent, @@ -66,7 +69,8 @@ instance PropertyParser a => PropertyParser (CSSBox a) where gridStyles = inherit $ gridStyles parent, cellStyles = inherit $ cellStyles parent, inlineStyles = inherit $ inlineStyles parent, - captionBelow = captionBelow parent + captionBelow = captionBelow parent, + pageOptions = pageOptions parent } -- Wasn't sure how to implement in FontConfig-Pure @@ -142,6 +146,11 @@ instance PropertyParser a => PropertyParser (CSSBox a) where longhand _ self "caption-side" [Ident "bottom"] = Just self { captionBelow = True } longhand _ self "caption-side" [Ident "initial"] = Just self {captionBelow = False} + longhand _ self "orphans" [Number _ (NVInteger x)] = + Just self { pageOptions = (pageOptions self) { pageOrphans = fromInteger x } } + longhand _ self "widows" [Number _ (NVInteger x)] = + Just self { pageOptions = (pageOptions self) { pageWidows = fromInteger x } } + longhand a b c d | Just x <- longhand (font a) (font b) c d, Just y <- longhand (font' a) (font' b) c d = Just b { font = x, font' = y } -- Those properties can overlap! -- 2.30.2