UT_Error OXML_Element_Run::addToPT(PD_Document * pDocument)
{
	UT_return_val_if_fail(pDocument != NULL, UT_ERROR);

	UT_Error ret = UT_OK;

	const gchar ** atts = getAttributesWithProps();
	if (atts != NULL) {
		//We open the formatting tag
		ret = pDocument->appendFmt(atts) ? UT_OK : UT_ERROR;
		if(ret != UT_OK)
		{
			UT_ASSERT_HARMLESS(ret == UT_OK);
			return ret;
		}
	}

	ret = addChildrenToPT(pDocument);
	if(ret != UT_OK)
	{
		UT_ASSERT_HARMLESS(ret == UT_OK);
		return ret;
	}

	if (atts != NULL) {
		//We close the formatting tag
		ret = pDocument->appendFmt((const gchar **)NULL) ? UT_OK : UT_ERROR;
		UT_return_val_if_fail(ret == UT_OK, ret);
	}
	return ret;
}
UT_Error OXML_Element_Table::addToPT(PD_Document * pDocument)
{
	UT_Error ret = UT_OK;

	const gchar * bgColor = NULL;
	if(getProperty("background-color", bgColor) != UT_OK)
		bgColor = NULL;

	//OpenXML supports bookmarks anywhere in the tables
	//We will append children bookmarks that go inside table here
	//to point to the beginning of table instead of correct locations
	//TODO: this needs to be fixed in piece table?
	OXML_ElementVector children = getChildren();
	OXML_ElementVector::size_type i;
	for (i = 0; i < children.size(); i++)
	{
		if(bgColor)
		{
			children[i]->setProperty("background-color", bgColor); //apply directly to row
		}
					
		if(children[i]->getTag() == BOOK_TAG)
		{
			ret = children[i]->addToPT(pDocument);
			if (ret != UT_OK)
				return ret;
		}
	}

	const gchar ** atts = getAttributesWithProps();
	if(!pDocument->appendStrux(PTX_SectionTable, atts))
		return UT_ERROR;
	
	ret = addChildrenToPT(pDocument);
	if(ret != UT_OK)
		return ret;
	
	if(!pDocument->appendStrux(PTX_EndTable,NULL))
		return UT_ERROR;

	return ret;
}
UT_Error OXML_Element_Cell::addToPT(PD_Document * pDocument)
{
	UT_Error ret = UT_OK;

	if(!startsHorizontalMerge() || !startsVerticalMerge())
		return UT_OK;

	//add props:bot-attach, left-attach, right-attach, top-attach
	std::string sTop = boost::lexical_cast<std::string>(m_iTop);
	std::string sBottom = boost::lexical_cast<std::string>(m_iBottom);
	std::string sLeft = boost::lexical_cast<std::string>(m_iLeft);
	std::string sRight = boost::lexical_cast<std::string>(m_iRight);

	ret = setProperty("top-attach", sTop);
	if(ret != UT_OK)
		return ret;	

	ret = setProperty("bot-attach", sBottom);
	if(ret != UT_OK)
		return ret;	

	ret = setProperty("left-attach", sLeft);
	if(ret != UT_OK)
		return ret;	

	ret = setProperty("right-attach", sRight);
	if(ret != UT_OK)
		return ret;	



	const gchar * szValue = NULL;
	const gchar * bgColor = NULL;

	if((getProperty("background-color", bgColor) == UT_OK) && bgColor)
	{
		OXML_ElementVector children = getChildren();
		OXML_ElementVector::size_type i;
		for (i = 0; i < children.size(); i++)
		{
			if(children[i]->getTag() == TBL_TAG)
			{
				if((children[i]->getProperty("background-color", szValue) != UT_OK) || !szValue)
				{			
					children[i]->setProperty("background-color", bgColor);
				}
			}
			else if((children[i]->getProperty("bgcolor", szValue) != UT_OK) || !szValue)
			{			
				children[i]->setProperty("bgcolor", bgColor);
			}
		}
	}

	if(!bgColor)
		bgColor = "ffffff";

	if((getProperty("top-style", szValue) != UT_OK) || !szValue)
	{
		ret = setProperty("top-color", bgColor); 
		if(ret != UT_OK)
			return ret;	
	}		

	szValue = NULL;
	if((getProperty("left-style", szValue) != UT_OK) || !szValue)
	{
		ret = setProperty("left-color", bgColor); 
		if(ret != UT_OK)
			return ret;	
	}

	szValue = NULL;
	if((getProperty("right-style", szValue) != UT_OK) || !szValue)
	{
		ret = setProperty("right-color", bgColor); 
		if(ret != UT_OK)
			return ret;	
	}

	szValue = NULL;
	if((getProperty("bot-style", szValue) != UT_OK) || !szValue)
	{
		ret = setProperty("bot-color", bgColor); 
		if(ret != UT_OK)
			return ret;	
	}

	const gchar** cell_props = getAttributesWithProps();

	if(!pDocument->appendStrux(PTX_SectionCell, cell_props))
		return UT_ERROR;

	ret = addChildrenToPT(pDocument);
	if(ret != UT_OK)
		return ret;

	if(!pDocument->appendStrux(PTX_EndCell,NULL))
		return UT_ERROR;
	
	return ret;
}