VOID TextFlow::position_lines(FramePtr frame, VERT_ALIGN_TYPE align_type) { PCOORD y_offset; L_INDEX l_index; LINE_PTR lp; PBOX refresh_offsets; PBOX bound = frame->get_bound(); PCOORD baseline; /* // Compute the height of all the lines so we can know how to align them. */ y_offset = 0; baseline = 0; SHORT line_count = frame->number_of_lines(); if (line_count == 0) { refresh_offsets.x0 = 0; refresh_offsets.x1 = 0; } else { PCOORD xmin, xmax; xmin = 0x7fffffff; xmax = -xmin; for (lp = frame->get_line(0), l_index = 0; l_index < line_count; lp++, l_index++) { xmin = __min(xmin, lp->refresh_xmin); xmax = __max(xmax, lp->refresh_xmax); if (l_index == 0) { baseline = y_offset + lp->ascend; } else { baseline = y_offset + lp->line_spacing - lp->descend; } y_offset = baseline + lp->descend; } refresh_offsets.x0 = xmin; refresh_offsets.x1 = xmax; } /* // Compute the offset value from the height of the text and the frame height. */ if ((y_offset = bound.y1 - bound.y0 - y_offset) > 0) { switch (align_type) { case ALIGN_top: { y_offset = 0; break; } case ALIGN_middle: { y_offset /= 2; break; } case ALIGN_bottom: default: { break; } } } else { /* Text too big for frame. Top align it. */ y_offset = 0; } refresh_offsets.y0 = y_offset; /* // We have the amount to offset. Do the offset now. */ for (lp = frame->get_line(0), l_index = 0; l_index < line_count; lp++, l_index++) { if (l_index == 0) { y_offset += lp->ascend; } else { y_offset += lp->line_spacing - lp->descend; } if (y_offset != lp->baseline) { if (lp->baseline != -1) { add_line_refresh_extent(frame, lp); } lp->baseline = y_offset; add_line_refresh_extent(frame, lp); } y_offset += lp->descend; } refresh_offsets.y1 = __min(y_offset, bound.y1 - bound.y0); frame->set_refresh_offsets(refresh_offsets); }