~alcinnz/CatTrap

e0d43db4f4ec4c34362dfb0f7541c3c3a957cf56 — Adrian Cochrane 1 year, 3 months ago 7abbe00
Strip out extraneous whitespace.
2 files changed, 11 insertions(+), 8 deletions(-)

M Graphics/Layout/CSS.hs
M Graphics/Layout/Inline/CSS.hs
M Graphics/Layout/CSS.hs => Graphics/Layout/CSS.hs +7 -6
@@ 200,13 200,14 @@ finalizeChilds :: PropertyParser x => Font' -> Font' -> [StyleTree (CSSBox x)] -
finalizeChilds root parent (StyleTree { style = CSSBox { display = None } }:childs) =
    finalizeChilds root parent childs
finalizeChilds root parent childs@(child:childs')
    | isInlineTree childs =
    | isInlineTree childs, Just self <- finalizeParagraph (flattenTree childs) parent =
        -- FIXME propagate display properties, how to handle the hierarchy.
        [LayoutInline temp parent (finalizeParagraph (flattenTree childs) parent)
                    (repeat temp)]
    | (inlines@(_:_), blocks) <- spanInlines childs =
        LayoutInline temp parent (finalizeParagraph (flattenTree childs) parent) []
            :finalizeChilds root parent blocks
        [LayoutInline temp parent self (repeat temp)]
    | (inlines@(_:_), blocks) <- spanInlines childs,
        Just self <- finalizeParagraph (flattenTree childs) parent  =
            LayoutInline temp parent self [] : finalizeChilds root parent blocks
    | (StyleTree { style = CSSBox { display = Inline } }:childs') <- childs =
        finalizeChilds root parent childs' -- Inline's all whitespace...
    | otherwise = finalizeCSS root parent child : finalizeChilds root parent childs'
  where
    isInlineTree = all isInlineTree0

M Graphics/Layout/Inline/CSS.hs => Graphics/Layout/Inline/CSS.hs +4 -2
@@ 10,6 10,7 @@ import Data.Text.ParagraphLayout (Span(..), SpanOptions(..), LineHeight(..),
                                Paragraph(..), ParagraphOptions(..))

import Graphics.Layout.CSS.Internal (Font'(..), hbScale)
import Data.Char (isSpace)

data CSSInline = CSSInline Lz.Text SpanOptions



@@ 38,8 39,9 @@ concatParagraph (ParagraphBuilder aTxt aOpts) (ParagraphBuilder bTxt bOps) =
    ParagraphBuilder (aTxt `Lz.append` bTxt)
                    (aOpts ++ [Span (toEnum (fromEnum $ Lz.length aTxt) + off) opts
                                | Span off opts <- bOps])
finalizeParagraph :: ParagraphBuilder -> Font' -> Paragraph
finalizeParagraph (ParagraphBuilder txt ops) font' = Paragraph txt' 0 ops pOps
finalizeParagraph :: ParagraphBuilder -> Font' -> Maybe Paragraph
finalizeParagraph (ParagraphBuilder txt _) _ | Lz.all isSpace txt || Lz.null txt = Nothing
finalizeParagraph (ParagraphBuilder txt ops) font' = Just $ Paragraph txt' 0 ops pOps
    where
        Text txt' _ _ = Lz.toStrict txt
        pOps = ParagraphOptions {