~jaro/balkon

4fda24fcf0fa3cfcd0458c15e53006d998ff8ca1 — Jaro 1 year, 5 months ago 4ebfe39
Add extensible filter for invisible lines.
M src/Data/Text/ParagraphLayout/Internal/Layout.hs => src/Data/Text/ParagraphLayout/Internal/Layout.hs +2 -1
@@ 68,7 68,8 @@ layoutAndAlignLines dir align maxWidth runs = frags
        (_, fragsInLines) = mapAccumL positionLine originY numberedLines
        positionLine = positionLineH dir align maxWidth
        numberedLines = zip [1 ..] canonicalLines
        canonicalLines = fmap reorderProtoFragments logicalLines
        canonicalLines = fmap reorderProtoFragments visibleLines
        visibleLines = filter PL.visible logicalLines
        logicalLines = nonEmptyItems $ layoutLines maxWidth [] runs
        originY = paragraphOriginY


M src/Data/Text/ParagraphLayout/Internal/ProtoLine.hs => src/Data/Text/ParagraphLayout/Internal/ProtoLine.hs +12 -0
@@ 1,6 1,7 @@
module Data.Text.ParagraphLayout.Internal.ProtoLine
    ( ProtoLine (..)
    , nonEmpty
    , visible
    , width
    , applyBoxes
    )


@@ 38,6 39,17 @@ nonEmpty (ProtoLine [] _ _) = Nothing
nonEmpty pl@(ProtoLine { protoFragments = (f : fs) }) =
    Just pl { protoFragments = f :| fs }

-- | `True` if this line should generate a visible line box.
visible :: Foldable f => ProtoLine f d -> Bool
visible pl = any visibleProtoFragment $ protoFragments pl

visibleProtoFragment :: WithSpan d ProtoFragment -> Bool
visibleProtoFragment (WithSpan _ pf) =
    hasGlyphs || hasHardBreak
    where
        hasGlyphs = not $ null $ glyphs pf
        hasHardBreak = hardBreak pf

-- | Total width of the line (content and spacing).
width :: (Foldable f, Functor f) => ProtoLine f d -> Int32
width pl = totalAdvances pl + totalBoxesStart pl + totalBoxesEnd pl