From 81d758baf4c7f7ab803edccb4dd1bb7e82a4753d Mon Sep 17 00:00:00 2001 From: Jaro Date: Fri, 9 Jun 2023 03:31:42 +0200 Subject: [PATCH] Test handling of empty lines. --- .../newline1Paragraph.golden | 15 ++++++++ .../newline1TextParagraph.golden | 26 ++++++++++++++ .../newline2Paragraph.golden | 25 +++++++++++++ .../newline2TextParagraph.golden | 36 +++++++++++++++++++ .../ParagraphLayout/Rich/ParagraphData.hs | 36 +++++++++++++++++++ test/Data/Text/ParagraphLayout/RichSpec.hs | 24 +++++++++++++ 6 files changed, 162 insertions(+) create mode 100644 .golden/richParagraphLayout/newline1Paragraph.golden create mode 100644 .golden/richParagraphLayout/newline1TextParagraph.golden create mode 100644 .golden/richParagraphLayout/newline2Paragraph.golden create mode 100644 .golden/richParagraphLayout/newline2TextParagraph.golden diff --git a/.golden/richParagraphLayout/newline1Paragraph.golden b/.golden/richParagraphLayout/newline1Paragraph.golden new file mode 100644 index 0000000..e860988 --- /dev/null +++ b/.golden/richParagraphLayout/newline1Paragraph.golden @@ -0,0 +1,15 @@ +ParagraphLayout + { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -1500} + , paragraphFragments = + [ Fragment + { fragmentUserData = "text" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -1500} + , fragmentPen = (0, -1085) + , fragmentGlyphs = + [] + } + ] + } diff --git a/.golden/richParagraphLayout/newline1TextParagraph.golden b/.golden/richParagraphLayout/newline1TextParagraph.golden new file mode 100644 index 0000000..ad9437b --- /dev/null +++ b/.golden/richParagraphLayout/newline1TextParagraph.golden @@ -0,0 +1,26 @@ +ParagraphLayout + { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 351, y_size = -3000} + , paragraphFragments = + [ Fragment + { fragmentUserData = "text" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -1500} + , fragmentPen = (0, -1085) + , fragmentGlyphs = + [] + } + , Fragment + { fragmentUserData = "text" + , fragmentLine = 2 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = -1500, x_size = 351, y_size = -1500} + , fragmentPen = (0, -1085) + , fragmentGlyphs = + [ (GlyphInfo {codepoint = 26, cluster = 7, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 351, y_advance = 0, x_offset = 0, y_offset = 0}) + ] + } + ] + } diff --git a/.golden/richParagraphLayout/newline2Paragraph.golden b/.golden/richParagraphLayout/newline2Paragraph.golden new file mode 100644 index 0000000..d506371 --- /dev/null +++ b/.golden/richParagraphLayout/newline2Paragraph.golden @@ -0,0 +1,25 @@ +ParagraphLayout + { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -3000} + , paragraphFragments = + [ Fragment + { fragmentUserData = "text" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -1500} + , fragmentPen = (0, -1085) + , fragmentGlyphs = + [] + } + , Fragment + { fragmentUserData = "text" + , fragmentLine = 2 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = -1500, x_size = 0, y_size = -1500} + , fragmentPen = (0, -1085) + , fragmentGlyphs = + [] + } + ] + } diff --git a/.golden/richParagraphLayout/newline2TextParagraph.golden b/.golden/richParagraphLayout/newline2TextParagraph.golden new file mode 100644 index 0000000..3776a88 --- /dev/null +++ b/.golden/richParagraphLayout/newline2TextParagraph.golden @@ -0,0 +1,36 @@ +ParagraphLayout + { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 351, y_size = -4500} + , paragraphFragments = + [ Fragment + { fragmentUserData = "text" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -1500} + , fragmentPen = (0, -1085) + , fragmentGlyphs = + [] + } + , Fragment + { fragmentUserData = "text" + , fragmentLine = 2 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = -1500, x_size = 0, y_size = -1500} + , fragmentPen = (0, -1085) + , fragmentGlyphs = + [] + } + , Fragment + { fragmentUserData = "text" + , fragmentLine = 3 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = -3000, x_size = 351, y_size = -1500} + , fragmentPen = (0, -1085) + , fragmentGlyphs = + [ (GlyphInfo {codepoint = 26, cluster = 8, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 351, 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 dfa020f..f6e226c 100644 --- a/test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs +++ b/test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs @@ -10,6 +10,10 @@ module Data.Text.ParagraphLayout.Rich.ParagraphData , mixedSizesParagraph , nestedBoxesParagraph , neutralDirectionParagraph + , newline1Paragraph + , newline1TextParagraph + , newline2Paragraph + , newline2TextParagraph , softBreakParagraph ) where @@ -261,6 +265,38 @@ neutralDirectionParagraph dir font = constructParagraph where t = (defaultTextOptions dir) { textFont = font, textLanguage = "zxx" } +newline1Paragraph :: Font -> ParagraphOptions -> Paragraph String +newline1Paragraph font = constructParagraph + (pack "prefix") + (rootBox t [ text "text" "\n" ]) + (pack "suffix") + where + t = tRTL { textFont = font, textLanguage = "zxx" } + +newline1TextParagraph :: Font -> ParagraphOptions -> Paragraph String +newline1TextParagraph font = constructParagraph + (pack "prefix") + (rootBox t [ text "text" "\nt" ]) + (pack "suffix") + where + t = tRTL { textFont = font, textLanguage = "zxx" } + +newline2Paragraph :: Font -> ParagraphOptions -> Paragraph String +newline2Paragraph font = constructParagraph + (pack "prefix") + (rootBox t [ text "text" "\n\n" ]) + (pack "suffix") + where + t = tRTL { textFont = font, textLanguage = "zxx" } + +newline2TextParagraph :: Font -> ParagraphOptions -> Paragraph String +newline2TextParagraph font = constructParagraph + (pack "prefix") + (rootBox t [ text "text" "\n\nt" ]) + (pack "suffix") + where + t = tRTL { textFont = font, textLanguage = "zxx" } + softBreakParagraph :: Int32 -> Font -> ParagraphOptions -> Paragraph String softBreakParagraph spacing font = constructParagraph (pack "prefix") diff --git a/test/Data/Text/ParagraphLayout/RichSpec.hs b/test/Data/Text/ParagraphLayout/RichSpec.hs index b218f32..3dd7f9f 100644 --- a/test/Data/Text/ParagraphLayout/RichSpec.hs +++ b/test/Data/Text/ParagraphLayout/RichSpec.hs @@ -127,6 +127,30 @@ spec = do describe "with Arabic font" $ do font <- runIO $ loadFont arabicFont 0 testingOptions + it "makes space for one newline" $ do + let opts = defaultParagraphOptions + let input = newline1Paragraph font opts + let result = layoutRich input + result `shouldBeGolden` "newline1Paragraph" + + it "makes space for one newline plus text" $ do + let opts = defaultParagraphOptions + let input = newline1TextParagraph font opts + let result = layoutRich input + result `shouldBeGolden` "newline1TextParagraph" + + it "makes space for two newlines" $ do + let opts = defaultParagraphOptions + let input = newline2Paragraph font opts + let result = layoutRich input + result `shouldBeGolden` "newline2Paragraph" + + it "makes space for two newlines plus text" $ do + let opts = defaultParagraphOptions + let input = newline2TextParagraph font opts + let result = layoutRich input + result `shouldBeGolden` "newline2TextParagraph" + it "handles hard break in RTL boxes" $ do let opts = defaultParagraphOptions let input = hardBoxBreakRTLParagraph font opts -- 2.30.2