Commit 147a8216 authored by ElenaSubbotina's avatar ElenaSubbotina

RtfFormatReader - review, fix fields

parent 0d94d873
...@@ -687,6 +687,10 @@ ...@@ -687,6 +687,10 @@
RelativePath="..\source\RtfDocument.h" RelativePath="..\source\RtfDocument.h"
> >
</File> </File>
<File
RelativePath="..\source\RtfField.cpp"
>
</File>
<File <File
RelativePath="..\source\RtfField.h" RelativePath="..\source\RtfField.h"
> >
......
...@@ -125,9 +125,10 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP ...@@ -125,9 +125,10 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
OOX::Logic::CFldSimple * pFldSimple = dynamic_cast<OOX::Logic::CFldSimple*>(m_ooxElement->m_arrItems[i]); OOX::Logic::CFldSimple * pFldSimple = dynamic_cast<OOX::Logic::CFldSimple*>(m_ooxElement->m_arrItems[i]);
RtfFieldPtr oCurField( new RtfField() ); RtfFieldPtr oCurField( new RtfField() );
oCurField->m_oInsert = TextItemContainerPtr( new TextItemContainer() );
oCurField->m_oResult = TextItemContainerPtr( new TextItemContainer() ); oCurField->m_pInsert = RtfFieldInstPtr ( new RtfFieldInst() );
//добавляем insert oCurField->m_pResult = RtfFieldInstPtr ( new RtfFieldInst() );
//добавляем insert
RtfCharPtr oNewChar( new RtfChar() ); RtfCharPtr oNewChar( new RtfChar() );
oNewChar->m_bRtfEncode = false; oNewChar->m_bRtfEncode = false;
if (pFldSimple->m_sInstr.IsInit()) if (pFldSimple->m_sInstr.IsInit())
...@@ -136,7 +137,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP ...@@ -136,7 +137,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
} }
RtfParagraphPtr oNewInsertParagraph( new RtfParagraph() ); RtfParagraphPtr oNewInsertParagraph( new RtfParagraph() );
oNewInsertParagraph->AddItem( oNewChar ); oNewInsertParagraph->AddItem( oNewChar );
oCurField->m_oInsert->AddItem( oNewInsertParagraph ); oCurField->m_pInsert->m_pTextItems->AddItem( oNewInsertParagraph );
//добаляем свойства //добаляем свойства
if( TRUE == pFldSimple->m_oFldLock.ToBool() ) if( TRUE == pFldSimple->m_oFldLock.ToBool() )
...@@ -156,7 +157,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP ...@@ -156,7 +157,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
{ {
OOXParagraphReader oSubParReader(pFldSimple); OOXParagraphReader oSubParReader(pFldSimple);
oSubParReader.Parse2( oParam, *oNewResultParagraph, CcnfStyle(), poExternalStyle); oSubParReader.Parse2( oParam, *oNewResultParagraph, CcnfStyle(), poExternalStyle);
oCurField->m_oResult->AddItem( oNewResultParagraph ); oCurField->m_pResult->m_pTextItems->AddItem( oNewResultParagraph );
} }
oOutputParagraph.AddItem( oCurField ); oOutputParagraph.AddItem( oCurField );
}break; }break;
...@@ -193,17 +194,19 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP ...@@ -193,17 +194,19 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
} }
} }
RtfFieldPtr oCurField( new RtfField() ); RtfFieldPtr oCurField( new RtfField() );
oCurField->m_oInsert = TextItemContainerPtr( new TextItemContainer() );
oCurField->m_oResult = TextItemContainerPtr( new TextItemContainer() ); oCurField->m_pInsert = RtfFieldInstPtr ( new RtfFieldInst() );
//добавляем insert oCurField->m_pResult = RtfFieldInstPtr ( new RtfFieldInst() );
//добавляем insert
RtfCharPtr oNewChar( new RtfChar() ); RtfCharPtr oNewChar( new RtfChar() );
oNewChar->m_bRtfEncode = true;// false; oNewChar->m_bRtfEncode = true;// false;
CString sFieldText; CString sFieldText;
sFieldText += L"HYPERLINK \"" + sTarget + L"\""; sFieldText += L"HYPERLINK \"" + sTarget + L"\"";
oNewChar->setText( sFieldText ); oNewChar->setText( sFieldText );
RtfParagraphPtr oNewInsertParagraph( new RtfParagraph() ); RtfParagraphPtr oNewInsertParagraph( new RtfParagraph() );
oNewInsertParagraph->AddItem( oNewChar ); oNewInsertParagraph->AddItem( oNewChar );
oCurField->m_oInsert->AddItem( oNewInsertParagraph ); oCurField->m_pInsert->m_pTextItems->AddItem( oNewInsertParagraph );
//добавляем свойства //добавляем свойства
//pHyperlink->m_arrItems todoooo //pHyperlink->m_arrItems todoooo
...@@ -225,7 +228,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP ...@@ -225,7 +228,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
{ {
OOXParagraphReader oSubParReader(pHyperlink); OOXParagraphReader oSubParReader(pHyperlink);
oSubParReader.Parse2( oParam, *oNewResultParagraph, CcnfStyle(), poExternalStyle); oSubParReader.Parse2( oParam, *oNewResultParagraph, CcnfStyle(), poExternalStyle);
oCurField->m_oResult->AddItem( oNewResultParagraph ); oCurField->m_pResult->m_pTextItems->AddItem( oNewResultParagraph );
} }
oOutputParagraph.AddItem( oCurField ); oOutputParagraph.AddItem( oCurField );
} }
...@@ -233,8 +236,9 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP ...@@ -233,8 +236,9 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
if( pHyperlink->m_sAnchor.IsInit() ) if( pHyperlink->m_sAnchor.IsInit() )
{ {
RtfFieldPtr oCurField( new RtfField() ); RtfFieldPtr oCurField( new RtfField() );
oCurField->m_oInsert = TextItemContainerPtr( new TextItemContainer() );
oCurField->m_oResult = TextItemContainerPtr( new TextItemContainer() ); oCurField->m_pInsert = RtfFieldInstPtr ( new RtfFieldInst() );
oCurField->m_pResult = RtfFieldInstPtr ( new RtfFieldInst() );
//добавляем insert //добавляем insert
RtfCharPtr oNewCharHYPER( new RtfChar() ); RtfCharPtr oNewCharHYPER( new RtfChar() );
oNewCharHYPER->m_bRtfEncode = false; oNewCharHYPER->m_bRtfEncode = false;
...@@ -243,7 +247,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP ...@@ -243,7 +247,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
RtfParagraphPtr oNewInsertParagraph( new RtfParagraph() ); RtfParagraphPtr oNewInsertParagraph( new RtfParagraph() );
oNewInsertParagraph->AddItem( oNewCharHYPER ); oNewInsertParagraph->AddItem( oNewCharHYPER );
oCurField->m_oInsert->AddItem( oNewInsertParagraph ); oCurField->m_pInsert->m_pTextItems->AddItem( oNewInsertParagraph );
////добаляем свойства ////добаляем свойства
//BOOL bLock = Strings::ToBoolean(oXmlReader.ReadNodeAttribute(i, L"w:fldLock" ,L"false")); //BOOL bLock = Strings::ToBoolean(oXmlReader.ReadNodeAttribute(i, L"w:fldLock" ,L"false"));
//if( TRUE == bLock ) //if( TRUE == bLock )
...@@ -263,7 +267,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP ...@@ -263,7 +267,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
{ {
OOXParagraphReader oSubParReader(pHyperlink); OOXParagraphReader oSubParReader(pHyperlink);
oSubParReader.Parse2( oParam, *oNewResultParagraph, CcnfStyle(), poExternalStyle); oSubParReader.Parse2( oParam, *oNewResultParagraph, CcnfStyle(), poExternalStyle);
oCurField->m_oResult->AddItem( oNewResultParagraph ); oCurField->m_pResult->m_pTextItems->AddItem( oNewResultParagraph );
} }
oOutputParagraph.AddItem( oCurField ); oOutputParagraph.AddItem( oCurField );
} }
...@@ -761,9 +765,11 @@ bool OOXRunReader::Parse( ReaderParameter oParam , RtfParagraph& oOutputParagrap ...@@ -761,9 +765,11 @@ bool OOXRunReader::Parse( ReaderParameter oParam , RtfParagraph& oOutputParagrap
oCurFont.m_sName = sFont; oCurFont.m_sName = sFont;
oParam.oRtf->m_oFontTable.DirectAddItem( oCurFont ); oParam.oRtf->m_oFontTable.DirectAddItem( oCurFont );
} }
RtfFieldPtr oNewField = RtfFieldPtr( new RtfField() ); RtfFieldPtr oNewField = RtfFieldPtr ( new RtfField() );
oNewField->m_oInsert = TextItemContainerPtr( new TextItemContainer() );
oNewField->m_oResult = TextItemContainerPtr( new TextItemContainer() ); oNewField->m_pInsert = RtfFieldInstPtr( new RtfFieldInst() );
oNewField->m_pResult = RtfFieldInstPtr( new RtfFieldInst() );
RtfCharPtr oNewChar( new RtfChar() ); RtfCharPtr oNewChar( new RtfChar() );
oNewChar->m_bRtfEncode = false; oNewChar->m_bRtfEncode = false;
CString sFieldText; CString sFieldText;
...@@ -777,9 +783,10 @@ bool OOXRunReader::Parse( ReaderParameter oParam , RtfParagraph& oOutputParagrap ...@@ -777,9 +783,10 @@ bool OOXRunReader::Parse( ReaderParameter oParam , RtfParagraph& oOutputParagrap
sFieldText.AppendFormat(L"%d", nFontSize ); sFieldText.AppendFormat(L"%d", nFontSize );
oNewChar->setText( sFieldText ); oNewChar->setText( sFieldText );
RtfParagraphPtr oNewInsertParagraph( new RtfParagraph() ); RtfParagraphPtr oNewInsertParagraph( new RtfParagraph() );
oNewInsertParagraph->AddItem( oNewChar ); oNewInsertParagraph->AddItem( oNewChar );
oNewField->m_oInsert->AddItem( oNewInsertParagraph ); oNewField->m_pInsert->m_pTextItems->AddItem( oNewInsertParagraph );
oOutputParagraph.AddItem( oNewField ); oOutputParagraph.AddItem( oNewField );
} }
......
/*
* (c) Copyright Ascensio System SIA 2010-2016
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "RtfField.h"
#include "Writer/OOXWriter.h"
#include "Writer/OOXRelsWriter.h"
CString OOXFieldBegin::RenderToRtf(RenderParameter oRenderParameter)
{
CString sResult;
sResult += L"{\\field ";
RENDER_RTF_BOOL( m_bDirty, sResult, L"flddirty" )
RENDER_RTF_BOOL( m_bLock, sResult, L"fldlock" )
sResult += L"{\\*\\fldinst";
sResult += m_oCharProperty.RenderToRtf(oRenderParameter);
return sResult;
}
CString OOXFieldBegin::RenderToOOX(RenderParameter oRenderParameter)
{
CString sResult;
sResult += L"<w:r>";
CString props = m_oCharProperty.RenderToOOX(oRenderParameter);
if (props.IsEmpty())
{
sResult += L"<w:rPr>";
sResult += props;
sResult += L"</w:rPr>";
}
sResult += L"<w:fldChar w:fldCharType=\"separate\"";
RENDER_OOX_INT_ATTRIBUTE( m_bDirty, sResult, L"dirty" )
RENDER_OOX_INT_ATTRIBUTE( m_bLock, sResult, L"fldLock" )
sResult += L"/>";
sResult += L"</w:r>";
return sResult;
}
CString OOXFieldInsertText::RenderToOOX(RenderParameter oRenderParameter)
{
if( NULL != m_oText )
{
CString sResult;
sResult += L"<w:r>";
sResult += L"<w:instrText>";
oRenderParameter.nType = RENDER_TO_RTF_PARAM_CHAR;
oRenderParameter.nValue = RENDER_TO_RTF_PARAM_NO_PAR;
sResult += m_oText->RenderToOOX( oRenderParameter );
sResult += L"</w:instrText>";
sResult += L"</w:r>";
return sResult;
}
else
return L"";
}
CString RtfFieldInst::RenderToRtf(RenderParameter oRenderParameter)
{
return L"";
}
CString RtfFieldInst::RenderToOOX(RenderParameter oRenderParameter)
{
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
OOXWriter* poOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
return L"";
}
CString RtfField::RenderToRtf(RenderParameter oRenderParameter)
{
CString sResult;
sResult += L"{\\field ";
if( fm_none != m_eMode )
{
switch( m_eMode )
{
case fm_flddirty: sResult += L"{\\flddirty "; break;
case fm_fldedit: sResult += L"{\\fldedit "; break;
case fm_fldlock: sResult += L"{\\fldlock "; break;
case fm_fldpriv: sResult += L"{\\fldpriv "; break;
}
}
sResult += L"{\\*\\fldinst ";
RenderParameter oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_RTF_PARAM_PLAIN;//RENDER_TO_RTF_PARAM_CHAR;
oNewParam.nValue = RENDER_TO_RTF_PARAM_NO_PAR;
sResult += m_pInsert->m_pTextItems->RenderToRtf( oNewParam );
if( true == m_bReferenceToEndnote )
sResult += L"\\fldalt";
if( !m_sData.IsEmpty() )
sResult += L"{\\*\\datafield " + m_sData + L"}";
sResult += L"}";
CString str = m_pResult->m_pTextItems->RenderToRtf( oRenderParameter ) ;
sResult += L"{\\fldrslt " + str + L"}";
sResult += L"}";
return sResult;
}
CString RtfField::RenderToOOX(RenderParameter oRenderParameter)
{
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
OOXWriter* poOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
CString sResult;
if( true == m_bTextOnly )
{
RenderParameter oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_OOX_PARAM_RUN;
sResult += m_pResult->m_pTextItems->RenderToOOX(oNewParam);
}
else
{
bool bInsert = false;
bool bDelete = false;
CString sAuthor, sDate;
if (m_pInsert->m_oCharProperty.m_nRevised != PROP_DEF)
{
bInsert = true;
sAuthor = m_pInsert->m_oCharProperty.m_nRevauth != PROP_DEF ? poRtfDocument->m_oRevisionTable[ m_pInsert->m_oCharProperty.m_nRevauth] : L"";
sDate = CString(RtfUtility::convertDateTime(m_pInsert->m_oCharProperty.m_nRevdttm).c_str());
sResult += L"<w:ins w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(poOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
m_pInsert->m_oCharProperty.m_nRevised = PROP_DEF;
}
if (m_pInsert->m_oCharProperty.m_nDeleted != PROP_DEF)
{
bDelete = true;
sAuthor = m_pInsert->m_oCharProperty.m_nRevauthDel != PROP_DEF ? poRtfDocument->m_oRevisionTable[ m_pInsert->m_oCharProperty.m_nRevauthDel ] : L"";
sDate = CString(RtfUtility::convertDateTime(m_pInsert->m_oCharProperty.m_nRevdttmDel).c_str());
sResult += L"<w:del w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(poOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
m_pInsert->m_oCharProperty.m_nDeleted = PROP_DEF;
}
//поверяем на наличие гиперссылки
RenderParameter oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_OOX_PARAM_PLAIN;
CString sInsertText = m_pInsert->m_pTextItems->RenderToOOX( oNewParam );
int nIndex = sInsertText.Find( L"HYPERLINK" );
if( -1 != nIndex )
{
CString sHyperlink = sInsertText;
sHyperlink.Delete( nIndex, 9/*(int)_tcslen( L"HYPERLINK" )*/ );
int nSplash = sHyperlink.Find( L"\\" );
if (nSplash > 0)
{
sHyperlink = sHyperlink.Left(nSplash);
}
//оставляем только одну ссылку
sHyperlink.Remove( '\"' );
sHyperlink.Trim();
//заменяем пробелы на %20
sHyperlink.Replace( L" ", L"%20" );
//добавляем в rels
OOXRelsWriter* poRelsWriter = static_cast<OOXRelsWriter*>( oRenderParameter.poRels );
CString sId = poRelsWriter->AddRelationship( L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", Utils::PrepareToXML( sHyperlink ), false );
//добавляем гиперссылку в документ
sResult += L"<w:hyperlink r:id=\"" + sId + L"\" >";
oNewParam.nType = RENDER_TO_OOX_PARAM_RUN;
sResult += m_pResult->RenderToOOX(oNewParam);
sResult += L"</w:hyperlink>";
}
else
{
RenderParameter oNewParametr = oRenderParameter;
oNewParametr.nType = RENDER_TO_OOX_PARAM_PLAIN;
CString props = m_pResult->m_oCharProperty.RenderToOOX(oRenderParameter);
if (!props.IsEmpty()) props = L"<w:rPr>" + props + L"</w:rPr>";
//начинаем Field
sResult += L"<w:r>";
if (!props.IsEmpty())
sResult += props;
sResult += L"<w:fldChar w:fldCharType=\"begin\"/>";
sResult += L"</w:r>";
CString str = Utils::PrepareToXML( m_pInsert->m_pTextItems->RenderToOOX(oNewParametr) );
sResult += L"<w:r>";
sResult += L"<w:instrText xml:space=\"preserve\">";
sResult += str;
sResult += L"</w:instrText></w:r>";
// разделитель
sResult += L"<w:r>";
sResult += L"<w:fldChar w:fldCharType=\"separate\"/></w:r>";
//пишем содержание-кэш
sResult += L"<w:r>";
if (!props.IsEmpty())
sResult += props;
sResult += m_pResult->m_pTextItems->RenderToOOX(oNewParametr);
sResult += L"</w:r>";
//заканчиваем Field
sResult += L"<w:r><w:fldChar w:fldCharType=\"end\"/></w:r>";
}
if (bDelete) sResult += L"</w:del>";
if (bInsert) sResult += L"</w:ins>";
}
return sResult;
}
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
*/ */
#pragma once #pragma once
#include "RtfParagraph.h" #include "RtfParagraph.h"
#include "Writer/OOXWriter.h"
#include "Writer/OOXRelsWriter.h"
class OOXFieldBegin : public IDocumentElement class OOXFieldBegin : public IDocumentElement
{ {
...@@ -56,39 +54,8 @@ public: ...@@ -56,39 +54,8 @@ public:
m_oCharProperty.SetDefault(); m_oCharProperty.SetDefault();
} }
CString RenderToRtf(RenderParameter oRenderParameter) CString RenderToRtf(RenderParameter oRenderParameter);
{ CString RenderToOOX(RenderParameter oRenderParameter);
CString sResult;
sResult += L"{\\field ";
RENDER_RTF_BOOL( m_bDirty, sResult, L"flddirty" )
RENDER_RTF_BOOL( m_bLock, sResult, L"fldlock" )
sResult += L"{\\*\\fldinst";
sResult += m_oCharProperty.RenderToRtf(oRenderParameter);
return sResult;
}
CString RenderToOOX(RenderParameter oRenderParameter)
{
CString sResult;
sResult += L"<w:r>";
CString props = m_oCharProperty.RenderToOOX(oRenderParameter);
if (props.IsEmpty())
{
sResult += L"<w:rPr>";
sResult += props;
sResult += L"</w:rPr>";
}
sResult += L"<w:fldChar w:fldCharType=\"separate\"";
RENDER_OOX_INT_ATTRIBUTE( m_bDirty, sResult, L"dirty" )
RENDER_OOX_INT_ATTRIBUTE( m_bLock, sResult, L"fldLock" )
sResult += L"/>";
sResult += L"</w:r>";
return sResult;
}
}; };
class OOXFieldInsertText : public IDocumentElement class OOXFieldInsertText : public IDocumentElement
{ {
...@@ -106,26 +73,7 @@ public: ...@@ -106,26 +73,7 @@ public:
else else
return L""; return L"";
} }
CString RenderToOOX(RenderParameter oRenderParameter) CString RenderToOOX(RenderParameter oRenderParameter);
{
if( NULL != m_oText )
{
CString sResult;
sResult += L"<w:r>";
sResult += L"<w:instrText>";
oRenderParameter.nType = RENDER_TO_RTF_PARAM_CHAR;
oRenderParameter.nValue = RENDER_TO_RTF_PARAM_NO_PAR;
sResult += m_oText->RenderToOOX( oRenderParameter );
sResult += L"</w:instrText>";
sResult += L"</w:r>";
return sResult;
}
else
return L"";
}
}; };
class OOXFieldSeparate : public IDocumentElement class OOXFieldSeparate : public IDocumentElement
...@@ -165,6 +113,32 @@ public: ...@@ -165,6 +113,32 @@ public:
}; };
class RtfFieldInst : public IDocumentElement
{
public:
void SetDefaultRtf()
{
SetDefault();
}
void SetDefaultOOX()
{
SetDefault();
}
void SetDefault()
{
m_pTextItems = TextItemContainerPtr( new TextItemContainer() );
}
CString RenderToRtf(RenderParameter oRenderParameter);
CString RenderToOOX(RenderParameter oRenderParameter);
RtfCharProperty m_oCharProperty;
TextItemContainerPtr m_pTextItems;
};
typedef boost::shared_ptr<RtfFieldInst> RtfFieldInstPtr;
class RtfField : public IDocumentElement class RtfField : public IDocumentElement
{ {
public: public:
...@@ -178,10 +152,12 @@ public: ...@@ -178,10 +152,12 @@ public:
}; };
_FieldMode m_eMode; _FieldMode m_eMode;
TextItemContainerPtr m_oInsert;
bool m_bReferenceToEndnote; bool m_bReferenceToEndnote;
CString m_sData; CString m_sData;
TextItemContainerPtr m_oResult;
RtfFieldInstPtr m_pInsert;
RtfFieldInstPtr m_pResult;
bool m_bTextOnly; bool m_bTextOnly;
RtfCharProperty m_oCharProperty; RtfCharProperty m_oCharProperty;
...@@ -215,190 +191,16 @@ public: ...@@ -215,190 +191,16 @@ public:
m_bTextOnly = false; m_bTextOnly = false;
m_sData = L""; m_sData = L"";
m_oInsert = TextItemContainerPtr( new TextItemContainer() ); m_pResult = RtfFieldInstPtr(new RtfFieldInst());
m_oResult = TextItemContainerPtr( new TextItemContainer() ); m_pInsert = RtfFieldInstPtr(new RtfFieldInst());
m_oCharProperty.SetDefault();
}
CString RenderToRtf(RenderParameter oRenderParameter)
{
CString sResult;
sResult += L"{\\field ";
if( fm_none != m_eMode )
{
switch( m_eMode )
{
case fm_flddirty: sResult += L"{\\flddirty "; break;
case fm_fldedit: sResult += L"{\\fldedit "; break;
case fm_fldlock: sResult += L"{\\fldlock "; break;
case fm_fldpriv: sResult += L"{\\fldpriv "; break;
}
}
sResult += L"{\\*\\fldinst ";
RenderParameter oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_RTF_PARAM_PLAIN;//RENDER_TO_RTF_PARAM_CHAR;
oNewParam.nValue = RENDER_TO_RTF_PARAM_NO_PAR;
sResult += m_oInsert->RenderToRtf( oNewParam );
if( true == m_bReferenceToEndnote )
sResult += L"\\fldalt";
if( !m_sData.IsEmpty() )
sResult += L"{\\*\\datafield " + m_sData + L"}";
sResult += L"}"; m_oCharProperty.SetDefault();
CString str = m_oResult->RenderToRtf( oRenderParameter ) ;
sResult += L"{\\fldrslt " + str + L"}";
sResult += L"}";
return sResult;
} }
CString RenderToOOX(RenderParameter oRenderParameter) CString RenderToRtf(RenderParameter oRenderParameter);
{ CString RenderToOOX(RenderParameter oRenderParameter);
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
OOXWriter* poOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
CString sResult;
if( true == m_bTextOnly )
{
RenderParameter oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_OOX_PARAM_RUN;
sResult += m_oResult->RenderToOOX(oNewParam);
}
else
{
bool bInsert = false;
bool bDelete = false;
if (m_oCharProperty.m_nRevised != PROP_DEF)
{
bInsert = true;
CString sAuthor = m_oCharProperty.m_nRevauth != PROP_DEF ? poRtfDocument->m_oRevisionTable[ m_oCharProperty.m_nRevauth] : L"";
CString sDate(RtfUtility::convertDateTime(m_oCharProperty.m_nRevdttm).c_str());
sResult += L"<w:ins w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(poOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
m_oCharProperty.m_nRevised = PROP_DEF;
}
if (m_oCharProperty.m_nDeleted != PROP_DEF)
{
bDelete = true;
CString sAuthor = m_oCharProperty.m_nRevauthDel != PROP_DEF ? poRtfDocument->m_oRevisionTable[ m_oCharProperty.m_nRevauthDel ] : L"";
CString sDate(RtfUtility::convertDateTime(m_oCharProperty.m_nRevdttmDel).c_str());
sResult += L"<w:del w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(poOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
m_oCharProperty.m_nDeleted = PROP_DEF;
}
//поверяем на наличие гиперссылки
RenderParameter oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_OOX_PARAM_PLAIN;
CString sInsertText = m_oInsert->RenderToOOX( oNewParam );
int nIndex = sInsertText.Find( L"HYPERLINK" );
if( -1 != nIndex )
{
CString sHyperlink = sInsertText;
sHyperlink.Delete( nIndex, 9/*(int)_tcslen( L"HYPERLINK" )*/ );
int nSplash = sHyperlink.Find( L"\\" );
if (nSplash > 0)
{
sHyperlink = sHyperlink.Left(nSplash);
}
//оставляем только одну ссылку
sHyperlink.Remove( '\"' );
sHyperlink.Trim();
//заменяем пробелы на %20
sHyperlink.Replace( L" ", L"%20" );
//добавляем в rels
OOXRelsWriter* poRelsWriter = static_cast<OOXRelsWriter*>( oRenderParameter.poRels );
CString sId = poRelsWriter->AddRelationship( L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", Utils::PrepareToXML( sHyperlink ), false );
//добавляем гиперссылку в документ
sResult += L"<w:hyperlink r:id=\"" + sId + L"\" >";
oNewParam.nType = RENDER_TO_OOX_PARAM_RUN;
sResult += m_oResult->RenderToOOX(oNewParam);
sResult += L"</w:hyperlink>";
}
else
{
nIndex = sInsertText.Find( L"PRIVATE" );
if( m_oResult->GetCount() <= 1 && nIndex < 0)
{
RenderParameter oNewParametr = oRenderParameter;
oNewParametr.nType = RENDER_TO_OOX_PARAM_PLAIN;
//sResult += L"<w:r>");
CString str = Utils::PrepareToXML( m_oInsert->RenderToOOX(oNewParametr) ).Trim();
sResult += L"<w:fldSimple w:instr=\"";
sResult += str;
sResult += L"\">";
RenderParameter oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_OOX_PARAM_RUN;
sResult += m_oResult->RenderToOOX(oNewParam);
sResult.AppendFormat(L"</w:fldSimple>");
//sResult += L"</w:r>");
}
else
{
//так добавляются лишние параграфы
RenderParameter oNewParametr = oRenderParameter;
oNewParametr.nType = RENDER_TO_OOX_PARAM_PLAIN;
CString props = m_oCharProperty.RenderToOOX(oRenderParameter);
if (!props.IsEmpty()) props = L"<w:rPr>" + props + L"</w:rPr>";
sResult += L"<w:r>";
if (!props.IsEmpty())
sResult += props;
sResult += L"<w:fldChar w:fldCharType=\"begin\"/>";
sResult += L"</w:r>";
CString str = Utils::PrepareToXML( m_oInsert->RenderToOOX(oNewParametr) );
sResult += L"<w:r>";
if (!props.IsEmpty())
sResult += props;
sResult += L"<w:instrText xml:space=\"preserve\">";
sResult += str;
sResult += L"</w:instrText></w:r>";
sResult += L"<w:r>";
if (!props.IsEmpty())
sResult += props;
sResult += L"<w:fldChar w:fldCharType=\"separate\"/></w:r>";
//заканчиваем этот параграф
sResult += L"</w:p>";
//пишем параграфы содержания
oNewParametr.nType = RENDER_TO_OOX_PARAM_UNKNOWN;
sResult += m_oResult->RenderToOOX(oNewParametr);
//заканчиваем Field
sResult += L"<w:p>";
sResult += L"<w:r><w:fldChar w:fldCharType=\"end\"/></w:r>";
}
}
if (bDelete)sResult += L"</w:del>";
if (bInsert)sResult += L"</w:ins>";
}
return sResult;
}
}; };
typedef boost::shared_ptr<RtfField> RtfFieldPtr; typedef boost::shared_ptr<RtfField> RtfFieldPtr;
typedef boost::shared_ptr<OOXFieldBegin> OOXFieldBeginPtr; typedef boost::shared_ptr<OOXFieldBegin> OOXFieldBeginPtr;
typedef boost::shared_ptr<OOXFieldInsertText> OOXFieldInsertTextPtr; typedef boost::shared_ptr<OOXFieldInsertText> OOXFieldInsertTextPtr;
......
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