Commit ea74d860 authored by konovalovsergey's avatar konovalovsergey

open/save footnote/endnote

parent a8a684bf
......@@ -64,6 +64,8 @@ namespace Writers
StylesWriter m_oStylesWriter;
NumberingWriter m_oNumberingWriter;
HeaderFooterWriter m_oHeaderFooterWriter;
FootnotesWriter m_oFootnotesWriter;
EndnotesWriter m_oEndnotesWriter;
SettingWriter m_oSettingWriter;
CommentsWriter m_oCommentsWriter;
ChartWriter m_oChartWriter;
......@@ -78,6 +80,8 @@ namespace Writers
m_pDrawingConverter(pDrawingConverter),m_sThemePath(sThemePath),m_bSaveChartAsImg(bSaveChartAsImg),
m_oContentTypesWriter(sDirOutput), m_oFontTableWriter(sDirOutput, sFontDir),
m_oHeaderFooterWriter(sDirOutput, m_oContentTypesWriter),
m_oFootnotesWriter(sDirOutput, m_oContentTypesWriter),
m_oEndnotesWriter(sDirOutput, m_oContentTypesWriter),
m_oMediaWriter(sDirOutput),
m_oStylesWriter(sDirOutput, nVersion),
m_oNumberingWriter(sDirOutput, m_oContentTypesWriter),
......
......@@ -64,6 +64,12 @@ namespace Writers
static CString g_string_ftr_Start = _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:ftr xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 wp14\">");
static CString g_string_ftr_End = _T("</w:ftr>");
static CString g_string_footnotes_Start = _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:footnotes xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 wp14\">");
static CString g_string_footnotes_End = _T("</w:footnotes>");
static CString g_string_endnotes_Start = _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:endnotes xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 wp14\">");
static CString g_string_endnotes_End = _T("</w:endnotes>");
class HeaderFooterWriter
{
CString m_sDir;
......@@ -122,5 +128,79 @@ namespace Writers
//return m_oDocumentRelsWriter.AddRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/") + sHeader, sFilename);
}
};
class FootnotesWriter
{
CString m_sDir;
ContentTypesWriter& m_oContentTypesWriter;
public:
ContentWriter m_oNotesWriter;
FootnotesWriter(CString sDir, ContentTypesWriter& oContentTypesWriter):m_sDir(sDir),m_oContentTypesWriter(oContentTypesWriter)
{
}
void Write()
{
if(!IsEmpty())
{
CString sFilename = getFilename();
CString filePath = m_sDir + FILE_SEPARATOR_STR +_T("word") + FILE_SEPARATOR_STR + sFilename;
CFile oFile;
oFile.CreateFile(filePath);
oFile.WriteStringUTF8(g_string_footnotes_Start);
oFile.WriteStringUTF8(m_oNotesWriter.m_oContent.GetData());
oFile.WriteStringUTF8(g_string_footnotes_End);
oFile.CloseFile();
//ContentType
m_oContentTypesWriter.AddOverride(_T("/word/") + sFilename, _T("application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"));
}
}
CString getFilename()
{
return _T("footnotes.xml");
}
bool IsEmpty()
{
return !(m_oNotesWriter.m_oContent.GetCurSize() > 0);
}
};
class EndnotesWriter
{
CString m_sDir;
ContentTypesWriter& m_oContentTypesWriter;
public:
ContentWriter m_oNotesWriter;
EndnotesWriter(CString sDir, ContentTypesWriter& oContentTypesWriter):m_sDir(sDir),m_oContentTypesWriter(oContentTypesWriter)
{
}
void Write()
{
if(!IsEmpty())
{
CString sFilename = getFilename();
CString filePath = m_sDir + FILE_SEPARATOR_STR +_T("word") + FILE_SEPARATOR_STR + sFilename;
CFile oFile;
oFile.CreateFile(filePath);
oFile.WriteStringUTF8(g_string_endnotes_Start);
oFile.WriteStringUTF8(m_oNotesWriter.m_oContent.GetData());
oFile.WriteStringUTF8(g_string_endnotes_End);
oFile.CloseFile();
//ContentType
m_oContentTypesWriter.AddOverride(_T("/word/") + sFilename, _T("application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"));
}
}
CString getFilename()
{
return _T("endnotes.xml");
}
bool IsEmpty()
{
return !(m_oNotesWriter.m_oContent.GetCurSize() > 0);
}
};
}
#endif // #ifndef HEADER_FOOTER_WRITER
......@@ -56,6 +56,8 @@ public:
CString sectPrChange;
CString cols;
CString pgBorders;
CString footnotePr;
CString endnotePr;
bool bHeader;
bool bFooter;
......@@ -97,6 +99,10 @@ public:
long nMFooter = SerializeCommon::Round(Footer * g_dKoef_mm_to_twips);
if(!sHeaderFooterReference.IsEmpty())
sRes.Append(sHeaderFooterReference);
if(!footnotePr.IsEmpty())
sRes.Append(footnotePr);
if(!endnotePr.IsEmpty())
sRes.Append(endnotePr);
if(bSectionType)
{
CString sType;
......
This diff is collapsed.
......@@ -150,7 +150,9 @@ extern int g_nCurFormatVersion;
Document = 6,
Other = 7,
Comments = 8,
Settings = 9
Settings = 9,
Footnotes = 10,
Endnotes = 11
};}
namespace c_oSerSigTypes{enum c_oSerSigTypes
{
......@@ -175,7 +177,7 @@ extern int g_nCurFormatVersion;
AbstractNum_Type = 3,
AbstractNum_Lvls = 4,
Lvl = 5,
lvl_Format = 6,
lvl_Format = 6,//deprecated (instead use lvl_NumFmt)
lvl_Jc = 7,
lvl_LvlText = 8,
lvl_LvlTextItem = 9,
......@@ -192,7 +194,10 @@ extern int g_nCurFormatVersion;
Num_NumId = 20,
lvl_PStyle = 21,
NumStyleLink = 22,
StyleLink = 23
StyleLink = 23,
lvl_NumFmt = 24,
NumFmtVal = 25,
NumFmtFormat = 26
};}
namespace c_oSerOtherTableTypes{enum c_oSerOtherTableTypes
{
......@@ -425,7 +430,9 @@ extern int g_nCurFormatVersion;
pageNumType = 6,
sectPrChange = 7,
cols = 8,
pgBorders = 9
pgBorders = 9,
footnotePr = 10,
endnotePr = 11
};}
namespace c_oSerProp_secPrSettingsType{enum c_oSerProp_secPrSettingsType
{
......@@ -492,7 +499,11 @@ extern int g_nCurFormatVersion;
noBreakHyphen = 20,
softHyphen = 21,
separator = 22,
continuationSeparator = 23
continuationSeparator = 23,
footnoteRef = 24,
endnoteRef = 25,
footnoteReference = 26,
endnoteReference = 27
};}
namespace c_oSerImageType{enum c_oSerImageType
{
......@@ -689,7 +700,9 @@ extern int g_nCurFormatVersion;
ClrSchemeMapping = 0,
DefaultTabStop = 1,
MathPr = 2,
TrackRevisions = 3
TrackRevisions = 3,
FootnotePr = 4,
EndnotePr = 5
};}
namespace c_oSer_MathPrType{enum c_oSer_SettingsType
{
......@@ -948,6 +961,21 @@ extern int g_nCurFormatVersion;
NoResize = 4,
NoSelect = 5
};}
namespace c_oSerNotes{enum c_oSerNotes
{
Note = 0,
NoteType = 1,
NoteId = 2,
NoteContent = 3,
RefCustomMarkFollows = 4,
RefId = 5,
PrFmt = 6,
PrRestart = 7,
PrStart = 8,
PrFntPos = 9,
PrEndPos = 10,
PrRef = 11
};}
}
#endif // #ifndef DOCX_BIN_READER_WRITER_DEFINES
This diff is collapsed.
......@@ -346,6 +346,8 @@ bool BinDocxRW::CDocxSerializer::loadFromFile(const CString& sSrcFileName, const
m_pCurFileWriter->m_oNumberingWriter.Write();
m_pCurFileWriter->m_oFontTableWriter.Write();
m_pCurFileWriter->m_oHeaderFooterWriter.Write();
m_pCurFileWriter->m_oFootnotesWriter.Write();
m_pCurFileWriter->m_oEndnotesWriter.Write();
//Setting пишем после HeaderFooter, чтобы заполнить evenAndOddHeaders
m_pCurFileWriter->m_oSettingWriter.Write();
m_pCurFileWriter->m_oWebSettingsWriter.Write();
......
......@@ -72,25 +72,33 @@ namespace OOX
CPath oRootPath;
read(oRootPath, oPath);
}
virtual void read(const CPath& oRootPath, const CPath& oPath)
virtual void read(const CPath& oRootPath, const CPath& oFilePath)
{
IFileContainer::Read( oRootPath, oPath );
m_oReadPath = oFilePath;
IFileContainer::Read( oRootPath, oFilePath );
XmlUtils::CXmlNode oEndnotes;
oEndnotes.FromXmlFile( oPath.GetPath(), true );
Common::readAllShapeTypes(oFilePath, m_arrShapeTypes);
if ( _T("w:endnotes") == oEndnotes.GetName() )
{
XmlUtils::CXmlNodes oEndnoteList;
oEndnotes.GetNodes( _T("w:endnote"), oEndnoteList );
XmlUtils::CXmlLiteReader oReader;
if ( !oReader.FromFile( oFilePath.GetPath() ) )
return;
if ( !oReader.ReadNextNode() )
return;
for ( int nIndex = 0; nIndex < oEndnoteList.GetCount(); nIndex++ )
CWCharWrapper sName = oReader.GetName();
if ( _T("w:endnotes") == sName && !oReader.IsEmptyNode() )
{
int nNumberingDepth = oReader.GetDepth();
while ( oReader.ReadNextSiblingNode( nNumberingDepth ) )
{
XmlUtils::CXmlNode oEndnoteNode;
if ( oEndnoteList.GetAt( nIndex, oEndnoteNode ) )
sName = oReader.GetName();
if ( _T("w:endnote") == sName )
{
CFtnEdn *pEndnote = new CFtnEdn( oEndnoteNode );
m_arrEndnote.push_back( pEndnote );
CFtnEdn *pEndnote = new CFtnEdn( oReader );
if (pEndnote) m_arrEndnote.push_back( pEndnote );
}
}
}
......@@ -150,8 +158,9 @@ namespace OOX
}
public:
CPath m_oReadPath;
std::vector<OOX::CFtnEdn*> m_arrEndnote;
std::vector<CString> m_arrShapeTypes;
};
} // namespace OOX
#endif // OOX_ENDNOTE_INCLUDE_H_
\ No newline at end of file
#endif // OOX_ENDNOTE_INCLUDE_H_
......@@ -72,25 +72,33 @@ namespace OOX
CPath oRootPath;
read(oRootPath, oPath);
}
virtual void read(const CPath& oRootPath, const CPath& oPath)
virtual void read(const CPath& oRootPath, const CPath& oFilePath)
{
IFileContainer::Read( oRootPath, oPath );
m_oReadPath = oFilePath;
IFileContainer::Read( oRootPath, oFilePath );
XmlUtils::CXmlNode oFootnotes;
oFootnotes.FromXmlFile( oPath.GetPath(), true );
Common::readAllShapeTypes(oFilePath, m_arrShapeTypes);
if ( _T("w:footnotes") == oFootnotes.GetName() )
{
XmlUtils::CXmlNodes oFootnoteList;
oFootnotes.GetNodes( _T("w:footnote"), oFootnoteList );
XmlUtils::CXmlLiteReader oReader;
if ( !oReader.FromFile( oFilePath.GetPath() ) )
return;
if ( !oReader.ReadNextNode() )
return;
for ( int nIndex = 0; nIndex < oFootnoteList.GetCount(); nIndex++ )
CWCharWrapper sName = oReader.GetName();
if ( _T("w:footnotes") == sName && !oReader.IsEmptyNode() )
{
int nNumberingDepth = oReader.GetDepth();
while ( oReader.ReadNextSiblingNode( nNumberingDepth ) )
{
XmlUtils::CXmlNode oFootnoteNode;
if ( oFootnoteList.GetAt( nIndex, oFootnoteNode ) )
sName = oReader.GetName();
if ( _T("w:footnote") == sName )
{
CFtnEdn *pFootnote = new CFtnEdn( oFootnoteNode );
CFtnEdn *pFootnote = new CFtnEdn( oReader );
if (pFootnote) m_arrFootnote.push_back( pFootnote );
}
}
}
......@@ -150,9 +158,10 @@ namespace OOX
}
public:
CPath m_oReadPath;
std::vector<OOX::CFtnEdn*> m_arrFootnote;
std::vector<CString> m_arrShapeTypes;
};
} // namespace OOX
#endif // OOX_FOOTNOTE_INCLUDE_H_
\ No newline at end of file
#endif // OOX_FOOTNOTE_INCLUDE_H_
......@@ -60,27 +60,15 @@ namespace OOX
class CFtnEdn : public WritingElementWithChilds<>
{
public:
WritingElement_AdditionConstructors(CFtnEdn)
CFtnEdn()
{
m_eType = et_Unknown;
}
CFtnEdn(const XmlUtils::CXmlNode& oNode)
{
m_eType = et_Unknown;
fromXML( (XmlUtils::CXmlNode&)oNode );
}
virtual ~CFtnEdn()
{
}
public:
const CFtnEdn& operator =(const XmlUtils::CXmlNode& oNode)
{
ClearItems();
fromXML( (XmlUtils::CXmlNode&)oNode );
return *this;
}
virtual void ClearItems()
{
m_eType = et_Unknown;
......@@ -183,6 +171,100 @@ namespace OOX
}
}
}
virtual void fromXML(XmlUtils::CXmlLiteReader& oReader)
{
CWCharWrapper sName = oReader.GetName();
if ( _T("w:footnote") == sName )
m_eType = et_w_footnote;
else if ( _T("w:endnote") == sName )
m_eType = et_w_endnote;
else
return;
ReadAttributes( oReader );
if ( oReader.IsEmptyNode() )
return;
int nParentDepth = oReader.GetDepth();
while( oReader.ReadNextSiblingNode( nParentDepth ) )
{
sName = oReader.GetName();
WritingElement *pItem = NULL;
/*if ( _T("w:altChunk") == sName )
pItem = new Logic::CAltChunk( oReader );
else */if ( _T("w:bookmarkEnd") == sName )
pItem = new Logic::CBookmarkEnd( oReader );
else if ( _T("w:bookmarkStart") == sName )
pItem = new Logic::CBookmarkStart( oReader );
else if ( _T("w:commentRangeEnd") == sName )
pItem = new Logic::CCommentRangeEnd( oReader );
else if ( _T("w:commentRangeStart") == sName )
pItem = new Logic::CCommentRangeStart( oReader );
//else if ( _T("w:customXml") == sName )
// pItem = new Logic::CCustomXml( oReader );
else if ( _T("w:customXmlDelRangeEnd") == sName )
pItem = new Logic::CCustomXmlDelRangeEnd( oReader );
else if ( _T("w:customXmlDelRangeStart") == sName )
pItem = new Logic::CCustomXmlDelRangeStart( oReader );
else if ( _T("w:customXmlInsRangeEnd") == sName )
pItem = new Logic::CCustomXmlInsRangeEnd( oReader );
else if ( _T("w:customXmlInsRangeStart") == sName )
pItem = new Logic::CCustomXmlInsRangeStart( oReader );
else if ( _T("w:customXmlMoveFromRangeEnd") == sName )
pItem = new Logic::CCustomXmlMoveFromRangeEnd( oReader );
else if ( _T("w:customXmlMoveFromRangeStart") == sName )
pItem = new Logic::CCustomXmlMoveFromRangeStart( oReader );
else if ( _T("w:customXmlMoveToRangeEnd") == sName )
pItem = new Logic::CCustomXmlMoveToRangeEnd( oReader );
else if ( _T("w:customXmlMoveToRangeStart") == sName )
pItem = new Logic::CCustomXmlMoveToRangeStart( oReader );
else if ( _T("w:del") == sName )
pItem = new Logic::CDel( oReader );
else if ( _T("w:ins") == sName )
pItem = new Logic::CIns( oReader );
//else if ( _T("w:moveFrom") == sName )
// pItem = new Logic::CMoveFrom( oReader );
else if ( _T("w:moveFromRangeEnd") == sName )
pItem = new Logic::CMoveToRangeEnd( oReader );
else if ( _T("w:moveFromRangeStart") == sName )
pItem = new Logic::CMoveToRangeStart( oReader );
//else if ( _T("w:moveTo") == sName )
// pItem = new Logic::CMoveTo( oReader );
else if ( _T("w:moveToRangeEnd") == sName )
pItem = new Logic::CMoveToRangeEnd( oReader );
else if ( _T("w:moveToRangeStart") == sName )
pItem = new Logic::CMoveToRangeStart( oReader );
else if ( _T("m:oMath") == sName )
pItem = new Logic::COMath( oReader );
else if ( _T("m:oMathPara") == sName )
pItem = new Logic::COMathPara( oReader );
else if ( _T("w:p") == sName )
pItem = new Logic::CParagraph( oReader );
else if ( _T("w:permEnd") == sName )
pItem = new Logic::CPermEnd( oReader );
else if ( _T("w:permStart") == sName )
pItem = new Logic::CPermStart( oReader );
else if ( _T("w:proofErr") == sName )
pItem = new Logic::CProofErr( oReader );
else if ( _T("w:sdt") == sName )
pItem = new Logic::CSdt( oReader );
else if ( _T("w:tbl") == sName )
pItem = new Logic::CTbl( oReader );
if ( pItem )
m_arrItems.push_back( pItem );
}
}
void ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
{
// Читаем атрибуты
WritingElement_ReadAttributes_Start( oReader )
WritingElement_ReadAttributes_Read_if( oReader, _T("w:id"), m_oId )
WritingElement_ReadAttributes_Read_else_if( oReader, _T("w:type"), m_oType )
WritingElement_ReadAttributes_End( oReader )
}
virtual CString toXML() const
{
CString sResult;
......
......@@ -1234,7 +1234,12 @@ namespace OOX
{
CString sResult = _T("<w:endnoteReference ");
ComplexTypes_WriteAttribute( _T("w:customMarkFollows=\""), m_oCustomMarkFollows );
if ( m_oCustomMarkFollows.IsInit() )
{
sResult += _T("w:customMarkFollows=\"");
sResult += m_oCustomMarkFollows->ToString2(SimpleTypes::onofftostring1);
sResult += _T("\" ");
}
ComplexTypes_WriteAttribute( _T("w:id=\""), m_oId );
sResult += _T("/>");
......@@ -1343,7 +1348,12 @@ namespace OOX
{
CString sResult = _T("<w:footnoteReference ");
ComplexTypes_WriteAttribute( _T("w:customMarkFollows=\""), m_oCustomMarkFollows );
if ( m_oCustomMarkFollows.IsInit() )
{
sResult += _T("w:customMarkFollows=\"");
sResult += m_oCustomMarkFollows->ToString2(SimpleTypes::onofftostring1);
sResult += _T("\" ");
}
ComplexTypes_WriteAttribute( _T("w:id=\""), m_oId );
sResult += _T("/>");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment