mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Added creating content in a docx file
This commit is contained in:
@ -28,6 +28,10 @@ SOURCES += src/CEpubFile.cpp \
|
||||
src/Docx/docRels/CDocRelationshipsXml.cpp \
|
||||
src/Docx/rels/CRelationships.cpp \
|
||||
src/Docx/rels/CRelationshipsXml.cpp \
|
||||
src/Docx/sdt/CSdt.cpp \
|
||||
src/Docx/sdt/CSdtContent.cpp \
|
||||
src/Docx/sdt/CSdtEndPr.cpp \
|
||||
src/Docx/sdt/CSdtPr.cpp \
|
||||
src/Docx/style/CStyle.cpp \
|
||||
src/Docx/style/CStyles.cpp \
|
||||
src/Docx/style/CStylesXml.cpp \
|
||||
@ -67,6 +71,10 @@ HEADERS += CEpubFile.h \
|
||||
src/Docx/docRels/CDocRelationshipsXml.h \
|
||||
src/Docx/rels/CRelationships.h \
|
||||
src/Docx/rels/CRelationshipsXml.h \
|
||||
src/Docx/sdt/CSdt.h \
|
||||
src/Docx/sdt/CSdtContent.h \
|
||||
src/Docx/sdt/CSdtEndPr.h \
|
||||
src/Docx/sdt/CSdtPr.h \
|
||||
src/Docx/style/CStyle.h \
|
||||
src/Docx/style/CStyles.h \
|
||||
src/Docx/style/CStylesXml.h \
|
||||
|
||||
@ -142,4 +142,16 @@ void CBookToc::ShowToc()
|
||||
}
|
||||
}
|
||||
|
||||
int CBookToc::GetCountToc()
|
||||
{
|
||||
return (int)m_arData.size();
|
||||
}
|
||||
|
||||
std::pair<std::wstring, std::wstring> CBookToc::GetTextAndRef(int nIndex)
|
||||
{
|
||||
if (nIndex < 0 || nIndex > (int)m_arData.size())
|
||||
return std::pair<std::wstring, std::wstring>(L"", L"");
|
||||
|
||||
return std::pair<std::wstring, std::wstring>(m_arData[nIndex].sText, m_arData[nIndex].sRef);
|
||||
}
|
||||
|
||||
|
||||
@ -30,6 +30,8 @@ public:
|
||||
bool ReadToc(XmlUtils::CXmlLiteReader &oXmlLiteReader);
|
||||
~CBookToc();
|
||||
void ShowToc();
|
||||
int GetCountToc();
|
||||
std::pair<std::wstring, std::wstring> GetTextAndRef(int nIndex);
|
||||
};
|
||||
|
||||
#endif // CBOOKTOC_H
|
||||
|
||||
@ -12,7 +12,7 @@ CEpubFile::CEpubFile()
|
||||
|
||||
CEpubFile::~CEpubFile()
|
||||
{
|
||||
NSDirectory::DeleteDirectory(m_sTempDir);
|
||||
// NSDirectory::DeleteDirectory(m_sTempDir);
|
||||
}
|
||||
|
||||
bool CEpubFile::IsEbubFile(const std::wstring &sfileName)
|
||||
@ -96,6 +96,31 @@ bool CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& sOut
|
||||
CDocxFile oDocxFile;
|
||||
oDocxFile.CreateTempFiles(sOutputFile, m_sTempDir);
|
||||
|
||||
oDocxFile.AddBookToc(&m_oToc);
|
||||
// CParagraph *oNewPar = new CParagraph;
|
||||
// CElement *oHypelink = new CElement(L"hyperlink", L"", L"w", false);
|
||||
// oHypelink->AddArgument(L"r:id", L"rId9");
|
||||
// CElement *oRun = new CElement(L"r", L"", L"w");
|
||||
// CElement *oRPr = new CElement(L"rPr", L"", L"w");
|
||||
// CElement *oRStyle = new CElement(L"rStyle", L"", L"w");
|
||||
// oRStyle->AddArgument(L"val", L"Hyperlink");
|
||||
// oRPr->AddChildren(oRStyle);
|
||||
// oRun->AddChildren(oRPr);
|
||||
// CElement *oText = new CElement(L"t", L"HYPERLINK", L"w");
|
||||
// oRun->AddChildren(oText);
|
||||
// oHypelink->AddChildren(oRun);
|
||||
// oNewPar->AddChildren(oHypelink);
|
||||
|
||||
// oDocxFile.AddParagraph(oNewPar);
|
||||
|
||||
// CElement *oRelationship = new CElement(L"Relationship", L"", L"");
|
||||
// oRelationship->AddArgument(L"Id", L"rId9");
|
||||
// oRelationship->AddArgument(L"Type", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink");
|
||||
// oRelationship->AddArgument(L"Target", L"http://www.google.com/");
|
||||
// oRelationship->AddArgument(L"TargetMode", L"External");
|
||||
|
||||
// oDocxFile.AddRelationship(oRelationship);
|
||||
|
||||
std::wstring sTempDir = m_sTempDir + L"/docx";
|
||||
std::wstring _sOutputFile = sOutputFile + L"/test.docx";
|
||||
|
||||
@ -105,7 +130,6 @@ bool CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& sOut
|
||||
|
||||
oDocxFile.SaveToFile();
|
||||
|
||||
|
||||
oOfficeUtils.CompressFileOrDirectory(sTempDir, _sOutputFile);
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
#include "../../../DesktopEditor/xml/include/xmlutils.h"
|
||||
|
||||
#include "document/CDocument.h"
|
||||
#include "sdt/CSdt.h"
|
||||
#include "hyperlink/CHyperlink.h"
|
||||
|
||||
CDocxFile::CDocxFile()
|
||||
{
|
||||
@ -22,7 +24,7 @@ CDocxFile::CDocxFile()
|
||||
|
||||
CDocxFile::~CDocxFile()
|
||||
{
|
||||
// NSDirectory::DeleteDirectory(m_sTempDir);
|
||||
NSDirectory::DeleteDirectory(m_sTempDir);
|
||||
}
|
||||
|
||||
bool CDocxFile::AddParagraph(std::wstring sText, bool bNewPAge)
|
||||
@ -41,11 +43,29 @@ bool CDocxFile::AddParagraph(CParagraph *oParagraph)
|
||||
m_oDocumentXml->AddParagraph(oParagraph);
|
||||
}
|
||||
|
||||
bool CDocxFile::AddBookContent(CBookToc *oBookToc)
|
||||
bool CDocxFile::AddBookToc(CBookToc *oBookToc)
|
||||
{
|
||||
CParagraph *oFirstP = m_oDocumentXml->GetParagraph(0);
|
||||
|
||||
oFirstP->
|
||||
if (oBookToc == NULL)
|
||||
return false;
|
||||
|
||||
CSdt *oSdt = new CSdt;
|
||||
oSdt->SetDefoult();
|
||||
for (int i = 0; i < oBookToc->GetCountToc(); i++)
|
||||
oSdt->AddHeader(oBookToc->GetTextAndRef(i), m_oDocumentXml, m_oDocRelationshipsXml);
|
||||
|
||||
m_oDocumentXml->AddElement(oSdt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDocxFile::AddRelationship(CElement *oRelationship)
|
||||
{
|
||||
if (oRelationship == NULL)
|
||||
return false;
|
||||
|
||||
m_oDocRelationshipsXml->GetXmlStructure()->AddChildren(oRelationship);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDocxFile::CreateRelsDir()
|
||||
|
||||
@ -72,8 +72,9 @@ public:
|
||||
|
||||
bool AddParagraph(std::wstring sText, bool bNewPAge = false);
|
||||
bool AddParagraph(CParagraph *oParagraph);
|
||||
bool AddBookContent(CBookToc *oBookToc);
|
||||
bool AddHypelink(std::wstring sText, );
|
||||
bool AddBookToc(CBookToc *oBookToc);
|
||||
bool AddRelationship(CElement *oRelationship);
|
||||
// bool AddHypelink(std::wstring sText, );
|
||||
// bool OpenFile(std::wstring sPathFile);
|
||||
|
||||
bool SaveToFile();
|
||||
|
||||
@ -149,6 +149,11 @@ void CElement::Clear(bool Children, bool NameElement, bool Value, bool Arguments
|
||||
m_bEmpty = true;
|
||||
}
|
||||
|
||||
void CElement::EditBoolNamespace(bool bNamespace)
|
||||
{
|
||||
m_bNamespaceArguments = bNamespace;
|
||||
}
|
||||
|
||||
void CElement::AddChildren(CElement* oChildren, int nIndex)
|
||||
{
|
||||
m_bEmpty = false;
|
||||
|
||||
@ -39,6 +39,7 @@ public:
|
||||
const bool NameElement = true,
|
||||
const bool Value = true,
|
||||
const bool Arguments = true);
|
||||
void EditBoolNamespace(bool bNamespace);
|
||||
|
||||
|
||||
std::wstring GetArguments();
|
||||
@ -103,6 +104,13 @@ private:
|
||||
{ L"Characters", true },
|
||||
{ L"created", true },
|
||||
{ L"modified", true },
|
||||
{ L"hyperlink", true },
|
||||
{ L"sdt", true },
|
||||
{ L"sdtPr", true },
|
||||
{ L"docPartObj", true },
|
||||
{ L"sdtEndPr", true },
|
||||
{ L"sdtContent", true },
|
||||
{ L"tabs", true },
|
||||
{ L"lang", false},
|
||||
{ L"bookmarkStart", false},
|
||||
{ L"bookmarkEnd", false},
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "CDocRelationshipsXml.h"
|
||||
#include "CDocRelationships.h"
|
||||
#include <string>
|
||||
|
||||
CDocRelationshipsXml::CDocRelationshipsXml()
|
||||
: CXmlFile()
|
||||
@ -13,3 +14,14 @@ void CDocRelationshipsXml::SetDefoult()
|
||||
oDocRelationships->SetDefoult();
|
||||
SetXmlStructure(oDocRelationships);
|
||||
}
|
||||
|
||||
void CDocRelationshipsXml::AddLinkToFile(std::wstring sPathFile, int nId)
|
||||
{
|
||||
CElement *oRelationship = new CElement(L"Relationship", L"", L"", false);
|
||||
oRelationship->AddArgument(L"Id", L"rId" + std::to_wstring(nId));
|
||||
oRelationship->AddArgument(L"Type", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink");
|
||||
oRelationship->AddArgument(L"Target", sPathFile);
|
||||
oRelationship->AddArgument(L"TargetMode", L"External");
|
||||
|
||||
GetXmlStructure()->AddChildren(oRelationship);
|
||||
}
|
||||
|
||||
@ -9,6 +9,8 @@ public:
|
||||
CDocRelationshipsXml();
|
||||
|
||||
void SetDefoult() override;
|
||||
|
||||
void AddLinkToFile(std::wstring sFilePath, int nId);
|
||||
};
|
||||
|
||||
#endif // CDOCRELATIONSHIPSXML_H
|
||||
|
||||
@ -32,7 +32,7 @@ bool CDocumentXml::AddParagraph(std::wstring sText, bool bNewPAge)
|
||||
|
||||
bool CDocumentXml::AddParagraph(CParagraph *oParagraph)
|
||||
{
|
||||
if (IsEmpty())
|
||||
if (IsEmpty() || oParagraph == NULL)
|
||||
return false;
|
||||
|
||||
CElement* oDocumentStructure = GetXmlStructure();
|
||||
@ -46,6 +46,23 @@ bool CDocumentXml::AddParagraph(CParagraph *oParagraph)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDocumentXml::AddElement(CElement *oElement, bool bEnd)
|
||||
{
|
||||
if (IsEmpty() || oElement == NULL)
|
||||
return false;
|
||||
|
||||
CElement* oDocumentStructure = GetXmlStructure();
|
||||
if (oDocumentStructure->GetName() != L"document")
|
||||
return false;
|
||||
|
||||
CDocument *oDocument = static_cast<CDocument*>(oDocumentStructure);
|
||||
if (bEnd)
|
||||
oDocument->AddChildren(oElement, oDocument->GetCountChildrens() - 1);
|
||||
else
|
||||
oDocument->AddChildren(oElement, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
CParagraph* CDocumentXml::GetParagraph(int nIndex)
|
||||
{
|
||||
return static_cast<CDocument*>(GetXmlStructure())->GetParagraph(nIndex);
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
#include "CParagraph.h"
|
||||
#include "CParagraphProperties.h"
|
||||
#include "CRun.h"
|
||||
#include "stack"
|
||||
#include "../hyperlink/CHyperlink.h"
|
||||
#include <stack>
|
||||
#include <string>
|
||||
|
||||
CParagraph::CParagraph()
|
||||
: CElement(L"p", L"", L"w")
|
||||
@ -59,10 +61,6 @@ void CParagraph::SetDefoult()
|
||||
AddArgument(L"rsidR", L"003939F5");
|
||||
AddArgument(L"rsidRDefault", L"00481163");
|
||||
|
||||
CParagraphProperties *oParagraphProperties = new CParagraphProperties;
|
||||
oParagraphProperties->SetDefoult();
|
||||
AddChildren(oParagraphProperties);
|
||||
|
||||
CElement *oBookmarkStart = new CElement(L"bookmarkStart", L"", L"w");
|
||||
oBookmarkStart->AddArgument(L"id", L"0");
|
||||
oBookmarkStart->AddArgument(L"name", L"_GoBack");
|
||||
@ -80,9 +78,58 @@ void CParagraph::SetDefoult()
|
||||
void CParagraph::SetTagNewPage()
|
||||
{
|
||||
CRun *oRun = new CRun;
|
||||
CElement *oBr = new CElement(L"br", L"", L"w");
|
||||
oBr->AddArgument(L"type", L"page");
|
||||
CElement *oBr = new CElement(L"br", L"", L"w");
|
||||
oBr->AddArgument(L"type", L"page");
|
||||
oRun->AddChildren(oBr);
|
||||
AddChildren(oRun);
|
||||
AddChildren(oRun, 0);
|
||||
|
||||
}
|
||||
|
||||
void CParagraph::AddHyperlinkToc(int nIdToc)
|
||||
{
|
||||
for (int i = 0; i < GetCountChildrens(); i++)
|
||||
{
|
||||
CElement *oElement = GetChildren(i);
|
||||
if (oElement->GetName() == L"bookmarkStart")
|
||||
{
|
||||
oElement->DeleteArgument(L"name");
|
||||
oElement->AddArgument(L"name", L"_Toc" + std::to_wstring(nIdToc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CParagraph::AddLinkToFile(CDocRelationshipsXml *oDocRel, std::wstring sPathFile)
|
||||
{
|
||||
CHyperlink *oHyperlink = new CHyperlink;
|
||||
oHyperlink->CreateFileLink(sPathFile);
|
||||
if (!IsEmpty())
|
||||
Clear();
|
||||
|
||||
AddArgument(L"rsidR", L"00EF05E0");
|
||||
AddArgument(L"rsidRDefault", L"006D386F");
|
||||
AddArgument(L"rsidP", L"00670FDF");
|
||||
|
||||
AddChildren(oHyperlink);
|
||||
|
||||
oDocRel->AddLinkToFile(sPathFile, oHyperlink->GetId());
|
||||
}
|
||||
|
||||
void CParagraph::SetInCenter()
|
||||
{
|
||||
for (int i = 0; i < GetCountChildrens(); i++)
|
||||
{
|
||||
CElement *oElement = GetChildren(i);
|
||||
if (oElement->GetName() == L"pPr")
|
||||
{
|
||||
CElement *oJc = new CElement(L"jc", L"", L"w");
|
||||
oJc->AddArgument(L"val", L"center");
|
||||
oElement->AddChildren(oJc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
CElement *oPPr = new CElement(L"pPr", L"", L"w");
|
||||
CElement *oJc = new CElement(L"jc", L"", L"w");
|
||||
oJc->AddArgument(L"val", L"center");
|
||||
oPPr->AddChildren(oJc, 0);
|
||||
AddChildren(oPPr, 0);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#define CPARAGRAPH_H
|
||||
|
||||
#include "../CElement.h"
|
||||
#include "../docRels/CDocRelationshipsXml.h"
|
||||
|
||||
class CParagraph : public CElement
|
||||
{
|
||||
@ -13,6 +14,11 @@ public:
|
||||
void SetDefoult() override;
|
||||
void SetText(std::wstring sText, bool newPage);
|
||||
void AddText(std::wstring sText, bool newPage);
|
||||
|
||||
void AddHyperlinkToc(int nIdToc);
|
||||
void AddLinkToFile(CDocRelationshipsXml *oDocRel, std::wstring sPathFile);
|
||||
|
||||
void SetInCenter();
|
||||
};
|
||||
|
||||
#endif // CPARAGRAPH_H
|
||||
|
||||
@ -9,6 +9,5 @@ CParagraphProperties::CParagraphProperties()
|
||||
void CParagraphProperties::SetDefoult()
|
||||
{
|
||||
CRunProperties *oRunProperties = new CRunProperties;
|
||||
oRunProperties->SetDefoult();
|
||||
AddChildren(oRunProperties);
|
||||
}
|
||||
|
||||
@ -7,6 +7,5 @@ CRunProperties::CRunProperties()
|
||||
|
||||
void CRunProperties::SetDefoult()
|
||||
{
|
||||
CElement *oI = new CElement(L"i", L"", L"w");
|
||||
AddChildren(oI);
|
||||
|
||||
}
|
||||
|
||||
@ -1,11 +1,149 @@
|
||||
#include "CHyperlink.h"
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
CHyperlink::CHyperlink()
|
||||
: CElement(L"hyperlink", L"", L"w")
|
||||
{
|
||||
std::mt19937 rng;
|
||||
rng.seed(std::random_device()());
|
||||
std::uniform_int_distribution<std::mt19937::result_type> dist(1, 999999);
|
||||
|
||||
m_nId = dist(rng);
|
||||
}
|
||||
|
||||
void CHyperlink::SetDefoult()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CHyperlink::GetId()
|
||||
{
|
||||
return m_nId;
|
||||
}
|
||||
|
||||
void CHyperlink::CreateTocHyperlink(std::wstring sText)
|
||||
{
|
||||
AddArgument(L"anchor", L"_Toc" + std::to_wstring(m_nId));
|
||||
|
||||
CElement *oRun1 = new CElement(L"r", L"", L"w");
|
||||
oRun1->AddArgument(L"rsidRPr", L"006E6199");
|
||||
CElement *oRPr1 = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oRStyle1 = new CElement(L"rStyle", L"", L"w");
|
||||
oRStyle1->AddArgument(L"val", L"a4");
|
||||
oRPr1->AddChildren(oRStyle1);
|
||||
CElement *oNoProof1 = new CElement(L"noProof", L"", L"w");
|
||||
oRPr1->AddChildren(oNoProof1);
|
||||
oRun1->AddChildren(oRPr1);
|
||||
CElement *oText = new CElement(L"t", sText, L"w");
|
||||
oRun1->AddChildren(oText);
|
||||
AddChildren(oRun1);
|
||||
|
||||
CElement *oRun2 = new CElement(L"r", L"", L"w");
|
||||
CElement *oRPr2 = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oNoProof2 = new CElement(L"noProof", L"", L"w");
|
||||
oRPr2->AddChildren(oNoProof2);
|
||||
CElement *oWebHidden2 = new CElement(L"webHidden", L"", L"w");
|
||||
oRPr2->AddChildren(oWebHidden2);
|
||||
oRun2->AddChildren(oRPr2);
|
||||
CElement *oTab = new CElement(L"tab", L"", L"w");
|
||||
oRun2->AddChildren(oTab);
|
||||
AddChildren(oRun2);
|
||||
|
||||
CElement *oRun3 = new CElement(L"r", L"", L"w");
|
||||
CElement *oRPr3 = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oNoProof3 = new CElement(L"noProof", L"", L"w");
|
||||
oRPr3->AddChildren(oNoProof3);
|
||||
CElement *oWebHidden3 = new CElement(L"webHidden", L"", L"w");
|
||||
oRPr3->AddChildren(oWebHidden3);
|
||||
oRun3->AddChildren(oRPr3);
|
||||
CElement *oFldChar3 = new CElement(L"fldChar", L"", L"w");
|
||||
oFldChar3->AddArgument(L"fldCharType", L"begin");
|
||||
oRun3->AddChildren(oFldChar3);
|
||||
AddChildren(oRun3);
|
||||
|
||||
CElement *oRun4 = new CElement(L"r", L"", L"w");
|
||||
CElement *oRPr4 = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oNoProof4 = new CElement(L"noProof", L"", L"w");
|
||||
oRPr4->AddChildren(oNoProof4);
|
||||
CElement *oWebHidden4 = new CElement(L"webHidden", L"", L"w");
|
||||
oRPr4->AddChildren(oWebHidden4);
|
||||
oRun4->AddChildren(oRPr4);
|
||||
CElement *oInstrText4 = new CElement(L"instrText", L" PAGEREF _Toc" + std::to_wstring(m_nId) +L" \\h ", L"w", false);
|
||||
oInstrText4->AddArgument(L"xml:space", L"preserve");
|
||||
oRun4->AddChildren(oInstrText4);
|
||||
AddChildren(oRun4);
|
||||
|
||||
CElement *oRun5 = new CElement(L"r", L"", L"w");
|
||||
CElement *oRPr5 = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oNoProof5 = new CElement(L"noProof", L"", L"w");
|
||||
oRPr5->AddChildren(oNoProof5);
|
||||
CElement *oWebHidden5 = new CElement(L"webHidden", L"", L"w");
|
||||
oRPr5->AddChildren(oWebHidden5);
|
||||
oRun5->AddChildren(oRPr5);
|
||||
AddChildren(oRun5);
|
||||
|
||||
CElement *oRun6 = new CElement(L"r", L"", L"w");
|
||||
CElement *oRPr6 = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oNoProof6 = new CElement(L"noProof", L"", L"w");
|
||||
oRPr6->AddChildren(oNoProof6);
|
||||
CElement *oWebHidden6 = new CElement(L"webHidden", L"", L"w");
|
||||
oRPr6->AddChildren(oWebHidden6);
|
||||
oRun6->AddChildren(oRPr6);
|
||||
CElement *oFldChar6 = new CElement(L"fldChar", L"", L"w");
|
||||
oFldChar6->AddArgument(L"fldCharType", L"separate");
|
||||
oRun6->AddChildren(oFldChar6);
|
||||
AddChildren(oRun6);
|
||||
|
||||
CElement *oRun7 = new CElement(L"r", L"", L"w");
|
||||
CElement *oRPr7 = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oNoProof7 = new CElement(L"noProof", L"", L"w");
|
||||
oRPr7->AddChildren(oNoProof7);
|
||||
CElement *oWebHidden7 = new CElement(L"webHidden", L"", L"w");
|
||||
oRPr7->AddChildren(oWebHidden7);
|
||||
oRun7->AddChildren(oRPr7);
|
||||
CElement *oText7 = new CElement(L"t", L"#", L"w");
|
||||
oRun7->AddChildren(oText7);
|
||||
AddChildren(oRun7);
|
||||
|
||||
CElement *oRun8 = new CElement(L"r", L"", L"w");
|
||||
CElement *oRPr8 = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oNoProof8 = new CElement(L"noProof", L"", L"w");
|
||||
oRPr8->AddChildren(oNoProof8);
|
||||
CElement *oWebHidden8 = new CElement(L"webHidden", L"", L"w");
|
||||
oRPr8->AddChildren(oWebHidden8);
|
||||
oRun8->AddChildren(oRPr8);
|
||||
CElement *oFldChar8 = new CElement(L"fldChar", L"", L"w");
|
||||
oFldChar8->AddArgument(L"fldCharType", L"end");
|
||||
oRun8->AddChildren(oFldChar8);
|
||||
AddChildren(oRun8);
|
||||
}
|
||||
|
||||
void CHyperlink::CreateFileLink(std::wstring sText)
|
||||
{
|
||||
std::wstring _sText = sText;
|
||||
if (_sText.find(L"\\") != std::wstring::npos)
|
||||
_sText = _sText.substr(_sText.find_last_of(L"\\") + 1, _sText.length());
|
||||
|
||||
EditBoolNamespace(false);
|
||||
AddArgument(L"r:id", L"rId" + std::to_wstring(m_nId));
|
||||
CElement *oRun = new CElement(L"r", L"", L"w");
|
||||
oRun->AddArgument(L"rsidR", L"00F17446");
|
||||
oRun->AddArgument(L"rsidRPr", L"006D386F");
|
||||
CElement *oRPr = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oRStyle = new CElement(L"rStyle", L"", L"w");
|
||||
oRStyle->AddArgument(L"val", L"a3");
|
||||
oRPr->AddChildren(oRStyle);
|
||||
oRun->AddChildren(oRPr);
|
||||
CElement *oText = new CElement(L"t", _sText, L"w");
|
||||
oRun->AddChildren(oText);
|
||||
AddChildren(oRun);
|
||||
CElement *oBookmarkStart = new CElement(L"bookmarkStart", L"", L"w");
|
||||
oBookmarkStart->AddArgument(L"id", std::to_wstring(m_nId + 3));
|
||||
oBookmarkStart->AddArgument(L"name", L"_GoBack");
|
||||
AddChildren(oBookmarkStart);
|
||||
CElement *oBookmarkEnd = new CElement(L"bookmarkEnd", L"", L"w");
|
||||
oBookmarkEnd->AddArgument(L"id", std::to_wstring(m_nId + 3));
|
||||
AddChildren(oBookmarkEnd);
|
||||
}
|
||||
|
||||
@ -5,12 +5,15 @@
|
||||
|
||||
class CHyperlink : public CElement
|
||||
{
|
||||
std::wstring m_sPageRef;
|
||||
int m_nId;
|
||||
public:
|
||||
CHyperlink();
|
||||
|
||||
void SetDefoult() override;
|
||||
void SetText(std::wstring sText);
|
||||
void CreateTocHyperlink(std::wstring sText);
|
||||
void CreateFileLink(std::wstring sText);
|
||||
|
||||
int GetId();
|
||||
};
|
||||
|
||||
#endif // CHYPERLINK_H
|
||||
|
||||
90
EpubFile/src/Docx/sdt/CSdt.cpp
Normal file
90
EpubFile/src/Docx/sdt/CSdt.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include "CSdt.h"
|
||||
|
||||
#include "../hyperlink/CHyperlink.h"
|
||||
#include "../../../../DesktopEditor/common/File.h"
|
||||
|
||||
CSdt::CSdt()
|
||||
: CElement(L"sdt", L"", L"w")
|
||||
{
|
||||
}
|
||||
|
||||
void CSdt::SetDefoult()
|
||||
{
|
||||
m_oSdtPr = new CSdtPr();
|
||||
m_oSdtPr->SetDefoult();
|
||||
AddChildren(m_oSdtPr);
|
||||
|
||||
m_oSdtEndPr = new CSdtEndPr();
|
||||
m_oSdtEndPr->SetDefoult();
|
||||
AddChildren(m_oSdtEndPr);
|
||||
|
||||
m_oSdtContent = new CSdtContent();
|
||||
m_oSdtContent->SetDefoult();
|
||||
AddChildren(m_oSdtContent);
|
||||
}
|
||||
|
||||
void CSdt::AddHeader(std::pair<std::wstring, std::wstring> pTextAndRef, CDocumentXml *oWhereToAdd, CDocRelationshipsXml *oDocRel)
|
||||
{
|
||||
nCountHyperlinks++;
|
||||
|
||||
CElement *oParagraph = new CElement(L"p", L"", L"w");
|
||||
oParagraph->AddArgument(L"rsidR", L"005D3816");
|
||||
oParagraph->AddArgument(L"rsidRDefault", L"005D3816");
|
||||
oParagraph->AddArgument(L"rsidP", L"005D3816");
|
||||
|
||||
CElement *oPPr = new CElement(L"pPr", L"", L"w");
|
||||
CElement *oPStyle = new CElement(L"pStyle", L"", L"w");
|
||||
oPStyle->AddArgument(L"val", L"21");
|
||||
oPPr->AddChildren(oPStyle);
|
||||
|
||||
CElement *oTabs = new CElement(L"tabs", L"", L"w");
|
||||
CElement *oTab = new CElement(L"tab", L"", L"w");
|
||||
oTab->AddArgument(L"val", L"right");
|
||||
oTab->AddArgument(L"leader", L"dot");
|
||||
oTab->AddArgument(L"pos", L"9623");
|
||||
oTabs->AddChildren(oTab);
|
||||
oPPr->AddChildren(oTabs);
|
||||
|
||||
CElement *oInd = new CElement(L"ind", L"", L"w");
|
||||
oInd->AddArgument(L"left", L"0");
|
||||
oPPr->AddChildren(oInd);
|
||||
|
||||
CElement *oRPr = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oNoProof = new CElement(L"noProof", L"", L"w");
|
||||
oRPr->AddChildren(oNoProof);
|
||||
oPPr->AddChildren(oRPr);
|
||||
oParagraph->AddChildren(oPPr);
|
||||
|
||||
CElement *oRun1 = new CElement(L"r", L"", L"w");
|
||||
CElement *oFldChar = new CElement(L"fldChar", L"", L"w");
|
||||
oFldChar->AddArgument(L"fldCharType", L"begin");
|
||||
oRun1->AddChildren(oFldChar);
|
||||
oParagraph->AddChildren(oRun1);
|
||||
|
||||
CElement *oRun2 = new CElement(L"r", L"", L"w");
|
||||
CElement *oInstrText = new CElement(L"instrText", L" TOC \\o \"1-3\" \\h \\z \\u ", L"w", false);
|
||||
oInstrText->AddArgument(L"xml:space", L"preserve");
|
||||
oRun2->AddChildren(oInstrText);
|
||||
oParagraph->AddChildren(oRun2);
|
||||
|
||||
CElement *oRun3 = new CElement(L"r", L"", L"w");
|
||||
CElement *oFldChar2 = new CElement(L"fldChar", L"", L"w");
|
||||
oFldChar2->AddArgument(L"fldCharType", L"separate");
|
||||
oRun3->AddChildren(oFldChar2);
|
||||
oParagraph->AddChildren(oRun3);
|
||||
|
||||
CHyperlink *oHyperlink = new CHyperlink;
|
||||
oHyperlink->CreateTocHyperlink(pTextAndRef.first);
|
||||
oParagraph->AddChildren(oHyperlink);
|
||||
|
||||
m_oSdtContent->AddChildren(oParagraph);
|
||||
|
||||
CParagraph *oTextParagraph = new CParagraph(pTextAndRef.first, true);
|
||||
oTextParagraph->AddHyperlinkToc(oHyperlink->GetId());
|
||||
oTextParagraph->SetInCenter();
|
||||
oWhereToAdd->AddParagraph(oTextParagraph);
|
||||
|
||||
// CParagraph *oFileLink = new CParagraph();
|
||||
// oFileLink->AddLinkToFile(oDocRel, std::wstring(NSFile::GetProcessDirectory()+ L"\\tmp\\" + pTextAndRef.second));
|
||||
// oWhereToAdd->AddParagraph(oFileLink);
|
||||
}
|
||||
27
EpubFile/src/Docx/sdt/CSdt.h
Normal file
27
EpubFile/src/Docx/sdt/CSdt.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef CSDT_H
|
||||
#define CSDT_H
|
||||
|
||||
#include "../CElement.h"
|
||||
#include "../document/CDocumentXml.h"
|
||||
#include "../../CBookToc.h"
|
||||
#include "../docRels/CDocRelationshipsXml.h"
|
||||
#include "CSdtPr.h"
|
||||
#include "CSdtEndPr.h"
|
||||
#include "CSdtContent.h"
|
||||
|
||||
class CSdt : public CElement
|
||||
{
|
||||
CSdtPr *m_oSdtPr;
|
||||
CSdtEndPr *m_oSdtEndPr;
|
||||
CSdtContent *m_oSdtContent;
|
||||
|
||||
int nCountHyperlinks;
|
||||
public:
|
||||
CSdt();
|
||||
|
||||
void SetDefoult() override;
|
||||
void AddHeader(std::pair<std::wstring, std::wstring> pTextAndRef, CDocumentXml *oWhereToAdd, CDocRelationshipsXml *oDocRel);
|
||||
|
||||
};
|
||||
|
||||
#endif // CSDT_H
|
||||
35
EpubFile/src/Docx/sdt/CSdtContent.cpp
Normal file
35
EpubFile/src/Docx/sdt/CSdtContent.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "CSdtContent.h"
|
||||
|
||||
CSdtContent::CSdtContent()
|
||||
: CElement(L"sdtContent", L"", L"w")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSdtContent::SetDefoult()
|
||||
{
|
||||
CElement *oParagraph = new CElement(L"p", L"", L"w");
|
||||
oParagraph->AddArgument(L"rsidR", L"005D3816");
|
||||
oParagraph->AddArgument(L"rsidRDefault", L"005D3816");
|
||||
|
||||
CElement *oPPr = new CElement(L"pPr", L"", L"w");
|
||||
CElement *oPStyle = new CElement(L"pStyle", L"", L"w");
|
||||
oPStyle->AddArgument(L"val", L"a3");
|
||||
|
||||
CElement *oJc = new CElement(L"jc", L"", L"w");
|
||||
oJc->AddArgument(L"val", L"center");
|
||||
|
||||
oPPr->AddChildren(oJc);
|
||||
oPPr->AddChildren(oPStyle);
|
||||
|
||||
oParagraph->AddChildren(oPPr);
|
||||
|
||||
CElement *oRun = new CElement(L"r", L"", L"w");
|
||||
CElement *oText = new CElement(L"t", L"Table of content", L"w");
|
||||
|
||||
oRun->AddChildren(oText);
|
||||
|
||||
oParagraph->AddChildren(oRun);
|
||||
|
||||
AddChildren(oParagraph);
|
||||
}
|
||||
14
EpubFile/src/Docx/sdt/CSdtContent.h
Normal file
14
EpubFile/src/Docx/sdt/CSdtContent.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef CSDTCONTENT_H
|
||||
#define CSDTCONTENT_H
|
||||
|
||||
#include "../CElement.h"
|
||||
|
||||
class CSdtContent : public CElement
|
||||
{
|
||||
public:
|
||||
CSdtContent();
|
||||
|
||||
void SetDefoult() override;
|
||||
};
|
||||
|
||||
#endif // CSDTCONTENT_H
|
||||
37
EpubFile/src/Docx/sdt/CSdtEndPr.cpp
Normal file
37
EpubFile/src/Docx/sdt/CSdtEndPr.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "CSdtEndPr.h"
|
||||
|
||||
CSdtEndPr::CSdtEndPr()
|
||||
: CElement(L"sdtEndPr", L"", L"w")
|
||||
{
|
||||
}
|
||||
|
||||
void CSdtEndPr::SetDefoult()
|
||||
{
|
||||
CElement *oRPr = new CElement(L"rPr", L"", L"w");
|
||||
CElement *oRFonts = new CElement(L"rFonts", L"", L"w");
|
||||
oRFonts->AddArgument(L"asciiTheme", L"minorHAnsi");
|
||||
oRFonts->AddArgument(L"eastAsiaTheme", L"minorEastAsia");
|
||||
oRFonts->AddArgument(L"hAnsiTheme", L"minorHAnsi");
|
||||
oRFonts->AddArgument(L"cstheme", L"minorBidi");
|
||||
oRPr->AddChildren(oRFonts);
|
||||
|
||||
CElement *oB = new CElement(L"b", L"", L"w");
|
||||
oRPr->AddChildren(oB);
|
||||
|
||||
CElement *oBCs = new CElement(L"bCs", L"", L"w");
|
||||
oRPr->AddChildren(oBCs);
|
||||
|
||||
CElement *oColor = new CElement(L"color", L"", L"w");
|
||||
oColor->AddArgument(L"val", L"auto");
|
||||
oRPr->AddChildren(oColor);
|
||||
|
||||
CElement *oSz = new CElement(L"sz", L"", L"w");
|
||||
oSz->AddArgument(L"val", L"22");
|
||||
oRPr->AddChildren(oSz);
|
||||
|
||||
CElement *oSzCs = new CElement(L"szCs", L"", L"w");
|
||||
oSzCs->AddArgument(L"val", L"22");
|
||||
oRPr->AddChildren(oSzCs);
|
||||
|
||||
AddChildren(oRPr);
|
||||
}
|
||||
14
EpubFile/src/Docx/sdt/CSdtEndPr.h
Normal file
14
EpubFile/src/Docx/sdt/CSdtEndPr.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef CSDTENDPR_H
|
||||
#define CSDTENDPR_H
|
||||
|
||||
#include "../CElement.h"
|
||||
|
||||
class CSdtEndPr : public CElement
|
||||
{
|
||||
public:
|
||||
CSdtEndPr();
|
||||
|
||||
void SetDefoult() override;
|
||||
};
|
||||
|
||||
#endif // CSDTENDPR_H
|
||||
23
EpubFile/src/Docx/sdt/CSdtPr.cpp
Normal file
23
EpubFile/src/Docx/sdt/CSdtPr.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "CSdtPr.h"
|
||||
|
||||
CSdtPr::CSdtPr()
|
||||
: CElement(L"stdPr", L"", L"w")
|
||||
{
|
||||
}
|
||||
|
||||
void CSdtPr::SetDefoult()
|
||||
{
|
||||
CElement *oId = new CElement(L"id", L"", L"w");
|
||||
oId->AddArgument(L"val", L"1");
|
||||
AddChildren(oId);
|
||||
|
||||
CElement *oDocPartObj = new CElement(L"docPartObj", L"", L"w");
|
||||
CElement *oDocPartGallery = new CElement(L"docPartGallery", L"", L"w");
|
||||
oDocPartGallery->AddArgument(L"val", L"Table of Contents");
|
||||
oDocPartObj->AddChildren(oDocPartGallery);
|
||||
|
||||
CElement *oDocPartUnique = new CElement(L"docPartUnique", L"", L"w");
|
||||
oDocPartObj->AddChildren(oDocPartUnique);
|
||||
|
||||
AddChildren(oDocPartObj);
|
||||
}
|
||||
14
EpubFile/src/Docx/sdt/CSdtPr.h
Normal file
14
EpubFile/src/Docx/sdt/CSdtPr.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef CSDTPR_H
|
||||
#define CSDTPR_H
|
||||
|
||||
#include "../CElement.h"
|
||||
|
||||
class CSdtPr : public CElement
|
||||
{
|
||||
public:
|
||||
CSdtPr();
|
||||
|
||||
void SetDefoult() override;
|
||||
};
|
||||
|
||||
#endif // CSDTPR_H
|
||||
Reference in New Issue
Block a user