From 5e218e2739e4175ea58ef98686426d80919e2f64 Mon Sep 17 00:00:00 2001 From: Jaro Date: Sat, 27 May 2023 17:18:24 +0200 Subject: [PATCH] Test with only directionally neutral characters. --- .../neutralDirectionLTR.golden | 18 ++++++++++++++++++ .../neutralDirectionRTL.golden | 18 ++++++++++++++++++ .../Text/ParagraphLayout/Rich/ParagraphData.hs | 12 ++++++++++++ test/Data/Text/ParagraphLayout/RichSpec.hs | 12 ++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 .golden/richParagraphLayout/neutralDirectionLTR.golden create mode 100644 .golden/richParagraphLayout/neutralDirectionRTL.golden diff --git a/.golden/richParagraphLayout/neutralDirectionLTR.golden b/.golden/richParagraphLayout/neutralDirectionLTR.golden new file mode 100644 index 0000000..76079bf --- /dev/null +++ b/.golden/richParagraphLayout/neutralDirectionLTR.golden @@ -0,0 +1,18 @@ +ParagraphLayout + { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 2003, y_size = -1500} + , paragraphFragments = + [ Fragment + { fragmentUserData = "text" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 2003, y_size = -1500} + , fragmentPen = (0, -1085) + , fragmentGlyphs = + [ (GlyphInfo {codepoint = 91, cluster = 3, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 803, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 1392, cluster = 6, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 600, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 148, cluster = 9, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 600, y_advance = 0, x_offset = 0, y_offset = 0}) + ] + } + ] + } diff --git a/.golden/richParagraphLayout/neutralDirectionRTL.golden b/.golden/richParagraphLayout/neutralDirectionRTL.golden new file mode 100644 index 0000000..5fe8599 --- /dev/null +++ b/.golden/richParagraphLayout/neutralDirectionRTL.golden @@ -0,0 +1,18 @@ +ParagraphLayout + { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 2003, y_size = -1500} + , paragraphFragments = + [ Fragment + { fragmentUserData = "text" + , fragmentLine = 1 + , fragmentAncestorBoxes = + [] + , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 2003, y_size = -1500} + , fragmentPen = (0, -1085) + , fragmentGlyphs = + [ (GlyphInfo {codepoint = 147, cluster = 9, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 600, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 1392, cluster = 6, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 600, y_advance = 0, x_offset = 0, y_offset = 0}) + , (GlyphInfo {codepoint = 91, cluster = 3, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 803, 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 b13cebb..6c61b37 100644 --- a/test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs +++ b/test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs @@ -7,6 +7,7 @@ module Data.Text.ParagraphLayout.Rich.ParagraphData , mixedScriptParagraph , mixedSizesParagraph , nestedBoxesParagraph + , neutralDirectionParagraph , softBreakParagraph ) where @@ -194,6 +195,17 @@ nestedBoxesParagraph font = constructParagraph where t = tLTR { textFont = font, textLanguage = "en" } +-- | A paragraph that contains only characters in the BiDi class +-- /Other neutrals (ON)/. This includes characters that can be mirrored. +neutralDirectionParagraph :: Direction -> Font -> ParagraphOptions -> + Paragraph String +neutralDirectionParagraph dir font = constructParagraph + (pack "_»") + (rootBox t [text "text" "…―>"]) + (pack "*†") + where + t = (defaultTextOptions dir) { 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 c9f28d1..fb50170 100644 --- a/test/Data/Text/ParagraphLayout/RichSpec.hs +++ b/test/Data/Text/ParagraphLayout/RichSpec.hs @@ -122,6 +122,18 @@ spec = do let result = layoutRich input result `shouldBeGolden` "hardBoxBreakRTL" + it "handles neutral characters in RTL paragraph" $ do + let opts = defaultParagraphOptions + let input = neutralDirectionParagraph DirRTL font opts + let result = layoutRich input + result `shouldBeGolden` "neutralDirectionRTL" + + it "handles neutral characters in LTR paragraph" $ do + let opts = defaultParagraphOptions + let input = neutralDirectionParagraph DirLTR font opts + let result = layoutRich input + result `shouldBeGolden` "neutralDirectionLTR" + it "handles simple mixed direction in RTL paragraph" $ do let opts = defaultParagraphOptions let input = mixedDirectionSimpleParagraph DirRTL font opts -- 2.30.2