コード例 #1
0
UT_Error OXML_Element_Table::serialize(IE_Exp_OpenXML* exporter)
{
	UT_Error err = UT_OK;

	err = exporter->startTable();
	if(err != UT_OK)
		return err;

	err = this->serializeProperties(exporter);
	if(err != UT_OK)
		return err;

	//set the row numbers
	std::vector<OXML_Element*>::size_type i;
	OXML_ElementVector children = getChildren();
	for (i = 0; i < children.size(); i++)
	{
		OXML_Element_Row* r = static_cast<OXML_Element_Row*>(get_pointer(children[i]));
		r->setRowNumber(i);
	}

	err = this->serializeChildren(exporter);
	if(err != UT_OK)
		return err;

	return exporter->finishTable();
}
コード例 #2
0
void OXML_Element_Table::addMissingCell(int rowNumber, OXML_Element_Cell* cell)
{
	std::vector<OXML_Element*>::size_type i;
	OXML_ElementVector children = getChildren();
	for (i = 0; i < children.size(); i++)
	{
		OXML_Element_Row* r = static_cast<OXML_Element_Row*>(get_pointer(children[i]));
		if(i == rowNumber)
		{
			r->addMissingCell(cell);
			return;
		}
	}
}
コード例 #3
0
UT_Error OXML_Element_Table::serializeChildren(IE_Exp_OpenXML* exporter)
{
	UT_Error ret = UT_OK;

	OXML_ElementVector::size_type i;
	OXML_ElementVector children = getChildren();
	for (i = 0; i < children.size(); i++)
	{
		m_currentRowNumber = i;
		ret = children[i]->serialize(exporter);
		if(ret != UT_OK)
			return ret;
	}

	return ret;
}
コード例 #4
0
UT_Error OXML_Element_Run::serializeChildren(IE_Exp_OpenXML* exporter)
{
	UT_Error ret = UT_OK;

	OXML_ElementVector children = getChildren();
	OXML_ElementVector::size_type i;
	for (i = 0; i < children.size(); i++)
	{
		if(getType() == LIST)
			children[i]->setType(LIST);
		ret = children[i]->serialize(exporter);
		if(ret != UT_OK)
			return ret;
	}

	return ret;
}
コード例 #5
0
UT_Error OXML_Element_Table::addChildrenToPT(PD_Document * pDocument)
{
	UT_Error ret = UT_OK;
	UT_Error temp = UT_OK;
	std::vector<OXML_Element*>::size_type i;
	OXML_ElementVector children = getChildren();
	
	for (i = 0; i < children.size(); i++)
	{
		m_currentRowNumber = i;
		if(children[i]->getTag() != BOOK_TAG)
		{
			temp = children[i]->addToPT(pDocument);
			if (temp != UT_OK)
				ret = temp;
		}
	}
	return ret;
}
コード例 #6
0
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;
}
コード例 #7
0
UT_Error OXML_Element_Cell::serializeProperties(IE_Exp_OpenXML* exporter)
{
	UT_Error err = UT_OK;
	const gchar* szValue = NULL;
	const gchar* borderType = NULL;
	const gchar* color = NULL;
	const gchar* size = NULL;

	err = exporter->startCellProperties(TARGET_DOCUMENT);
	if(err != UT_OK)
		return err;

	UT_sint32 hspan = getRight()-getLeft();
	UT_sint32 vspan = getBottom()-getTop();
	bool isVertCont = getTop() == -1;
	
	err = exporter->setColumnWidth(TARGET_DOCUMENT, m_table->getColumnWidth(getLeft()).c_str());
	if(err != UT_OK)
		return err;

	if(getProperty("background-color", szValue) == UT_OK)
	{
		err = exporter->setBackgroundColor(TARGET_DOCUMENT, szValue);
		if(err != UT_OK)
			return err;

		const gchar * bgColor = szValue;

		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);
			}
		}
	}
	
	err = exporter->startCellBorderProperties(TARGET_DOCUMENT);
	if(err != UT_OK)
		return err;

	//left border
	borderType = "single";
	if(getProperty("left-style", szValue) == UT_OK)
	{
		if(strcmp(szValue, "1") != 0)
		{
			 borderType = "dashed";
		}
	}

	color = NULL; 
	if(getProperty("left-color", szValue) == UT_OK)
	{
		color = szValue;
	}

	size = NULL;
	if(getProperty("left-thickness", szValue) == UT_OK)
	{
		size = szValue;
	}

	err = exporter->setTableBorder(TARGET_DOCUMENT, "left", borderType, color, size);
	if(err != UT_OK)
		return err;

	//right border
	borderType = "single";
	if(getProperty("right-style", szValue) == UT_OK)
	{
		if(strcmp(szValue, "1") != 0)
		{
			 borderType = "dashed";
		}
	}

	color = NULL; 
	if(getProperty("right-color", szValue) == UT_OK)
	{
		color = szValue;
	}

	size = NULL;
	if(getProperty("right-thickness", szValue) == UT_OK)
	{
		size = szValue;
	}
	err = exporter->setTableBorder(TARGET_DOCUMENT, "right", borderType, color, size);
	if(err != UT_OK)
		return err;

	if(!isVertCont)
	{
		//top border
		borderType = "single";
		if(getProperty("top-style", szValue) == UT_OK)
		{
			if(strcmp(szValue, "1") != 0)
			{
				 borderType = "dashed";
			}
		}

		color = NULL; 
		if(getProperty("top-color", szValue) == UT_OK)
		{
			color = szValue;
		}

		size = NULL;
		if(getProperty("top-thickness", szValue) == UT_OK)
		{
			size = szValue;
		}
		err = exporter->setTableBorder(TARGET_DOCUMENT, "top", borderType, color, size);
		if(err != UT_OK)
			return err;
	}

	if(vspan == 1)
	{
		//bottom border
		borderType = "single";
		if(getProperty("bot-style", szValue) == UT_OK)
		{
			if(strcmp(szValue, "1") != 0)
			{
				 borderType = "dashed";
			}
		}
	
		color = NULL; 
		if(getProperty("bot-color", szValue) == UT_OK)
		{
			color = szValue;
		}
	
		size = NULL;
		if(getProperty("bot-thickness", szValue) == UT_OK)
		{
			size = szValue;
		}
		err = exporter->setTableBorder(TARGET_DOCUMENT, "bottom", borderType, color, size);
		if(err != UT_OK)
			return err;
	}

	err = exporter->finishCellBorderProperties(TARGET_DOCUMENT);
	if(err != UT_OK)
		return err;

	if(hspan > 1)
	{
		err = exporter->setGridSpan(TARGET_DOCUMENT, hspan);
		if(err != UT_OK)
			return err;
	}

	if(vspan > 1)
	{
		if(!isVertCont)
		{
			err = exporter->setVerticalMerge(TARGET_DOCUMENT, "restart");
			if(err != UT_OK)
				return err;
		}
		
		//add the remaining part of the cell as a missing cell
		OXML_Element_Cell* missingCell = new OXML_Element_Cell("", m_table, NULL, m_iLeft, m_iRight, -1, 1); //vertically continued cell
		OXML_SharedElement dummy(new OXML_Element_Paragraph(""));
		missingCell->appendElement(dummy); //cells can't be empty!
		m_table->addMissingCell(m_row->getRowNumber()+1, missingCell);
	}

	if(isVertCont)
	{
		err = exporter->setVerticalMerge(TARGET_DOCUMENT, "continue");
		if(err != UT_OK)
			return err;
	}

	return exporter->finishCellProperties(TARGET_DOCUMENT);
}
コード例 #8
0
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;
}