@@ -111,7 +111,7 @@ build_spans pic region = do
111111 -- The ops builder recursively descends the image and outputs span ops that would
112112 -- display that image. The number of columns remaining in this row before exceeding the
113113 -- bounds is also provided. This is used to clip the span ops produced.
114− ops_for_row mrow_ops (pic_background pic) region (pic_image pic) 0 0 0 (region_width region)
114+ _ <- ops_for_row mrow_ops (pic_background pic) region (pic_image pic) 0 0 0 (region_width region)
115115 -- Fill in any unspecified columns with the background pattern.
116116 forM_ [0 .. region_height region - 1] $ \row -> do
117117 end_x <- readSTArray mrow_ops row >>= return . span_ops_effected_columns
@@ -123,39 +123,51 @@ build_spans pic region = do
123123
124124type MRowOps s = STArray s Word SpanOps
125125
126−ops_for_row :: MRowOps s -> Background -> DisplayRegion -> Image -> Word -> Word -> Word -> Word -> ST s ()
126+ops_for_row :: MRowOps s -> Background -> DisplayRegion -> Image -> Word -> Word -> Word -> Word -> ST s Word
127127ops_for_row mrow_ops bg region image skip_row skip_col y remaining_columns
128− | remaining_columns == 0 = return ()
129− | y >= region_height region = return ()
128+ | remaining_columns == 0 = return skip_row
129+ | y >= region_height region = return skip_row
130130 | otherwise = case image of
131− EmptyImage -> return ()
131+ EmptyImage -> return skip_row
132132 -- The width provided is the number of columns this text span will occupy when displayed.
133133 -- if this is greater than the number of remaining columsn the output has to be produced a
134134 -- character at a time.
135135 HorizText a text_str _ _ -> do
136− if y < skip_row
137− then return ()
138− else snoc_text_span a text_str mrow_ops skip_col y remaining_columns
136+ if skip_row > 0
137+ then return $ skip_row - 1
138+ else do
139+ snoc_text_span a text_str mrow_ops skip_col y remaining_columns
140+ return skip_row
139141 VertJoin t b _ _ -> do
140− ops_for_row mrow_ops bg region t skip_row skip_col y remaining_columns
141− ops_for_row mrow_ops bg region b skip_row skip_col (y + image_height t) remaining_columns
142+ skip_row' <- ops_for_row mrow_ops bg region t skip_row skip_col y remaining_columns
143+ ops_for_row mrow_ops bg region b skip_row' skip_col (y + image_height t - (skip_row - skip_row')) remaining_columns
142144 HorizJoin l r _ _ -> do
143− ops_for_row mrow_ops bg region l skip_row skip_col y remaining_columns
145+ skip_row' <- ops_for_row mrow_ops bg region l skip_row skip_col y remaining_columns
144146 -- Don't output the right part unless there is at least a single column left after
145147 -- outputting the left part.
146− if image_width l < remaining_columns
147− then ops_for_row mrow_ops bg region r skip_row skip_col y (remaining_columns - image_width l)
148− else return ()
148+ if image_width l > remaining_columns
149+ then return skip_row'
150+ else do
151+ skip_row'' <- ops_for_row mrow_ops bg region r skip_row skip_col y (remaining_columns - image_width l)
152+ return $ min skip_row' skip_row''
149153 BGFill width height -> do
150− let actual_height = if y + height > region_height region
151− then region_height region - y
152− else height
153− actual_width = if width > remaining_columns
154− then remaining_columns
155− else width
156− -- XXX: Do we need to notify this of skip_rows or skip_cols?
154+ let min_height = if y + height > region_height region
155+ then region_height region - y
156+ else height
157+ min_width = if width > remaining_columns
158+ then remaining_columns
159+ else width
160+ actual_height = if skip_row > min_height
161+ then 0
162+ else min_height - skip_row
163+ actual_width = if skip_col > min_width
164+ then 0
165+ else min_width - skip_col
157166 forM_ [y .. y + actual_height - 1] $ \y' -> snoc_bg_fill mrow_ops bg actual_width y'
158− Translation (dx,dy) i ->
167+ if actual_height > skip_row
168+ then return 0
169+ else return $ skip_row - min_height
170+ Translation (dx,dy) i -> do
159171 if dx < 0
160172 -- Translation left
161173 -- Extract the delta and add it to skip_col.