diff options
| author | tv <tv@krebsco.de> | 2026-03-05 21:01:36 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-03-06 20:42:17 +0100 |
| commit | 809465f70417ca3c7122f635ea6a1f15914b2976 (patch) | |
| tree | dcc6636363b71b8ef78f5592874a69e1e220be53 /TextViewport.hs | |
| parent | 9859fbd33efc4ec5050d8864593156584543cb05 (diff) | |
bump
Diffstat (limited to 'TextViewport.hs')
| -rw-r--r-- | TextViewport.hs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/TextViewport.hs b/TextViewport.hs index f39ee84..b97936e 100644 --- a/TextViewport.hs +++ b/TextViewport.hs @@ -87,14 +87,25 @@ renderItem width itemIx (Item txt strategy) = -------------------------------------------------------------------------------- applyStrategy :: WrapStrategy -> Int -> Text -> [(Int, Text)] -applyStrategy NoWrap w t = - [(0, T.take w t)] +applyStrategy NoWrap _ t = + let ls = T.splitOn "\n" t + in zip (scanOffsets ls) ls applyStrategy FixedWidthWrap w t = - zip [0,w..] (chunkFixed w t) + concatMap chunkOne (T.splitOn "\n" t) + where + chunkOne line = + let chunks = chunkFixed w line + offs = scanOffsets chunks + in zip offs chunks applyStrategy (HyphenateWrap dict) w t = - hyphenateWrapped dict w t + concatMap wrapOne (T.splitOn "\n" t) + where + wrapOne line = + let chunks = wrapWithHyphenationTeXLite dict w line + offsets = scanOffsets chunks + in zip offsets chunks chunkFixed :: Int -> Text -> [Text] chunkFixed w t @@ -111,12 +122,6 @@ chunkFixed w t -- Hyphenation-aware wrapping (TeX-lite) -------------------------------------------------------------------------------- -hyphenateWrapped :: H.Hyphenator -> Int -> Text -> [(Int, Text)] -hyphenateWrapped dict w txt = - let chunks = wrapWithHyphenationTeXLite dict w txt - offsets = scanOffsets chunks - in zip offsets chunks - scanOffsets :: [Text] -> [Int] scanOffsets [] = [] scanOffsets (x:xs) = 0 : go (T.length x) xs @@ -160,9 +165,7 @@ lineCandidates dict width = go [] [] -- hyphenation candidates for this word hyphs = hyphenateWord dict w hyphCands = - [ let preTxt = baseTxt <> space <> pre <> "-" - preLen = T.length preTxt - in (preTxt, suf : ws, True) + [ (preTxt, suf : ws, True) | (pre, suf) <- hyphs , not (T.null pre) , let preTxt = baseTxt <> space <> pre <> "-" |
