diff --git a/OOXML/DocxFormat/Document.cpp b/OOXML/DocxFormat/Document.cpp index d887148c67..7440d6b27d 100644 --- a/OOXML/DocxFormat/Document.cpp +++ b/OOXML/DocxFormat/Document.cpp @@ -384,23 +384,32 @@ namespace OOX pItem = new Logic::CSdt( document ); else if (L"sectPr" == sName ) { - m_oSectPr = new Logic::CSectionProperty( document ); - m_oSectPr->fromXML(oReader); -//------------------------------------------------------------------------- - OOX::CDocx* docx = dynamic_cast(document); - OOX::CDocument* document = docx ? (docx->m_bGlossaryRead ? docx->m_oGlossary.document : (docx->m_oMain.document ? docx->m_oMain.document : this)) : this; + Logic::CSectionProperty *pSectPr = new Logic::CSectionProperty( document ); + pSectPr->fromXML(oReader); - if (document) + if (pSectPr->m_bEmpty) { - if (document->m_arrSections.empty()) - { - OOX::CDocument::_section section; - document->m_arrSections.push_back(section); - } - document->m_arrSections.back().sect = m_oSectPr.GetPointer(); - document->m_arrSections.back().end_elm = document->m_arrItems.size(); //активный рутовый еще не добавлен + delete pSectPr; + pSectPr = NULL; + } + else + { + m_oSectPr = pSectPr; + + OOX::CDocx* docx = dynamic_cast(document); + OOX::CDocument* document = docx ? (docx->m_bGlossaryRead ? docx->m_oGlossary.document : (docx->m_oMain.document ? docx->m_oMain.document : this)) : this; + + if (document) + { + if (document->m_arrSections.empty()) + { + OOX::CDocument::_section section; + document->m_arrSections.push_back(section); + } + document->m_arrSections.back().sect = m_oSectPr.GetPointer(); + document->m_arrSections.back().end_elm = document->m_arrItems.size(); //активный рутовый еще не добавлен + } } -//------------------------------------------------------------------------- } else if (L"tbl" == sName ) pItem = new Logic::CTbl( document ); diff --git a/OOXML/DocxFormat/Logic/ParagraphProperty.cpp b/OOXML/DocxFormat/Logic/ParagraphProperty.cpp index ecfb005ba0..346700e229 100644 --- a/OOXML/DocxFormat/Logic/ParagraphProperty.cpp +++ b/OOXML/DocxFormat/Logic/ParagraphProperty.cpp @@ -640,27 +640,36 @@ namespace OOX m_oRPr = oReader; else if ( !m_bPPrChange && L"sectPr" == sName ) { - m_oSectPr = new CSectionProperty(document); - m_oSectPr->fromXML(oReader); -//------------------------------------------------------------------------------------ - OOX::CDocx *docx = dynamic_cast(document); - if (docx) - { - OOX::CDocument *doc = docx->m_bGlossaryRead ? docx->m_oGlossary.document : docx->m_oMain.document; + Logic::CSectionProperty* pSectPr = new Logic::CSectionProperty(document); + pSectPr->fromXML(oReader); - if (doc->m_arrSections.empty()) + if (pSectPr->m_bEmpty) + { + delete pSectPr; + pSectPr = NULL; + } + else + { + m_oSectPr = pSectPr; + + OOX::CDocx* docx = dynamic_cast(document); + if (docx) { + OOX::CDocument* doc = docx->m_bGlossaryRead ? docx->m_oGlossary.document : docx->m_oMain.document; + + if (doc->m_arrSections.empty()) + { + OOX::CDocument::_section section; + doc->m_arrSections.push_back(section); + } + doc->m_arrSections.back().sect = m_oSectPr.GetPointer(); + doc->m_arrSections.back().end_elm = doc->m_arrItems.size() + 1; // порядок выше - сначала читаем, потом добавляем + OOX::CDocument::_section section; + section.start_elm = doc->m_arrItems.size() + 1; doc->m_arrSections.push_back(section); } - doc->m_arrSections.back().sect = m_oSectPr.GetPointer(); - doc->m_arrSections.back().end_elm = doc->m_arrItems.size() + 1; // порядок выше - сначала читаем, потом добавляем - - OOX::CDocument::_section section; - section.start_elm = doc->m_arrItems.size() + 1; - doc->m_arrSections.push_back(section); } -//------------------------------------------------------------------------------------ } else if ( L"shd" == sName ) m_oShd = oReader; diff --git a/OOXML/DocxFormat/Logic/SectionProperty.cpp b/OOXML/DocxFormat/Logic/SectionProperty.cpp index 45f1c0a919..785c9ab18a 100644 --- a/OOXML/DocxFormat/Logic/SectionProperty.cpp +++ b/OOXML/DocxFormat/Logic/SectionProperty.cpp @@ -78,7 +78,6 @@ namespace ComplexTypes } void CColumn::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { - // Читаем атрибуты WritingElement_ReadAttributes_Start( oReader ) WritingElement_ReadAttributes_Read_if ( oReader, (L"w:space"), m_oSpace ) WritingElement_ReadAttributes_Read_else_if( oReader, (L"w:w"), m_oW ) @@ -245,7 +244,6 @@ namespace ComplexTypes } void CLineNumber::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { - // Читаем атрибуты WritingElement_ReadAttributes_Start( oReader ) WritingElement_ReadAttributes_Read_if ( oReader, (L"w:countBy"), m_oCountBy ) WritingElement_ReadAttributes_Read_else_if( oReader, (L"w:distance"), m_oDistance ) @@ -298,7 +296,6 @@ namespace ComplexTypes } void CPaperSource::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { - // Читаем атрибуты WritingElement_ReadAttributes_Start( oReader ) WritingElement_ReadAttributes_Read_if ( oReader, (L"w:first"), m_oFirst ) WritingElement_ReadAttributes_Read_else_if( oReader, (L"w:other"), m_oOther ) @@ -851,7 +848,6 @@ namespace ComplexTypes } void CPageNumber::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { - // Читаем атрибуты WritingElement_ReadAttributes_Start( oReader ) WritingElement_ReadAttributes_Read_if ( oReader, (L"w:chapSep"), m_oChapSep ) WritingElement_ReadAttributes_Read_else_if( oReader, (L"w:chapStyle"), m_oChapStyle ) @@ -918,7 +914,6 @@ namespace ComplexTypes } void CPageSz::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { - // Читаем атрибуты WritingElement_ReadAttributes_Start( oReader ) WritingElement_ReadAttributes_Read_if ( oReader, (L"w:code"), m_oCode ) WritingElement_ReadAttributes_Read_else_if( oReader, (L"w:h"), m_oH ) @@ -963,7 +958,6 @@ namespace ComplexTypes } void CSectType::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { - // Читаем атрибуты WritingElement_ReadAttributes_Start( oReader ) WritingElement_ReadAttributes_ReadSingle( oReader, (L"w:val"), m_oVal ) WritingElement_ReadAttributes_End( oReader ) @@ -1081,7 +1075,6 @@ namespace OOX } void CColumns::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { - // Читаем атрибуты WritingElement_ReadAttributes_Start( oReader ) WritingElement_ReadAttributes_Read_if ( oReader, (L"w:equalWidth"), m_oEqualWidth ) WritingElement_ReadAttributes_Read_else_if( oReader, (L"w:num"), m_oNum ) @@ -1378,11 +1371,10 @@ namespace OOX } void CPageBorders::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { - // Читаем атрибуты WritingElement_ReadAttributes_Start( oReader ) - WritingElement_ReadAttributes_Read_if ( oReader, (L"w:display"), m_oDisplay ) - WritingElement_ReadAttributes_Read_else_if( oReader, (L"w:offsetFrom"), m_oOffsetFrom ) - WritingElement_ReadAttributes_Read_else_if( oReader, (L"w:zOrder"), m_oZOrder ) + WritingElement_ReadAttributes_Read_if ( oReader, L"w:display", m_oDisplay ) + WritingElement_ReadAttributes_Read_else_if( oReader, L"w:offsetFrom", m_oOffsetFrom ) + WritingElement_ReadAttributes_Read_else_if( oReader, L"w:zOrder", m_oZOrder ) WritingElement_ReadAttributes_End( oReader ) } @@ -1400,14 +1392,14 @@ namespace OOX } void CSectPrChange::fromXML(XmlUtils::CXmlNode& oNode) { - XmlMacroReadAttributeBase( oNode, _T("w:author"), m_sAuthor ); - XmlMacroReadAttributeBase( oNode, _T("w:date"), m_oDate ); - XmlMacroReadAttributeBase( oNode, _T("w:id"), m_oId ); - XmlMacroReadAttributeBase( oNode, _T("oouserid"), m_sUserId ); + XmlMacroReadAttributeBase( oNode, L"w:author", m_sAuthor ); + XmlMacroReadAttributeBase( oNode, L"w:date", m_oDate ); + XmlMacroReadAttributeBase( oNode, L"w:id", m_oId ); + XmlMacroReadAttributeBase( oNode, L"oouserid", m_sUserId ); XmlUtils::CXmlNode oNode_sectPr; - if ( m_pSecPr.IsInit() && oNode.GetNode( _T("w:sectPr"), oNode_sectPr ) ) + if ( m_pSecPr.IsInit() && oNode.GetNode( L"w:sectPr", oNode_sectPr ) ) m_pSecPr->fromXML( oNode_sectPr ); } @@ -1422,13 +1414,13 @@ namespace OOX while( oReader.ReadNextSiblingNode( nParentDepth ) ) { std::wstring sName = oReader.GetName(); - if ( _T("w:sectPr") == sName ) + if ( L"w:sectPr" == sName ) m_pSecPr->fromXML( oReader ); } } std::wstring CSectPrChange::toXML() const { - std::wstring sResult = _T("ToString(); - sResult += _T("\" "); + sResult += L"\" "; } if ( m_oId.IsInit() ) { - sResult += _T("w:id=\""); + sResult += L"w:id=\""; sResult += m_oId->ToString(); - sResult += _T("\" "); + sResult += L"\" "; } if ( m_sUserId.IsInit() ) { - sResult += _T("oouserid=\""); + sResult += L"oouserid=\""; sResult += m_sUserId.get2(); - sResult += _T("\" "); + sResult += L"\" "; } - sResult += _T(">"); + sResult += L">"; if ( m_pSecPr.IsInit() ) sResult += m_pSecPr->toXML(); - sResult += _T(""); + sResult += L""; return sResult; } @@ -1473,12 +1465,11 @@ namespace OOX } void CSectPrChange::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { - // Читаем атрибуты WritingElement_ReadAttributes_Start( oReader ) - WritingElement_ReadAttributes_Read_if ( oReader, _T("w:author"), m_sAuthor ) - WritingElement_ReadAttributes_Read_else_if( oReader, _T("w:date"), m_oDate ) - WritingElement_ReadAttributes_Read_else_if( oReader, _T("w:id"), m_oId ) - WritingElement_ReadAttributes_Read_else_if( oReader, _T("oouserid"), m_sUserId ) + WritingElement_ReadAttributes_Read_if ( oReader, L"w:author", m_sAuthor ) + WritingElement_ReadAttributes_Read_else_if( oReader, L"w:date", m_oDate ) + WritingElement_ReadAttributes_Read_else_if( oReader, L"w:id", m_oId ) + WritingElement_ReadAttributes_Read_else_if( oReader, L"oouserid", m_sUserId ) WritingElement_ReadAttributes_End( oReader ) } @@ -1511,116 +1502,70 @@ namespace OOX } void CSectionProperty::fromXML(XmlUtils::CXmlNode &oNode) { - if ( (L"w:sectPr") != oNode.GetName() ) - return; + std::vector oChilds; + oNode.GetNodes(L"*", oChilds); + if (oChilds.empty() && oNode.GetAttributesCount() < 1) + { + m_bEmpty = true; + return; + } XmlMacroReadAttributeBase( oNode, (L"w:rsidDel"), m_oRsidDel ); XmlMacroReadAttributeBase( oNode, (L"w:rsidR"), m_oRsidR ); XmlMacroReadAttributeBase( oNode, (L"w:rsidRPr"), m_oRsidRPr ); XmlMacroReadAttributeBase( oNode, (L"w:rsidSect"), m_oRsidSect ); - XmlUtils::CXmlNode oChild; - - if ( oNode.GetNode( (L"w:bidi"), oChild ) ) - m_oBidi = oChild; - - if ( oNode.GetNode( (L"w:cols"), oChild ) ) - m_oCols = oChild; - - if ( oNode.GetNode( (L"w:docGrid"), oChild ) ) - m_oDocGrid = oChild; - - if ( oNode.GetNode( (L"w:endnotePr"), oChild ) ) - m_oEndnotePr = oChild; - - if ( !m_bSectPrChange ) + for (size_t nIndex = 0; nIndex < oChilds.size(); nIndex++) { - std::vector oNodes; - if ( oNode.GetNodes( (L"w:footerReference"), oNodes ) ) + XmlUtils::CXmlNode& oChild = oChilds[nIndex]; + if (oChild.IsValid()) { - for ( int nIndex = 0; nIndex < oNodes.size(); nIndex++ ) - { - XmlUtils::CXmlNode& oNode = oNodes[nIndex]; - if ( oNode.IsValid() ) - { - nullable oFooter; oFooter.Init(); - oFooter->FromXML(oNode); + std::wstring sName = oChild.GetName(); - m_arrFooterReference.push_back( oFooter ); - } + if (L"w:bidi" == sName) m_oBidi = oChild; + else if (L"w:cols" == sName) m_oCols = oChild; + else if (L"w:docGrid" == sName) m_oDocGrid = oChild; + else if (L"w:endnotePr" == sName) m_oEndnotePr = oChild; + else if (L"w:footnotePr" == sName) m_oFootnotePr = oChild; + else if (L"w:formProt" == sName) m_oFormProt = oChild; + else if (!m_bSectPrChange && L"w:footerReference" == sName) + { + nullable oFooter; oFooter.Init(); + oFooter->FromXML(oChild); + + m_arrFooterReference.push_back(oFooter); } + else if (!m_bSectPrChange && L"w:headerReference" == sName) + { + nullable < ComplexTypes::Word::CHdrFtrRef> oHeader; oHeader.Init(); + oHeader->FromXML(oChild); + + m_arrHeaderReference.push_back(oHeader); + } + else if (L"w:lnNumType" == sName) m_oLnNumType = oChild; + else if (L"w:noEndnote" == sName) m_oNoEndnote = oChild; + else if (L"w:paperSrc" == sName) m_oPaperSrc = oChild; + else if (L"w:pgBorders" == sName) m_oPgBorders = oChild; + else if (L"w:pgMar" == sName) m_oPgMar = oChild; + else if (L"w:pgNumType" == sName) m_oPgNumType = oChild; + else if (L"w:pgSz" == sName) m_oPgSz = oChild; + else if (L"w:printerSettings" == sName) m_oPrinterSettings = oChild; + else if (L"w:rtlGutter" == sName) m_oRtlGutter = oChild; + else if (!m_bSectPrChange && L"w:sectPrChange" == sName) m_oSectPrChange = oChild; + else if (L"w:textDirection" == sName) m_oTextDirection = oChild; + else if (L"w:titlePg" == sName) m_oTitlePg = oChild; + else if (L"w:type" == sName) m_oType = oChild; + else if (L"w:vAlign" == sName) m_oVAlign = oChild; } } - - if ( oNode.GetNode( (L"w:footnotePr"), oChild ) ) - m_oFootnotePr = oChild; - - if ( oNode.GetNode( (L"w:formProt"), oChild ) ) - m_oFormProt = oChild; - - if ( !m_bSectPrChange ) - { - std::vector oNodes; - if ( oNode.GetNodes( L"w:headerReference", oNodes ) ) - { - for ( size_t nIndex = 0; nIndex < oNodes.size(); nIndex++ ) - { - XmlUtils::CXmlNode& oNode = oNodes[nIndex]; - if ( oNode.IsValid()) - { - nullable < ComplexTypes::Word::CHdrFtrRef> oHeader; oHeader.Init(); - oHeader->FromXML(oNode); - - m_arrHeaderReference.push_back( oHeader ); - } - } - } - } - - if ( oNode.GetNode( (L"w:lnNumType"), oChild ) ) - m_oLnNumType = oChild; - - if ( oNode.GetNode( (L"w:noEndnote"), oChild ) ) - m_oNoEndnote = oChild; - - if ( oNode.GetNode( (L"w:paperSrc"), oChild ) ) - m_oPaperSrc = oChild; - - if ( oNode.GetNode( (L"w:pgBorders"), oChild ) ) - m_oPgBorders = oChild; - - if ( oNode.GetNode( (L"w:pgMar"), oChild ) ) - m_oPgMar = oChild; - - if ( oNode.GetNode( (L"w:pgNumType"), oChild ) ) - m_oPgNumType = oChild; - - if ( oNode.GetNode( (L"w:pgSz"), oChild ) ) - m_oPgSz = oChild; - - if ( oNode.GetNode( (L"w:printerSettings"), oChild ) ) - m_oPrinterSettings = oChild; - - if ( oNode.GetNode( (L"w:rtlGutter"), oChild ) ) - m_oRtlGutter = oChild; - - if ( !m_bSectPrChange && oNode.GetNode( (L"w:sectPrChange"), oChild ) ) - m_oSectPrChange = oChild; - - if ( oNode.GetNode( (L"w:textDirection"), oChild ) ) - m_oTextDirection = oChild; - - if ( oNode.GetNode( (L"w:titlePg"), oChild ) ) - m_oTitlePg = oChild; - - if ( oNode.GetNode( (L"w:type"), oChild ) ) - m_oType = oChild; - - if ( oNode.GetNode( (L"w:vAlign"), oChild ) ) - m_oVAlign = oChild; } void CSectionProperty::fromXML(XmlUtils::CXmlLiteReader& oReader) { + if (oReader.IsEmptyNode() && oReader.GetAttributesCount() < 1) + { + m_bEmpty = true; + return; + } ReadAttributes( oReader ); if ( oReader.IsEmptyNode() ) diff --git a/OOXML/DocxFormat/Logic/SectionProperty.h b/OOXML/DocxFormat/Logic/SectionProperty.h index 27c7aa490f..8ff29a160b 100644 --- a/OOXML/DocxFormat/Logic/SectionProperty.h +++ b/OOXML/DocxFormat/Logic/SectionProperty.h @@ -503,7 +503,8 @@ namespace OOX void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); public: - bool m_bSectPrChange; + bool m_bSectPrChange = false; + bool m_bEmpty = false; nullable m_oRsidDel; nullable m_oRsidR;