From 251c3259030b67d4821fec98d8c882cf7a7f0fd0 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 16 Feb 2016 20:58:54 +0000 Subject: Transition to wrapping only at word-boundaries --- server/src/Thermoprint/Server/Printer/Generic.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'server/src') diff --git a/server/src/Thermoprint/Server/Printer/Generic.hs b/server/src/Thermoprint/Server/Printer/Generic.hs index 24150cf..df84e06 100644 --- a/server/src/Thermoprint/Server/Printer/Generic.hs +++ b/server/src/Thermoprint/Server/Printer/Generic.hs @@ -170,20 +170,21 @@ renderLine (cotext . Line -> word) = modify' $ insertWord where insertWord doc | TL.null wordTail = checkBreak $ doc' - | otherwise = checkBreak $ doc' { remainingSpace = space doc' - (wordTail' `mod` space doc') - , lines = (lines doc' |> currentLine doc') <> cs - , currentLine = c - , overflows = overflows doc' + 1 + (toInteger $ Seq.length cs) - } + | otherwise = checkBreak $ doc { remainingSpace = space doc - (word' `mod` space doc) + , lines = (lines doc |> currentLine doc) <> cs + , currentLine = c + , overflows = overflows doc + (toInteger $ Seq.length cs) + } where (wordInit, wordTail) = TL.splitAt (fromInteger $ remainingSpace doc) word + word' = toInteger $ TL.length word wordInit' = toInteger $ TL.length wordInit wordTail' = toInteger $ TL.length wordTail doc' = insertInit doc insertInit doc@(Doc{..}) = doc { remainingSpace = remainingSpace - wordInit' , currentLine = currentLine >> encode'' wordInit } - (cs :> c) = viewr . Seq.fromList . map encode'' $ TL.chunksOf (fromInteger $ space doc) wordTail + (cs :> c) = viewr . Seq.fromList . map encode'' $ TL.chunksOf (fromInteger $ space doc) word checkBreak doc@(Doc{..}) | remainingSpace == 0 = doc { remainingSpace = space , lines = lines |> currentLine -- cgit v1.2.3