~jaro/balkon

8260355fb3f33df740336431f49546ec581eef92 — Jaro 1 year, 9 months ago d1b417e
Store span index in ResolvedSpan.
M src/Data/Text/ParagraphLayout/Plain.hs => src/Data/Text/ParagraphLayout/Plain.hs +13 -2
@@ 93,6 93,15 @@ data WithSpan a = WithSpan RS.ResolvedSpan a
instance Functor WithSpan where
    fmap f (WithSpan s a) = WithSpan s (f a)

splitBySpanIndex :: [WithSpan a] -> [[a]]
splitBySpanIndex xs = [getBySpanIndex i xs | i <- [0..]]

getBySpanIndex :: Int -> [WithSpan a] -> [a]
getBySpanIndex idx xs = map contents $ filter matchingIndex $ xs
    where
        matchingIndex (WithSpan rs _) = (RS.spanIndex rs) == idx
        contents (WithSpan _ x) = x

spanRects :: SpanLayout -> [Rect Int32]
spanRects (SpanLayout frags) = map fragmentRect frags



@@ 190,9 199,11 @@ shapeRun (WithSpan rs run) = shape font buffer features
resolveSpans :: Paragraph -> [RS.ResolvedSpan]
resolveSpans (Paragraph arr off spans opts) = do
    let texts = cuts arr off spans
    (s, t) <- zip spans texts
    let indexes = [0..]
    (s, t, i) <- zip3 spans texts indexes
    return RS.ResolvedSpan
        { RS.spanText = t
        { RS.spanIndex = i
        , RS.spanText = t
        , RS.spanFont = paragraphFont opts
        , RS.spanLineHeight = paragraphLineHeight opts
        , RS.spanLanguage = spanLanguage s

M src/Data/Text/ParagraphLayout/ResolvedSpan.hs => src/Data/Text/ParagraphLayout/ResolvedSpan.hs +6 -2
@@ 9,9 9,13 @@ import Data.Text.ParagraphLayout.LineHeight
-- | Internal structure containing resolved values that may be shared with
-- other spans across the paragraph.
data ResolvedSpan = ResolvedSpan
    { spanText :: Text
    { spanIndex :: Int
    , spanText :: Text
    , spanFont :: Font
    , spanLineHeight :: LineHeight
    , spanLanguage :: String
    }
    deriving (Eq, Show)
    deriving (Show)

instance Eq ResolvedSpan where
    a == b = spanIndex a == spanIndex b

M test/Data/Text/ParagraphLayout/SpanData.hs => test/Data/Text/ParagraphLayout/SpanData.hs +6 -3
@@ 12,7 12,8 @@ import Data.Text.ParagraphLayout.ResolvedSpan (ResolvedSpan(..))

emptySpan :: Font -> ResolvedSpan
emptySpan font = ResolvedSpan
    { spanText = pack ""
    { spanIndex = 0
    , spanText = pack ""
    , spanFont = font
    , spanLineHeight = Normal
    , spanLanguage = "en"


@@ 20,7 21,8 @@ emptySpan font = ResolvedSpan

czechHello :: Font -> ResolvedSpan
czechHello font = ResolvedSpan
    { spanText = pack "Ahoj, světe!"
    { spanIndex = 0
    , spanText = pack "Ahoj, světe!"
    , spanFont = font
    , spanLineHeight = Normal
    , spanLanguage = "cs"


@@ 28,7 30,8 @@ czechHello font = ResolvedSpan

serbianMixedScript :: Font -> ResolvedSpan
serbianMixedScript font = ResolvedSpan
    { spanText = pack "Vikipedija (Википедија)"
    { spanIndex = 0
    , spanText = pack "Vikipedija (Википедија)"
    , spanFont = font
    , spanLineHeight = Normal
    , spanLanguage = "sr"