From ddfeaa503aaca344bc22d438fef5af45f7e00463 Mon Sep 17 00:00:00 2001 From: Jaro Date: Fri, 23 Jun 2023 17:29:45 +0200 Subject: [PATCH] Test boxes with no text or only a space. --- .../richParagraphLayout/emptyBoxMiddle.golden | 46 +++++++++++++++++++ .../richParagraphLayout/spaceBoxMiddle.golden | 45 ++++++++++++++++++ .../ParagraphLayout/Rich/ParagraphData.hs | 36 ++++++++++++++- test/Data/Text/ParagraphLayout/RichSpec.hs | 18 ++++++++ 4 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 .golden/richParagraphLayout/emptyBoxMiddle.golden create mode 100644 .golden/richParagraphLayout/spaceBoxMiddle.golden diff --git a/.golden/richParagraphLayout/emptyBoxMiddle.golden b/.golden/richParagraphLayout/emptyBoxMiddle.golden new file mode 100644 index 0000000..b5869d9 --- /dev/null +++ b/.golden/richParagraphLayout/emptyBoxMiddle.golden @@ -0,0 +1,46 @@ +ParagraphLayout + { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 5193, y_size = -1121} + , paragraphFragments = + [ Fragment + { fragmentUserData = "text1" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 3139, y_size = -1121} + , fragmentPen = (0, -932) + , fragmentGlyphs = + [ (GlyphInfo {codepoint = 72, cluster = 6, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 559, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 80, cluster = 7, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 861, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 83, cluster = 8, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 87, cluster = 9, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 402, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 92, cluster = 10, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 497, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 3, cluster = 11, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 231, y_advance = 0, x_offset = 0, y_offset = 0}) + ] + } + , Fragment + { fragmentUserData = "emptyText" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [ AncestorBox {boxUserData = "box1", boxLeftEdge = SpacedEdge 50, boxRightEdge = SpacedEdge 100, boxStartEdge = SpacedEdge 50, boxEndEdge = SpacedEdge 100} + ] + , fragmentRect = Rect {x_origin = 3189, y_origin = 0, x_size = 0, y_size = -1121} + , fragmentPen = (0, -932) + , fragmentGlyphs = + [] + } + , Fragment + { fragmentUserData = "text2" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 3289, y_origin = 0, x_size = 1904, y_size = -1121} + , fragmentPen = (0, -932) + , fragmentGlyphs = + [ (GlyphInfo {codepoint = 3, cluster = 12, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 231, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 69, cluster = 13, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 82, cluster = 14, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 573, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 91, cluster = 15, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 511, y_advance = 0, x_offset = 0, y_offset = 0}) + ] + } + ] + } diff --git a/.golden/richParagraphLayout/spaceBoxMiddle.golden b/.golden/richParagraphLayout/spaceBoxMiddle.golden new file mode 100644 index 0000000..0832245 --- /dev/null +++ b/.golden/richParagraphLayout/spaceBoxMiddle.golden @@ -0,0 +1,45 @@ +ParagraphLayout + { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 4635, y_size = -1121} + , paragraphFragments = + [ Fragment + { fragmentUserData = "text1" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 2581, 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}) + , (GlyphInfo {codepoint = 83, cluster = 7, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 68, cluster = 8, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 522, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 70, cluster = 9, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 465, y_advance = 0, x_offset = 0, y_offset = 0}) + , (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 = 1 + , fragmentAncestorBoxes = + [ AncestorBox {boxUserData = "box1", boxLeftEdge = SpacedEdge 50, boxRightEdge = SpacedEdge 100, boxStartEdge = SpacedEdge 50, boxEndEdge = SpacedEdge 100} + ] + , fragmentRect = Rect {x_origin = 2631, y_origin = 0, x_size = 231, y_size = -1121} + , fragmentPen = (0, -932) + , fragmentGlyphs = + [ (GlyphInfo {codepoint = 3, cluster = 11, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 231, y_advance = 0, x_offset = 0, y_offset = 0}) + ] + } + , Fragment + { fragmentUserData = "text3" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 2962, y_origin = 0, x_size = 1673, 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}) + , (GlyphInfo {codepoint = 82, cluster = 13, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 573, y_advance = 0, x_offset = 0, y_offset = 0}) + , (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 f6e226c..b2ba52f 100644 --- a/test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs +++ b/test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs @@ -1,5 +1,6 @@ module Data.Text.ParagraphLayout.Rich.ParagraphData - ( hardBoxBreakLTRParagraph + ( emptyBoxParagraph + , hardBoxBreakLTRParagraph , hardBoxBreakRTLParagraph , intraWordBreakParagraph , loremIpsumParagraph @@ -15,6 +16,7 @@ module Data.Text.ParagraphLayout.Rich.ParagraphData , newline2Paragraph , newline2TextParagraph , softBreakParagraph + , spaceBoxParagraph ) where @@ -48,6 +50,22 @@ box label boxOpts textOpts nodes = InlineBox label (Box nodes textOpts) boxOpts text :: d -> String -> InnerNode Text d text label contents = TextSequence label (pack contents) +emptyBoxParagraph :: Font -> ParagraphOptions -> Paragraph String +emptyBoxParagraph font = constructParagraph + (pack "prefix") + (rootBox t + [ text "text1" "empty " + , box "box1" b t + [ text "emptyText" "" + ] + , text "text2" " box" + ] + ) + (pack "suffix") + where + b = b_ { boxSpacing = BoxSpacingLeftRight 50 100 } + t = tLTR { textFont = font, textLanguage = "en" } + hardBoxBreakLTRParagraph :: Font -> ParagraphOptions -> Paragraph String hardBoxBreakLTRParagraph font = constructParagraph (pack "prefix") @@ -314,3 +332,19 @@ softBreakParagraph spacing font = constructParagraph where b = b_ { boxSpacing = BoxSpacingLeftRight spacing spacing } t = tLTR { textFont = font, textLanguage = "en" } + +spaceBoxParagraph :: Font -> ParagraphOptions -> Paragraph String +spaceBoxParagraph font = constructParagraph + (pack "prefix") + (rootBox t + [ text "text1" "space" + , box "box1" b t + [ text "text2" " " + ] + , text "text3" "box" + ] + ) + (pack "suffix") + where + b = b_ { 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 6c77add..9df9eca 100644 --- a/test/Data/Text/ParagraphLayout/RichSpec.hs +++ b/test/Data/Text/ParagraphLayout/RichSpec.hs @@ -166,6 +166,24 @@ spec = do let result = layoutRich input result `shouldBeGolden` "mixedScriptWrap" + it "handles empty box in the middle of the line" $ do + let opts = defaultParagraphOptions + { paragraphAlignment = AlignStart + , paragraphMaxWidth = 5193 + } + let input = emptyBoxParagraph font opts + let result = layoutRich input + result `shouldBeGolden` "emptyBoxMiddle" + + it "handles space box in the middle of the line" $ do + let opts = defaultParagraphOptions + { paragraphAlignment = AlignStart + , paragraphMaxWidth = 4635 + } + let input = spaceBoxParagraph font opts + let result = layoutRich input + result `shouldBeGolden` "spaceBoxMiddle" + it "handles nested boxes" $ do let opts = defaultParagraphOptions { paragraphAlignment = AlignStart -- 2.30.2