aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-02-16 20:58:54 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-02-16 20:58:54 +0000
commit251c3259030b67d4821fec98d8c882cf7a7f0fd0 (patch)
treee6b53ff93f1256f9599eeb2173e630e3c30932e2 /server/src
parent5f0351bb2a7f20b72b6a001e8891263d751c247a (diff)
downloadthermoprint-251c3259030b67d4821fec98d8c882cf7a7f0fd0.tar
thermoprint-251c3259030b67d4821fec98d8c882cf7a7f0fd0.tar.gz
thermoprint-251c3259030b67d4821fec98d8c882cf7a7f0fd0.tar.bz2
thermoprint-251c3259030b67d4821fec98d8c882cf7a7f0fd0.tar.xz
thermoprint-251c3259030b67d4821fec98d8c882cf7a7f0fd0.zip
Transition to wrapping only at word-boundaries
Diffstat (limited to 'server/src')
-rw-r--r--server/src/Thermoprint/Server/Printer/Generic.hs13
1 files changed, 7 insertions, 6 deletions
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
170 where 170 where
171 insertWord doc 171 insertWord doc
172 | TL.null wordTail = checkBreak $ doc' 172 | TL.null wordTail = checkBreak $ doc'
173 | otherwise = checkBreak $ doc' { remainingSpace = space doc' - (wordTail' `mod` space doc') 173 | otherwise = checkBreak $ doc { remainingSpace = space doc - (word' `mod` space doc)
174 , lines = (lines doc' |> currentLine doc') <> cs 174 , lines = (lines doc |> currentLine doc) <> cs
175 , currentLine = c 175 , currentLine = c
176 , overflows = overflows doc' + 1 + (toInteger $ Seq.length cs) 176 , overflows = overflows doc + (toInteger $ Seq.length cs)
177 } 177 }
178 where 178 where
179 (wordInit, wordTail) = TL.splitAt (fromInteger $ remainingSpace doc) word 179 (wordInit, wordTail) = TL.splitAt (fromInteger $ remainingSpace doc) word
180 word' = toInteger $ TL.length word
180 wordInit' = toInteger $ TL.length wordInit 181 wordInit' = toInteger $ TL.length wordInit
181 wordTail' = toInteger $ TL.length wordTail 182 wordTail' = toInteger $ TL.length wordTail
182 doc' = insertInit doc 183 doc' = insertInit doc
183 insertInit doc@(Doc{..}) = doc { remainingSpace = remainingSpace - wordInit' 184 insertInit doc@(Doc{..}) = doc { remainingSpace = remainingSpace - wordInit'
184 , currentLine = currentLine >> encode'' wordInit 185 , currentLine = currentLine >> encode'' wordInit
185 } 186 }
186 (cs :> c) = viewr . Seq.fromList . map encode'' $ TL.chunksOf (fromInteger $ space doc) wordTail 187 (cs :> c) = viewr . Seq.fromList . map encode'' $ TL.chunksOf (fromInteger $ space doc) word
187 checkBreak doc@(Doc{..}) 188 checkBreak doc@(Doc{..})
188 | remainingSpace == 0 = doc { remainingSpace = space 189 | remainingSpace == 0 = doc { remainingSpace = space
189 , lines = lines |> currentLine 190 , lines = lines |> currentLine