Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
onlyoffice_core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
onlyoffice_core
Commits
147a8216
Commit
147a8216
authored
Nov 11, 2016
by
ElenaSubbotina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RtfFormatReader - review, fix fields
parent
0d94d873
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
515 additions
and
381 deletions
+515
-381
ASCOfficeRtfFile/RtfFormatLib/Win32/RtfFormatLib.vcproj
ASCOfficeRtfFile/RtfFormatLib/Win32/RtfFormatLib.vcproj
+4
-0
ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp
ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp
+81
-48
ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.h
ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.h
+107
-78
ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXParagraphElementReaders.cpp
...RtfFormatLib/source/Reader/OOXParagraphElementReaders.cpp
+25
-18
ASCOfficeRtfFile/RtfFormatLib/source/RtfField.cpp
ASCOfficeRtfFile/RtfFormatLib/source/RtfField.cpp
+259
-0
ASCOfficeRtfFile/RtfFormatLib/source/RtfField.h
ASCOfficeRtfFile/RtfFormatLib/source/RtfField.h
+39
-237
No files found.
ASCOfficeRtfFile/RtfFormatLib/Win32/RtfFormatLib.vcproj
View file @
147a8216
...
...
@@ -687,6 +687,10 @@
RelativePath=
"..\source\RtfDocument.h"
>
</File>
<File
RelativePath=
"..\source\RtfField.cpp"
>
</File>
<File
RelativePath=
"..\source\RtfField.h"
>
...
...
ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp
View file @
147a8216
This diff is collapsed.
Click to expand it.
ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.h
View file @
147a8216
This diff is collapsed.
Click to expand it.
ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXParagraphElementReaders.cpp
View file @
147a8216
...
...
@@ -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
]);
RtfFieldPtr
oCurField
(
new
RtfField
()
);
oCurField
->
m_oInsert
=
TextItemContainerPtr
(
new
TextItemContainer
()
);
oCurField
->
m_oResult
=
TextItemContainerPtr
(
new
TextItemContainer
()
);
//добавляем insert
oCurField
->
m_pInsert
=
RtfFieldInstPtr
(
new
RtfFieldInst
()
);
oCurField
->
m_pResult
=
RtfFieldInstPtr
(
new
RtfFieldInst
()
);
//добавляем insert
RtfCharPtr
oNewChar
(
new
RtfChar
()
);
oNewChar
->
m_bRtfEncode
=
false
;
if
(
pFldSimple
->
m_sInstr
.
IsInit
())
...
...
@@ -136,7 +137,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
}
RtfParagraphPtr
oNewInsertParagraph
(
new
RtfParagraph
()
);
oNewInsertParagraph
->
AddItem
(
oNewChar
);
oCurField
->
m_
oInsert
->
AddItem
(
oNewInsertParagraph
);
oCurField
->
m_
pInsert
->
m_pTextItems
->
AddItem
(
oNewInsertParagraph
);
//добаляем свойства
if
(
TRUE
==
pFldSimple
->
m_oFldLock
.
ToBool
()
)
...
...
@@ -156,7 +157,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
{
OOXParagraphReader
oSubParReader
(
pFldSimple
);
oSubParReader
.
Parse2
(
oParam
,
*
oNewResultParagraph
,
CcnfStyle
(),
poExternalStyle
);
oCurField
->
m_
oResult
->
AddItem
(
oNewResultParagraph
);
oCurField
->
m_
pResult
->
m_pTextItems
->
AddItem
(
oNewResultParagraph
);
}
oOutputParagraph
.
AddItem
(
oCurField
);
}
break
;
...
...
@@ -193,17 +194,19 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
}
}
RtfFieldPtr
oCurField
(
new
RtfField
()
);
oCurField
->
m_oInsert
=
TextItemContainerPtr
(
new
TextItemContainer
()
);
oCurField
->
m_oResult
=
TextItemContainerPtr
(
new
TextItemContainer
()
);
//добавляем insert
oCurField
->
m_pInsert
=
RtfFieldInstPtr
(
new
RtfFieldInst
()
);
oCurField
->
m_pResult
=
RtfFieldInstPtr
(
new
RtfFieldInst
()
);
//добавляем insert
RtfCharPtr
oNewChar
(
new
RtfChar
()
);
oNewChar
->
m_bRtfEncode
=
true
;
// false;
CString
sFieldText
;
sFieldText
+=
L"HYPERLINK
\"
"
+
sTarget
+
L"
\"
"
;
oNewChar
->
setText
(
sFieldText
);
RtfParagraphPtr
oNewInsertParagraph
(
new
RtfParagraph
()
);
oNewInsertParagraph
->
AddItem
(
oNewChar
);
oCurField
->
m_
oInsert
->
AddItem
(
oNewInsertParagraph
);
oCurField
->
m_
pInsert
->
m_pTextItems
->
AddItem
(
oNewInsertParagraph
);
//добавляем свойства
//pHyperlink->m_arrItems todoooo
...
...
@@ -225,7 +228,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
{
OOXParagraphReader
oSubParReader
(
pHyperlink
);
oSubParReader
.
Parse2
(
oParam
,
*
oNewResultParagraph
,
CcnfStyle
(),
poExternalStyle
);
oCurField
->
m_
oResult
->
AddItem
(
oNewResultParagraph
);
oCurField
->
m_
pResult
->
m_pTextItems
->
AddItem
(
oNewResultParagraph
);
}
oOutputParagraph
.
AddItem
(
oCurField
);
}
...
...
@@ -233,8 +236,9 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
if
(
pHyperlink
->
m_sAnchor
.
IsInit
()
)
{
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
RtfCharPtr
oNewCharHYPER
(
new
RtfChar
()
);
oNewCharHYPER
->
m_bRtfEncode
=
false
;
...
...
@@ -243,7 +247,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
RtfParagraphPtr
oNewInsertParagraph
(
new
RtfParagraph
()
);
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"));
//if( TRUE == bLock )
...
...
@@ -263,7 +267,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
{
OOXParagraphReader
oSubParReader
(
pHyperlink
);
oSubParReader
.
Parse2
(
oParam
,
*
oNewResultParagraph
,
CcnfStyle
(),
poExternalStyle
);
oCurField
->
m_
oResult
->
AddItem
(
oNewResultParagraph
);
oCurField
->
m_
pResult
->
m_pTextItems
->
AddItem
(
oNewResultParagraph
);
}
oOutputParagraph
.
AddItem
(
oCurField
);
}
...
...
@@ -761,9 +765,11 @@ bool OOXRunReader::Parse( ReaderParameter oParam , RtfParagraph& oOutputParagrap
oCurFont
.
m_sName
=
sFont
;
oParam
.
oRtf
->
m_oFontTable
.
DirectAddItem
(
oCurFont
);
}
RtfFieldPtr
oNewField
=
RtfFieldPtr
(
new
RtfField
()
);
oNewField
->
m_oInsert
=
TextItemContainerPtr
(
new
TextItemContainer
()
);
oNewField
->
m_oResult
=
TextItemContainerPtr
(
new
TextItemContainer
()
);
RtfFieldPtr
oNewField
=
RtfFieldPtr
(
new
RtfField
()
);
oNewField
->
m_pInsert
=
RtfFieldInstPtr
(
new
RtfFieldInst
()
);
oNewField
->
m_pResult
=
RtfFieldInstPtr
(
new
RtfFieldInst
()
);
RtfCharPtr
oNewChar
(
new
RtfChar
()
);
oNewChar
->
m_bRtfEncode
=
false
;
CString
sFieldText
;
...
...
@@ -777,9 +783,10 @@ bool OOXRunReader::Parse( ReaderParameter oParam , RtfParagraph& oOutputParagrap
sFieldText
.
AppendFormat
(
L"%d"
,
nFontSize
);
oNewChar
->
setText
(
sFieldText
);
RtfParagraphPtr
oNewInsertParagraph
(
new
RtfParagraph
()
);
oNewInsertParagraph
->
AddItem
(
oNewChar
);
oNewField
->
m_
oInsert
->
AddItem
(
oNewInsertParagraph
);
oNewField
->
m_
pInsert
->
m_pTextItems
->
AddItem
(
oNewInsertParagraph
);
oOutputParagraph
.
AddItem
(
oNewField
);
}
...
...
ASCOfficeRtfFile/RtfFormatLib/source/RtfField.cpp
0 → 100644
View file @
147a8216
/*
* (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
;
}
ASCOfficeRtfFile/RtfFormatLib/source/RtfField.h
View file @
147a8216
...
...
@@ -31,8 +31,6 @@
*/
#pragma once
#include "RtfParagraph.h"
#include "Writer/OOXWriter.h"
#include "Writer/OOXRelsWriter.h"
class
OOXFieldBegin
:
public
IDocumentElement
{
...
...
@@ -56,39 +54,8 @@ public:
m_oCharProperty
.
SetDefault
();
}
CString
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
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
RenderToRtf
(
RenderParameter
oRenderParameter
);
CString
RenderToOOX
(
RenderParameter
oRenderParameter
);
};
class
OOXFieldInsertText
:
public
IDocumentElement
{
...
...
@@ -106,26 +73,7 @@ public:
else
return
L""
;
}
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""
;
}
CString
RenderToOOX
(
RenderParameter
oRenderParameter
);
};
class
OOXFieldSeparate
:
public
IDocumentElement
...
...
@@ -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
{
public:
...
...
@@ -178,10 +152,12 @@ public:
};
_FieldMode
m_eMode
;
TextItemContainerPtr
m_oInsert
;
bool
m_bReferenceToEndnote
;
CString
m_sData
;
TextItemContainerPtr
m_oResult
;
RtfFieldInstPtr
m_pInsert
;
RtfFieldInstPtr
m_pResult
;
bool
m_bTextOnly
;
RtfCharProperty
m_oCharProperty
;
...
...
@@ -215,190 +191,16 @@ public:
m_bTextOnly
=
false
;
m_sData
=
L""
;
m_oInsert
=
TextItemContainerPtr
(
new
TextItemContainer
()
);
m_oResult
=
TextItemContainerPtr
(
new
TextItemContainer
()
);
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"}"
;
m_pResult
=
RtfFieldInstPtr
(
new
RtfFieldInst
());
m_pInsert
=
RtfFieldInstPtr
(
new
RtfFieldInst
());
sResult
+=
L"}"
;
CString
str
=
m_oResult
->
RenderToRtf
(
oRenderParameter
)
;
sResult
+=
L"{
\\
fldrslt "
+
str
+
L"}"
;
sResult
+=
L"}"
;
return
sResult
;
m_oCharProperty
.
SetDefault
();
}
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
;
}
CString
RenderToRtf
(
RenderParameter
oRenderParameter
);
CString
RenderToOOX
(
RenderParameter
oRenderParameter
);
};
typedef
boost
::
shared_ptr
<
RtfField
>
RtfFieldPtr
;
typedef
boost
::
shared_ptr
<
OOXFieldBegin
>
OOXFieldBeginPtr
;
typedef
boost
::
shared_ptr
<
OOXFieldInsertText
>
OOXFieldInsertTextPtr
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment