diff --git a/ASCOfficeDocxFile2/BinReader/Common.h b/ASCOfficeDocxFile2/BinReader/Common.h index 2d667405b9..c2a297c56b 100644 --- a/ASCOfficeDocxFile2/BinReader/Common.h +++ b/ASCOfficeDocxFile2/BinReader/Common.h @@ -3,6 +3,7 @@ #define BINREADER_COMMON #include "FileDownloader.h" +#include "../../Common/Base64.h" bool IsUnicodeSymbol( WCHAR symbol ) { diff --git a/ASCOfficeDocxFile2/BinReader/DocumentWriter.h b/ASCOfficeDocxFile2/BinReader/DocumentWriter.h index 5d385917f7..dd6aa9b53b 100644 --- a/ASCOfficeDocxFile2/BinReader/DocumentWriter.h +++ b/ASCOfficeDocxFile2/BinReader/DocumentWriter.h @@ -1,6 +1,6 @@ #pragma once #include "Common.h" - +#include "../BinWriter/BinReaderWriterDefines.h"; namespace Writers { class DocumentWriter : public ContentWriter @@ -29,27 +29,52 @@ namespace Writers CString WriteSectPrHdrFtr() { CString sResult; - bool bTitlePage = false; - if(!m_oHeaderFooterWriter.m_oHeaderFirst.rId.IsEmpty()) + if(g_nCurFormatVersion < 5) { - sResult += _T(""); - bTitlePage = true; + bool bTitlePage = false; + for(int i = 0, length = m_oHeaderFooterWriter.m_aHeaders.GetCount(); i < length; ++i) + { + HdrFtrItem* pHeader = m_oHeaderFooterWriter.m_aHeaders[i]; + if(false == pHeader->rId.IsEmpty()) + { + if(SimpleTypes::hdrftrFirst == pHeader->eType) + { + sResult += _T("rId + _T("\"/>"); + bTitlePage = true; + } + else if(SimpleTypes::hdrftrEven == pHeader->eType) + { + sResult += _T("rId + _T("\"/>"); + } + else + { + sResult += _T("rId + _T("\"/>"); + } + } + } + for(int i = 0, length = m_oHeaderFooterWriter.m_aFooters.GetCount(); i < length; ++i) + { + HdrFtrItem* pFooter = m_oHeaderFooterWriter.m_aFooters[i]; + if(false == pFooter->rId.IsEmpty()) + { + if(SimpleTypes::hdrftrFirst == pFooter->eType) + { + sResult += _T("rId + _T("\"/>"); + bTitlePage = true; + } + else if(SimpleTypes::hdrftrEven == pFooter->eType) + { + sResult += _T("rId + _T("\"/>"); + } + else + { + sResult += _T("rId + _T("\"/>"); + } + } + } + if(true == bTitlePage) + sResult += _T(""); } - if(!m_oHeaderFooterWriter.m_oHeaderEven.rId.IsEmpty()) - sResult += _T(""); - if(!m_oHeaderFooterWriter.m_oHeaderOdd.rId.IsEmpty()) - sResult += _T(""); - if(!m_oHeaderFooterWriter.m_oFooterFirst.rId.IsEmpty()) - { - sResult += _T(""); - bTitlePage = true; - } - if(!m_oHeaderFooterWriter.m_oFooterEven.rId.IsEmpty()) - sResult += _T(""); - if(!m_oHeaderFooterWriter.m_oFooterOdd.rId.IsEmpty()) - sResult += _T(""); - if(true == bTitlePage) - sResult += _T(""); return sResult; } }; diff --git a/ASCOfficeDocxFile2/BinReader/HeaderFooterWriter.h b/ASCOfficeDocxFile2/BinReader/HeaderFooterWriter.h index 42962459a7..bf8fd775dc 100644 --- a/ASCOfficeDocxFile2/BinReader/HeaderFooterWriter.h +++ b/ASCOfficeDocxFile2/BinReader/HeaderFooterWriter.h @@ -12,8 +12,9 @@ namespace Writers class HdrFtrItem { public: - HdrFtrItem(CString sDir) + HdrFtrItem(SimpleTypes::EHdrFtr _eType) { + eType = _eType; } bool IsEmpty() { @@ -22,6 +23,7 @@ namespace Writers CString m_sFilename; ContentWriter Header; CString rId; + SimpleTypes::EHdrFtr eType; }; static CString g_string_hdr_Start = _T(""); static CString g_string_hdr_End = _T(""); @@ -34,50 +36,38 @@ namespace Writers CString m_sDir; ContentTypesWriter& m_oContentTypesWriter; public: - HdrFtrItem m_oHeaderFirst; - HdrFtrItem m_oHeaderEven; - HdrFtrItem m_oHeaderOdd; - - HdrFtrItem m_oFooterFirst; - HdrFtrItem m_oFooterEven; - HdrFtrItem m_oFooterOdd; + CAtlArray m_aHeaders; + CAtlArray m_aFooters; public: - HeaderFooterWriter(CString sDir, ContentTypesWriter& oContentTypesWriter):m_sDir(sDir),m_oContentTypesWriter(oContentTypesWriter), - m_oHeaderFirst(sDir),m_oHeaderEven(sDir),m_oHeaderOdd(sDir),m_oFooterFirst(sDir),m_oFooterEven(sDir),m_oFooterOdd(sDir) + HeaderFooterWriter(CString sDir, ContentTypesWriter& oContentTypesWriter):m_sDir(sDir),m_oContentTypesWriter(oContentTypesWriter) { } + ~HeaderFooterWriter() + { + for(int i = 0, length = m_aHeaders.GetCount(); i < length; ++i) + delete m_aHeaders[i]; + m_aHeaders.RemoveAll(); + for(int i = 0, length = m_aFooters.GetCount(); i < length; ++i) + delete m_aFooters[i]; + m_aFooters.RemoveAll(); + } void Write() { - if(false == m_oHeaderFirst.IsEmpty()) + for(int i = 0, length = m_aHeaders.GetCount(); i < length; ++i) { - WriteItem(_T("header"), m_oHeaderFirst.m_sFilename, m_oHeaderFirst.Header, true); - //m_oHeaderFirst.RelsWriter.Write(sFilename + _T(".rels")); + HdrFtrItem* pHeader = m_aHeaders[i]; + if(false == pHeader->IsEmpty()) + { + WriteItem(_T("header"), pHeader->m_sFilename, pHeader->Header, true); + } } - if(false == m_oHeaderEven.IsEmpty()) + for(int i = 0, length = m_aFooters.GetCount(); i < length; ++i) { - WriteItem(_T("header"), m_oHeaderEven.m_sFilename, m_oHeaderEven.Header, true); - //m_oHeaderEven.RelsWriter.Write(sFilename + _T(".rels")); - } - if(false == m_oHeaderOdd.IsEmpty()) - { - WriteItem(_T("header"), m_oHeaderOdd.m_sFilename, m_oHeaderOdd.Header, true); - //m_oHeaderOdd.RelsWriter.Write(sFilename + _T(".rels")); - } - - if(false == m_oFooterFirst.IsEmpty()) - { - WriteItem(_T("footer"), m_oFooterFirst.m_sFilename, m_oFooterFirst.Header, false); - //m_oFooterFirst.RelsWriter.Write(sFilename + _T(".rels")); - } - if(false == m_oFooterEven.IsEmpty()) - { - WriteItem(_T("footer"), m_oFooterEven.m_sFilename, m_oFooterEven.Header, false); - //m_oFooterEven.RelsWriter.Write(sFilename + _T(".rels")); - } - if(false == m_oFooterOdd.IsEmpty()) - { - WriteItem(_T("footer"), m_oFooterOdd.m_sFilename, m_oFooterOdd.Header, false); - //m_oFooterOdd.RelsWriter.Write(sFilename + _T(".rels")); + HdrFtrItem* pFooter = m_aFooters[i]; + if(false == pFooter->IsEmpty()) + { + WriteItem(_T("footer"), pFooter->m_sFilename, pFooter->Header, false); + } } } void WriteItem(CString sHeader, CString& sFilename, ContentWriter& m_oWriter, bool bHeader) diff --git a/ASCOfficeDocxFile2/BinReader/ReaderClasses.h b/ASCOfficeDocxFile2/BinReader/ReaderClasses.h index 790d0df11e..0333c9b3a2 100644 --- a/ASCOfficeDocxFile2/BinReader/ReaderClasses.h +++ b/ASCOfficeDocxFile2/BinReader/ReaderClasses.h @@ -5,6 +5,7 @@ namespace BinDocxRW { class SectPr { public: + CString sHeaderFooterReference; double W; double H; BYTE cOrientation; @@ -14,9 +15,13 @@ public: double Bottom; double Header; double Footer; + bool TitlePg; + bool EvenAndOddHeaders; bool bHeader; bool bFooter; + bool bTitlePg; + bool bEvenAndOddHeaders; SectPr() { W = Page_Width; @@ -28,9 +33,40 @@ public: Bottom = 20; Header = 12.5; Footer = 12.5; + sHeaderFooterReference = _T(""); bHeader = false; bFooter = false; + bTitlePg = false; + bEvenAndOddHeaders = false; + } + CString Write() + { + CString sRes = _T(""); + long nWidth = Round(W * g_dKoef_mm_to_twips); + long nHeight = Round(H * g_dKoef_mm_to_twips); + long nMLeft = Round(Left * g_dKoef_mm_to_twips); + long nMTop = Round(Top * g_dKoef_mm_to_twips); + long nMRight = Round(Right * g_dKoef_mm_to_twips); + long nMBottom = Round(Bottom * g_dKoef_mm_to_twips); + long nMHeader = Round(Header * g_dKoef_mm_to_twips); + long nMFooter = Round(Footer * g_dKoef_mm_to_twips); + if(!sHeaderFooterReference.IsEmpty()) + sRes.Append(sHeaderFooterReference); + if(orientation_Portrait == cOrientation) + sRes.AppendFormat(_T(""), nWidth, nHeight); + else + sRes.AppendFormat(_T(""), nWidth, nHeight); + sRes.AppendFormat(_T("")); + sRes.Append(_T("")); + if(bTitlePg && TitlePg) + sRes.Append(_T("")); + return sRes; } }; class docRGB @@ -1946,7 +1982,7 @@ public: { if(false == Layout.IsEmpty()) sRes.Append(Layout); - else if(g_nFormatVersion < 4) + else if(g_nCurFormatVersion < 4) sRes.Append(_T("")); } if(false == TableCellMar.IsEmpty()) diff --git a/ASCOfficeDocxFile2/BinReader/Readers.h b/ASCOfficeDocxFile2/BinReader/Readers.h index 3f86db1d0a..b79856a015 100644 --- a/ASCOfficeDocxFile2/BinReader/Readers.h +++ b/ASCOfficeDocxFile2/BinReader/Readers.h @@ -141,6 +141,21 @@ private: return res; }; }; +class Binary_HdrFtrTableReader : public Binary_CommonReader +{ + Writers::FileWriter& m_oFileWriter; + int nCurType; + int nCurHeaderType; +public: + Writers::HeaderFooterWriter& m_oHeaderFooterWriter; +public: + Binary_HdrFtrTableReader(Streams::CBufferedStream& poBufferedStream, Writers::FileWriter& oFileWriter); + int Read(); + int ReadHdrFtrContent(BYTE type, long length, void* poResult); + int ReadHdrFtrFEO(BYTE type, long length, void* poResult); + int ReadHdrFtrItem(BYTE type, long length, void* poResult); + int ReadHdrFtrItemContent(BYTE type, long length, void* poResult); +}; class Binary_rPrReader : public Binary_CommonReader { protected: @@ -371,11 +386,14 @@ private: public: Binary_CommonReader2 oBinary_CommonReader2; Binary_rPrReader oBinary_rPrReader; + Binary_HdrFtrTableReader oBinary_HdrFtrTableReader; + Writers::FileWriter& m_oFileWriter; bool bDoNotWriteNullProp; long m_nCurNumId; long m_nCurLvl; - Binary_pPrReader(Streams::CBufferedStream& poBufferedStream, Writers::FileWriter& oFileWriter):m_oFontTableWriter(oFileWriter.m_oFontTableWriter),Binary_CommonReader(poBufferedStream),oBinary_CommonReader2(poBufferedStream),oBinary_rPrReader(poBufferedStream) + Binary_pPrReader(Streams::CBufferedStream& poBufferedStream, Writers::FileWriter& oFileWriter): + m_oFontTableWriter(oFileWriter.m_oFontTableWriter),Binary_CommonReader(poBufferedStream),oBinary_CommonReader2(poBufferedStream),oBinary_rPrReader(poBufferedStream),oBinary_HdrFtrTableReader(poBufferedStream,oFileWriter),m_oFileWriter(oFileWriter) { bDoNotWriteNullProp = false; m_nCurNumId = -1; @@ -619,6 +637,15 @@ public: oFramePr.Write(*pCStringWriter); break; } + case c_oSerProp_pPrType::SectPr: + { + SectPr oSectPr; + res = Read1(length, &Binary_pPrReader::Read_SecPr, this, &oSectPr); + pCStringWriter->WriteString(CString(_T(""))); + pCStringWriter->WriteString(oSectPr.Write()); + pCStringWriter->WriteString(CString(_T(""))); + break; + } default: res = c_oSerConstants::ReadUnknown; break; @@ -904,6 +931,156 @@ public: res = c_oSerConstants::ReadUnknown; return res; }; + int Read_SecPr(BYTE type, long length, void* poResult) + { + SectPr* pSectPr = static_cast(poResult); + int res = c_oSerConstants::ReadOk; + if( c_oSerProp_secPrType::pgSz == type ) + { + res = Read2(length, &Binary_pPrReader::Read_pgSz, this, poResult); + } + else if( c_oSerProp_secPrType::pgMar == type ) + { + res = Read2(length, &Binary_pPrReader::Read_pgMar, this, poResult); + } + else if( c_oSerProp_secPrType::setting == type ) + { + res = Read2(length, &Binary_pPrReader::Read_pgSetting, this, poResult); + } + else if( c_oSerProp_secPrType::headers == type ) + { + res = Read1(length, &Binary_pPrReader::Read_pgHeader, this, poResult); + } + else if( c_oSerProp_secPrType::footers == type ) + { + res = Read1(length, &Binary_pPrReader::Read_pgFooter, this, poResult); + } + else + res = c_oSerConstants::ReadUnknown; + return res; + } + int Read_pgSz(BYTE type, long length, void* poResult) + { + SectPr* pSectPr = static_cast(poResult); + int res = c_oSerConstants::ReadOk; + if( c_oSer_pgSzType::Orientation == type ) + { + pSectPr->cOrientation = m_oBufferedStream.ReadByte(); + } + else if( c_oSer_pgSzType::W == type ) + { + pSectPr->W = m_oBufferedStream.ReadDouble2(); + } + else if( c_oSer_pgSzType::H == type ) + { + pSectPr->H = m_oBufferedStream.ReadDouble2(); + } + else + res = c_oSerConstants::ReadUnknown; + return res; + } + int Read_pgMar(BYTE type, long length, void* poResult) + { + SectPr* pSectPr = static_cast(poResult); + int res = c_oSerConstants::ReadOk; + if( c_oSer_pgMarType::Left == type ) + { + pSectPr->Left = m_oBufferedStream.ReadDouble2(); + } + else if( c_oSer_pgMarType::Top == type ) + { + pSectPr->Top = m_oBufferedStream.ReadDouble2(); + } + else if( c_oSer_pgMarType::Right == type ) + { + pSectPr->Right = m_oBufferedStream.ReadDouble2(); + } + else if( c_oSer_pgMarType::Bottom == type ) + { + pSectPr->Bottom = m_oBufferedStream.ReadDouble2(); + } + else if( c_oSer_pgMarType::Header == type ) + { + pSectPr->bHeader = true; + pSectPr->Header = m_oBufferedStream.ReadDouble2(); + } + else if( c_oSer_pgMarType::Footer == type ) + { + pSectPr->bFooter = true; + pSectPr->Footer = m_oBufferedStream.ReadDouble2(); + } + else + res = c_oSerConstants::ReadUnknown; + return res; + } + int Read_pgSetting(BYTE type, long length, void* poResult) + { + SectPr* pSectPr = static_cast(poResult); + int res = c_oSerConstants::ReadOk; + if( c_oSerProp_secPrSettingsType::titlePg == type ) + { + pSectPr->bTitlePg = true; + pSectPr->TitlePg = m_oBufferedStream.ReadBool(); + } + else if( c_oSerProp_secPrSettingsType::EvenAndOddHeaders == type ) + { + pSectPr->bEvenAndOddHeaders = true; + pSectPr->EvenAndOddHeaders = m_oBufferedStream.ReadBool(); + } + else + res = c_oSerConstants::ReadUnknown; + return res; + } + int Read_pgHeader(BYTE type, long length, void* poResult) + { + SectPr* pSectPr = static_cast(poResult); + int res = c_oSerConstants::ReadOk; + if( c_oSerProp_secPrType::hdrftrelem == type ) + { + int nHdrFtrIndex = m_oBufferedStream.ReadLong(); + if(nHdrFtrIndex >= 0 && nHdrFtrIndex <= m_oFileWriter.m_oHeaderFooterWriter.m_aHeaders.GetCount()) + { + Writers::HdrFtrItem* pHdrFtrItem = m_oFileWriter.m_oHeaderFooterWriter.m_aHeaders[nHdrFtrIndex]; + pHdrFtrItem->m_sFilename; + CString sType; + if(SimpleTypes::hdrftrFirst == pHdrFtrItem->eType) + sType = _T("first"); + else if(SimpleTypes::hdrftrEven == pHdrFtrItem->eType) + sType = _T("even"); + else + sType = _T("default"); + pSectPr->sHeaderFooterReference += _T("rId + _T("\"/>"); + } + } + else + res = c_oSerConstants::ReadUnknown; + return res; + } + int Read_pgFooter(BYTE type, long length, void* poResult) + { + SectPr* pSectPr = static_cast(poResult); + int res = c_oSerConstants::ReadOk; + if( c_oSerProp_secPrType::hdrftrelem == type ) + { + int nHdrFtrIndex = m_oBufferedStream.ReadLong(); + if(nHdrFtrIndex >= 0 && nHdrFtrIndex <= oBinary_HdrFtrTableReader.m_oHeaderFooterWriter.m_aFooters.GetCount()) + { + Writers::HdrFtrItem* pHdrFtrItem = oBinary_HdrFtrTableReader.m_oHeaderFooterWriter.m_aFooters[nHdrFtrIndex]; + pHdrFtrItem->m_sFilename; + CString sType; + if(SimpleTypes::hdrftrFirst == pHdrFtrItem->eType) + sType = _T("first"); + else if(SimpleTypes::hdrftrEven == pHdrFtrItem->eType) + sType = _T("even"); + else + sType = _T("default"); + pSectPr->sHeaderFooterReference += _T("rId + _T("\"/>"); + } + } + else + res = c_oSerConstants::ReadUnknown; + return res; + } }; class Binary_tblPrReader : public Binary_CommonReader { @@ -2662,35 +2839,9 @@ public: { SectPr oSectPr; res = Read1(length, &Binary_DocumentTableReader::Read_SecPr, this, &oSectPr); - long nWidth = Round(oSectPr.W * g_dKoef_mm_to_twips); - long nHeight = Round(oSectPr.H * g_dKoef_mm_to_twips); - long nMLeft = Round(oSectPr.Left * g_dKoef_mm_to_twips); - long nMTop = Round(oSectPr.Top * g_dKoef_mm_to_twips); - long nMRight = Round(oSectPr.Right * g_dKoef_mm_to_twips); - long nMBottom = Round(oSectPr.Bottom * g_dKoef_mm_to_twips); - long nMHeader = Round(oSectPr.Header * g_dKoef_mm_to_twips); - long nMFooter = Round(oSectPr.Footer * g_dKoef_mm_to_twips); - - CString pgSz; - if(orientation_Portrait == oSectPr.cOrientation) - pgSz.Format(_T(""), nWidth, nHeight); - else - pgSz.Format(_T(""), nWidth, nHeight); - CString pgMar;pgMar.Format(_T(""); - m_oDocumentWriter.m_oSecPr.WriteString(pgSz); - m_oDocumentWriter.m_oSecPr.WriteString(pgMar); - m_oDocumentWriter.m_oSecPr.WriteString(CString(_T(""))); + m_oDocumentWriter.m_oSecPr.WriteString(oSectPr.Write()); + if(oSectPr.bEvenAndOddHeaders && oSectPr.EvenAndOddHeaders) + m_oFileWriter.m_oSettingWriter.AddSetting(_T("")); } else res = c_oSerConstants::ReadUnknown; @@ -5265,75 +5416,6 @@ public: Binary_DocumentTableReader* pBinary_DocumentTableReader = static_cast(poResult); return pBinary_DocumentTableReader->ReadDocumentContent(type, length, NULL); } - int Read_SecPr(BYTE type, long length, void* poResult) - { - int res = c_oSerConstants::ReadOk; - if( c_oSerProp_secPrType::pgSz == type ) - { - res = Read2(length, &Binary_DocumentTableReader::Read_pgSz, this, poResult); - } - else if( c_oSerProp_secPrType::pgMar == type ) - { - res = Read2(length, &Binary_DocumentTableReader::Read_pgMar, this, poResult); - } - else - res = c_oSerConstants::ReadUnknown; - return res; - } - int Read_pgSz(BYTE type, long length, void* poResult) - { - SectPr* pSectPr = static_cast(poResult); - int res = c_oSerConstants::ReadOk; - if( c_oSer_pgSzType::Orientation == type ) - { - pSectPr->cOrientation = m_oBufferedStream.ReadByte(); - } - else if( c_oSer_pgSzType::W == type ) - { - pSectPr->W = m_oBufferedStream.ReadDouble2(); - } - else if( c_oSer_pgSzType::H == type ) - { - pSectPr->H = m_oBufferedStream.ReadDouble2(); - } - else - res = c_oSerConstants::ReadUnknown; - return res; - } - int Read_pgMar(BYTE type, long length, void* poResult) - { - SectPr* pSectPr = static_cast(poResult); - int res = c_oSerConstants::ReadOk; - if( c_oSer_pgMarType::Left == type ) - { - pSectPr->Left = m_oBufferedStream.ReadDouble2(); - } - else if( c_oSer_pgMarType::Top == type ) - { - pSectPr->Top = m_oBufferedStream.ReadDouble2(); - } - else if( c_oSer_pgMarType::Right == type ) - { - pSectPr->Right = m_oBufferedStream.ReadDouble2(); - } - else if( c_oSer_pgMarType::Bottom == type ) - { - pSectPr->Bottom = m_oBufferedStream.ReadDouble2(); - } - else if( c_oSer_pgMarType::Header == type ) - { - pSectPr->bHeader = true; - pSectPr->Header = m_oBufferedStream.ReadDouble2(); - } - else if( c_oSer_pgMarType::Footer == type ) - { - pSectPr->bFooter = true; - pSectPr->Footer = m_oBufferedStream.ReadDouble2(); - } - else - res = c_oSerConstants::ReadUnknown; - return res; - } int ReadImage(BYTE type, long length, void* poResult) { int res = c_oSerConstants::ReadOk; @@ -5715,76 +5797,65 @@ public: int res = c_oSerConstants::ReadUnknown; return res; } -}; -class Binary_HdrFtrTableReader : public Binary_CommonReader -{ - Writers::FileWriter& m_oFileWriter; - Writers::HeaderFooterWriter& m_oHeaderFooterWriter; - int nCurType; - int nCurHeaderType; - int nHeaderCount; - int nFooterCount; -public: - Binary_HdrFtrTableReader(Streams::CBufferedStream& poBufferedStream, Writers::FileWriter& oFileWriter):Binary_CommonReader(poBufferedStream),m_oFileWriter(oFileWriter),m_oHeaderFooterWriter(oFileWriter.m_oHeaderFooterWriter) + int Read_SecPr(BYTE type, long length, void* poResult) { - nHeaderCount = 0; - nFooterCount = 0; + return oBinary_pPrReader.Read_SecPr(type, length, poResult); } - int Read() - { - return ReadTable(&Binary_HdrFtrTableReader::ReadHdrFtrContent, this); - }; - int ReadHdrFtrContent(BYTE type, long length, void* poResult) - { - int res = c_oSerConstants::ReadOk; - if ( c_oSerHdrFtrTypes::Header == type || c_oSerHdrFtrTypes::Footer == type ) - { - nCurType = type; - res = Read1(length, &Binary_HdrFtrTableReader::ReadHdrFtrFEO, this, poResult); - } - else - res = c_oSerConstants::ReadUnknown; - return res; - }; - int ReadHdrFtrFEO(BYTE type, long length, void* poResult) - { - int res = c_oSerConstants::ReadOk; - if ( c_oSerHdrFtrTypes::HdrFtr_First == type || c_oSerHdrFtrTypes::HdrFtr_Even == type || c_oSerHdrFtrTypes::HdrFtr_Odd == type ) - { - nCurHeaderType = type; - res = Read1(length, &Binary_HdrFtrTableReader::ReadHdrFtrItem, this, poResult); - } - else - res = c_oSerConstants::ReadUnknown; - return res; - }; - int ReadHdrFtrItem(BYTE type, long length, void* poResult) - { - int res = c_oSerConstants::ReadOk; - if ( c_oSerHdrFtrTypes::HdrFtr_Content == type ) - { - Writers::HdrFtrItem* poHdrFtrItem = NULL; +}; +Binary_HdrFtrTableReader::Binary_HdrFtrTableReader(Streams::CBufferedStream& poBufferedStream, Writers::FileWriter& oFileWriter):Binary_CommonReader(poBufferedStream),m_oFileWriter(oFileWriter),m_oHeaderFooterWriter(oFileWriter.m_oHeaderFooterWriter) +{ +} +int Binary_HdrFtrTableReader::Read() +{ + return ReadTable(&Binary_HdrFtrTableReader::ReadHdrFtrContent, this); +}; +int Binary_HdrFtrTableReader::ReadHdrFtrContent(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + if ( c_oSerHdrFtrTypes::Header == type || c_oSerHdrFtrTypes::Footer == type ) + { + nCurType = type; + res = Read1(length, &Binary_HdrFtrTableReader::ReadHdrFtrFEO, this, poResult); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +}; +int Binary_HdrFtrTableReader::ReadHdrFtrFEO(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + if ( c_oSerHdrFtrTypes::HdrFtr_First == type || c_oSerHdrFtrTypes::HdrFtr_Even == type || c_oSerHdrFtrTypes::HdrFtr_Odd == type ) + { + nCurHeaderType = type; + res = Read1(length, &Binary_HdrFtrTableReader::ReadHdrFtrItem, this, poResult); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +}; +int Binary_HdrFtrTableReader::ReadHdrFtrItem(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + if ( c_oSerHdrFtrTypes::HdrFtr_Content == type ) + { + Writers::HdrFtrItem* poHdrFtrItem = NULL; + switch(nCurHeaderType) + { + case c_oSerHdrFtrTypes::HdrFtr_First:poHdrFtrItem = new Writers::HdrFtrItem(SimpleTypes::hdrftrFirst);break; + case c_oSerHdrFtrTypes::HdrFtr_Even:poHdrFtrItem = new Writers::HdrFtrItem(SimpleTypes::hdrftrEven);break; + case c_oSerHdrFtrTypes::HdrFtr_Odd:poHdrFtrItem = new Writers::HdrFtrItem(SimpleTypes::hdrftrDefault);break; + } + if(NULL != poHdrFtrItem) + { if(nCurType == c_oSerHdrFtrTypes::Header) { - switch(nCurHeaderType) - { - case c_oSerHdrFtrTypes::HdrFtr_First:poHdrFtrItem = &m_oHeaderFooterWriter.m_oHeaderFirst;break; - case c_oSerHdrFtrTypes::HdrFtr_Even:poHdrFtrItem = &m_oHeaderFooterWriter.m_oHeaderEven;break; - case c_oSerHdrFtrTypes::HdrFtr_Odd:poHdrFtrItem = &m_oHeaderFooterWriter.m_oHeaderOdd;break; - } - nHeaderCount++; - poHdrFtrItem->m_sFilename.Format(_T("header%d.xml"), nHeaderCount); + m_oHeaderFooterWriter.m_aHeaders.Add(poHdrFtrItem); + poHdrFtrItem->m_sFilename.Format(_T("header%d.xml"), m_oHeaderFooterWriter.m_aHeaders.GetCount()); } else { - switch(nCurHeaderType) - { - case c_oSerHdrFtrTypes::HdrFtr_First:poHdrFtrItem = &m_oHeaderFooterWriter.m_oFooterFirst;break; - case c_oSerHdrFtrTypes::HdrFtr_Even:poHdrFtrItem = &m_oHeaderFooterWriter.m_oFooterEven;break; - case c_oSerHdrFtrTypes::HdrFtr_Odd:poHdrFtrItem = &m_oHeaderFooterWriter.m_oFooterOdd;break; - } - nFooterCount++; - poHdrFtrItem->m_sFilename.Format(_T("footer%d.xml"), nFooterCount); + m_oHeaderFooterWriter.m_aFooters.Add(poHdrFtrItem); + poHdrFtrItem->m_sFilename.Format(_T("footer%d.xml"), m_oHeaderFooterWriter.m_aFooters.GetCount()); } m_oFileWriter.m_pDrawingConverter->SetDstContentRels(); Binary_DocumentTableReader oBinary_DocumentTableReader(m_oBufferedStream, m_oFileWriter, poHdrFtrItem->Header, NULL); @@ -5797,17 +5868,16 @@ public: m_oFileWriter.m_pDrawingConverter->SaveDstContentRels(bstrRelsPath); SysFreeString(bstrRelsPath); } - - } - else - res = c_oSerConstants::ReadUnknown; - return res; - }; - int ReadHdrFtrItemContent(BYTE type, long length, void* poResult) - { - Binary_DocumentTableReader* pBinary_DocumentTableReader = static_cast(poResult); - return pBinary_DocumentTableReader->ReadDocumentContent(type, length, NULL); - }; + } + } + else + res = c_oSerConstants::ReadUnknown; + return res; +}; +int Binary_HdrFtrTableReader::ReadHdrFtrItemContent(BYTE type, long length, void* poResult) +{ + Binary_DocumentTableReader* pBinary_DocumentTableReader = static_cast(poResult); + return pBinary_DocumentTableReader->ReadDocumentContent(type, length, NULL); }; class BinaryFileReader { @@ -5953,53 +6023,29 @@ public: BinaryFileReader(CString& sFileInDir, Streams::CBufferedStream& oBuffere long rId; m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"), _T("numbering.xml"), NULL, &rId); } - if(false == m_oFileWriter.m_oHeaderFooterWriter.m_oHeaderFirst.IsEmpty()) + for(int i = 0, length = m_oFileWriter.m_oHeaderFooterWriter.m_aHeaders.GetCount(); i < length; ++i) { - long rId; - BSTR bstrFilename = m_oFileWriter.m_oHeaderFooterWriter.m_oHeaderFirst.m_sFilename.AllocSysString(); - m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"), bstrFilename, NULL, &rId); - SysFreeString(bstrFilename); - m_oFileWriter.m_oHeaderFooterWriter.m_oHeaderFirst.rId.Format(_T("rId%d"), rId); + Writers::HdrFtrItem* pHeader = m_oFileWriter.m_oHeaderFooterWriter.m_aHeaders[i]; + if(false == pHeader->IsEmpty()) + { + long rId; + BSTR bstrFilename = pHeader->m_sFilename.AllocSysString(); + m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"), bstrFilename, NULL, &rId); + SysFreeString(bstrFilename); + pHeader->rId.Format(_T("rId%d"), rId); + } } - if(false == m_oFileWriter.m_oHeaderFooterWriter.m_oHeaderEven.IsEmpty()) + for(int i = 0, length = m_oFileWriter.m_oHeaderFooterWriter.m_aFooters.GetCount(); i < length; ++i) { - long rId; - BSTR bstrFilename = m_oFileWriter.m_oHeaderFooterWriter.m_oHeaderEven.m_sFilename.AllocSysString(); - m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"), bstrFilename, NULL, &rId); - SysFreeString(bstrFilename); - m_oFileWriter.m_oHeaderFooterWriter.m_oHeaderEven.rId.Format(_T("rId%d"), rId); - } - if(false == m_oFileWriter.m_oHeaderFooterWriter.m_oHeaderOdd.IsEmpty()) - { - long rId; - BSTR bstrFilename = m_oFileWriter.m_oHeaderFooterWriter.m_oHeaderOdd.m_sFilename.AllocSysString(); - m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"), bstrFilename, NULL, &rId); - SysFreeString(bstrFilename); - m_oFileWriter.m_oHeaderFooterWriter.m_oHeaderOdd.rId.Format(_T("rId%d"), rId); - } - if(false == m_oFileWriter.m_oHeaderFooterWriter.m_oFooterFirst.IsEmpty()) - { - long rId; - BSTR bstrFilename = m_oFileWriter.m_oHeaderFooterWriter.m_oFooterFirst.m_sFilename.AllocSysString(); - m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"), bstrFilename, NULL, &rId); - SysFreeString(bstrFilename); - m_oFileWriter.m_oHeaderFooterWriter.m_oFooterFirst.rId.Format(_T("rId%d"), rId); - } - if(false == m_oFileWriter.m_oHeaderFooterWriter.m_oFooterEven.IsEmpty()) - { - long rId; - BSTR bstrFilename = m_oFileWriter.m_oHeaderFooterWriter.m_oFooterEven.m_sFilename.AllocSysString(); - m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"), bstrFilename, NULL, &rId); - SysFreeString(bstrFilename); - m_oFileWriter.m_oHeaderFooterWriter.m_oFooterEven.rId.Format(_T("rId%d"), rId); - } - if(false == m_oFileWriter.m_oHeaderFooterWriter.m_oFooterOdd.IsEmpty()) - { - long rId; - BSTR bstrFilename = m_oFileWriter.m_oHeaderFooterWriter.m_oFooterOdd.m_sFilename.AllocSysString(); - m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"), bstrFilename, NULL, &rId); - SysFreeString(bstrFilename); - m_oFileWriter.m_oHeaderFooterWriter.m_oFooterOdd.rId.Format(_T("rId%d"), rId); + Writers::HdrFtrItem* pFooter = m_oFileWriter.m_oHeaderFooterWriter.m_aFooters[i]; + if(false == pFooter->IsEmpty()) + { + long rId; + BSTR bstrFilename = pFooter->m_sFilename.AllocSysString(); + m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"), bstrFilename, NULL, &rId); + SysFreeString(bstrFilename); + pFooter->rId.Format(_T("rId%d"), rId); + } } res = Binary_DocumentTableReader(m_oBufferedStream, m_oFileWriter, m_oFileWriter.m_oDocumentWriter, &oBinary_CommentsTableReader.m_oComments).Read(); CString sRelsPath = m_oFileWriter.m_oDocumentWriter.m_sDir + _T("\\word\\_rels\\document.xml.rels"); diff --git a/ASCOfficeDocxFile2/BinReader/SettingWriter.h b/ASCOfficeDocxFile2/BinReader/SettingWriter.h index 56a8bb7811..f34836d9ee 100644 --- a/ASCOfficeDocxFile2/BinReader/SettingWriter.h +++ b/ASCOfficeDocxFile2/BinReader/SettingWriter.h @@ -34,13 +34,24 @@ namespace Writers } void Prepare() { - bool bevenAndOddHeaders = false; - if(!m_oHeaderFooterWriter.m_oHeaderEven.rId.IsEmpty()) - bevenAndOddHeaders = true; - if(!m_oHeaderFooterWriter.m_oFooterEven.rId.IsEmpty()) - bevenAndOddHeaders = true; - if(bevenAndOddHeaders) - AddSetting(_T("")); + if(g_nCurFormatVersion < 5) + { + bool bevenAndOddHeaders = false; + for(int i = 0, length = m_oHeaderFooterWriter.m_aHeaders.GetCount(); i < length; ++i) + { + HdrFtrItem* pHeader = m_oHeaderFooterWriter.m_aHeaders[i]; + if(SimpleTypes::hdrftrEven == pHeader->eType) + bevenAndOddHeaders = true; + } + for(int i = 0, length = m_oHeaderFooterWriter.m_aFooters.GetCount(); i < length; ++i) + { + HdrFtrItem* pFooter = m_oHeaderFooterWriter.m_aFooters[i]; + if(SimpleTypes::hdrftrEven == pFooter->eType) + bevenAndOddHeaders = true; + } + if(bevenAndOddHeaders) + AddSetting(_T("")); + } } }; } \ No newline at end of file diff --git a/ASCOfficeDocxFile2/BinWriter/BinReaderWriterDefines.h b/ASCOfficeDocxFile2/BinWriter/BinReaderWriterDefines.h index 58c70bab70..22a713c812 100644 --- a/ASCOfficeDocxFile2/BinWriter/BinReaderWriterDefines.h +++ b/ASCOfficeDocxFile2/BinWriter/BinReaderWriterDefines.h @@ -1,4 +1,5 @@ #pragma once +extern int g_nCurFormatVersion; namespace BinDocxRW { const double eps = 0.001; @@ -93,7 +94,7 @@ const double g_dKoef_mm_to_eightpoint = 8 * g_dKoef_mm_to_pt; const double g_dKoef_mm_to_hps = 2 * g_dKoef_mm_to_pt; const static TCHAR* g_sFormatSignature = _T("DOCY"); -const int g_nFormatVersion = 4; +const int g_nFormatVersion = 5; namespace c_oAscWrapStyle{enum c_oSerFormat { Inline = 0, @@ -293,7 +294,8 @@ const int g_nFormatVersion = 4; pBdr = 27, Spacing_BeforeAuto = 28, Spacing_AfterAuto = 29, - FramePr = 30 + FramePr = 30, + SectPr = 31 };} namespace c_oSerProp_rPrType{enum c_oSerProp_rPrType { @@ -358,7 +360,10 @@ const int g_nFormatVersion = 4; { pgSz = 0, pgMar = 1, - setting = 2 + setting = 2, + headers = 3, + footers = 4, + hdrftrelem = 5 };} namespace c_oSerProp_secPrSettingsType{enum c_oSerProp_secPrSettingsType { diff --git a/ASCOfficeDocxFile2/BinWriter/BinWriters.h b/ASCOfficeDocxFile2/BinWriter/BinWriters.h index 889813c887..ef26422fbf 100644 --- a/ASCOfficeDocxFile2/BinWriter/BinWriters.h +++ b/ASCOfficeDocxFile2/BinWriter/BinWriters.h @@ -347,6 +347,27 @@ namespace BinDocxRW } }; + class BinaryHeaderFooterTableWriter + { + BinaryCommonWriter m_oBcw; + OOX::CSettings* m_oSettings; + OOX::CTheme* m_poTheme; + DocWrapper::FontProcessor& m_oFontProcessor; + PPTXFile::IAVSOfficeDrawingConverter* m_pOfficeDrawingConverter; + public: + OOX::IFileContainer* m_oDocumentRels; + CAtlArray m_aHeaders; + CAtlArray m_aHeaderTypes; + CAtlArray m_aHeaderSectPrs; + CAtlArray m_aFooters; + CAtlArray m_aFooterTypes; + CAtlArray m_aFooterSectPrs; + public: + BinaryHeaderFooterTableWriter(Streams::CBufferedStream &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, DocWrapper::FontProcessor& oFontProcessor, OOX::CSettings* oSettings, PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter, OOX::IFileContainer* oDocumentRels); + void Write(); + void WriteHdrFtrContent(CAtlArray& aHdrFtrs, CAtlArray& aHdrFtrTypes, CAtlArray& aHdrSectPrs, bool bHdr); + void WriteHdrFtrItem(OOX::Logic::CSectionProperty* pSectPr, OOX::CHdrFtr* pHdrFtr, bool bHdr); + }; class BinarySigTableWriter { BinaryCommonWriter m_oBcw; @@ -679,8 +700,12 @@ namespace BinDocxRW class Binary_pPrWriter { BinaryCommonWriter m_oBcw; - Binary_rPrWriter brPrs; - public: Binary_pPrWriter(Streams::CBufferedStream &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, DocWrapper::FontProcessor& oFontProcessor):m_oBcw(oCBufferedStream, pEmbeddedFontsManager),brPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor) + Binary_rPrWriter brPrs; + OOX::CSettings* m_oSettings; + public: + BinaryHeaderFooterTableWriter* m_oBinaryHeaderFooterTableWriter; + public: Binary_pPrWriter(Streams::CBufferedStream &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, DocWrapper::FontProcessor& oFontProcessor, OOX::CSettings* oSettings, PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter, OOX::IFileContainer* oDocumentRels, BinaryHeaderFooterTableWriter* oBinaryHeaderFooterTableWriter): + m_oBcw(oCBufferedStream, pEmbeddedFontsManager),brPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor),m_oSettings(oSettings),m_oBinaryHeaderFooterTableWriter(oBinaryHeaderFooterTableWriter) { } void Write_pPr(const OOX::Logic::CParagraphProperty& pPr) @@ -696,41 +721,37 @@ namespace BinDocxRW m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable); m_oBcw.m_oStream.WriteString2(sStyleId); } - OOX::Logic::CParagraphProperty pCurPr = pPr; //Списки надо писать после стилей, т.к. при открытии в методах добавления списка проверяются стили //Списки могут быть заданы с стилях.Это надо учитывать. //NumPr - OOX::Logic::CNumPr oCurNumPr; - if(pCurPr.m_oNumPr.IsInit()) - oCurNumPr = pCurPr.m_oNumPr.get(); - if(oCurNumPr.m_oNumID.IsInit() || oCurNumPr.m_oIlvl.IsInit()) + if(pPr.m_oNumPr.IsInit() && (pPr.m_oNumPr->m_oNumID.IsInit() || pPr.m_oNumPr->m_oIlvl.IsInit())) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::numPr); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable); nCurPos = m_oBcw.WriteItemWithLengthStart(); - WriteNumPr(oCurNumPr, pPr); + WriteNumPr(pPr.m_oNumPr.get(), pPr); m_oBcw.WriteItemWithLengthEnd(nCurPos); } //ContextualSpacing - if(false != pCurPr.m_oContextualSpacing.IsInit()) + if(false != pPr.m_oContextualSpacing.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::ContextualSpacing); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); - m_oBcw.m_oStream.WriteBool(SimpleTypes::onoffTrue == pCurPr.m_oContextualSpacing.get().m_oVal.GetValue()); + m_oBcw.m_oStream.WriteBool(SimpleTypes::onoffTrue == pPr.m_oContextualSpacing.get().m_oVal.GetValue()); } //Ind - if(false != pCurPr.m_oInd.IsInit()) + if(false != pPr.m_oInd.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::Ind); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable); nCurPos = m_oBcw.WriteItemWithLengthStart(); - WriteInd(pCurPr.m_oInd.get()); + WriteInd(pPr.m_oInd.get()); m_oBcw.WriteItemWithLengthEnd(nCurPos); } //Jc - if(false != pCurPr.m_oJc.IsInit()) + if(false != pPr.m_oJc.IsInit()) { - const ComplexTypes::Word::CJc& oJc = pCurPr.m_oJc.get(); + const ComplexTypes::Word::CJc& oJc = pPr.m_oJc.get(); if(oJc.m_oVal.IsInit()) { const SimpleTypes::CJc<>& oEJc = oJc.m_oVal.get(); @@ -751,88 +772,96 @@ namespace BinDocxRW } } //KeepLines - if(false != pCurPr.m_oKeepLines.IsInit()) + if(false != pPr.m_oKeepLines.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::KeepLines); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); - m_oBcw.m_oStream.WriteBool(SimpleTypes::onoffTrue == pCurPr.m_oKeepLines.get().m_oVal.GetValue()); + m_oBcw.m_oStream.WriteBool(SimpleTypes::onoffTrue == pPr.m_oKeepLines.get().m_oVal.GetValue()); } //KeepNext - if(false != pCurPr.m_oKeepNext.IsInit()) + if(false != pPr.m_oKeepNext.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::KeepNext); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); - m_oBcw.m_oStream.WriteBool(SimpleTypes::onoffTrue == pCurPr.m_oKeepNext.get().m_oVal.GetValue()); + m_oBcw.m_oStream.WriteBool(SimpleTypes::onoffTrue == pPr.m_oKeepNext.get().m_oVal.GetValue()); } //PageBreakBefore - if(false != pCurPr.m_oPageBreakBefore.IsInit()) + if(false != pPr.m_oPageBreakBefore.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::PageBreakBefore); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); - m_oBcw.m_oStream.WriteBool(SimpleTypes::onoffTrue == pCurPr.m_oPageBreakBefore.get().m_oVal.GetValue()); + m_oBcw.m_oStream.WriteBool(SimpleTypes::onoffTrue == pPr.m_oPageBreakBefore.get().m_oVal.GetValue()); } //Spacing - if(false != pCurPr.m_oSpacing.IsInit()) + if(false != pPr.m_oSpacing.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::Spacing); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable); nCurPos = m_oBcw.WriteItemWithLengthStart(); - WriteSpacing(pCurPr.m_oSpacing.get()); + WriteSpacing(pPr.m_oSpacing.get()); m_oBcw.WriteItemWithLengthEnd(nCurPos); } //Shd - if(false != pCurPr.m_oShd.IsInit()) + if(false != pPr.m_oShd.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::Shd); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable); nCurPos = m_oBcw.WriteItemWithLengthStart(); - m_oBcw.WriteShd(pCurPr.m_oShd.get()); + m_oBcw.WriteShd(pPr.m_oShd.get()); m_oBcw.WriteItemWithLengthEnd(nCurPos); } //WidowControl - if(false != pCurPr.m_oWidowControl.IsInit()) + if(false != pPr.m_oWidowControl.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::WidowControl); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); - m_oBcw.m_oStream.WriteBool(SimpleTypes::onoffTrue == pCurPr.m_oWidowControl.get().m_oVal.GetValue()); + m_oBcw.m_oStream.WriteBool(SimpleTypes::onoffTrue == pPr.m_oWidowControl.get().m_oVal.GetValue()); } //Tabs - if(false != pCurPr.m_oTabs.IsInit()) + if(false != pPr.m_oTabs.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::Tab); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable); nCurPos = m_oBcw.WriteItemWithLengthStart(); - WriteTabs(pCurPr.m_oTabs.get(), pCurPr.m_oInd); + WriteTabs(pPr.m_oTabs.get(), pPr.m_oInd); m_oBcw.WriteItemWithLengthEnd(nCurPos); } //pBdr - if(false != pCurPr.m_oPBdr.IsInit()) + if(false != pPr.m_oPBdr.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::pBdr); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable); nCurPos = m_oBcw.WriteItemWithLengthStart(); - m_oBcw.WritePBorders(pCurPr.m_oPBdr.get()); + m_oBcw.WritePBorders(pPr.m_oPBdr.get()); m_oBcw.WriteItemWithLengthEnd(nCurPos); } //pPr_rPr - if(false != pCurPr.m_oRPr.IsInit()) + if(false != pPr.m_oRPr.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::pPr_rPr); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable); nCurPos = m_oBcw.WriteItemWithLengthStart(); - brPrs.Write_rPr(pCurPr.m_oRPr.get()); + brPrs.Write_rPr(pPr.m_oRPr.get()); m_oBcw.WriteItemWithLengthEnd(nCurPos); } //FramePr - if(pCurPr.m_oFramePr.IsInit()) + if(pPr.m_oFramePr.IsInit()) { m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::FramePr); m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable); nCurPos = m_oBcw.WriteItemWithLengthStart(); - WriteFramePr(pCurPr.m_oFramePr.get()); + WriteFramePr(pPr.m_oFramePr.get()); m_oBcw.WriteItemWithLengthEnd(nCurPos); } - + //SectPr + if(NULL != m_oBinaryHeaderFooterTableWriter && pPr.m_oSectPr.IsInit()) + { + m_oBcw.m_oStream.WriteByte(c_oSerProp_pPrType::SectPr); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable); + int nCurPos2 = m_oBcw.WriteItemWithLengthStart(); + WriteSectPr(pPr.m_oSectPr.GetPointer()); + m_oBcw.WriteItemWithLengthEnd(nCurPos2); + } }; void WriteInd(const ComplexTypes::Word::CInd& Ind) { @@ -1088,6 +1117,175 @@ namespace BinDocxRW m_oBcw.m_oStream.WriteByte((BYTE)oFramePr.m_oYAlign->GetValue()); } } + void WriteSectPr(OOX::Logic::CSectionProperty* pSectPr) + { + int nCurPos = 0; + //pgSz + nCurPos = m_oBcw.WriteItemStart(c_oSerProp_secPrType::pgSz); + WritePageSize(pSectPr); + m_oBcw.WriteItemEnd(nCurPos); + //pgMar + nCurPos = m_oBcw.WriteItemStart(c_oSerProp_secPrType::pgMar); + WritePageMargin(pSectPr); + m_oBcw.WriteItemEnd(nCurPos); + //titlePg + nCurPos = m_oBcw.WriteItemStart(c_oSerProp_secPrType::setting); + WritePageSettings(pSectPr); + m_oBcw.WriteItemEnd(nCurPos); + //Header + if(pSectPr->m_arrHeaderReference.GetSize() > 0) + { + nCurPos = m_oBcw.WriteItemStart(c_oSerProp_secPrType::headers); + WriteHeaderFooter(pSectPr, pSectPr->m_arrHeaderReference, true); + m_oBcw.WriteItemEnd(nCurPos); + } + //Footer + if(pSectPr->m_arrFooterReference.GetSize() > 0) + { + nCurPos = m_oBcw.WriteItemStart(c_oSerProp_secPrType::footers); + WriteHeaderFooter(pSectPr, pSectPr->m_arrFooterReference, false); + m_oBcw.WriteItemEnd(nCurPos); + } + }; + void WritePageSettings(OOX::Logic::CSectionProperty* pSectPr) + { + bool titlePg = false; + bool EvenAndOddHeaders = false; + if(NULL != pSectPr && pSectPr->m_oTitlePg.IsInit() && SimpleTypes::onoffTrue == pSectPr->m_oTitlePg->m_oVal.GetValue()) + titlePg = true; + if(NULL != m_oSettings && m_oSettings->m_oEvenAndOddHeaders.IsInit() && SimpleTypes::onoffTrue == m_oSettings->m_oEvenAndOddHeaders.get().m_oVal.GetValue()) + EvenAndOddHeaders = true; + //titlePg + m_oBcw.m_oStream.WriteByte(c_oSerProp_secPrSettingsType::titlePg); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); + m_oBcw.m_oStream.WriteBool(titlePg); + //EvenAndOddHeaders + m_oBcw.m_oStream.WriteByte(c_oSerProp_secPrSettingsType::EvenAndOddHeaders); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); + m_oBcw.m_oStream.WriteBool(EvenAndOddHeaders); + }; + void WritePageSize(OOX::Logic::CSectionProperty* pSectPr) + { + double W = Page_Width; + double H = Page_Height; + BYTE Orientation = orientation_Portrait; + if(NULL != pSectPr && pSectPr->m_oPgSz.IsInit()) + { + const ComplexTypes::Word::CPageSz& pSz = pSectPr->m_oPgSz.get(); + if(pSz.m_oW.IsInit()) + W = pSz.m_oW.get().ToMm(); + if(pSz.m_oH.IsInit()) + H = pSz.m_oH.get().ToMm(); + if(pSz.m_oOrient.IsInit()) + { + switch(pSz.m_oOrient.get().GetValue()) + { + case SimpleTypes::pageorientPortrait: Orientation = orientation_Portrait;break; + case SimpleTypes::pageorientLandscape: Orientation = orientation_Landscape;break; + } + } + } + //W + m_oBcw.m_oStream.WriteByte(c_oSer_pgSzType::W); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); + m_oBcw.m_oStream.WriteDouble2(W); + //H + m_oBcw.m_oStream.WriteByte(c_oSer_pgSzType::H); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); + m_oBcw.m_oStream.WriteDouble2(H); + //Orientation + m_oBcw.m_oStream.WriteByte(c_oSer_pgSzType::Orientation); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); + m_oBcw.m_oStream.WriteByte(Orientation); + }; + void WritePageMargin(OOX::Logic::CSectionProperty* pSectPr) + { + double H = Page_Height; + double L = X_Left_Margin; + double T = Y_Top_Margin; + double R = X_Right_Margin; + double B = Y_Bottom_Margin; + double Header = Y_Default_Header; + double Footer = Y_Default_Footer; + if(NULL != pSectPr && pSectPr->m_oPgSz.IsInit() && pSectPr->m_oPgMar.IsInit()) + { + const ComplexTypes::Word::CPageSz& pSz = pSectPr->m_oPgSz.get(); + if(pSz.m_oH.IsInit()) + H = pSz.m_oH.get().ToMm(); + + const ComplexTypes::Word::CPageMar& pMar = pSectPr->m_oPgMar.get(); + if(pMar.m_oLeft.IsInit()) + L = pMar.m_oLeft.get().ToMm(); + if(pMar.m_oTop.IsInit()) + T = pMar.m_oTop.get().ToMm(); + if(pMar.m_oRight.IsInit()) + R = pMar.m_oRight.get().ToMm(); + if(pMar.m_oBottom.IsInit()) + B = pMar.m_oBottom.get().ToMm(); + if(pMar.m_oHeader.IsInit()) + Header = pMar.m_oHeader.get().ToMm(); + if(pMar.m_oFooter.IsInit()) + Footer = pMar.m_oFooter.get().ToMm(); + } + //Left + m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Left); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); + m_oBcw.m_oStream.WriteDouble2(L); + //Top + m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Top); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); + m_oBcw.m_oStream.WriteDouble2(T); + //Right + m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Right); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); + m_oBcw.m_oStream.WriteDouble2(R); + //Bottom + m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Bottom); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); + m_oBcw.m_oStream.WriteDouble2(B); + //Header + m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Header); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); + m_oBcw.m_oStream.WriteDouble2(Header); + //Footer + m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Footer); + m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); + m_oBcw.m_oStream.WriteDouble2(Footer); + }; + void WriteHeaderFooter(OOX::Logic::CSectionProperty* pSectPr, CSimpleArray& aRefs, bool bHdr) + { + int nCurPos = 0; + for(int i = 0, length = aRefs.GetSize(); i < length; ++i) + { + const ComplexTypes::Word::CHdrFtrRef& oRef = aRefs[i]; + if( oRef.m_oType.IsInit() && oRef.m_oId.IsInit()) + { + smart_ptr oFile = m_oBinaryHeaderFooterTableWriter->m_oDocumentRels->Find(oRef.m_oId->GetValue()); + if (oFile.IsInit() && (OOX::FileTypes::Header == oFile->type() || OOX::FileTypes::Footer == oFile->type())) + { + int nIndex = 0; + OOX::CHdrFtr* pHdrFtr = (OOX::CHdrFtr*)oFile.operator->(); + if(bHdr) + { + nIndex = m_oBinaryHeaderFooterTableWriter->m_aHeaders.GetCount(); + m_oBinaryHeaderFooterTableWriter->m_aHeaders.Add(pHdrFtr); + m_oBinaryHeaderFooterTableWriter->m_aHeaderTypes.Add(oRef.m_oType->GetValue()); + m_oBinaryHeaderFooterTableWriter->m_aHeaderSectPrs.Add(pSectPr); + } + else + { + nIndex = m_oBinaryHeaderFooterTableWriter->m_aFooters.GetCount(); + m_oBinaryHeaderFooterTableWriter->m_aFooters.Add(pHdrFtr); + m_oBinaryHeaderFooterTableWriter->m_aFooterTypes.Add(oRef.m_oType->GetValue()); + m_oBinaryHeaderFooterTableWriter->m_aFooterSectPrs.Add(pSectPr); + } + nCurPos = m_oBcw.WriteItemStart(c_oSerProp_secPrType::hdrftrelem); + m_oBcw.m_oStream.WriteLong(nIndex); + m_oBcw.WriteItemEnd(nCurPos); + } + } + } + } }; class Binary_tblPrWriter { @@ -1528,7 +1726,8 @@ namespace BinDocxRW Binary_tblPrWriter btblPrs; int m_nReaderGenName; public: - BinaryStyleTableWriter(Streams::CBufferedStream &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, DocWrapper::FontProcessor& oFontProcessor):m_oBcw(oCBufferedStream, pEmbeddedFontsManager),bpPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor),brPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor),btblPrs(oCBufferedStream, pEmbeddedFontsManager) + BinaryStyleTableWriter(Streams::CBufferedStream &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, DocWrapper::FontProcessor& oFontProcessor, OOX::CSettings* oSettings, PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter): + m_oBcw(oCBufferedStream, pEmbeddedFontsManager),bpPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor, oSettings, pOfficeDrawingConverter, NULL, NULL),brPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor),btblPrs(oCBufferedStream, pEmbeddedFontsManager) { m_nReaderGenName = 0; }; @@ -1794,7 +1993,8 @@ namespace BinDocxRW Binary_pPrWriter bpPrs; Binary_rPrWriter brPrs; public: - BinaryNumberingTableWriter(Streams::CBufferedStream &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, DocWrapper::FontProcessor& oFontProcessor):m_oBcw(oCBufferedStream, pEmbeddedFontsManager),bpPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor),brPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor) + BinaryNumberingTableWriter(Streams::CBufferedStream &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, DocWrapper::FontProcessor& oFontProcessor, OOX::CSettings* oSettings, PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter): + m_oBcw(oCBufferedStream, pEmbeddedFontsManager),bpPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor, oSettings, pOfficeDrawingConverter, NULL, NULL),brPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor) { }; void Write(const OOX::CNumbering& numbering) @@ -2155,7 +2355,6 @@ namespace BinDocxRW BinaryCommonWriter m_oBcw; Binary_pPrWriter bpPrs; Binary_rPrWriter brPrs; - OOX::Logic::CRunProperty* m_pCurDef_rPr; CString m_sCurParStyle; OOX::CSettings* m_oSettings; @@ -2173,17 +2372,16 @@ namespace BinDocxRW OOX::Logic::CSectionProperty* pSectPr; bool m_bWriteSectPr;//Записывать ли свойства секции в данном экземпляре BinaryOtherTableWriter public: - BinaryDocumentTableWriter(Streams::CBufferedStream &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, OOX::CSettings* oSettings, DocWrapper::FontProcessor& oFontProcessor, OOX::IFileContainer* oDocumentRels, PPTXFile::IAVSOfficeDrawingConverter* oOfficeDrawingConverter, CAtlMap* mapIgnoreComments):m_oBcw(oCBufferedStream, pEmbeddedFontsManager),bpPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor),brPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor),m_oSettings(oSettings),m_oDocumentRels(oDocumentRels),btblPrs(oCBufferedStream, pEmbeddedFontsManager),m_pOfficeDrawingConverter(oOfficeDrawingConverter),m_mapIgnoreComments(mapIgnoreComments) + BinaryDocumentTableWriter(Streams::CBufferedStream &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, OOX::CSettings* oSettings, DocWrapper::FontProcessor& oFontProcessor, OOX::IFileContainer* oDocumentRels, PPTXFile::IAVSOfficeDrawingConverter* oOfficeDrawingConverter, CAtlMap* mapIgnoreComments, BinaryHeaderFooterTableWriter* oBinaryHeaderFooterTableWriter): + m_oBcw(oCBufferedStream, pEmbeddedFontsManager),bpPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor, oSettings, oOfficeDrawingConverter, oDocumentRels, oBinaryHeaderFooterTableWriter),brPrs(oCBufferedStream, pEmbeddedFontsManager, poTheme, oFontProcessor),m_oSettings(oSettings),m_oDocumentRels(oDocumentRels),btblPrs(oCBufferedStream, pEmbeddedFontsManager),m_pOfficeDrawingConverter(oOfficeDrawingConverter),m_mapIgnoreComments(mapIgnoreComments) { pSectPr = NULL; - m_pCurDef_rPr = NULL; m_bWriteSectPr = false; m_nSkipFldChar = 0; m_eFldState = SimpleTypes::fldchartypeEnd; }; ~BinaryDocumentTableWriter() { - RELEASEOBJECT(m_pCurDef_rPr); for(int i = 0, length = m_aFldChars.GetSize(); i < length; ++i) { RELEASEOBJECT(m_aFldChars[i]); @@ -2219,28 +2417,16 @@ namespace BinDocxRW OOX::Logic::CParagraph* pParagraph = static_cast(item); //Ищем pPr OOX::Logic::CParagraphProperty* pPr = NULL; - OOX::Logic::CParagraphProperty* pPr_Ref = NULL; for(int i = 0, length = pParagraph->m_arrItems.GetSize(); i < length; ++i) { OOX::WritingElement* pElem = pParagraph->m_arrItems[i]; if(OOX::et_w_pPr == pElem->getType()) - { - pPr_Ref = static_cast(pElem); - if(NULL == pPr) - pPr = new OOX::Logic::CParagraphProperty(); - *pPr = OOX::Logic::CParagraphProperty::Merge(*pPr_Ref, *pPr); - } + pPr = static_cast(pElem); } - //не добавляем параграф если в нем присутствуют только sectPr - //todo обработать случай когда есть w:r, но он пустой - if(false == (NULL != pPr && pPr->m_oSectPr.IsInit() && 1 == pParagraph->m_arrItems.GetSize())) - { - m_oBcw.m_oStream.WriteByte(c_oSerParType::Par); - nCurPos = m_oBcw.WriteItemWithLengthStart(); - WriteParapraph(*pParagraph, pPr); - m_oBcw.WriteItemWithLengthEnd(nCurPos); - } - RELEASEOBJECT(pPr); + m_oBcw.m_oStream.WriteByte(c_oSerParType::Par); + nCurPos = m_oBcw.WriteItemWithLengthStart(); + WriteParapraph(*pParagraph, pPr); + m_oBcw.WriteItemWithLengthEnd(nCurPos); } else if(OOX::et_w_tbl == item->getType()) { @@ -2276,15 +2462,13 @@ namespace BinDocxRW if(true == m_bWriteSectPr && NULL != pSectPr) { nCurPos = m_oBcw.WriteItemStart(c_oSerParType::sectPr); - WriteSectPr(pSectPr); + bpPrs.WriteSectPr(pSectPr); m_oBcw.WriteItemEnd(nCurPos); } }; void WriteParapraph(OOX::Logic::CParagraph& par, OOX::Logic::CParagraphProperty* pPr) { int nCurPos = 0; - OOX::Logic::CRunProperty* pPr_rPr = NULL; - RELEASEOBJECT(m_pCurDef_rPr); //pPr if(NULL != pPr) { @@ -2292,21 +2476,14 @@ namespace BinDocxRW nCurPos = m_oBcw.WriteItemWithLengthStart(); bpPrs.Write_pPr(*pPr); m_oBcw.WriteItemWithLengthEnd(nCurPos); - - if(pPr->m_oRPr.IsInit()) - { - pPr_rPr = new OOX::Logic::CRunProperty(); - (*pPr_rPr) = pPr->m_oRPr.get(); - } } //Content m_oBcw.m_oStream.WriteByte(c_oSerParType::Content); nCurPos = m_oBcw.WriteItemWithLengthStart(); - WriteParagraphContent(par.m_arrItems, &pPr_rPr); + WriteParagraphContent(par.m_arrItems); m_oBcw.WriteItemWithLengthEnd(nCurPos); - RELEASEOBJECT(pPr_rPr); }; FldStruct* ParseField(CString& sFld) { @@ -2382,7 +2559,7 @@ namespace BinDocxRW RELEASEOBJECT(pFldStruct); return bRes; } - void WriteParagraphContent(const CSimpleArray& Content, OOX::Logic::CRunProperty** pPr_rPr, bool bHyperlink = false) + void WriteParagraphContent(const CSimpleArray& Content, bool bHyperlink = false) { int nCurPos = 0; for ( int i = 0, length = Content.GetSize(); i < length; ++i ) @@ -2542,7 +2719,7 @@ namespace BinDocxRW } else { - WriteParagraphContent(pHyperlink->m_arrItems, NULL, true); + WriteParagraphContent(pHyperlink->m_arrItems, true); } } void WriteHyperlinkContent(CString& sLink, OOX::Logic::CHyperlink* pHyperlink) @@ -2589,7 +2766,7 @@ namespace BinDocxRW } //Content nCurPos = m_oBcw.WriteItemStart(c_oSer_HyperlinkType::Content); - WriteParagraphContent(pHyperlink->m_arrItems, NULL, true); + WriteParagraphContent(pHyperlink->m_arrItems, true); m_oBcw.WriteItemWithLengthEnd(nCurPos); } OOX::Logic::CRunProperty* getRunStyle(CSimpleArray& m_arrItems) @@ -5237,226 +5414,59 @@ namespace BinDocxRW } //Content - BinaryDocumentTableWriter oBinaryDocumentTableWriter(m_oBcw.m_oStream, m_oBcw.m_pEmbeddedFontsManager, brPrs.m_poTheme, m_oSettings, brPrs.m_oFontProcessor, m_oDocumentRels, m_pOfficeDrawingConverter, m_mapIgnoreComments); + BinaryDocumentTableWriter oBinaryDocumentTableWriter(m_oBcw.m_oStream, m_oBcw.m_pEmbeddedFontsManager, brPrs.m_poTheme, m_oSettings, brPrs.m_oFontProcessor, m_oDocumentRels, m_pOfficeDrawingConverter, m_mapIgnoreComments, bpPrs.m_oBinaryHeaderFooterTableWriter); nCurPos = m_oBcw.WriteItemStart(c_oSerDocTableType::Cell_Content); oBinaryDocumentTableWriter.WriteDocumentContent(tc.m_arrItems); m_oBcw.WriteItemEnd(nCurPos); RELEASEOBJECT(pTcPr); }; - void WriteSectPr(OOX::Logic::CSectionProperty* pSectPr) - { - int nCurPos = 0; - //pgSz - nCurPos = m_oBcw.WriteItemStart(c_oSerProp_secPrType::pgSz); - WritePageSize(pSectPr); - m_oBcw.WriteItemEnd(nCurPos); - //pgMar - nCurPos = m_oBcw.WriteItemStart(c_oSerProp_secPrType::pgMar); - WritePageMargin(pSectPr); - m_oBcw.WriteItemEnd(nCurPos); - //titlePg - nCurPos = m_oBcw.WriteItemStart(c_oSerProp_secPrType::setting); - WritePageSettings(pSectPr); - m_oBcw.WriteItemEnd(nCurPos); - }; - void WritePageSettings(OOX::Logic::CSectionProperty* pSectPr) - { - bool titlePg = false; - bool EvenAndOddHeaders = false; - if(NULL != pSectPr && pSectPr->m_oTitlePg.IsInit() && SimpleTypes::onoffTrue == pSectPr->m_oTitlePg->m_oVal.GetValue()) - titlePg = true; - if(NULL != m_oSettings && m_oSettings->m_oEvenAndOddHeaders.IsInit() && SimpleTypes::onoffTrue == m_oSettings->m_oEvenAndOddHeaders.get().m_oVal.GetValue()) - EvenAndOddHeaders = true; - //titlePg - m_oBcw.m_oStream.WriteByte(c_oSerProp_secPrSettingsType::titlePg); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); - m_oBcw.m_oStream.WriteBool(titlePg); - //EvenAndOddHeaders - m_oBcw.m_oStream.WriteByte(c_oSerProp_secPrSettingsType::EvenAndOddHeaders); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); - m_oBcw.m_oStream.WriteBool(EvenAndOddHeaders); - }; - void WritePageSize(OOX::Logic::CSectionProperty* pSectPr) - { - double W = Page_Width; - double H = Page_Height; - BYTE Orientation = orientation_Portrait; - if(NULL != pSectPr && pSectPr->m_oPgSz.IsInit()) - { - const ComplexTypes::Word::CPageSz& pSz = pSectPr->m_oPgSz.get(); - if(pSz.m_oW.IsInit()) - W = pSz.m_oW.get().ToMm(); - if(pSz.m_oH.IsInit()) - H = pSz.m_oH.get().ToMm(); - if(pSz.m_oOrient.IsInit()) - { - switch(pSz.m_oOrient.get().GetValue()) - { - case SimpleTypes::pageorientPortrait: Orientation = orientation_Portrait;break; - case SimpleTypes::pageorientLandscape: Orientation = orientation_Landscape;break; - } - } - } - //W - m_oBcw.m_oStream.WriteByte(c_oSer_pgSzType::W); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); - m_oBcw.m_oStream.WriteDouble2(W); - //H - m_oBcw.m_oStream.WriteByte(c_oSer_pgSzType::H); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); - m_oBcw.m_oStream.WriteDouble2(H); - //Orientation - m_oBcw.m_oStream.WriteByte(c_oSer_pgSzType::Orientation); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Byte); - m_oBcw.m_oStream.WriteByte(Orientation); - }; - void WritePageMargin(OOX::Logic::CSectionProperty* pSectPr) - { - double H = Page_Height; - double L = X_Left_Margin; - double T = Y_Top_Margin; - double R = X_Right_Margin; - double B = Y_Bottom_Margin; - double Header = Y_Default_Header; - double Footer = Y_Default_Footer; - if(NULL != pSectPr && pSectPr->m_oPgSz.IsInit() && pSectPr->m_oPgMar.IsInit()) - { - const ComplexTypes::Word::CPageSz& pSz = pSectPr->m_oPgSz.get(); - if(pSz.m_oH.IsInit()) - H = pSz.m_oH.get().ToMm(); - - const ComplexTypes::Word::CPageMar& pMar = pSectPr->m_oPgMar.get(); - if(pMar.m_oLeft.IsInit()) - L = pMar.m_oLeft.get().ToMm(); - if(pMar.m_oTop.IsInit()) - T = pMar.m_oTop.get().ToMm(); - if(pMar.m_oRight.IsInit()) - R = pMar.m_oRight.get().ToMm(); - if(pMar.m_oBottom.IsInit()) - B = pMar.m_oBottom.get().ToMm(); - if(pMar.m_oHeader.IsInit()) - Header = pMar.m_oHeader.get().ToMm(); - if(pMar.m_oFooter.IsInit()) - Footer = pMar.m_oFooter.get().ToMm(); - } - //Left - m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Left); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); - m_oBcw.m_oStream.WriteDouble2(L); - //Top - m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Top); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); - m_oBcw.m_oStream.WriteDouble2(T); - //Right - m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Right); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); - m_oBcw.m_oStream.WriteDouble2(R); - //Bottom - m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Bottom); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); - m_oBcw.m_oStream.WriteDouble2(B); - //Header - m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Header); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); - m_oBcw.m_oStream.WriteDouble2(Header); - //Footer - m_oBcw.m_oStream.WriteByte(c_oSer_pgMarType::Footer); - m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Double); - m_oBcw.m_oStream.WriteDouble2(Footer); - }; }; - class BinaryHeaderFooterTableWriter + BinaryHeaderFooterTableWriter::BinaryHeaderFooterTableWriter(Streams::CBufferedStream &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, DocWrapper::FontProcessor& oFontProcessor, OOX::CSettings* oSettings, PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter, OOX::IFileContainer* oDocumentRels): + m_oBcw(oCBufferedStream, pEmbeddedFontsManager), m_poTheme(poTheme), m_oFontProcessor(oFontProcessor), m_oSettings(oSettings),m_pOfficeDrawingConverter(pOfficeDrawingConverter), m_oDocumentRels(oDocumentRels) { - BinaryCommonWriter m_oBcw; - CSimpleArray* m_aHdrFirst; - CSimpleArray* m_aHdrEven; - CSimpleArray* m_aHdrOdd; - CSimpleArray* m_aFtrFirst; - CSimpleArray* m_aFtrEven; - CSimpleArray* m_aFtrOdd; - OOX::CHdrFtr* m_oHdrFirstRels; - OOX::CHdrFtr* m_oHdrEvenRels; - OOX::CHdrFtr* m_oHdrOddRels; - OOX::CHdrFtr* m_oFtrFirstRels; - OOX::CHdrFtr* m_oFtrEvenRels; - OOX::CHdrFtr* m_oFtrOddRels; - - OOX::Logic::CSectionProperty* m_pSectPr; - OOX::CSettings* m_oSettings; - OOX::CTheme* m_poTheme; - DocWrapper::FontProcessor& m_oFontProcessor; - PPTXFile::IAVSOfficeDrawingConverter* m_pOfficeDrawingConverter; - OOX::IFileContainer** m_ppCurRels; - public: - OOX::Logic::CSectionProperty* pSectPr; - public: - BinaryHeaderFooterTableWriter(Streams::CBufferedStream &oCBufferedStream, OOX::IFileContainer** ppCurRels, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* poTheme, DocWrapper::FontProcessor& oFontProcessor, - CSimpleArray* aHdrFirst, CSimpleArray* aHdrEven, CSimpleArray* aHdrOdd, - CSimpleArray* aFtrFirst, CSimpleArray* aFtrEven, CSimpleArray* aFtrOdd, - OOX::CHdrFtr* oHdrFirstRels, OOX::CHdrFtr* oHdrEvenRels, OOX::CHdrFtr* oHdrOddRels, OOX::CHdrFtr* oFtrFirstRels, OOX::CHdrFtr* oFtrEvenRels, OOX::CHdrFtr* oFtrOddRels, - OOX::Logic::CSectionProperty* pSectPr, OOX::CSettings* oSettings, PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter): - m_ppCurRels(ppCurRels), - m_oBcw(oCBufferedStream, pEmbeddedFontsManager), m_poTheme(poTheme), m_oFontProcessor(oFontProcessor), - m_aHdrFirst(aHdrFirst),m_aHdrEven(aHdrEven),m_aHdrOdd(aHdrOdd), - m_aFtrFirst(aFtrFirst),m_aFtrEven(aFtrEven),m_aFtrOdd(aFtrOdd), - m_oHdrFirstRels(oHdrFirstRels),m_oHdrEvenRels(oHdrEvenRels),m_oHdrOddRels(oHdrOddRels), - m_oFtrFirstRels(oFtrFirstRels),m_oFtrEvenRels(oFtrEvenRels),m_oFtrOddRels(oFtrOddRels), - m_pSectPr(pSectPr),m_oSettings(oSettings),m_pOfficeDrawingConverter(pOfficeDrawingConverter) + }; + void BinaryHeaderFooterTableWriter::Write() + { + int nStart = m_oBcw.WriteItemWithLengthStart(); + int nCurPos = 0; + //Header + if(m_aHeaders.GetCount() > 0) { - pSectPr = NULL; - }; - void Write() - { - int nStart = m_oBcw.WriteItemWithLengthStart(); - WriteHeaderFooterContent(); - m_oBcw.WriteItemWithLengthEnd(nStart); + nCurPos = m_oBcw.WriteItemStart(c_oSerHdrFtrTypes::Header); + WriteHdrFtrContent(m_aHeaders, m_aHeaderTypes, m_aHeaderSectPrs, true); + m_oBcw.WriteItemEnd(nCurPos); } - void WriteHeaderFooterContent() + //Footer + if(m_aFooters.GetCount() > 0) { - int nCurPos = 0; - //Header - if(NULL != m_aHdrFirst || NULL != m_aHdrEven || NULL != m_aHdrOdd) - { - nCurPos = m_oBcw.WriteItemStart(c_oSerHdrFtrTypes::Header); - WriteHdrFtrContent(m_aHdrFirst, m_aHdrEven, m_aHdrOdd, m_oHdrFirstRels, m_oHdrEvenRels, m_oHdrOddRels, true); - m_oBcw.WriteItemEnd(nCurPos); - } - //Footer - if(NULL != m_aFtrFirst || NULL != m_aFtrEven || NULL != m_aFtrOdd) - { - nCurPos = m_oBcw.WriteItemStart(c_oSerHdrFtrTypes::Footer); - WriteHdrFtrContent(m_aFtrFirst, m_aFtrEven, m_aFtrOdd, m_oFtrFirstRels, m_oFtrEvenRels, m_oFtrOddRels, false); - m_oBcw.WriteItemEnd(nCurPos); - } - }; - void WriteHdrFtrContent(CSimpleArray* aFirst, CSimpleArray* aEven, CSimpleArray* aOdd, - OOX::CHdrFtr* oFirstRels, OOX::CHdrFtr* oEvenRels, OOX::CHdrFtr* oOddRels, bool bHdr) + nCurPos = m_oBcw.WriteItemStart(c_oSerHdrFtrTypes::Footer); + WriteHdrFtrContent(m_aFooters, m_aFooterTypes, m_aFooterSectPrs, false); + m_oBcw.WriteItemEnd(nCurPos); + } + m_oBcw.WriteItemWithLengthEnd(nStart); + }; + void BinaryHeaderFooterTableWriter::WriteHdrFtrContent(CAtlArray& aHdrFtrs, CAtlArray& aHdrFtrTypes, CAtlArray& aHdrSectPrs, bool bHdr) + { + int nCurPos = 0; + for(int i = 0, length = aHdrFtrs.GetCount(); i < length; ++i) { - int nCurPos = 0; - //Odd - if(NULL != aOdd) + OOX::CHdrFtr* pHdrFtr = aHdrFtrs[i]; + SimpleTypes::EHdrFtr eType = aHdrFtrTypes[i]; + OOX::Logic::CSectionProperty* pSectPr = aHdrSectPrs[i]; + BYTE byteHdrFtrType = c_oSerHdrFtrTypes::HdrFtr_Odd; + switch(eType) { - nCurPos = m_oBcw.WriteItemStart(c_oSerHdrFtrTypes::HdrFtr_Odd); - WriteHdrFtrItem(aOdd, bHdr, oOddRels); - m_oBcw.WriteItemEnd(nCurPos); + case SimpleTypes::hdrftrFirst: byteHdrFtrType = c_oSerHdrFtrTypes::HdrFtr_First;break; + case SimpleTypes::hdrftrEven: byteHdrFtrType = c_oSerHdrFtrTypes::HdrFtr_Even;break; + default: byteHdrFtrType = c_oSerHdrFtrTypes::HdrFtr_Odd;break; } - //Even - if(NULL != aEven && NULL != m_oSettings && m_oSettings->m_oEvenAndOddHeaders.IsInit() && SimpleTypes::onoffTrue == m_oSettings->m_oEvenAndOddHeaders.get().m_oVal.GetValue() ) - { - nCurPos = m_oBcw.WriteItemStart(c_oSerHdrFtrTypes::HdrFtr_Even); - WriteHdrFtrItem(aEven, bHdr, oEvenRels); - m_oBcw.WriteItemEnd(nCurPos); - } - //First - if(NULL != aFirst && NULL != m_pSectPr && m_pSectPr->m_oTitlePg.IsInit() && SimpleTypes::onoffTrue == m_pSectPr->m_oTitlePg.get().m_oVal.GetValue()) - { - nCurPos = m_oBcw.WriteItemStart(c_oSerHdrFtrTypes::HdrFtr_First); - WriteHdrFtrItem(aFirst, bHdr, oFirstRels); - m_oBcw.WriteItemEnd(nCurPos); - } - }; - void WriteHdrFtrItem(CSimpleArray* aContent, bool bHdr, OOX::CHdrFtr* oHdrFtr) + nCurPos = m_oBcw.WriteItemStart(byteHdrFtrType); + WriteHdrFtrItem(pSectPr, pHdrFtr, bHdr); + m_oBcw.WriteItemEnd(nCurPos); + } + }; + void BinaryHeaderFooterTableWriter::WriteHdrFtrItem(OOX::Logic::CSectionProperty* pSectPr, OOX::CHdrFtr* pHdrFtr, bool bHdr) { int nCurPos = 0; double BoundY = 0; @@ -5465,26 +5475,26 @@ namespace BinDocxRW { BoundY = Y_Top_Margin; BoundY2 = Y_Default_Header; - if(NULL != m_pSectPr && m_pSectPr->m_oPgMar.IsInit() && m_pSectPr->m_oPgMar->m_oTop.IsInit()) - BoundY = m_pSectPr->m_oPgMar->m_oTop.get().ToMm(); - if(NULL != m_pSectPr && m_pSectPr->m_oPgMar.IsInit() && m_pSectPr->m_oPgMar->m_oHeader.IsInit()) - BoundY2 = m_pSectPr->m_oPgMar->m_oHeader.get().ToMm(); + if(NULL != pSectPr && pSectPr->m_oPgMar.IsInit() && pSectPr->m_oPgMar->m_oTop.IsInit()) + BoundY = pSectPr->m_oPgMar->m_oTop.get().ToMm(); + if(NULL != pSectPr && pSectPr->m_oPgMar.IsInit() && pSectPr->m_oPgMar->m_oHeader.IsInit()) + BoundY2 = pSectPr->m_oPgMar->m_oHeader.get().ToMm(); } else { double H = Page_Height; double B = Y_Bottom_Margin; double F = Y_Default_Footer; - if(NULL != m_pSectPr) + if(NULL != pSectPr) { - if(m_pSectPr->m_oPgSz.IsInit() && m_pSectPr->m_oPgSz->m_oH.IsInit()) - H = m_pSectPr->m_oPgSz->m_oH.get().ToMm(); - if(m_pSectPr->m_oPgMar.IsInit()) + if(pSectPr->m_oPgSz.IsInit() && pSectPr->m_oPgSz->m_oH.IsInit()) + H = pSectPr->m_oPgSz->m_oH.get().ToMm(); + if(pSectPr->m_oPgMar.IsInit()) { - if(m_pSectPr->m_oPgMar->m_oBottom.IsInit()) - B = m_pSectPr->m_oPgMar->m_oBottom.get().ToMm(); - if(m_pSectPr->m_oPgMar->m_oFooter.IsInit()) - F = m_pSectPr->m_oPgMar->m_oFooter.get().ToMm(); + if(pSectPr->m_oPgMar->m_oBottom.IsInit()) + B = pSectPr->m_oPgMar->m_oBottom.get().ToMm(); + if(pSectPr->m_oPgMar->m_oFooter.IsInit()) + F = pSectPr->m_oPgMar->m_oFooter.get().ToMm(); } } BoundY = H - B; @@ -5501,15 +5511,12 @@ namespace BinDocxRW m_oBcw.m_oStream.WriteDouble2(BoundY2); m_oBcw.WriteItemEnd(nCurPos); //Content - (*m_ppCurRels) = oHdrFtr; - BinaryDocumentTableWriter oBinaryDocumentTableWriter(m_oBcw.m_oStream, m_oBcw.m_pEmbeddedFontsManager, m_poTheme, m_oSettings, m_oFontProcessor, oHdrFtr, m_pOfficeDrawingConverter, NULL); - oBinaryDocumentTableWriter.prepareOfficeDrawingConverter(m_pOfficeDrawingConverter, oHdrFtr->m_oReadPath.GetPath(), oHdrFtr->m_arrShapeTypes); - oBinaryDocumentTableWriter.pSectPr = pSectPr; + BinaryDocumentTableWriter oBinaryDocumentTableWriter(m_oBcw.m_oStream, m_oBcw.m_pEmbeddedFontsManager, m_poTheme, m_oSettings, m_oFontProcessor, pHdrFtr, m_pOfficeDrawingConverter, NULL, NULL); + oBinaryDocumentTableWriter.prepareOfficeDrawingConverter(m_pOfficeDrawingConverter, pHdrFtr->m_oReadPath.GetPath(), pHdrFtr->m_arrShapeTypes); nCurPos = m_oBcw.WriteItemStart(c_oSerHdrFtrTypes::HdrFtr_Content); - oBinaryDocumentTableWriter.WriteDocumentContent(*aContent); + oBinaryDocumentTableWriter.WriteDocumentContent(pHdrFtr->m_arrItems); m_oBcw.WriteItemEnd(nCurPos); }; - }; class BinaryCommentsTableWriter { class CCommentWriteTemp @@ -6068,17 +6075,6 @@ namespace BinDocxRW //Seek в конец m_oBcw.m_oStream.Seek(m_nLastFilePos); } - int ReserveTable(BYTE type) - { - //Записываем чтобы просто занять место - int nCurPos = m_oBcw.m_oStream.GetPosition(); - //Write mtItem - //Write mtiType - m_oBcw.m_oStream.WriteByte(type); - //Write mtiOffBits - m_oBcw.m_oStream.WriteLong(m_nLastFilePos); - return nCurPos; - } int WriteTableStart(BYTE type, int nStartPos = -1) { if(-1 != nStartPos) @@ -6117,91 +6113,8 @@ namespace BinDocxRW //ищем первый SectPr и расставляем pageBreak OOX::CDocument* poDocument = oDocx.GetDocument(); - OOX::Logic::CSectionProperty* pFirstSectPr = NULL; - OOX::Logic::CParagraph* pStartSectionParagraph = NULL; - for(int i = 0, length = poDocument->m_arrItems.GetSize(); i < length; ++i) - { - OOX::WritingElement* we = poDocument->m_arrItems[i]; - if(OOX::et_w_p == we->getType()) - { - OOX::Logic::CParagraph* pParagraph = static_cast(we); - if(NULL != pFirstSectPr && NULL == pStartSectionParagraph) - { - pStartSectionParagraph = pParagraph; - } - for(int j = 0, length2 = pParagraph->m_arrItems.GetSize(); j < length2; ++j) - { - OOX::WritingElement* we2 = pParagraph->m_arrItems[j]; - if(OOX::et_w_pPr == we2->getType()) - { - OOX::Logic::CParagraphProperty* pParagraphProperty = static_cast(we2); - if(pParagraphProperty->m_oSectPr.IsInit()) - { - if(NULL == pFirstSectPr) - pFirstSectPr = pParagraphProperty->m_oSectPr.GetPointer(); - const OOX::Logic::CSectionProperty& oSectPr = pParagraphProperty->m_oSectPr.get(); - if(NULL != pStartSectionParagraph && !(oSectPr.m_oType.IsInit() && oSectPr.m_oType->m_oVal.IsInit() && SimpleTypes::sectionmarkContinious == oSectPr.m_oType->m_oVal->GetValue())) - ParagraphAddBreak(pStartSectionParagraph); - pStartSectionParagraph = NULL; - } - } - } - } - } - if(poDocument->m_oSectPr.IsInit()) - { - if(NULL == pFirstSectPr) - pFirstSectPr = poDocument->m_oSectPr.GetPointer(); - const OOX::Logic::CSectionProperty& oSectPr = poDocument->m_oSectPr.get2(); - if(NULL != pStartSectionParagraph && !(oSectPr.m_oType.IsInit() && oSectPr.m_oType->m_oVal.IsInit() && SimpleTypes::sectionmarkContinious == oSectPr.m_oType->m_oVal->GetValue())) - ParagraphAddBreak(pStartSectionParagraph); - pStartSectionParagraph = NULL; - } - OOX::CHdrFtr* pHdrFirst = NULL; - OOX::CHdrFtr* pHdrEven = NULL; - OOX::CHdrFtr* pHdrDefault = NULL; - OOX::CHdrFtr* pFtrFirst = NULL; - OOX::CHdrFtr* pFtrEven = NULL; - OOX::CHdrFtr* pFtrDefault = NULL; - if(NULL != pFirstSectPr) - { - for(int i = 0, length = pFirstSectPr->m_arrHeaderReference.GetSize(); i < length; ++i) - { - const ComplexTypes::Word::CHdrFtrRef& oHdrFtrRef = pFirstSectPr->m_arrHeaderReference[i]; - if(oHdrFtrRef.m_oType.IsInit() && oHdrFtrRef.m_oId.IsInit()) - { - smart_ptr pFile = poDocument->Find(OOX::RId(oHdrFtrRef.m_oId->GetValue())); - if (pFile.IsInit() && OOX::FileTypes::Header == pFile->type()) - { - OOX::CHdrFtr* pHdrFtr = (OOX::CHdrFtr*)pFile.operator->(); - switch(oHdrFtrRef.m_oType->GetValue()) - { - case SimpleTypes::hdrftrDefault: pHdrDefault = pHdrFtr;break; - case SimpleTypes::hdrftrEven: pHdrEven = pHdrFtr;break; - case SimpleTypes::hdrftrFirst: pHdrFirst = pHdrFtr;break; - } - } - } - } - for(int i = 0, length = pFirstSectPr->m_arrFooterReference.GetSize(); i < length; ++i) - { - const ComplexTypes::Word::CHdrFtrRef& oHdrFtrRef = pFirstSectPr->m_arrFooterReference[i]; - if(oHdrFtrRef.m_oType.IsInit() && oHdrFtrRef.m_oId.IsInit()) - { - smart_ptr pFile = poDocument->Find(OOX::RId(oHdrFtrRef.m_oId->GetValue())); - if (pFile.IsInit() && OOX::FileTypes::Footer == pFile->type()) - { - OOX::CHdrFtr* pHdrFtr = (OOX::CHdrFtr*)pFile.operator->(); - switch(oHdrFtrRef.m_oType->GetValue()) - { - case SimpleTypes::hdrftrDefault: pFtrDefault = pHdrFtr;break; - case SimpleTypes::hdrftrEven: pFtrEven = pHdrFtr;break; - case SimpleTypes::hdrftrFirst: pFtrFirst = pHdrFtr;break; - } - } - } - } - } + OOX::Logic::CSectionProperty* pFirstSectPr = poDocument->m_oSectPr.GetPointer(); + this->WriteMainTableStart(); int nCurPos = 0; @@ -6239,7 +6152,7 @@ namespace BinDocxRW //Write StyleTable OOX::CStyles* pStyles = oDocx.GetStyles(); - BinDocxRW::BinaryStyleTableWriter oBinaryStyleTableWriter(oBufferedStream, m_oEmbeddedFontsManager, m_pTheme, oFontProcessor); + BinDocxRW::BinaryStyleTableWriter oBinaryStyleTableWriter(oBufferedStream, m_oEmbeddedFontsManager, m_pTheme, oFontProcessor, m_pSettings, m_pOfficeDrawingConverter); if(NULL != pStyles) { int nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::Style); @@ -6248,7 +6161,7 @@ namespace BinDocxRW } //Write Numbering OOX::CNumbering* pNumbering = oDocx.GetNumbering(); - BinDocxRW::BinaryNumberingTableWriter oBinaryNumberingTableWriter(oBufferedStream, m_oEmbeddedFontsManager, m_pTheme, oFontProcessor); + BinDocxRW::BinaryNumberingTableWriter oBinaryNumberingTableWriter(oBufferedStream, m_oEmbeddedFontsManager, m_pTheme, oFontProcessor, m_pSettings, m_pOfficeDrawingConverter); if(NULL != pNumbering) { nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::Numbering); @@ -6256,48 +6169,23 @@ namespace BinDocxRW this->WriteTableEnd(nCurPos); } - //Write HeaderFooter - if(NULL != pHdrFirst || NULL != pHdrEven || NULL != pHdrDefault || NULL != pFtrFirst || NULL != pFtrEven || NULL != pFtrDefault) - { - CSimpleArray* aHdrFirst = NULL; - if(NULL != pHdrFirst) - aHdrFirst = &pHdrFirst->m_arrItems; - CSimpleArray* aHdrEven = NULL; - if(NULL != pHdrEven) - aHdrEven = &pHdrEven->m_arrItems; - CSimpleArray* aHdrOdd = NULL; - if(NULL != pHdrDefault) - aHdrOdd = &pHdrDefault->m_arrItems; - CSimpleArray* aFtrFirst = NULL; - if(NULL != pFtrFirst) - aFtrFirst = &pFtrFirst->m_arrItems; - CSimpleArray* aFtrEven = NULL; - if(NULL != pFtrEven) - aFtrEven = &pFtrEven->m_arrItems; - CSimpleArray* aFtrOdd = NULL; - if(NULL != pFtrDefault) - aFtrOdd = &pFtrDefault->m_arrItems; - nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::HdrFtr); - BinDocxRW::BinaryHeaderFooterTableWriter oBinaryHeaderFooterTableWriter(oBufferedStream, &m_pCurRels,m_oEmbeddedFontsManager, m_pTheme, oFontProcessor, - aHdrFirst, aHdrEven, aHdrOdd, aFtrFirst, aFtrEven, aFtrOdd, - pHdrFirst, pHdrEven, pHdrDefault, pFtrFirst, pFtrEven, pFtrDefault, - pFirstSectPr, m_pSettings, m_pOfficeDrawingConverter); - oBinaryHeaderFooterTableWriter.pSectPr = pFirstSectPr; - oBinaryHeaderFooterTableWriter.Write(); - this->WriteTableEnd(nCurPos); - } + BinDocxRW::BinaryHeaderFooterTableWriter oBinaryHeaderFooterTableWriter(oBufferedStream, m_oEmbeddedFontsManager, m_pTheme, oFontProcessor, m_pSettings, m_pOfficeDrawingConverter, poDocument); //Write DocumentTable m_pCurRels = poDocument; //DocumentTable всегда пишем последней, чтобы сначала заполнить все вспомогательные структуры, а при заполении документа, вызывать методы типа Style_Add... nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::Document); - BinDocxRW::BinaryDocumentTableWriter oBinaryDocumentTableWriter(oBufferedStream, m_oEmbeddedFontsManager, m_pTheme, m_pSettings, oFontProcessor, poDocument, m_pOfficeDrawingConverter, &mapIgnoreComments); + BinDocxRW::BinaryDocumentTableWriter oBinaryDocumentTableWriter(oBufferedStream, m_oEmbeddedFontsManager, m_pTheme, m_pSettings, oFontProcessor, poDocument, m_pOfficeDrawingConverter, &mapIgnoreComments, &oBinaryHeaderFooterTableWriter); oBinaryDocumentTableWriter.prepareOfficeDrawingConverter(m_pOfficeDrawingConverter, poDocument->m_oReadPath.GetPath(), poDocument->m_arrShapeTypes); oBinaryDocumentTableWriter.pSectPr = pFirstSectPr; oBinaryDocumentTableWriter.m_bWriteSectPr = true; oBinaryDocumentTableWriter.Write(poDocument->m_arrItems); this->WriteTableEnd(nCurPos); + nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::HdrFtr); + oBinaryHeaderFooterTableWriter.Write(); + this->WriteTableEnd(nCurPos); + this->WriteMainTableEnd(pThemeData); } void ParagraphAddBreak(OOX::Logic::CParagraph* pParagraph) diff --git a/ASCOfficeDocxFile2/DocxFile2.h b/ASCOfficeDocxFile2/DocxFile2.h index 2f816fe94e..203b0599c3 100644 --- a/ASCOfficeDocxFile2/DocxFile2.h +++ b/ASCOfficeDocxFile2/DocxFile2.h @@ -10,6 +10,8 @@ #error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms." #endif +int g_nCurFormatVersion = 0; + #define BUFFER_GROW_SIZE 1 * 1024 * 1024 // IAVSOfficeDocxFile2 @@ -226,7 +228,7 @@ public: BinDocxRW::BinaryCommonWriter oBinaryCommonWriter(oBufferedStream, m_oBinaryFileWriter->m_oEmbeddedFontsManager); int nCurPos = oBinaryCommonWriter.WriteItemWithLengthStart(); - BinDocxRW::BinaryDocumentTableWriter oBinaryDocumentTableWriter(oBufferedStream, m_oBinaryFileWriter->m_oEmbeddedFontsManager, m_oBinaryFileWriter->m_pTheme, m_oBinaryFileWriter->m_pSettings, m_oBinaryFileWriter->m_oFontProcessor, m_oBinaryFileWriter->m_pCurRels, m_oBinaryFileWriter->m_pOfficeDrawingConverter, NULL); + BinDocxRW::BinaryDocumentTableWriter oBinaryDocumentTableWriter(oBufferedStream, m_oBinaryFileWriter->m_oEmbeddedFontsManager, m_oBinaryFileWriter->m_pTheme, m_oBinaryFileWriter->m_pSettings, m_oBinaryFileWriter->m_oFontProcessor, m_oBinaryFileWriter->m_pCurRels, m_oBinaryFileWriter->m_pOfficeDrawingConverter, NULL, NULL); oBinaryDocumentTableWriter.WriteDocumentContent(oSdtContent.m_arrItems); oBinaryCommonWriter.WriteItemWithLengthEnd(nCurPos); @@ -321,7 +323,9 @@ public: version = version.Right(version.GetLength() - 1); int nTempVersion = atoi(version); if(0 != nTempVersion) - nVersion = nTempVersion; + { + g_nCurFormatVersion = nVersion = nTempVersion; + } } PPTXFile::IAVSOfficeDrawingConverter* pDrawingConverter = NULL; CoCreateInstance(__uuidof(PPTXFile::CAVSOfficeDrawingConverter), NULL, CLSCTX_ALL, __uuidof(PPTXFile::IAVSOfficeDrawingConverter), (void**) &pDrawingConverter); diff --git a/ASCOfficeDocxFile2/version.h b/ASCOfficeDocxFile2/version.h index 45094cfbcd..2614e29d78 100644 --- a/ASCOfficeDocxFile2/version.h +++ b/ASCOfficeDocxFile2/version.h @@ -2,6 +2,6 @@ //2 //0 //0 -//163 -#define INTVER 2,0,0,163 -#define STRVER "2,0,0,163\0" +//164 +#define INTVER 2,0,0,164 +#define STRVER "2,0,0,164\0" diff --git a/Common/DocxFormat/Source/Base/Nullable.h b/Common/DocxFormat/Source/Base/Nullable.h index 861cb330ec..48a7cd4c31 100644 --- a/Common/DocxFormat/Source/Base/Nullable.h +++ b/Common/DocxFormat/Source/Base/Nullable.h @@ -198,7 +198,7 @@ namespace NSCommon return IsInit(); } - Type* GetPointer() + Type* GetPointer() const { return m_pPointer; } diff --git a/XlsxSerializerCom/ASCOfficeXlsxSerizer.h b/XlsxSerializerCom/ASCOfficeXlsxSerizer.h index 841f2330a0..907b0ca786 100644 --- a/XlsxSerializerCom/ASCOfficeXlsxSerizer.h +++ b/XlsxSerializerCom/ASCOfficeXlsxSerizer.h @@ -4,6 +4,9 @@ #include "Reader/BinaryWriter.h" #include "Reader/FontProcessor.h" #include "Writer/BinaryReader.h" + +int g_nCurFormatVersion = 0; + [ object, uuid("87476A4D-6A42-44e9-A947-42B8E8613070"), diff --git a/XlsxSerializerCom/Common/BinReaderWriterDefines.h b/XlsxSerializerCom/Common/BinReaderWriterDefines.h index c6abafa276..f2c4fa2e29 100644 --- a/XlsxSerializerCom/Common/BinReaderWriterDefines.h +++ b/XlsxSerializerCom/Common/BinReaderWriterDefines.h @@ -1,4 +1,7 @@ #pragma once + +extern int g_nCurFormatVersion; + namespace BinXlsxRW { const double g_dKoef_mm_to_pt = 72 / (2.54 * 10); diff --git a/XlsxSerializerCom/Writer/BinaryReader.h b/XlsxSerializerCom/Writer/BinaryReader.h index 5838a1a869..de1b60289e 100644 --- a/XlsxSerializerCom/Writer/BinaryReader.h +++ b/XlsxSerializerCom/Writer/BinaryReader.h @@ -2586,7 +2586,7 @@ namespace BinXlsxRW { { pRow->m_oHt.Init(); pRow->m_oHt->SetValue(m_oBufferedStream.ReadDouble()); - if(g_nFormatVersion < 2) + if(g_nCurFormatVersion < 2) { pRow->m_oCustomHeight.Init(); pRow->m_oCustomHeight->SetValue(SimpleTypes::onoffTrue); @@ -2990,7 +2990,9 @@ namespace BinXlsxRW { version = version.Right(version.GetLength() - 1); int nTempVersion = atoi(version); if(0 != nTempVersion) - nVersion = nTempVersion; + { + g_nCurFormatVersion = nVersion = nTempVersion; + } } OOX::Spreadsheet::CXlsx oXlsx; CSimpleArray aDeleteFiles;