@@ -136,6 +136,7 @@ build_spans pic region = do
136136 (0,0)
137137 0
138138 (region_width region)
139+ (fromEnum $ region_height region)
139140 -- Fill in any unspecified columns with the background pattern.
140141 forM_ [0 .. (fromEnum $ region_height region - 1)] $! \row -> do
141142 end_x <- Vector.read mrow_ops row >>= return . span_ops_effected_columns
@@ -145,7 +146,7 @@ build_spans pic region = do
145146 else return ()
146147 return mrow_ops
147148
148−row_ops_for_image :: MRowOps s -> Image -> Background -> DisplayRegion -> (Word, Word) -> Int -> Word -> ST s (Word, Word)
149+row_ops_for_image :: MRowOps s -> Image -> Background -> DisplayRegion -> (Word, Word) -> Int -> Word -> Int -> ST s (Word, Word)
149150row_ops_for_image mrow_ops -- the image to output the ops to
150151 image -- the image to rasterize in column order to mrow_ops
151152 bg -- the background fill
@@ -153,7 +154,9 @@ row_ops_for_image mrow_ops -- the image to output the ops t
153154 skip_dim@(skip_row,skip_col) -- the number of rows
154155 y -- ???
155156 remaining_columns -- ???
157+ remain_rows
156158 | remaining_columns == 0 = return skip_dim
159+ | remain_rows == 0 = return skip_dim
157160 | y >= fromEnum (region_height region) = return skip_dim
158161 | otherwise = case image of
159162 EmptyImage -> return skip_dim
@@ -174,30 +177,31 @@ row_ops_for_image mrow_ops -- the image to output the ops t
174177 skip_dim
175178 y
176179 remaining_columns
180+ remain_rows
181+ let top_height = (fromEnum $! image_height top_image) - (fromEnum $! skip_row - skip_row')
177182 (skip_row'',skip_col'') <- row_ops_for_image mrow_ops
178183 bottom_image
179184 bg
180185 region
181186 (skip_row', skip_col)
182− (y + (fromEnum $! image_height top_image) - (fromEnum $! skip_row - skip_row'))
187+ (y + top_height)
183188 remaining_columns
189+ (remain_rows - top_height)
184190 return (skip_row'', min skip_col' skip_col'')
185191 HorizJoin l r _ _ -> do
186− (skip_row',skip_col') <- row_ops_for_image mrow_ops l bg region skip_dim y remaining_columns
192+ (skip_row',skip_col') <- row_ops_for_image mrow_ops l bg region skip_dim y remaining_columns remain_rows
187193 -- Don't output the right part unless there is at least a single column left after
188194 -- outputting the left part.
189195 if image_width l - (skip_col - skip_col') > remaining_columns
190196 then return (skip_row,skip_col')
191197 else do
192− (skip_row'',skip_col'') <- row_ops_for_image mrow_ops r bg region (skip_row, skip_col') y (remaining_columns - image_width l + (skip_col - skip_col'))
198+ (skip_row'',skip_col'') <- row_ops_for_image mrow_ops r bg region (skip_row, skip_col') y (remaining_columns - image_width l + (skip_col - skip_col')) remain_rows
193199 return (min skip_row' skip_row'', skip_col'')
194200 BGFill width height -> do
195201 let min_height = if y + (fromEnum height) > (fromEnum $! region_height region)
196202 then region_height region - (toEnum y)
197− else height
198− min_width = if width > remaining_columns
199− then remaining_columns
200− else width
203+ else min height (toEnum remain_rows)
204+ min_width = min width remaining_columns
201205 actual_height = if skip_row > min_height
202206 then 0
203207 else min_height - skip_row
@@ -216,25 +220,23 @@ row_ops_for_image mrow_ops -- the image to output the ops t
216220 if dx < 0
217221 -- Translation left
218222 -- Extract the delta and add it to skip_col.
219− then row_ops_for_image mrow_ops (translate (0, dy) i) bg region (skip_row, skip_col + dw) y remaining_columns
223+ then row_ops_for_image mrow_ops (translate (0, dy) i) bg region (skip_row, skip_col + dw) y remaining_columns remain_rows
220224 -- Translation right
221225 else if dy < 0
222226 -- Translation up
223227 -- Extract the delta and add it to skip_row.
224− then row_ops_for_image mrow_ops (translate (dx, 0) i) bg region (skip_row + dh, skip_col) y remaining_columns
228+ then row_ops_for_image mrow_ops (translate (dx, 0) i) bg region (skip_row + dh, skip_col) y remaining_columns remain_rows
225229 -- Translation down
226230 -- Pad the start of lines and above the image with a
227− -- background_fill image.
228− else row_ops_for_image mrow_ops (background_fill ow dh <-> (background_fill dw ih <|> i)) bg region skip_dim y remaining_columns
231+ -- background_fill image
232+ else row_ops_for_image mrow_ops (background_fill ow dh <-> (background_fill dw ih <|> i)) bg region skip_dim y remaining_columns remain_rows
229233 where
230234 dw = toEnum $ abs dx
231235 dh = toEnum $ abs dy
232236 ow = image_width image
233237 ih = image_height i
234238 ImageCrop (max_w,max_h) i ->
235− if y >= fromEnum max_h
236− then return skip_dim
237− else row_ops_for_image mrow_ops i bg region skip_dim y (min remaining_columns max_w)
239+ row_ops_for_image mrow_ops i bg region skip_dim y (min remaining_columns max_w) (min remain_rows $ fromEnum max_h)
238240 ImagePad (min_w,min_h) i -> do
239241 let hpad = if image_width i < min_w
240242 then background_fill (min_w - image_width i) (image_height i)
@@ -242,7 +244,7 @@ row_ops_for_image mrow_ops -- the image to output the ops t
242244 let vpad = if image_height i < min_h
243245 then background_fill (image_width i) (min_h - image_height i)
244246 else empty_image
245− row_ops_for_image mrow_ops ((i <|> hpad) <-> vpad) bg region skip_dim y remaining_columns
247+ row_ops_for_image mrow_ops ((i <|> hpad) <-> vpad) bg region skip_dim y remaining_columns remain_rows
246248
247249snoc_text_span :: Attr -- the display attributes of the text span
248250 -> DisplayString -- the text to output