*/
lo_EndCellSubDoc(MWContext *context, lo_DocState *state, lo_DocState *old_state,	LO_Element *element, Bool relayout){	LO_Element *eptr;	LO_SubDocStruct *subdoc;	PA_Block buff;	char *str;	Bool line_break;	int32 baseline_inc;	int32 line_inc;	int32 subdoc_height, subdoc_width;	int32 doc_height;	LO_TextStruct tmp_text;	LO_TextInfo text_info;	LO_Element **line_array;	Bool dynamic_width;	Bool dynamic_height;#ifdef LOCAL_DEBUG fprintf(stderr, "lo_EndCellSubDoc called\n");#endif /* LOCAL_DEBUG */    /* Close any layers (blocks) that were opened in this cell, in case	   the document author forgot to. */    while (old_state->layer_nest_level > 0)	{		lo_EndLayer(context, old_state, PR_TRUE);	}	subdoc = (LO_SubDocStruct *)element;	subdoc->state = (void *)old_state;	/*	 * All this work is to get the text_info filled in for the current	 * font in the font stack. Yuck, there must be a better way.	 */	memset (&tmp_text, 0, sizeof (tmp_text));	buff = PA_ALLOC(1);	if (buff == NULL)	{		state->top_state->out_of_memory = TRUE;		return(NULL);	}	PA_LOCK(str, char *, buff);	str[0] = ' ';	PA_UNLOCK(buff);	tmp_text.text = buff;	tmp_text.text_len = 1;	tmp_text.text_attr =		state->font_stack->text_attr;	FE_GetTextInfo(context, &tmp_text, &text_info);	PA_FREE(buff);	if (relayout == FALSE)	{		/*		 * We don't want to leave any end paragraph linbreaks in the subdoc		 * as they give us a really ugly blank line at the bottom of a cell. So,		 * if the last element in the list is paragraph break linefeed, then		 * we kill it.		 */		eptr = old_state->end_last_line;		if ( (eptr != NULL) && (eptr->type == LO_LINEFEED) &&			(eptr->lo_linefeed.break_type == LO_LINEFEED_BREAK_PARAGRAPH) )		{			LO_Element *prev;						prev = eptr->lo_any.prev;			/*			 * Kill this layout element and reset the subdoc height			 */			if ( prev != NULL )			{				prev->lo_any.next = NULL;				old_state->end_last_line = prev;			}			else			{				old_state->line_list = NULL;				old_state->end_last_line = NULL;			}						/* The if condition checks to make sure that the linefeed that we just killed			 * was sticking out of the bottom of the cell.  This fixes bug 81282.			 */			if (eptr->lo_linefeed.y + eptr->lo_linefeed.line_height >= old_state->y) {				/* shrink the document */				old_state->y -= eptr->lo_linefeed.line_height;			}			lo_RecycleElements ( context, old_state, eptr );		}	}		dynamic_width = FALSE;	dynamic_height = FALSE;	if (subdoc->width == 0)	{		dynamic_width = TRUE;		/*		 * Subdocs that were dynamically widthed, and which		 * contained right aligned items, must be relaid out		 * once their width is determined.		 */		eptr = old_state->float_list;		while (eptr != NULL)		{			if ((eptr->type == LO_IMAGE)&&				(eptr->lo_image.image_attr->alignment == LO_ALIGN_RIGHT))			{				old_state->must_relayout_subdoc = TRUE;				break;			}			else if ((eptr->type == LO_SUBDOC)&&				(eptr->lo_subdoc.alignment == LO_ALIGN_RIGHT))			{				old_state->must_relayout_subdoc = TRUE;				break;			}			eptr = eptr->lo_any.next;		}		subdoc->width = old_state->max_width;	}	/*	 * Add in the size of the subdoc's borders	 */	subdoc->width += (2 * subdoc->border_width);	/*	 * Figure the height the subdoc laid out in.	 * Use this if we were passed no height, or if it is greater	 * than the passed height.	 */	doc_height = old_state->y + (2 * subdoc->border_width);	if (subdoc->height == 0)	{		dynamic_height = TRUE;		subdoc->height = doc_height;	}	else if (subdoc->height < doc_height)	{		subdoc->height = doc_height;	}	/*	 * Make eptr point to the start of the element chain	 * for this subdoc.	 */#ifdef XP_WIN16{	XP_Block *larray_array;	XP_LOCK_BLOCK(larray_array, XP_Block *, old_state->larray_array);	old_state->line_array = larray_array[0];	XP_UNLOCK_BLOCK(old_state->larray_array);}#endif /* XP_WIN16 */	XP_LOCK_BLOCK(line_array, LO_Element **, old_state->line_array);	eptr = line_array[0];	XP_UNLOCK_BLOCK(old_state->line_array);	while (eptr != NULL)	{		switch (eptr->type)		{		    case LO_LINEFEED:			if ((eptr->lo_linefeed.x + eptr->lo_linefeed.x_offset +				eptr->lo_linefeed.width) >= (subdoc->width - 1 -				(2 * subdoc->border_width)))			{				eptr->lo_linefeed.width = (subdoc->width - 1 -					(2 * subdoc->border_width)) -					(eptr->lo_linefeed.x +					eptr->lo_linefeed.x_offset);				if (eptr->lo_linefeed.width < 0)				{					eptr->lo_linefeed.width = 0;				}			}#ifdef OLD_DELAY_CENTERED			if (eptr->lo_linefeed.ele_attrmask &				LO_ELE_DELAY_CENTERED)			{				int32 side_inc;				LO_Element *c_eptr;				c_eptr = eptr;				side_inc = subdoc->width - 1 -					(2 * subdoc->border_width) -					(eptr->lo_linefeed.x +					eptr->lo_linefeed.x_offset);				side_inc = side_inc / 2;				if (side_inc > 0)				{					c_eptr->lo_linefeed.width -= side_inc;					if (c_eptr->lo_linefeed.width < 0)					{						c_eptr->lo_linefeed.width = 0;					}					while ((c_eptr->lo_any.prev != NULL)&&						(c_eptr->lo_any.prev->type !=							LO_LINEFEED))					{						c_eptr->lo_any.x += side_inc;						if (c_eptr->type == LO_CELL)						{						    lo_ShiftCell(							(LO_CellStruct *)c_eptr,							side_inc, 0);						}						c_eptr = c_eptr->lo_any.prev;					}					c_eptr->lo_any.x += side_inc;					if (c_eptr->type == LO_CELL)					{					    lo_ShiftCell(						(LO_CellStruct *)c_eptr,						side_inc, 0);					}				}				eptr->lo_linefeed.ele_attrmask &=					(~(LO_ELE_DELAY_CENTERED));			}#endif /* OLD_DELAY_CENTERED */			break;		    /*		     * This is awful, but any dynamically dimenstioned		     * subdoc that contains one of these elements		     * must be relayed out to take care of window		     * width and height dependencies.		     */			/* case LO_HRULE:		    case LO_SUBDOC:		    case LO_TABLE:				old_state->must_relayout_subdoc = TRUE;			*/			break;		    case LO_IMAGE:/* WILL NEED THIS LATER FOR PERCENT WIDTH IMAGES			if ((old_state->allow_percent_width == FALSE)||				(old_state->allow_percent_height == FALSE))			{				old_state->must_relayout_subdoc = TRUE;			}*/			break;		    default:			break;		}		eptr = eptr->lo_any.next;	}	/*	 * Remember: (2 * subdoc->border_width) has already been added to the subdoc	 * width above...	 */	subdoc_width = subdoc->width + (2 * subdoc->border_horiz_space);	subdoc_height = subdoc->height + (2 * subdoc->border_width) +		(2 * subdoc->border_vert_space);	if (old_state->display_blocked != FALSE)	{		old_state->display_blocked = FALSE;	}	/*	 * Will this subdoc make the line too wide.	 */	if ((state->x + subdoc_width) > state->right_margin)	{		line_break = TRUE;	}	else	{		line_break = FALSE;	}	/*	 * if we are at the beginning of the line.  There is	 * no point in breaking, we are just too wide.	 * Also don't break in unwrappedpreformatted text.	 * Also can't break inside a NOBR section.	 */	if ((state->at_begin_line != FALSE)||		(state->preformatted == PRE_TEXT_YES)||		(state->breakable == FALSE))	{		line_break = FALSE;	}	/*         * break on the subdoc if we have         * a break.         *//* DOn't break in cell        if (line_break != FALSE)        {                lo_SoftLineBreak(context, state, TRUE);                subdoc->x = state->x;                subdoc->y = state->y;        }*/	/*	 * Figure out how to align this subdoc.	 * baseline_inc is how much to increase the baseline	 * of previous element of this line.  line_inc is how	 * much to increase the line height below the baseline.	 */	baseline_inc = 0;	line_inc = 0;	/*	 * If we are at the beginning of a line, with no baseline,	 * we first set baseline and line_height based on the current	 * font, then place the subdoc.	 */	if (state->baseline == 0)	{		state->baseline = 0;	}	lo_CalcAlignOffsets(state, &text_info, (intn)subdoc->alignment,		subdoc_width, subdoc_height,		&subdoc->x_offset, &subdoc->y_offset, &line_inc, &baseline_inc);	subdoc->x_offset += (int16)subdoc->border_horiz_space;	subdoc->y_offset += (int32)subdoc->border_vert_space;	old_state->base_x = subdoc->x + subdoc->x_offset +		subdoc->border_width;	old_state->base_y = subdoc->y + subdoc->y_offset +		subdoc->border_width;	/*	 * Clean up state	state->x = state->x + subdoc->x_offset +		subdoc_width - subdoc->border_horiz_space;	state->linefeed_state = 0;	state->at_begin_line = FALSE;	state->trailing_space = FALSE;	state->cur_ele_type = LO_SUBDOC;	 */	return(subdoc);}