Commit 92e97d24 authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander Trofimov

(2.0.0.162): ASCOfficeDocxFile2

Открытие/сохранение, copy/paste в структуры с run.
Убран CommitFirstRun, потому что он был нужен в первых версиях, когда table был внутри paragraph.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@55007 954022d7-b5bf-4e40-9824-e11837661b57
parent d1e6fe61
...@@ -2143,3 +2143,43 @@ public: CFramePr() ...@@ -2143,3 +2143,43 @@ public: CFramePr()
oStringWriter.WriteString(CString(_T("/>"))); oStringWriter.WriteString(CString(_T("/>")));
} }
}; };
class CHyperlink{
public:
CString rId;
CString sLink;
CString sAnchor;
CString sTooltip;
bool History;
CString sDocLocation;
CString sTgtFrame;
CStringWriter writer;
bool bHistory;
public:
CHyperlink()
{
bHistory = false;
}
void Write(CStringWriter& wr)
{
if(false == rId.IsEmpty())
{
CString sCorrect_rId = rId;
CString sCorrect_tooltip = sTooltip;
CString sCorrect_anchor = sAnchor;
CorrectString(sCorrect_rId);
CorrectString(sCorrect_tooltip);
CorrectString(sCorrect_anchor);
CString sStart;
sStart.Format(_T("<w:hyperlink r:id=\"%s\""), sCorrect_rId);
if(false == sTooltip.IsEmpty())
sStart.AppendFormat(_T(" w:tooltip=\"%s\""), sCorrect_tooltip);
if(false == sAnchor.IsEmpty())
sStart.AppendFormat(_T(" w:anchor=\"%s\""), sCorrect_anchor);
sStart.Append(_T(" w:history=\"1\">"));
wr.WriteString(sStart);
wr.Write(writer);
wr.WriteString(CString(_T("</w:hyperlink>")));
}
}
};
\ No newline at end of file
...@@ -2606,11 +2606,10 @@ class Binary_DocumentTableReader : public Binary_CommonReader<Binary_DocumentTab ...@@ -2606,11 +2606,10 @@ class Binary_DocumentTableReader : public Binary_CommonReader<Binary_DocumentTab
Binary_pPrReader oBinary_pPrReader; Binary_pPrReader oBinary_pPrReader;
Binary_rPrReader oBinary_rPrReader; Binary_rPrReader oBinary_rPrReader;
Binary_tblPrReader oBinary_tblPrReader; Binary_tblPrReader oBinary_tblPrReader;
WriteHyperlink* m_pCurHyperlink;// , (todo .) CHyperlink* m_pCurHyperlink;
rPr m_oCur_rPr; rPr m_oCur_rPr;
rPr m_oMath_rPr; rPr m_oMath_rPr;
CStringWriter m_oCur_pPr; CStringWriter m_oCur_pPr;
bool bFirstRun;
BYTE m_byteLastElemType; BYTE m_byteLastElemType;
CComments* m_pComments; CComments* m_pComments;
public: public:
...@@ -2624,7 +2623,6 @@ public: ...@@ -2624,7 +2623,6 @@ public:
} }
~Binary_DocumentTableReader() ~Binary_DocumentTableReader()
{ {
RELEASEOBJECT(m_pCurHyperlink);
} }
int Read() int Read()
{ {
...@@ -2644,12 +2642,9 @@ public: ...@@ -2644,12 +2642,9 @@ public:
{ {
m_byteLastElemType = c_oSerParType::Par; m_byteLastElemType = c_oSerParType::Par;
m_oCur_pPr.ClearNoAttack(); m_oCur_pPr.ClearNoAttack();
bFirstRun = true;
//m_oDocumentWriter.m_oContent.WriteString(CString(_T("<w:p>"))); m_oDocumentWriter.m_oContent.WriteString(CString(_T("<w:p>")));
res = Read1(length, &Binary_DocumentTableReader::ReadParagraph, this, NULL); res = Read1(length, &Binary_DocumentTableReader::ReadParagraph, this, NULL);
//
CommitFirstRun();
m_oDocumentWriter.m_oContent.WriteString(CString(_T("</w:p>"))); m_oDocumentWriter.m_oContent.WriteString(CString(_T("</w:p>")));
} }
else if(c_oSerParType::Table == type) else if(c_oSerParType::Table == type)
...@@ -2707,41 +2702,30 @@ public: ...@@ -2707,41 +2702,30 @@ public:
if ( c_oSerParType::pPr == type ) if ( c_oSerParType::pPr == type )
{ {
res = oBinary_pPrReader.Read(length, &m_oCur_pPr); res = oBinary_pPrReader.Read(length, &m_oCur_pPr);
if(m_oCur_pPr.GetCurSize() > 0)
{
m_oDocumentWriter.m_oContent.WriteString(CString(_T("<w:pPr>")));
m_oDocumentWriter.m_oContent.Write(m_oCur_pPr);
m_oDocumentWriter.m_oContent.WriteString(CString(_T("</w:pPr>")));
}
} }
else if ( c_oSerParType::Content == type ) else if ( c_oSerParType::Content == type )
{ {
res = Read1(length, &Binary_DocumentTableReader::ReadParagraphContent, this, NULL); res = Read1(length, &Binary_DocumentTableReader::ReadParagraphContent, this, NULL);
if(NULL != m_pCurHyperlink)
{
m_pCurHyperlink->Write(m_oDocumentWriter.m_oContent);
RELEASEOBJECT(m_pCurHyperlink);
}
} }
else else
res = c_oSerConstants::ReadUnknown; res = c_oSerConstants::ReadUnknown;
return res; return res;
}; };
void CommitFirstRun()
{
if(true == bFirstRun)
{
bFirstRun = false;
m_oDocumentWriter.m_oContent.WriteString(CString(_T("<w:p>")));
if(m_oCur_pPr.GetCurSize() > 0)
{
m_oDocumentWriter.m_oContent.WriteString(CString(_T("<w:pPr>")));
m_oDocumentWriter.m_oContent.Write(m_oCur_pPr);
m_oDocumentWriter.m_oContent.WriteString(CString(_T("</w:pPr>")));
}
}
}
int ReadParagraphContent(BYTE type, long length, void* poResult) int ReadParagraphContent(BYTE type, long length, void* poResult)
{ {
int res = c_oSerConstants::ReadOk; int res = c_oSerConstants::ReadOk;
if ( c_oSerParType::Run == type ) if ( c_oSerParType::Run == type )
{ {
m_oCur_rPr.Reset(); m_oCur_rPr.Reset();
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
res = Read1(length, &Binary_DocumentTableReader::ReadRun, this, NULL); res = Read1(length, &Binary_DocumentTableReader::ReadRun, this, NULL);
GetRunStringWriter().WriteString(CString(_T("</w:r>")));
} }
else if ( c_oSerParType::CommentStart == type ) else if ( c_oSerParType::CommentStart == type )
{ {
...@@ -2752,7 +2736,6 @@ public: ...@@ -2752,7 +2736,6 @@ public:
CComment* pComment = m_pComments->get(nId); CComment* pComment = m_pComments->get(nId);
if(NULL != pComment) if(NULL != pComment)
{ {
CommitFirstRun();
int nNewId = m_pComments->getNextId(pComment->getCount()); int nNewId = m_pComments->getNextId(pComment->getCount());
pComment->setFormatStart(nNewId); pComment->setFormatStart(nNewId);
GetRunStringWriter().WriteString(pComment->writeRef(CString(_T("")), CString(_T("w:commentRangeStart")), CString(_T("")))); GetRunStringWriter().WriteString(pComment->writeRef(CString(_T("")), CString(_T("w:commentRangeStart")), CString(_T(""))));
...@@ -2767,26 +2750,74 @@ public: ...@@ -2767,26 +2750,74 @@ public:
{ {
CComment* pComment = m_pComments->get(nId); CComment* pComment = m_pComments->get(nId);
if(NULL != pComment && pComment->bIdFormat) if(NULL != pComment && pComment->bIdFormat)
{
CommitFirstRun();
GetRunStringWriter().WriteString(pComment->writeRef(CString(_T("")), CString(_T("w:commentRangeEnd")), CString(_T("")))); GetRunStringWriter().WriteString(pComment->writeRef(CString(_T("")), CString(_T("w:commentRangeEnd")), CString(_T(""))));
} }
} }
}
else if ( c_oSerParType::OMathPara == type ) else if ( c_oSerParType::OMathPara == type )
{ {
CommitFirstRun();
m_oDocumentWriter.m_oContent.WriteString(CString(_T("<m:oMathPara>"))); m_oDocumentWriter.m_oContent.WriteString(CString(_T("<m:oMathPara>")));
res = Read1(length, &Binary_DocumentTableReader::ReadMathOMathPara, this, poResult); res = Read1(length, &Binary_DocumentTableReader::ReadMathOMathPara, this, poResult);
m_oDocumentWriter.m_oContent.WriteString(CString(_T("</m:oMathPara>"))); m_oDocumentWriter.m_oContent.WriteString(CString(_T("</m:oMathPara>")));
} }
else if ( c_oSerParType::OMath == type ) else if ( c_oSerParType::OMath == type )
{ {
CommitFirstRun();
m_oDocumentWriter.m_oContent.WriteString(CString(_T("<m:oMath>"))); m_oDocumentWriter.m_oContent.WriteString(CString(_T("<m:oMath>")));
res = Read1(length, &Binary_DocumentTableReader::ReadMathArg, this, poResult); res = Read1(length, &Binary_DocumentTableReader::ReadMathArg, this, poResult);
m_oDocumentWriter.m_oContent.WriteString(CString(_T("</m:oMath>"))); m_oDocumentWriter.m_oContent.WriteString(CString(_T("</m:oMath>")));
} }
else if ( c_oSerParType::Hyperlink == type )
{
CHyperlink oHyperlink;
res = Read1(length, &Binary_DocumentTableReader::ReadHyperlink, this, &oHyperlink);
if(!oHyperlink.sLink.IsEmpty())
{
long rId;
BSTR bstrHref = oHyperlink.sLink.AllocSysString();
m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"), bstrHref, _T("External"), &rId);
SysFreeString(bstrHref);
CString srId;srId.Format(_T("rId%d"), rId);
oHyperlink.rId = srId;
oHyperlink.Write(GetRunStringWriter());
}
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadHyperlink(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
CHyperlink* pHyperlink = static_cast<CHyperlink*>(poResult);
if ( c_oSer_HyperlinkType::Link == type )
pHyperlink->sLink = m_oBufferedStream.ReadString2(length);
else if ( c_oSer_HyperlinkType::Anchor == type )
pHyperlink->sAnchor = m_oBufferedStream.ReadString2(length);
else if ( c_oSer_HyperlinkType::Tooltip == type )
pHyperlink->sTooltip = m_oBufferedStream.ReadString2(length);
else if ( c_oSer_HyperlinkType::History == type )
{
pHyperlink->bHistory = true;
pHyperlink->History = m_oBufferedStream.ReadBool();
}
else if ( c_oSer_HyperlinkType::DocLocation == type )
pHyperlink->sDocLocation = m_oBufferedStream.ReadString2(length);
else if ( c_oSer_HyperlinkType::TgtFrame == type )
pHyperlink->sTgtFrame = m_oBufferedStream.ReadString2(length);
else if ( c_oSer_HyperlinkType::Content == type )
{
CHyperlink* pPrevHyperlink = m_pCurHyperlink;
m_pCurHyperlink = pHyperlink;
res = Read1(length, &Binary_DocumentTableReader::ReadParagraphContent, this, NULL);
long rId;
CString sHref = pHyperlink->sLink;
CorrectString(sHref);
BSTR bstrHref = sHref.AllocSysString();
m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"), bstrHref, _T("External"), &rId);
SysFreeString(bstrHref);
CString srId;srId.Format(_T("rId%d"), rId);
pHyperlink->rId = srId;
m_pCurHyperlink = pPrevHyperlink;
}
else else
res = c_oSerConstants::ReadUnknown; res = c_oSerConstants::ReadUnknown;
return res; return res;
...@@ -4941,6 +4972,8 @@ public: ...@@ -4941,6 +4972,8 @@ public:
if ( c_oSerRunType::rPr == type ) if ( c_oSerRunType::rPr == type )
{ {
res = oBinary_rPrReader.Read(length, &m_oCur_rPr); res = oBinary_rPrReader.Read(length, &m_oCur_rPr);
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
} }
else if ( c_oSerRunType::Content == type ) else if ( c_oSerRunType::Content == type )
{ {
...@@ -4955,32 +4988,18 @@ public: ...@@ -4955,32 +4988,18 @@ public:
int res = c_oSerConstants::ReadOk; int res = c_oSerConstants::ReadOk;
if (c_oSerRunType::run == type) if (c_oSerRunType::run == type)
{ {
CommitFirstRun();
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(CString(_T("<w:t xml:space=\"preserve\">"))); GetRunStringWriter().WriteString(CString(_T("<w:t xml:space=\"preserve\">")));
CString sText((wchar_t*)m_oBufferedStream.ReadPointer(length), length / 2); CString sText((wchar_t*)m_oBufferedStream.ReadPointer(length), length / 2);
CorrectString(sText); CorrectString(sText);
GetRunStringWriter().WriteString(sText); GetRunStringWriter().WriteString(sText);
GetRunStringWriter().WriteString(CString(_T("</w:t>"))); GetRunStringWriter().WriteString(CString(_T("</w:t>")));
GetRunStringWriter().WriteString(CString(_T("</w:r>")));
} }
else if (c_oSerRunType::tab == type) else if (c_oSerRunType::tab == type)
{ {
CommitFirstRun();
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(CString(_T("<w:tab/>"))); GetRunStringWriter().WriteString(CString(_T("<w:tab/>")));
GetRunStringWriter().WriteString(CString(_T("</w:r>")));
} }
else if (c_oSerRunType::pagenum == type) else if (c_oSerRunType::pagenum == type)
{ {
CommitFirstRun();
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"begin\"/></w:r><w:r>"))); GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"begin\"/></w:r><w:r>")));
if(m_oCur_rPr.IsNoEmpty()) if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter()); m_oCur_rPr.Write(&GetRunStringWriter());
...@@ -4990,29 +5009,18 @@ public: ...@@ -4990,29 +5009,18 @@ public:
GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"separate\"/></w:r><w:r>"))); GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"separate\"/></w:r><w:r>")));
if(m_oCur_rPr.IsNoEmpty()) if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter()); m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"end\"/></w:r>"))); GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"end\"/>")));
} }
else if (c_oSerRunType::pagebreak == type) else if (c_oSerRunType::pagebreak == type)
{ {
CommitFirstRun();
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(CString(_T("<w:br w:type=\"page\"/>"))); GetRunStringWriter().WriteString(CString(_T("<w:br w:type=\"page\"/>")));
GetRunStringWriter().WriteString(CString(_T("</w:r>")));
} }
else if (c_oSerRunType::linebreak == type) else if (c_oSerRunType::linebreak == type)
{ {
CommitFirstRun();
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(CString(_T("<w:br />"))); GetRunStringWriter().WriteString(CString(_T("<w:br />")));
GetRunStringWriter().WriteString(CString(_T("</w:r>")));
} }
else if(c_oSerRunType::image == type) else if(c_oSerRunType::image == type)
{ {
CommitFirstRun();
docImg odocImg(m_oFileWriter.getNextDocPr()); docImg odocImg(m_oFileWriter.getNextDocPr());
res = Read2(length, &Binary_DocumentTableReader::ReadImage, this, &odocImg); res = Read2(length, &Binary_DocumentTableReader::ReadImage, this, &odocImg);
if(odocImg.MediaId >= 0 && odocImg.MediaId < m_oMediaWriter.nImageCount) if(odocImg.MediaId >= 0 && odocImg.MediaId < m_oMediaWriter.nImageCount)
...@@ -5029,11 +5037,7 @@ public: ...@@ -5029,11 +5037,7 @@ public:
//odocImg.srId = m_oMediaWriter.m_aImageRels[odocImg.MediaId]; //odocImg.srId = m_oMediaWriter.m_aImageRels[odocImg.MediaId];
if(!odocImg.srId.IsEmpty()) if(!odocImg.srId.IsEmpty())
{ {
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
odocImg.Write(&GetRunStringWriter()); odocImg.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(CString(_T("</w:r>")));
} }
} }
} }
...@@ -5044,12 +5048,7 @@ public: ...@@ -5044,12 +5048,7 @@ public:
if(oCDrawingProperty.IsChart()) if(oCDrawingProperty.IsChart())
{ {
CommitFirstRun();
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(oCDrawingProperty.Write()); GetRunStringWriter().WriteString(oCDrawingProperty.Write());
GetRunStringWriter().WriteString(CString(_T("</w:r>")));
} }
else if(oCDrawingProperty.bDataPos && oCDrawingProperty.bDataLength) else if(oCDrawingProperty.bDataPos && oCDrawingProperty.bDataLength)
{ {
...@@ -5074,12 +5073,7 @@ public: ...@@ -5074,12 +5073,7 @@ public:
if(false == sDrawingXml.IsEmpty()) if(false == sDrawingXml.IsEmpty())
{ {
CommitFirstRun();
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(sDrawingXml); GetRunStringWriter().WriteString(sDrawingXml);
GetRunStringWriter().WriteString(CString(_T("</w:r>")));
SysFreeString(bstrDrawingXml); SysFreeString(bstrDrawingXml);
} }
} }
...@@ -5089,48 +5083,25 @@ public: ...@@ -5089,48 +5083,25 @@ public:
{ {
// Shd // Shd
oBinary_tblPrReader.m_sCurTableShd.Empty(); oBinary_tblPrReader.m_sCurTableShd.Empty();
if(false == bFirstRun) //todo
{
if(NULL != m_pCurHyperlink)
{
m_pCurHyperlink->Write(m_oDocumentWriter.m_oContent);
RELEASEOBJECT(m_pCurHyperlink);
}
m_oDocumentWriter.m_oContent.WriteString(CString(_T("</w:p>"))); m_oDocumentWriter.m_oContent.WriteString(CString(_T("</w:p>")));
}
m_oDocumentWriter.m_oContent.WriteString(CString(_T("<w:tbl>"))); m_oDocumentWriter.m_oContent.WriteString(CString(_T("<w:tbl>")));
res = Read1(length, &Binary_DocumentTableReader::ReadDocTable, this, &m_oDocumentWriter.m_oContent); res = Read1(length, &Binary_DocumentTableReader::ReadDocTable, this, &m_oDocumentWriter.m_oContent);
m_oDocumentWriter.m_oContent.WriteString(CString(_T("</w:tbl>"))); m_oDocumentWriter.m_oContent.WriteString(CString(_T("</w:tbl>")));
bFirstRun = true; m_oDocumentWriter.m_oContent.WriteString(CString(_T("<w:p>")));
if(m_oCur_pPr.GetCurSize() > 0)
{
m_oDocumentWriter.m_oContent.WriteString(CString(_T("<w:pPr>")));
m_oDocumentWriter.m_oContent.Write(m_oCur_pPr);
m_oDocumentWriter.m_oContent.WriteString(CString(_T("</w:pPr>")));
}
// Shd // Shd
oBinary_tblPrReader.m_sCurTableShd.Empty(); oBinary_tblPrReader.m_sCurTableShd.Empty();
} }
else if(c_oSerRunType::fldstart == type) else if(c_oSerRunType::fldstart == type)
{ {
CommitFirstRun();
CString sField((wchar_t*)m_oBufferedStream.ReadPointer(length), length / 2); CString sField((wchar_t*)m_oBufferedStream.ReadPointer(length), length / 2);
if(-1 != sField.Find(_T("HYPERLINK")))
{
RELEASEOBJECT(m_pCurHyperlink);
m_pCurHyperlink = WriteHyperlink::Parse(sField);
if(NULL != m_pCurHyperlink)
{
long rId;
CString sHref = m_pCurHyperlink->href;
CorrectString(sHref);
BSTR bstrHref = sHref.AllocSysString();
m_oFileWriter.m_pDrawingConverter->WriteRels(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"), bstrHref, _T("External"), &rId);
SysFreeString(bstrHref);
CString srId;srId.Format(_T("rId%d"), rId);
m_pCurHyperlink->rId = srId;
}
}
else
{
CorrectString(sField); CorrectString(sField);
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"begin\"/></w:r><w:r>"))); GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"begin\"/></w:r><w:r>")));
if(m_oCur_rPr.IsNoEmpty()) if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter()); m_oCur_rPr.Write(&GetRunStringWriter());
...@@ -5139,24 +5110,11 @@ public: ...@@ -5139,24 +5110,11 @@ public:
GetRunStringWriter().WriteString(CString(_T("</w:instrText></w:r><w:r>"))); GetRunStringWriter().WriteString(CString(_T("</w:instrText></w:r><w:r>")));
if(m_oCur_rPr.IsNoEmpty()) if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter()); m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"separate\"/></w:r>"))); GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"separate\"/>")));
}
} }
else if(c_oSerRunType::fldend == type) else if(c_oSerRunType::fldend == type)
{ {
CommitFirstRun(); GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"end\"/>")));
if(NULL != m_pCurHyperlink)
{
m_pCurHyperlink->Write(m_oDocumentWriter.m_oContent);
RELEASEOBJECT(m_pCurHyperlink);
}
else
{
GetRunStringWriter().WriteString(CString(_T("<w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"end\"/></w:r>")));
}
} }
else if ( c_oSerRunType::CommentReference == type ) else if ( c_oSerRunType::CommentReference == type )
{ {
...@@ -5167,8 +5125,7 @@ public: ...@@ -5167,8 +5125,7 @@ public:
CComment* pComment = m_pComments->get(nId); CComment* pComment = m_pComments->get(nId);
if(NULL != pComment && pComment->bIdFormat) if(NULL != pComment && pComment->bIdFormat)
{ {
CommitFirstRun(); GetRunStringWriter().WriteString(pComment->writeRef(CString(_T("")), CString(_T("w:commentReference")), CString(_T(""))));
GetRunStringWriter().WriteString(pComment->writeRef(CString(_T("<w:r>")), CString(_T("w:commentReference")), CString(_T("</w:r>"))));
} }
} }
} }
......
...@@ -376,7 +376,8 @@ const int g_nFormatVersion = 4; ...@@ -376,7 +376,8 @@ const int g_nFormatVersion = 4;
CommentStart = 6, CommentStart = 6,
CommentEnd = 7, CommentEnd = 7,
OMathPara = 8, OMathPara = 8,
OMath = 9 OMath = 9,
Hyperlink = 10
};} };}
namespace c_oSerDocTableType{enum c_oSerDocTableType namespace c_oSerDocTableType{enum c_oSerDocTableType
{ {
...@@ -763,4 +764,14 @@ const int g_nFormatVersion = 4; ...@@ -763,4 +764,14 @@ const int g_nFormatVersion = 4;
Y = 12, Y = 12,
YAlign = 13 YAlign = 13
};} };}
namespace c_oSer_HyperlinkType{ enum c_oSer_HyperlinkType
{
Content = 0,
Link = 1,
Anchor = 2,
Tooltip = 3,
History = 4,
DocLocation = 5,
TgtFrame = 6
};}
} }
...@@ -2385,21 +2385,6 @@ namespace BinDocxRW ...@@ -2385,21 +2385,6 @@ namespace BinDocxRW
void WriteParagraphContent(const CSimpleArray<OOX::WritingElement *>& Content, OOX::Logic::CRunProperty** pPr_rPr, bool bHyperlink = false) void WriteParagraphContent(const CSimpleArray<OOX::WritingElement *>& Content, OOX::Logic::CRunProperty** pPr_rPr, bool bHyperlink = false)
{ {
int nCurPos = 0; int nCurPos = 0;
// hyperlink
for(int i = 0, length = m_aFldChars.GetSize(); i < length; ++i)
{
FldStruct* pFldStruct= m_aFldChars[i];
if(fieldstruct_hyperlink == pFldStruct->GetType())
{
int nCurPos = m_oBcw.WriteItemStart(c_oSerParType::Run);
int nCurPos2 = m_oBcw.WriteItemStart(c_oSerRunType::Content);
m_oBcw.m_oStream.WriteByte(c_oSerRunType::fldstart);
m_oBcw.m_oStream.WriteString2(pFldStruct->m_sFld);
m_oBcw.WriteItemEnd(nCurPos2);
m_oBcw.WriteItemEnd(nCurPos);
break;
}
}
for ( int i = 0, length = Content.GetSize(); i < length; ++i ) for ( int i = 0, length = Content.GetSize(); i < length; ++i )
{ {
OOX::WritingElement* item = Content[i]; OOX::WritingElement* item = Content[i];
...@@ -2510,21 +2495,6 @@ namespace BinDocxRW ...@@ -2510,21 +2495,6 @@ namespace BinDocxRW
}*/ }*/
} }
} }
// hyperlink
for(int i = 0, length = m_aFldChars.GetSize(); i < length; ++i)
{
FldStruct* pFldStruct= m_aFldChars[i];
if(fieldstruct_hyperlink == pFldStruct->GetType())
{
int nCurPos = m_oBcw.WriteItemStart(c_oSerParType::Run);
int nCurPos2 = m_oBcw.WriteItemStart(c_oSerRunType::Content);
m_oBcw.m_oStream.WriteByte(c_oSerRunType::fldend);
m_oBcw.m_oStream.WriteLong(c_oSerPropLenType::Null);
m_oBcw.WriteItemEnd(nCurPos2);
m_oBcw.WriteItemEnd(nCurPos);
break;
}
}
}; };
void WriteComment(OOX::EElementType eType, nullable<SimpleTypes::CDecimalNumber<>>& oId) void WriteComment(OOX::EElementType eType, nullable<SimpleTypes::CDecimalNumber<>>& oId)
{ {
...@@ -2550,7 +2520,6 @@ namespace BinDocxRW ...@@ -2550,7 +2520,6 @@ namespace BinDocxRW
int nCurPos = 0; int nCurPos = 0;
CString sField; CString sField;
CString sLink; CString sLink;
CString sTooltip;
if(pHyperlink->m_oId.IsInit()) if(pHyperlink->m_oId.IsInit())
{ {
OOX::Rels::CRelationShip* oRels = NULL; OOX::Rels::CRelationShip* oRels = NULL;
...@@ -2561,42 +2530,14 @@ namespace BinDocxRW ...@@ -2561,42 +2530,14 @@ namespace BinDocxRW
{ {
OOX::HyperLink* pHyperlinkFile = static_cast<OOX::HyperLink*>(pFile.operator ->()); OOX::HyperLink* pHyperlinkFile = static_cast<OOX::HyperLink*>(pFile.operator ->());
sLink = pHyperlinkFile->Uri().GetPath(); sLink = pHyperlinkFile->Uri().GetPath();
if(pHyperlink->m_sAnchor.IsInit())
{
sLink += _T("#") + pHyperlink->m_sAnchor.get();
} }
} }
} }
if(pHyperlink->m_sTooltip.IsInit())
sTooltip = pHyperlink->m_sTooltip.get();
}
if(!sLink.IsEmpty()) if(!sLink.IsEmpty())
{ {
sLink.Replace(_T("\""), _T("\\\"")); nCurPos = m_oBcw.WriteItemStart(c_oSerParType::Hyperlink);
sTooltip.Replace(_T("\""), _T("\\\"")); WriteHyperlinkContent(sLink, pHyperlink);
if(sTooltip.IsEmpty())
sField.Format(_T("HYPERLINK \"%s\""), sLink);
else
sField.Format(_T("HYPERLINK \"%s\" \\o \"%s\""), sLink, sTooltip);
int nCurPos2 = 0;
int nCurPos3 = 0;
nCurPos = m_oBcw.WriteItemStart(c_oSerParType::Run);
nCurPos2 = m_oBcw.WriteItemStart(c_oSerRunType::Content);
m_oBcw.m_oStream.WriteByte(c_oSerRunType::fldstart);
m_oBcw.m_oStream.WriteString2(sField);
m_oBcw.WriteItemWithLengthEnd(nCurPos2);
m_oBcw.WriteItemWithLengthEnd(nCurPos);
WriteParagraphContent(pHyperlink->m_arrItems, NULL, true);
nCurPos = m_oBcw.WriteItemStart(c_oSerParType::Run);
nCurPos2 = m_oBcw.WriteItemStart(c_oSerRunType::Content);
m_oBcw.m_oStream.WriteByte(c_oSerRunType::fldend);
m_oBcw.m_oStream.WriteLong(c_oSerPropLenType::Null);
m_oBcw.WriteItemWithLengthEnd(nCurPos2);
m_oBcw.WriteItemWithLengthEnd(nCurPos); m_oBcw.WriteItemWithLengthEnd(nCurPos);
} }
else else
...@@ -2604,6 +2545,53 @@ namespace BinDocxRW ...@@ -2604,6 +2545,53 @@ namespace BinDocxRW
WriteParagraphContent(pHyperlink->m_arrItems, NULL, true); WriteParagraphContent(pHyperlink->m_arrItems, NULL, true);
} }
} }
void WriteHyperlinkContent(CString& sLink, OOX::Logic::CHyperlink* pHyperlink)
{
int nCurPos = 0;
//Link
nCurPos = m_oBcw.WriteItemStart(c_oSer_HyperlinkType::Link);
m_oBcw.m_oStream.WriteString3(sLink);
m_oBcw.WriteItemWithLengthEnd(nCurPos);
//Anchor
if(pHyperlink->m_sAnchor.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_HyperlinkType::Anchor);
m_oBcw.m_oStream.WriteString3(pHyperlink->m_sAnchor.get2());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
//Tooltip
if(pHyperlink->m_sTooltip.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_HyperlinkType::Tooltip);
m_oBcw.m_oStream.WriteString3(pHyperlink->m_sTooltip.get2());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
//History
if(pHyperlink->m_oHistory.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_HyperlinkType::History);
m_oBcw.m_oStream.WriteBool(pHyperlink->m_oHistory->ToBool());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
//DocLocation
if(pHyperlink->m_sDocLocation.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_HyperlinkType::DocLocation);
m_oBcw.m_oStream.WriteString3(pHyperlink->m_sDocLocation.get2());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
//TgtFrame
if(pHyperlink->m_sTgtFrame.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_HyperlinkType::TgtFrame);
m_oBcw.m_oStream.WriteString3(pHyperlink->m_sTgtFrame.get2());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
//Content
nCurPos = m_oBcw.WriteItemStart(c_oSer_HyperlinkType::Content);
WriteParagraphContent(pHyperlink->m_arrItems, NULL, true);
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
OOX::Logic::CRunProperty* getRunStyle(CSimpleArray<OOX::WritingElement*>& m_arrItems) OOX::Logic::CRunProperty* getRunStyle(CSimpleArray<OOX::WritingElement*>& m_arrItems)
{ {
OOX::Logic::CRunProperty* oCur_rPr = NULL; OOX::Logic::CRunProperty* oCur_rPr = NULL;
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
//2 //2
//0 //0
//0 //0
//161 //162
#define INTVER 2,0,0,161 #define INTVER 2,0,0,162
#define STRVER "2,0,0,161\0" #define STRVER "2,0,0,162\0"
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