From 5fa1efb1b56816aa7c3034856fac9ef709889e99 Mon Sep 17 00:00:00 2001 From: Jaro Date: Fri, 10 Mar 2023 07:45:14 +0100 Subject: [PATCH] Decompose ProtoFragment construction. --- src/Data/Text/ParagraphLayout/Internal/Plain.hs | 6 ++---- .../Text/ParagraphLayout/Internal/ProtoFragment.hs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Data/Text/ParagraphLayout/Internal/Plain.hs b/src/Data/Text/ParagraphLayout/Internal/Plain.hs index 4fa5119..9392d2c 100644 --- a/src/Data/Text/ParagraphLayout/Internal/Plain.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Plain.hs @@ -20,7 +20,7 @@ import Data.Text.Glyphize ,Direction(..) ,FontExtents(..) ,GlyphInfo - ,GlyphPos(x_advance) + ,GlyphPos ,defaultBuffer ,fontExtentsForDir ,shape @@ -207,10 +207,8 @@ breakSplits closed (x:xs) = splits ++ breakSplits (x:closed) xs layoutRunH :: WithSpan Run -> WithSpan PF.ProtoFragment layoutRunH (WithSpan rs run) = WithSpan rs pf where - pf = PF.ProtoFragment dir totalX glyphs + pf = PF.protoFragmentH dir glyphs glyphs = shapeRun (WithSpan rs run) - positions = map snd glyphs - totalX = sum $ map x_advance positions dir = runDirection run -- | Calculate layout for the given run independently of its position. diff --git a/src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs b/src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs index c5ae878..1a7b8cc 100644 --- a/src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs +++ b/src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs @@ -1,8 +1,11 @@ -module Data.Text.ParagraphLayout.Internal.ProtoFragment (ProtoFragment(..)) +module Data.Text.ParagraphLayout.Internal.ProtoFragment + (ProtoFragment(direction, advance, glyphs) + ,protoFragmentH + ) where import Data.Int (Int32) -import Data.Text.Glyphize (Direction, GlyphInfo, GlyphPos) +import Data.Text.Glyphize (Direction, GlyphInfo, GlyphPos(x_advance)) -- | A box fragment which has not been positioned yet. data ProtoFragment = ProtoFragment @@ -13,3 +16,10 @@ data ProtoFragment = ProtoFragment -- depending on the text direction. , glyphs :: [(GlyphInfo, GlyphPos)] } + +-- | Construct a `ProtoFragment`, automatically calculating the total advance +-- for a horizontal text direction. +protoFragmentH :: Maybe Direction -> [(GlyphInfo, GlyphPos)] -> ProtoFragment +protoFragmentH dir gs = ProtoFragment dir adv gs + where + adv = sum $ map (x_advance . snd) gs -- 2.30.2