diff --git a/OOXML/Binary/Document/BinReader/BinaryReaderD.cpp b/OOXML/Binary/Document/BinReader/BinaryReaderD.cpp index 70a2f07c39..295239bb7d 100644 --- a/OOXML/Binary/Document/BinReader/BinaryReaderD.cpp +++ b/OOXML/Binary/Document/BinReader/BinaryReaderD.cpp @@ -1891,7 +1891,7 @@ int Binary_pPrReader::Read_pgHeader(BYTE type, long length, void* poResult) { Writers::HdrFtrItem* pHdrFtrItem = m_oFileWriter.get_headers_footers_writer().m_aHeaders[nHdrFtrIndex]; - ComplexTypes::Word::CHdrFtrRef* pRef = new ComplexTypes::Word::CHdrFtrRef(); + nullable pRef; pRef.Init(); pRef->m_oType.Init(); pRef->m_oType->SetValueFromByte(pHdrFtrItem->eType); @@ -1918,7 +1918,7 @@ int Binary_pPrReader::Read_pgFooter(BYTE type, long length, void* poResult) { Writers::HdrFtrItem* pHdrFtrItem = oBinary_HdrFtrTableReader.m_oHeaderFooterWriter.m_aFooters[nHdrFtrIndex]; - ComplexTypes::Word::CHdrFtrRef* pRef = new ComplexTypes::Word::CHdrFtrRef(); + nullable pRef; pRef.Init(); pRef->m_oType.Init(); pRef->m_oType->SetValueFromByte(pHdrFtrItem->eType); @@ -2016,8 +2016,8 @@ int Binary_pPrReader::ReadCols(BYTE type, long length, void* poResult) } else if ( c_oSerProp_Columns::Column == type ) { - ComplexTypes::Word::CColumn* pCol = new ComplexTypes::Word::CColumn(); - READ1_DEF(length, res, this->ReadCol, pCol); + nullable pCol; pCol.Init(); + READ1_DEF(length, res, this->ReadCol, pCol.GetPointer()); pCols->m_arrColumns.push_back(pCol); } else diff --git a/OOXML/Binary/Document/BinWriter/BinaryWriterD.cpp b/OOXML/Binary/Document/BinWriter/BinaryWriterD.cpp index 7aa5530d9b..6d72aa7bf2 100644 --- a/OOXML/Binary/Document/BinWriter/BinaryWriterD.cpp +++ b/OOXML/Binary/Document/BinWriter/BinaryWriterD.cpp @@ -1672,18 +1672,18 @@ void Binary_pPrWriter::WritePageMargin(OOX::Logic::CSectionProperty* pSectPr) } } } -void Binary_pPrWriter::WriteHeaderFooter(OOX::Logic::CSectionProperty* pSectPr, std::vector& aRefs, bool bHdr) +void Binary_pPrWriter::WriteHeaderFooter(OOX::Logic::CSectionProperty* pSectPr, std::vector>& aRefs, bool bHdr) { int nCurPos = 0; for (size_t i = 0, length = aRefs.size(); i < length; ++i) { - const ComplexTypes::Word::CHdrFtrRef& oRef = *aRefs[i]; - if ( oRef.m_oType.IsInit() && oRef.m_oId.IsInit()) + nullable& oRef = aRefs[i]; + if (oRef.IsInit() && oRef->m_oType.IsInit() && oRef->m_oId.IsInit()) { int nIndex = 0; OOX::CHdrFtr* pHdrFtr = NULL; - smart_ptr oFile = m_oBinaryHeaderFooterTableWriter->m_oDocumentRelsWriter->Find(oRef.m_oId->GetValue()); + smart_ptr oFile = m_oBinaryHeaderFooterTableWriter->m_oDocumentRelsWriter->Find(oRef->m_oId->GetValue()); if (oFile.IsInit() && (OOX::FileTypes::Header == oFile->type() || OOX::FileTypes::Footer == oFile->type())) { pHdrFtr = (OOX::CHdrFtr*)oFile.GetPointer(); @@ -1695,14 +1695,14 @@ void Binary_pPrWriter::WriteHeaderFooter(OOX::Logic::CSectionProperty* pSectPr, { nIndex = (int)m_oBinaryHeaderFooterTableWriter->m_aHeaders.size(); m_oBinaryHeaderFooterTableWriter->m_aHeaders.push_back(pHdrFtr); - m_oBinaryHeaderFooterTableWriter->m_aHeaderTypes.push_back(oRef.m_oType->GetValue()); + m_oBinaryHeaderFooterTableWriter->m_aHeaderTypes.push_back(oRef->m_oType->GetValue()); m_oBinaryHeaderFooterTableWriter->m_aHeaderSectPrs.push_back(pSectPr); } else { nIndex = (int)m_oBinaryHeaderFooterTableWriter->m_aFooters.size(); m_oBinaryHeaderFooterTableWriter->m_aFooters.push_back(pHdrFtr); - m_oBinaryHeaderFooterTableWriter->m_aFooterTypes.push_back(oRef.m_oType->GetValue()); + m_oBinaryHeaderFooterTableWriter->m_aFooterTypes.push_back(oRef->m_oType->GetValue()); m_oBinaryHeaderFooterTableWriter->m_aFooterSectPrs.push_back(pSectPr); } nCurPos = m_oBcw.WriteItemStart(c_oSerProp_secPrType::hdrftrelem); diff --git a/OOXML/Binary/Document/BinWriter/BinaryWriterD.h b/OOXML/Binary/Document/BinWriter/BinaryWriterD.h index 38d742f38f..2e39ec9758 100644 --- a/OOXML/Binary/Document/BinWriter/BinaryWriterD.h +++ b/OOXML/Binary/Document/BinWriter/BinaryWriterD.h @@ -199,7 +199,7 @@ namespace BinDocxRW void WritePageSettings(OOX::Logic::CSectionProperty* pSectPr); void WritePageSize(OOX::Logic::CSectionProperty* pSectPr); void WritePageMargin(OOX::Logic::CSectionProperty* pSectPr); - void WriteHeaderFooter(OOX::Logic::CSectionProperty* pSectPr, std::vector& aRefs, bool bHdr); + void WriteHeaderFooter(OOX::Logic::CSectionProperty* pSectPr, std::vector< nullable>& aRefs, bool bHdr); void WritePageNumType(const ComplexTypes::Word::CPageNumber& pPageNumber); void WriteLineNumType(const ComplexTypes::Word::CLineNumber& pLineNumber); void WriteSectPrChange(const OOX::Logic::CSectPrChange& sectPrChange); diff --git a/OOXML/DocxFormat/Logic/Paragraph.cpp b/OOXML/DocxFormat/Logic/Paragraph.cpp index a1dcf4c085..347854242e 100644 --- a/OOXML/DocxFormat/Logic/Paragraph.cpp +++ b/OOXML/DocxFormat/Logic/Paragraph.cpp @@ -333,10 +333,8 @@ namespace OOX { CParagraphProperty prop2(document); prop2.fromXML(oReader); - - CParagraphProperty newProp = CParagraphProperty::Merge(*m_oParagraphProperty, prop2); - pItem = m_oParagraphProperty = new CParagraphProperty(newProp); + pItem = m_oParagraphProperty = new CParagraphProperty(CParagraphProperty::Merge(*m_oParagraphProperty, prop2)); m_arrItems.push_back( pItem ); continue; } diff --git a/OOXML/DocxFormat/Logic/ParagraphProperty.cpp b/OOXML/DocxFormat/Logic/ParagraphProperty.cpp index 5f4d01af35..ecfb005ba0 100644 --- a/OOXML/DocxFormat/Logic/ParagraphProperty.cpp +++ b/OOXML/DocxFormat/Logic/ParagraphProperty.cpp @@ -939,7 +939,10 @@ namespace OOX oProperties.m_oPPrChange = Merge(oPrev.m_oPPrChange, oCurrent.m_oPPrChange); oProperties.m_oPStyle = Merge(oPrev.m_oPStyle, oCurrent.m_oPStyle); oProperties.m_oRPr = Merge(oPrev.m_oRPr, oCurrent.m_oRPr); - oProperties.m_oSectPr = Merge(oPrev.m_oSectPr, oCurrent.m_oSectPr); + if (oCurrent.m_oSectPr.IsInit() && oPrev.m_oSectPr.IsInit()) + oProperties.m_oSectPr = OOX::Logic::CSectionProperty::Merge(oPrev.m_oSectPr.get(), oCurrent.m_oSectPr.get()); + else + oProperties.m_oSectPr = Merge(oPrev.m_oSectPr, oCurrent.m_oSectPr); oProperties.m_oShd = Merge(oPrev.m_oShd, oCurrent.m_oShd); oProperties.m_oSnapToGrid = Merge(oPrev.m_oSnapToGrid, oCurrent.m_oSnapToGrid); diff --git a/OOXML/DocxFormat/Logic/SectionProperty.cpp b/OOXML/DocxFormat/Logic/SectionProperty.cpp index 7b285e12f0..45f1c0a919 100644 --- a/OOXML/DocxFormat/Logic/SectionProperty.cpp +++ b/OOXML/DocxFormat/Logic/SectionProperty.cpp @@ -986,12 +986,6 @@ namespace OOX } CColumns::~CColumns() { - for ( unsigned int nIndex = 0; nIndex < m_arrColumns.size(); nIndex++ ) - { - if ( m_arrColumns[nIndex] ) delete m_arrColumns[nIndex]; - m_arrColumns[nIndex] = NULL; - } - m_arrColumns.clear(); } void CColumns::fromXML(XmlUtils::CXmlNode& oNode) { @@ -1006,13 +1000,13 @@ namespace OOX { for ( size_t nIndex = 0; nIndex < oCols.size(); nIndex++ ) { - XmlUtils::CXmlNode& oCol = oCols[nIndex]; - if ( oCol.IsValid() ) + XmlUtils::CXmlNode& oColNode = oCols[nIndex]; + if (oColNode.IsValid() ) { - ComplexTypes::Word::CColumn *oColumn = new ComplexTypes::Word::CColumn(); - *oColumn = oCol; + nullable oColumn; oColumn.Init(); + oColumn->FromXML(oColNode); - if (oColumn) m_arrColumns.push_back( oColumn ); + m_arrColumns.push_back( oColumn ); } } } @@ -1030,10 +1024,10 @@ namespace OOX std::wstring sName = oReader.GetName(); if ( L"w:col" == sName ) { - ComplexTypes::Word::CColumn *oColumn = new ComplexTypes::Word::CColumn(); - *oColumn = oReader; + nullable oColumn; oColumn.Init(); + oColumn->FromXML(oReader); - if (oColumn) m_arrColumns.push_back( oColumn ); + m_arrColumns.push_back( oColumn ); } } } @@ -1072,7 +1066,7 @@ namespace OOX for ( unsigned int nIndex = 0; nIndex < m_arrColumns.size(); nIndex++ ) { sResult += L"ToString(); sResult += L"/>"; } @@ -1502,19 +1496,6 @@ namespace OOX } void CSectionProperty::ClearItems() { - for ( unsigned int nIndex = 0; nIndex < m_arrFooterReference.size(); nIndex++ ) - { - if ( m_arrFooterReference[nIndex] ) delete m_arrFooterReference[nIndex]; - m_arrFooterReference[nIndex] = NULL; - } - m_arrFooterReference.clear(); - - for ( unsigned int nIndex = 0; nIndex < m_arrHeaderReference.size(); nIndex++ ) - { - if ( m_arrHeaderReference[nIndex] ) delete m_arrHeaderReference[nIndex]; - m_arrHeaderReference[nIndex] = NULL; - } - m_arrHeaderReference.clear(); } CSectionProperty& CSectionProperty::operator =(const XmlUtils::CXmlNode& oNode) { @@ -1562,10 +1543,10 @@ namespace OOX XmlUtils::CXmlNode& oNode = oNodes[nIndex]; if ( oNode.IsValid() ) { - ComplexTypes::Word::CHdrFtrRef *oFooter = new ComplexTypes::Word::CHdrFtrRef(); + nullable oFooter; oFooter.Init(); oFooter->FromXML(oNode); - if (oFooter) m_arrFooterReference.push_back( oFooter ); + m_arrFooterReference.push_back( oFooter ); } } } @@ -1587,10 +1568,10 @@ namespace OOX XmlUtils::CXmlNode& oNode = oNodes[nIndex]; if ( oNode.IsValid()) { - ComplexTypes::Word::CHdrFtrRef *oHeader = new ComplexTypes::Word::CHdrFtrRef(); + nullable < ComplexTypes::Word::CHdrFtrRef> oHeader; oHeader.Init(); oHeader->FromXML(oNode); - if (oHeader) m_arrHeaderReference.push_back( oHeader ); + m_arrHeaderReference.push_back( oHeader ); } } } @@ -1661,10 +1642,10 @@ namespace OOX m_oEndnotePr = oReader; else if ( !m_bSectPrChange && L"w:footerReference" == sName ) { - ComplexTypes::Word::CHdrFtrRef *oFooter = new ComplexTypes::Word::CHdrFtrRef(); - *oFooter = oReader; + nullable oFooter; oFooter.Init(); + oFooter->FromXML(oReader); - if (oFooter) m_arrFooterReference.push_back( oFooter ); + m_arrFooterReference.push_back( oFooter ); } else if ( L"w:footnotePr" == sName ) m_oFootnotePr = oReader; @@ -1672,10 +1653,10 @@ namespace OOX m_oFormProt = oReader; else if ( !m_bSectPrChange && L"w:headerReference" == sName ) { - ComplexTypes::Word::CHdrFtrRef *oHeader = new ComplexTypes::Word::CHdrFtrRef(); - *oHeader = oReader; + nullable < ComplexTypes::Word::CHdrFtrRef> oHeader; oHeader.Init(); + oHeader->FromXML(oReader); - if (oHeader) m_arrHeaderReference.push_back( oHeader ); + m_arrHeaderReference.push_back( oHeader ); } else if ( L"w:lnNumType" == sName ) m_oLnNumType = oReader; @@ -1710,10 +1691,10 @@ namespace OOX CDocxFlat* docx_flat = dynamic_cast(document); if (docx_flat) { - ComplexTypes::Word::CHdrFtrRef *pHeaderRef = new ComplexTypes::Word::CHdrFtrRef(); + nullable pHeaderRef; pHeaderRef.Init(); NSCommon::smart_ptr pHeader = new OOX::CHdrFtr(document); - if (pHeaderRef && pHeader.IsInit()) + if (pHeaderRef.IsInit() && pHeader.IsInit()) { OOX::IFileContainer* oldContainer = docx_flat->m_currentContainer; docx_flat->m_currentContainer = dynamic_cast(pHeader.GetPointer()); @@ -1735,10 +1716,10 @@ namespace OOX CDocxFlat* docx_flat = dynamic_cast(document); if (docx_flat) { - ComplexTypes::Word::CHdrFtrRef *pFooterRef = new ComplexTypes::Word::CHdrFtrRef(); + nullable pFooterRef; pFooterRef.Init(); NSCommon::smart_ptr pFooter = new OOX::CHdrFtr(document); - if (pFooter.IsInit() && pFooterRef) + if (pFooter.IsInit() && pFooterRef.IsInit()) { OOX::IFileContainer* oldContainer = docx_flat->m_currentContainer; docx_flat->m_currentContainer = dynamic_cast(pFooter.GetPointer()); @@ -1783,14 +1764,14 @@ namespace OOX for (size_t nIndex = 0; nIndex < m_arrHeaderReference.size(); nIndex++) { sResult += (L"ToString(); sResult += (L"/>"); } for (size_t nIndex = 0; nIndex < m_arrFooterReference.size(); nIndex++) { sResult += (L"ToString(); sResult += (L"/>"); } @@ -1891,6 +1872,11 @@ namespace OOX WritingElement_ReadAttributes_Read_else_if( oReader, (L"w:rsidSect"), m_oRsidSect ) WritingElement_ReadAttributes_End( oReader ) } + const CSectionProperty CSectionProperty::Merge(const CSectionProperty& oPrev, const CSectionProperty& oCurrent) + { + // ??? ну не хорошо это + return oPrev; + } } // Logic } diff --git a/OOXML/DocxFormat/Logic/SectionProperty.h b/OOXML/DocxFormat/Logic/SectionProperty.h index ef2907f7c2..27c7aa490f 100644 --- a/OOXML/DocxFormat/Logic/SectionProperty.h +++ b/OOXML/DocxFormat/Logic/SectionProperty.h @@ -54,12 +54,10 @@ namespace ComplexTypes virtual std::wstring ToString() const; - private: - void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); - - public: nullable m_oSpace; nullable m_oW; + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); }; //-------------------------------------------------------------------------------- @@ -351,23 +349,20 @@ namespace OOX CColumns(); virtual ~CColumns(); - public: virtual void fromXML(XmlUtils::CXmlNode& oNode); virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); virtual std::wstring toXML() const; virtual EElementType getType () const; - private: - void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); - - public: nullable m_oEqualWidth; nullable m_oNum; nullable m_oSep; nullable m_oSpace; - std::vector m_arrColumns; + std::vector< nullable> m_arrColumns; + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); }; //-------------------------------------------------------------------------------- @@ -503,6 +498,7 @@ namespace OOX virtual std::wstring toXML() const; virtual EElementType getType() const; + static const CSectionProperty Merge(const CSectionProperty& oPrev, const CSectionProperty& oCurrent); private: void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); @@ -518,10 +514,10 @@ namespace OOX nullable m_oCols; nullable m_oDocGrid; nullable m_oEndnotePr; - std::vector m_arrFooterReference; + std::vector< nullable> m_arrFooterReference; nullable m_oFootnotePr; nullable m_oFormProt; - std::vector m_arrHeaderReference; + std::vector< nullable> m_arrHeaderReference; nullable m_oLnNumType; nullable m_oNoEndnote; nullable m_oPaperSrc; diff --git a/OdfFile/Writer/Converter/DocxConverter.cpp b/OdfFile/Writer/Converter/DocxConverter.cpp index 189a808d94..57c514c159 100644 --- a/OdfFile/Writer/Converter/DocxConverter.cpp +++ b/OdfFile/Writer/Converter/DocxConverter.cpp @@ -1840,16 +1840,9 @@ void DocxConverter::apply_HF_from(OOX::Logic::CSectionProperty *props, OOX::Logi if (other->m_arrFooterReference.size() > 0) { - for (size_t i =0 ; i < props->m_arrFooterReference.size() ; i++) - { - if (props->m_arrFooterReference[i]) delete props->m_arrFooterReference[i]; - props->m_arrFooterReference[i] = NULL; - } - props->m_arrFooterReference.clear(); - for (size_t i =0 ; i < other->m_arrFooterReference.size() ; i++) { - ComplexTypes::Word::CHdrFtrRef* ref = new ComplexTypes::Word::CHdrFtrRef(); + nullable < ComplexTypes::Word::CHdrFtrRef> ref; ref.Init(); ref->m_oId= other->m_arrFooterReference[i]->m_oId; ref->m_oType= other->m_arrFooterReference[i]->m_oType; @@ -1860,17 +1853,10 @@ void DocxConverter::apply_HF_from(OOX::Logic::CSectionProperty *props, OOX::Logi } if (other->m_arrHeaderReference.size() > 0) { - for (size_t i =0 ; i < props->m_arrHeaderReference.size() ; i++) - { - if (props->m_arrHeaderReference[i]) delete props->m_arrHeaderReference[i]; - props->m_arrHeaderReference[i] = NULL; - } - props->m_arrHeaderReference.clear(); - for (size_t i =0 ; i < other->m_arrHeaderReference.size() ; i++) { - ComplexTypes::Word::CHdrFtrRef* ref = new ComplexTypes::Word::CHdrFtrRef(); - + nullable < ComplexTypes::Word::CHdrFtrRef> ref; ref.Init(); + ref->m_oId= other->m_arrHeaderReference[i]->m_oId; ref->m_oType= other->m_arrHeaderReference[i]->m_oType; @@ -2122,7 +2108,7 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty* oox_section_pr, bool b for (size_t i = 0; i < s->m_arrHeaderReference.size(); i++) { - if (s->m_arrHeaderReference[i] == NULL) continue; + if (false == s->m_arrHeaderReference[i].IsInit()) continue; int type = s->m_arrHeaderReference[i]->m_oType.IsInit() ? s->m_arrHeaderReference[i]->m_oType->GetValue() : 0; @@ -2153,7 +2139,7 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty* oox_section_pr, bool b for (size_t i = 0; i < s->m_arrFooterReference.size(); i++) { - if (s->m_arrFooterReference[i] == NULL) continue; + if (false == s->m_arrFooterReference[i].IsInit()) continue; int type = s->m_arrFooterReference[i]->m_oType.IsInit() ? s->m_arrFooterReference[i]->m_oType->GetValue() : 0; @@ -2267,7 +2253,7 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty* oox_section_pr, bool b for (size_t i = 0; i < oox_section_pr->m_oCols->m_arrColumns.size(); i++) { - if (oox_section_pr->m_oCols->m_arrColumns[i] == NULL) continue; + if (false == oox_section_pr->m_oCols->m_arrColumns[i].IsInit()) continue; double space = default_space_pt; if (oox_section_pr->m_oCols->m_arrColumns[i]->m_oSpace.IsInit()) diff --git a/RtfFile/OOXml/Reader/OOXParagraphElementReaders.cpp b/RtfFile/OOXml/Reader/OOXParagraphElementReaders.cpp index f41cd7ec4a..c2d29de5b9 100644 --- a/RtfFile/OOXml/Reader/OOXParagraphElementReaders.cpp +++ b/RtfFile/OOXml/Reader/OOXParagraphElementReaders.cpp @@ -2110,7 +2110,7 @@ bool OOXSectionPropertyReader::Parse( ReaderParameter oParam , RtfSectionPropert { RtfSectionProperty::ColumnProperty::CollumnVar oNewColumn; - if (m_ooxSectionProperty->m_oCols->m_arrColumns[i] != NULL) + if (m_ooxSectionProperty->m_oCols->m_arrColumns[i].IsInit()) { if(m_ooxSectionProperty->m_oCols->m_arrColumns[i]->m_oW.IsInit() ) oNewColumn.m_nColumnWidth = m_ooxSectionProperty->m_oCols->m_arrColumns[i]->m_oW->ToTwips(); //twips??? todooo @@ -2336,7 +2336,7 @@ bool OOXSectionPropertyReader::Parse( ReaderParameter oParam , RtfSectionPropert } for (size_t i = 0 ; i < m_ooxSectionProperty->m_arrHeaderReference.size(); i++ ) { - OOXHeaderReader oHeaderReader(m_ooxSectionProperty->m_arrHeaderReference[i]); + OOXHeaderReader oHeaderReader(m_ooxSectionProperty->m_arrHeaderReference[i].GetPointer()); if(m_ooxSectionProperty->m_arrHeaderReference[i]->m_oType.IsInit() && m_ooxSectionProperty->m_arrHeaderReference[i]->m_oId.IsInit() ) @@ -2375,7 +2375,7 @@ bool OOXSectionPropertyReader::Parse( ReaderParameter oParam , RtfSectionPropert } for (size_t i = 0 ; i < m_ooxSectionProperty->m_arrFooterReference.size(); i++ ) { - OOXHeaderReader oFooterReader(m_ooxSectionProperty->m_arrFooterReference[i]); + OOXHeaderReader oFooterReader(m_ooxSectionProperty->m_arrFooterReference[i].GetPointer()); if(m_ooxSectionProperty->m_arrFooterReference[i]->m_oType.IsInit() && m_ooxSectionProperty->m_arrFooterReference[i]->m_oId.IsInit() )