From b983e599d307315572e33b209ac5595c44959466 Mon Sep 17 00:00:00 2001 From: Jaro Date: Sat, 24 Jun 2023 19:05:34 +0200 Subject: [PATCH] Test preservation of lines with boxes. --- .../spaceBoxCollapsed.golden | 93 ++++++++++++++++ .../spaceBoxPreserved.golden | 104 ++++++++++++++++++ .../ParagraphLayout/Rich/ParagraphData.hs | 9 +- test/Data/Text/ParagraphLayout/RichSpec.hs | 20 +++- 4 files changed, 222 insertions(+), 4 deletions(-) create mode 100644 .golden/richParagraphLayout/spaceBoxCollapsed.golden create mode 100644 .golden/richParagraphLayout/spaceBoxPreserved.golden diff --git a/.golden/richParagraphLayout/spaceBoxCollapsed.golden b/.golden/richParagraphLayout/spaceBoxCollapsed.golden new file mode 100644 index 0000000..d17a210 --- /dev/null +++ b/.golden/richParagraphLayout/spaceBoxCollapsed.golden @@ -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}) + ] + } + ] + } diff --git a/.golden/richParagraphLayout/spaceBoxPreserved.golden b/.golden/richParagraphLayout/spaceBoxPreserved.golden new file mode 100644 index 0000000..33de7e0 --- /dev/null +++ b/.golden/richParagraphLayout/spaceBoxPreserved.golden @@ -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}) + ] + } + ] + } diff --git a/test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs b/test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs index b2ba52f..d5f1959 100644 --- a/test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs +++ b/test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs @@ -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" } diff --git a/test/Data/Text/ParagraphLayout/RichSpec.hs b/test/Data/Text/ParagraphLayout/RichSpec.hs index 9df9eca..6a34a2f 100644 --- a/test/Data/Text/ParagraphLayout/RichSpec.hs +++ b/test/Data/Text/ParagraphLayout/RichSpec.hs @@ -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 -- 2.30.2