bool IE_Exp_OpenXML_Listener::populateStrux(pf_Frag_Strux* sdh, const PX_ChangeRecord* pcr , fl_ContainerLayout** /* psfh */) { if(pcr->getType() != PX_ChangeRecord::PXT_InsertStrux) return false; const PX_ChangeRecord_Strux* pcrx = static_cast<const PX_ChangeRecord_Strux *> (pcr); PT_AttrPropIndex api = pcr->getIndexAP(); const PP_AttrProp* pAP = NULL; bool bHaveProp = pdoc->getAttrProp(api,&pAP); switch (pcrx->getStruxType()) { case PTX_Section: { section = new OXML_Section(); section->setTarget(TARGET_DOCUMENT); OXML_SharedSection shared_section(section); //add section properties if(bHaveProp && pAP) { const gchar* szValue; const gchar* szName; size_t propCount = pAP->getPropertyCount(); size_t i; for(i=0; i<propCount; i++) { if(pAP->getNthProperty(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Section Property: %s=%s\n", szName, szValue)); if(section->setProperty(szName, szValue) != UT_OK) return false; } } size_t attrCount = pAP->getAttributeCount(); for(i=0; i<attrCount; i++) { if(pAP->getNthAttribute(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Section Attribute: %s=%s\n", szName, szValue)); if(section->setAttribute(szName, szValue) != UT_OK) return false; } } } return document->appendSection(shared_section) == UT_OK; } case PTX_Block: { paragraph = new OXML_Element_Paragraph(getNextId()); OXML_SharedElement shared_paragraph(static_cast<OXML_Element*>(paragraph)); //add paragraph properties if(bHaveProp && pAP) { const gchar* szValue; const gchar* szName; size_t propCount = pAP->getPropertyCount(); size_t i; for(i=0; i<propCount; i++) { if(pAP->getNthProperty(i, szName, szValue)) { if(paragraph->setProperty(szName, szValue) != UT_OK) return false; } } size_t attrCount = pAP->getAttributeCount(); for(i=0; i<attrCount; i++) { if(pAP->getNthAttribute(i, szName, szValue)) { if(paragraph->setAttribute(szName, szValue) != UT_OK) return false; } } } if(!m_cellStack.empty()) { OXML_Element_Cell* cell = m_cellStack.top(); return cell->appendElement(shared_paragraph) == UT_OK; } else if(bInTextbox) return textbox->appendElement(shared_paragraph) == UT_OK; return section->appendElement(shared_paragraph) == UT_OK; } case PTX_SectionHdrFtr: { section = new OXML_Section(getNextId()); OXML_SharedSection shared_section(static_cast<OXML_Section*>(section)); if(bHaveProp && pAP) { const gchar* szValue; const gchar* szName; size_t propCount = pAP->getPropertyCount(); size_t i; for(i=0; i<propCount; i++) { if(pAP->getNthProperty(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Header/Footer Property: %s=%s\n", szName, szValue)); if(section->setProperty(szName, szValue) != UT_OK) return false; } } size_t attrCount = pAP->getAttributeCount(); for(i=0; i<attrCount; i++) { if(pAP->getNthAttribute(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Header/Footer Attribute: %s=%s\n", szName, szValue)); if(section->setAttribute(szName, szValue) != UT_OK) return false; } } if(pAP->getAttribute("type", szValue)) { if(strstr(szValue, "header")) { section->setTarget(TARGET_HEADER); return document->addHeader(shared_section) == UT_OK; } else if(strstr(szValue, "footer")) { section->setTarget(TARGET_FOOTER); return document->addFooter(shared_section) == UT_OK; } } } return true; } case PTX_SectionEndnote: { savedSection = section; //save the current section savedParagraph = paragraph; //save the current paragraph section = new OXML_Section(getNextId()); OXML_SharedSection shared_section(static_cast<OXML_Section*>(section)); section->setTarget(TARGET_ENDNOTE); if(bHaveProp && pAP) { const gchar* szValue; const gchar* szName; size_t propCount = pAP->getPropertyCount(); size_t i; for(i=0; i<propCount; i++) { if(pAP->getNthProperty(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Endnote Property: %s=%s\n", szName, szValue)); if(section->setProperty(szName, szValue) != UT_OK) return false; } } size_t attrCount = pAP->getAttributeCount(); for(i=0; i<attrCount; i++) { if(pAP->getNthAttribute(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Endnote Attribute: %s=%s\n", szName, szValue)); if(section->setAttribute(szName, szValue) != UT_OK) return false; } } } return document->addEndnote(shared_section) == UT_OK; } case PTX_SectionTable: { OXML_Element_Table* table = new OXML_Element_Table(getNextId()); OXML_SharedElement shared_table(static_cast<OXML_Element*>(table)); if(bHaveProp && pAP) { const gchar* szValue; const gchar* szName; size_t propCount = pAP->getPropertyCount(); size_t i; for(i=0; i<propCount; i++) { if(pAP->getNthProperty(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Table Property: %s=%s\n", szName, szValue)); if(table->setProperty(szName, szValue) != UT_OK) return false; } } size_t attrCount = pAP->getAttributeCount(); for(i=0; i<attrCount; i++) { if(pAP->getNthAttribute(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Table Attribute: %s=%s\n", szName, szValue)); if(table->setAttribute(szName, szValue) != UT_OK) return false; } } } tableHelper.OpenTable(sdh, pcr->getIndexAP()); bool tableInTable = !m_tableStack.empty(); m_tableStack.push(table); if(tableInTable) { //this is a table inside another table OXML_Element_Cell* cell = m_cellStack.top(); return cell->appendElement(shared_table) == UT_OK; } return section->appendElement(shared_table) == UT_OK; } case PTX_SectionCell: { OXML_Element_Table* table = NULL; if(!m_tableStack.empty()) table = m_tableStack.top(); if(!table) { UT_DEBUGMSG(("FRT: OpenXML exporter corrupted table layout. Invalid Cell Open.")); return false; } OXML_Element_Row* row = NULL; if(!m_rowStack.empty()) row = m_rowStack.top(); tableHelper.OpenCell(api); UT_sint32 left = tableHelper.getLeft(); UT_sint32 right = tableHelper.getRight(); UT_sint32 top = tableHelper.getTop(); UT_sint32 bottom = tableHelper.getBot(); if(!row || tableHelper.isNewRow()) { row = new OXML_Element_Row(getNextId(), table); m_rowStack.push(row); row->setNumCols(tableHelper.getNumCols()); OXML_SharedElement shared_row(static_cast<OXML_Element*>(row)); if(table->appendElement(shared_row) != UT_OK) return false; } OXML_Element_Cell* cell = new OXML_Element_Cell(getNextId(), table, row, left, right, top, bottom); m_cellStack.push(cell); OXML_SharedElement shared_cell(static_cast<OXML_Element*>(cell)); if(bHaveProp && pAP) { const gchar* szValue; const gchar* szName; size_t propCount = pAP->getPropertyCount(); size_t i; for(i=0; i<propCount; i++) { if(pAP->getNthProperty(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Cell Property: %s=%s\n", szName, szValue)); if(cell->setProperty(szName, szValue) != UT_OK) return false; } } size_t attrCount = pAP->getAttributeCount(); for(i=0; i<attrCount; i++) { if(pAP->getNthAttribute(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Cell Attribute: %s=%s\n", szName, szValue)); if(cell->setAttribute(szName, szValue) != UT_OK) return false; } } } return row->appendElement(shared_cell) == UT_OK; } case PTX_SectionFootnote: { savedSection = section; //save the current section savedParagraph = paragraph; //save the current paragraph section = new OXML_Section(getNextId()); OXML_SharedSection shared_section(static_cast<OXML_Section*>(section)); section->setTarget(TARGET_FOOTNOTE); if(bHaveProp && pAP) { const gchar* szValue; const gchar* szName; size_t propCount = pAP->getPropertyCount(); size_t i; for(i=0; i<propCount; i++) { if(pAP->getNthProperty(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Footnote Property: %s=%s\n", szName, szValue)); if(section->setProperty(szName, szValue) != UT_OK) return false; } } size_t attrCount = pAP->getAttributeCount(); for(i=0; i<attrCount; i++) { if(pAP->getNthAttribute(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("Footnote Attribute: %s=%s\n", szName, szValue)); if(section->setAttribute(szName, szValue) != UT_OK) return false; } } } return document->addFootnote(shared_section) == UT_OK; } case PTX_SectionFrame: { const gchar* frameType = NULL; if(!(bHaveProp && pAP)) return true; if(!(pAP->getProperty("frame-type",frameType) && frameType && *frameType)) return true; if(!strcmp(frameType,"textbox")) { bInTextbox = true; } else if(!strcmp(frameType,"image")) { // TODO: handle positioned images } if(bInTextbox) { textbox = new OXML_Element_TextBox(getNextId()); OXML_SharedElement shared_textbox(static_cast<OXML_Element*>(textbox)); OXML_Element_Run* element_run = new OXML_Element_Run(getNextId()); OXML_SharedElement shared_element_run(static_cast<OXML_Element*>(element_run)); if(element_run->appendElement(shared_textbox) != UT_OK) return false; const gchar* szValue; const gchar* szName; size_t propCount = pAP->getPropertyCount(); size_t i; for(i=0; i<propCount; i++) { if(pAP->getNthProperty(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("TextBox Property: %s=%s\n", szName, szValue)); if(textbox->setProperty(szName, szValue) != UT_OK) return false; } } size_t attrCount = pAP->getAttributeCount(); for(i=0; i<attrCount; i++) { if(pAP->getNthAttribute(i, szName, szValue)) { //TODO: Take the debug message out when we are done UT_DEBUGMSG(("TextBox Attribute: %s=%s\n", szName, szValue)); if(textbox->setAttribute(szName, szValue) != UT_OK) return false; } } return paragraph->appendElement(shared_element_run) == UT_OK; } return true; } case PTX_EndCell: { tableHelper.CloseCell(); if(m_cellStack.empty()) return false; m_cellStack.pop(); return true; } case PTX_EndTable: { tableHelper.CloseTable(); if(m_tableStack.empty()) return false; //pop the rows that belong to this table int nRows = m_tableStack.top()->getNumberOfRows(); for(int i=0; i<nRows; i++) { if(m_rowStack.empty()) return false; m_rowStack.pop(); } //pop the table m_tableStack.pop(); return true; } case PTX_EndFootnote: { section = savedSection; //recover the last section paragraph = savedParagraph; //recover the last paragraph return true; } case PTX_EndEndnote: { section = savedSection; //recover the last section paragraph = savedParagraph; //recover the last paragraph return true; } case PTX_EndFrame: { if(bInTextbox) bInTextbox = false; return true; } case PTX_SectionMarginnote: case PTX_SectionAnnotation: case PTX_SectionTOC: case PTX_EndMarginnote: case PTX_EndAnnotation: case PTX_EndTOC: default: return true; } return true; }
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); }