A .golden/richParagraphLayout/spaceBoxCollapsed.golden => .golden/richParagraphLayout/spaceBoxCollapsed.golden +93 -0
@@ 0,0 1,93 @@
+ParagraphLayout
+ { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 590, y_size = -8968}
+ , paragraphFragments =
+ [ Fragment
+ { fragmentUserData = "text1"
+ , fragmentLine = 1
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 446, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 86, cluster = 6, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 446, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text1"
+ , fragmentLine = 2
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -1121, x_size = 589, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 83, cluster = 7, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text1"
+ , fragmentLine = 3
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -2242, x_size = 522, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 68, cluster = 8, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 522, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text1"
+ , fragmentLine = 4
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -3363, x_size = 465, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 70, cluster = 9, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 465, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text1"
+ , fragmentLine = 5
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -4484, x_size = 559, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 72, cluster = 10, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 559, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text3"
+ , fragmentLine = 6
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -5605, x_size = 589, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 69, cluster = 12, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text3"
+ , fragmentLine = 7
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -6726, x_size = 590, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 82, cluster = 13, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 590, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text3"
+ , fragmentLine = 8
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -7847, x_size = 511, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 91, cluster = 14, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 511, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ ]
+ }
A .golden/richParagraphLayout/spaceBoxPreserved.golden => .golden/richParagraphLayout/spaceBoxPreserved.golden +104 -0
@@ 0,0 1,104 @@
+ParagraphLayout
+ { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 590, y_size = -10089}
+ , paragraphFragments =
+ [ Fragment
+ { fragmentUserData = "text1"
+ , fragmentLine = 1
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 446, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 86, cluster = 6, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 446, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text1"
+ , fragmentLine = 2
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -1121, x_size = 589, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 83, cluster = 7, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text1"
+ , fragmentLine = 3
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -2242, x_size = 522, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 68, cluster = 8, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 522, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text1"
+ , fragmentLine = 4
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -3363, x_size = 465, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 70, cluster = 9, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 465, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text1"
+ , fragmentLine = 5
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -4484, x_size = 559, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 72, cluster = 10, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 559, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text2"
+ , fragmentLine = 6
+ , fragmentAncestorBoxes =
+ [ AncestorBox {boxUserData = "box1", boxLeftEdge = SpacedEdge 50, boxRightEdge = SpacedEdge 100, boxStartEdge = SpacedEdge 50, boxEndEdge = SpacedEdge 100}
+ ]
+ , fragmentRect = Rect {x_origin = 50, y_origin = -5605, x_size = 0, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ []
+ }
+ , Fragment
+ { fragmentUserData = "text3"
+ , fragmentLine = 7
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -6726, x_size = 589, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 69, cluster = 12, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text3"
+ , fragmentLine = 8
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -7847, x_size = 590, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 82, cluster = 13, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 590, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ , Fragment
+ { fragmentUserData = "text3"
+ , fragmentLine = 9
+ , fragmentAncestorBoxes =
+ []
+ , fragmentRect = Rect {x_origin = 0, y_origin = -8968, x_size = 511, y_size = -1121}
+ , fragmentPen = (0, -932)
+ , fragmentGlyphs =
+ [ (GlyphInfo {codepoint = 91, cluster = 14, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 511, y_advance = 0, x_offset = 0, y_offset = 0})
+ ]
+ }
+ ]
+ }
M test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs => test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs +6 -3
@@ 333,8 333,8 @@ softBreakParagraph spacing font = constructParagraph
b = b_ { boxSpacing = BoxSpacingLeftRight spacing spacing }
t = tLTR { textFont = font, textLanguage = "en" }
-spaceBoxParagraph :: Font -> ParagraphOptions -> Paragraph String
-spaceBoxParagraph font = constructParagraph
+spaceBoxParagraph :: BoxCollapse -> Font -> ParagraphOptions -> Paragraph String
+spaceBoxParagraph collapse font = constructParagraph
(pack "prefix")
(rootBox t
[ text "text1" "space"
@@ 346,5 346,8 @@ spaceBoxParagraph font = constructParagraph
)
(pack "suffix")
where
- b = b_ { boxSpacing = BoxSpacingLeftRight 50 100 }
+ b = b_
+ { boxCollapse = collapse
+ , boxSpacing = BoxSpacingLeftRight 50 100
+ }
t = tLTR { textFont = font, textLanguage = "en" }
M test/Data/Text/ParagraphLayout/RichSpec.hs => test/Data/Text/ParagraphLayout/RichSpec.hs +19 -1
@@ 180,10 180,28 @@ spec = do
{ paragraphAlignment = AlignStart
, paragraphMaxWidth = 4635
}
- let input = spaceBoxParagraph font opts
+ let input = spaceBoxParagraph AllowBoxCollapse font opts
let result = layoutRich input
result `shouldBeGolden` "spaceBoxMiddle"
+ it "can collapse space box when on its own line" $ do
+ let opts = defaultParagraphOptions
+ { paragraphAlignment = AlignStart
+ , paragraphMaxWidth = 100
+ }
+ let input = spaceBoxParagraph AllowBoxCollapse font opts
+ let result = layoutRich input
+ result `shouldBeGolden` "spaceBoxCollapsed"
+
+ it "can preserve space box when on its own line" $ do
+ let opts = defaultParagraphOptions
+ { paragraphAlignment = AlignStart
+ , paragraphMaxWidth = 100
+ }
+ let input = spaceBoxParagraph AvoidBoxCollapse font opts
+ let result = layoutRich input
+ result `shouldBeGolden` "spaceBoxPreserved"
+
it "handles nested boxes" $ do
let opts = defaultParagraphOptions
{ paragraphAlignment = AlignStart