Commit 8f45da5a authored by ElenaSubbotina's avatar ElenaSubbotina

RtfWriter - fix read section with fields

parent 84fb75ab
......@@ -246,7 +246,7 @@ public:
CString RenderToRtf(RenderParameter oRenderParameter)
{
CString sResult;
for( int i = 0; i < (int)m_aArray.size(); i++ )
for( int i = 0; i < (int)m_aArray.size(); i++ )//идем с конца - из за св-в секций
{
sResult += m_aArray[i]->RenderToRtf( oRenderParameter );
......@@ -260,8 +260,10 @@ public:
CString RenderToOOX(RenderParameter oRenderParameter)
{
CString sResult;
for( int i = 0; i < (int)m_aArray.size(); i++ )
sResult += m_aArray[i]->RenderToOOX(oRenderParameter);
for( int i = (int)m_aArray.size() - 1; i >= 0; i-- )
{
sResult = m_aArray[i]->RenderToOOX(oRenderParameter) + sResult;
}
return sResult;
}
bool IsValid()
......
......@@ -1705,7 +1705,8 @@ public:
}
void ExitReader( RtfDocument& oDocument, RtfReader& oReader )
{
m_oParPropDest.Finalize( oReader/*, RtfSectionPtr()*/);
m_oParPropDest.Finalize( oReader );
m_oRtfFootnote.m_oContent = m_oParPropDest.m_oTextItems;
oReader.m_nFootnote = PROP_DEF;
}
......@@ -2409,7 +2410,7 @@ public:
}
void ExitReader( RtfDocument& oDocument, RtfReader& oReader )
{
m_oParPropDest.Finalize( oReader /*, RtfSectionPtr()*/ );
m_oParPropDest.Finalize( oReader );
}
};
......@@ -2422,6 +2423,7 @@ class RtfSectionCommand
{
private:
typedef enum{ is_none, is_border_left, is_border_top, is_border_right, is_border_bottom }InternalState;
InternalState m_eInternalState;
int nCurCollumnNumber;
public:
......@@ -2457,7 +2459,7 @@ public:
}
void ExitReader(RtfDocument& oDocument, RtfReader& oReader)
{
oParagraphReaderDestination.Finalize(oReader/*, RtfSectionPtr()*/);
oParagraphReaderDestination.Finalize( oReader );
_section section;
if(true == oDocument.GetItem( section) )
......@@ -2514,6 +2516,7 @@ private:
void SectDef( RtfDocument& oDocument, RtfReader& oReader )
{
oReader.m_oCurSectionProp.SetDefaultRtf();
//в соответствии с документацией ставим Page Information свойства как у документа
oReader.m_oCurSectionProp.m_nPageWidth = oDocument.m_oProperty.m_nPaperWidth;
oReader.m_oCurSectionProp.m_nPageHeight = oDocument.m_oProperty.m_nPaperHeight;
......
......@@ -90,7 +90,6 @@ public:
}
}
}
m_poDocument->RemoveItem(0);
_section last_section;
m_poDocument->GetItem(last_section);
......@@ -112,6 +111,8 @@ public:
m_poDocument->AddItem( section );
}
m_poDocument->RemoveItem(0);
for (int sect = 0 ; sect < m_poDocument->GetCount(); sect++)
{
m_oTextItemReader.m_oTextItems = m_poDocument->m_aArray[sect].props;
......
......@@ -163,9 +163,11 @@ CString RtfFootnote::RenderToOOX(RenderParameter oRenderParameter)
{
int nID = poDocument->m_oIdGenerator.Generate_FootnoteNumber();
OOXFootnoteWriter* poFootnoteWriter = static_cast<OOXFootnoteWriter*>( poOOXWriter->m_poFootnoteWriter );
RenderParameter oNewParameter = oRenderParameter;
oNewParameter.nType = RENDER_TO_OOX_PARAM_UNKNOWN;
oNewParameter.poRels = poFootnoteWriter->m_oRelsWriter.get();
poFootnoteWriter->AddFootnote( _T(""), nID, m_oContent->RenderToOOX(oNewParameter) );
sResult += _T("<w:r>");
......
......@@ -46,10 +46,8 @@ const long g_cdMaxPercent = 1000000;
//#define RTF_MATH_OOX
#define ELEMENT_UNDEFINED 0x001;
#define ELEMENT_OOXFIELD 0x010;
#define TYPE_UNKNOWN 0
#define TYPE_RTF_DOCUMENT 1
#define TYPE_RTF_PARAGRAPH 2
......@@ -81,6 +79,7 @@ const long g_cdMaxPercent = 1000000;
#define TYPE_RTF_OLE 29
#define TYPE_OOX_FIELD 29
#define TYPE_RTF_FOOTNOTE 30
#define RENDER_TO_OOX_PARAM_UNKNOWN 0
......
......@@ -43,6 +43,7 @@ RtfDocument::RtfDocument()
{
RtfSectionPtr s(new RtfSection());
_section section(s, 0, 0);
m_aArray.push_back( section );
m_oProperty.SetDefaultOOX();
......
......@@ -163,6 +163,17 @@ public:
}
else
{
CString ParagraphContent;// todooo проследить за вложенными объектами (inset fields) - св-ва секций
// нужно чтобы были в последнем параграфе!!! - так что и начнем с него - Australia Electronic Transactions Act 1999.rtf
RenderParameter oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_OOX_PARAM_RUN;
for( int i = m_aArray.size() - 1; i >= 0; i-- )
{
ParagraphContent = m_aArray[i]->RenderToOOX(oNewParam) + ParagraphContent;
}
bool bCanConvertToNumbering = false;
if( NULL != m_oOldList )
bCanConvertToNumbering = m_oOldList->CanConvertToNumbering();
......@@ -190,7 +201,7 @@ public:
if( NULL != m_oOldList->m_oText )
oCharProp.m_nFont = m_oOldList->m_oText->m_oProperty.m_oCharProperty.m_nFont;
RenderParameter oNewParam = oRenderParameter;
oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_OOX_PARAM_TEXT;
for( int i = 0; i < m_oOldList->m_oText->GetCount(); i++ )
......@@ -206,13 +217,8 @@ public:
}
}
RenderParameter oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_OOX_PARAM_RUN;
sResult += ParagraphContent;
for( int i = 0; i < (int)m_aArray.size(); i++ )
{
sResult += m_aArray[i]->RenderToOOX(oNewParam);
}
sResult += _T("</w:p>");
}
return sResult;
......
......@@ -1868,8 +1868,8 @@ CString RtfParagraphProperty::RenderToRtf(RenderParameter oRenderParameter)
}
CString RtfParagraphProperty::RenderToOOX(RenderParameter oRenderParameter)
{
RtfDocument* poRtfDocument = static_cast<RtfDocument*>(oRenderParameter.poDocument);
OOXWriter* poOOXWriter = static_cast<OOXWriter*>(oRenderParameter.poWriter);
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
OOXWriter* poOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
CString sResult;
if( PROP_DEF != m_nStyle )
......@@ -1882,21 +1882,13 @@ CString RtfParagraphProperty::RenderToOOX(RenderParameter oRenderParameter)
sResult += _T("\"/>") ;
}
}
if ( 0 == m_bAutoHyphenation ) sResult += _T("<w:suppressAutoHyphens/>");
else if ( 1 == m_bAutoHyphenation ) sResult += _T("<w:suppressAutoHyphens w:val=\"false\"/>");
_section section;
if(true == poRtfDocument->GetItem( section ) )
{
sResult += section.props->RenderToOOX(oRenderParameter);
section.props->m_bFinalize = false;
}
if( 0 == m_bAutoHyphenation ) sResult += _T("<w:suppressAutoHyphens/>");
else if( 1 == m_bAutoHyphenation ) sResult += _T("<w:suppressAutoHyphens w:val=\"false\"/>");
RENDER_OOX_BOOL( m_bKeep, sResult, _T("w:keepLines") );
RENDER_OOX_BOOL( m_bKeepNext, sResult, _T("w:keepNext") );
RENDER_OOX_INT( m_nOutlinelevel, sResult, _T("w:outlineLvl") );
RENDER_OOX_BOOL( m_bPageBB, sResult, _T("w:pageBreakBefore") );
RENDER_OOX_BOOL ( m_bKeep , sResult, _T("w:keepLines") );
RENDER_OOX_BOOL ( m_bKeepNext , sResult, _T("w:keepNext") );
RENDER_OOX_INT ( m_nOutlinelevel , sResult, _T("w:outlineLvl") );
RENDER_OOX_BOOL ( m_bPageBB , sResult, _T("w:pageBreakBefore") );
switch(m_eAlign)
......
......@@ -33,7 +33,6 @@
#include "Basic.h"
#include "Utils.h"
#include "RtfDefine.h"
#include "../../../Common/DocxFormat/Source/Common/SimpleTypes_Drawing.h"
......@@ -1823,12 +1822,12 @@ public:
typedef enum{hr_none,
hr_phmrg, //\tphmrg Use margin as horizontal reference frame.
hr_phpg, //tphpg Use page as horizontal reference frame.
hr_phcol//tphcol Use column as horizontal reference frame. This is the default if no horizontal table positioning information is given.
hr_phcol //tphcol Use column as horizontal reference frame. This is the default if no horizontal table positioning information is given.
} HRef;
typedef enum{vr_none,
vr_pvmrg, //tpvmrg Position table vertically relative to the top margin. This is the default if no vertical table positioning information is given.
vr_pvpg, //tpvpg Position table vertically relative to the top of the page.
vr_pvpara//tpvpara Position table vertically relative to the upper left corner of the next unframed paragraph in the stream.
vr_pvpara //tpvpara Position table vertically relative to the upper left corner of the next unframed paragraph in the stream.
} VRef;
typedef enum{hp_none,
hp_posxc, //tposxc Center table within the horizontal reference frame.
......@@ -1843,7 +1842,7 @@ public:
vp_posyb, //tposyb Position table at the bottom of the vertical reference frame.
vp_posyc, //tposyc Center table within the vertical reference frame
vp_posyin, //tposyin Position table inside within the vertical reference frame.
vp_posyout//tposyout Position table outside within the vertical reference frame.
vp_posyout //tposyout Position table outside within the vertical reference frame.
} VPos;
int m_bBidi; //taprtl Table direction is right to left.
......@@ -1853,12 +1852,14 @@ public:
int nTableIndent; //tblindN
int nTableIndentUnits; //\tblindtypeN
typedef enum{rj_none,
typedef enum
{
rj_none,
rj_trql, //trql Left-justifies a table row with respect to its containing column.
rj_trqr, //trqr Right-justifies a table row with respect to its containing column.
rj_trqc //trqc Centers a table row with respect to its containing column.
} RowJust;
RowJust m_eJust; //
RowJust m_eJust;
int m_nWrapLeft; //tdfrmtxtLeftN Distance in twips, between the left of the table and surrounding text (default is 0).
int m_nWrapRight; //tdfrmtxtRightN Distance in twips, between the right of the table and surrounding text (default is 0).
......@@ -2586,6 +2587,7 @@ class RtfParagraphProperty: public IRenderableProperty
{
public:
bool m_bOldList;
//-------------------------------------------------------------------
int m_bAutoHyphenation; //hyphpar Switches automatic hyphenation for the paragraph. Append 1 or nothing to toggle property on; append 0 to turn it off.
int m_bInTable; //intbl Paragraph is part of a table.
......@@ -2605,8 +2607,8 @@ public:
pa_qr, //qr Right-aligned.
pa_qd, //qd Distributed.
pa_qk0, //qkN Percentage of line occupied by Kashida justification (0 – low, 10 – medium, 20 – high).
pa_qk10, //
pa_qk20, //
pa_qk10,
pa_qk20,
} ParagraphAlign;
ParagraphAlign m_eAlign;
......@@ -2658,18 +2660,20 @@ public:
int m_nListId; //lsN Should exactly match the \lsN for one of the list overrides in the List Override table.
int m_nListLevel; //ilvlN The 0-based level of the list to which the paragraph belongs. For all simple lists, N should always be 0. For multilevel lists, it can be 0 through 8. The value 9 is never used. The values 10 through 12 have the special meanings for documents generated by Word 6: 10 = ilvlBullet (a bulleted paragraph in Word 6), 11 = ilvlList (a numbered paragraph in Word 6), 12 = ilvlContinue (a paragraph that was not itself numbered, but took its indenting scheme from its numbering properties and did not “break” numbering (that in Word 6 required otherwise contiguous paragraphs).
RtfShadingPar m_oShading; //
RtfShadingPar m_oShading;
RtfBorder m_oBorderTop; //
RtfBorder m_oBorderLeft; //
RtfBorder m_oBorderBottom; //
RtfBorder m_oBorderRight; //
RtfBorder m_oBorderBox; //
RtfBorder m_oBorderBar; //
RtfBorder m_oBorderTop;
RtfBorder m_oBorderLeft;
RtfBorder m_oBorderBottom;
RtfBorder m_oBorderRight;
RtfBorder m_oBorderBox;
RtfBorder m_oBorderBar;
RtfFrame m_oFrame; //
RtfFrame m_oFrame;
int m_bOverlap; //1\absnoovrlpN Allow overlap with other frames or objects with similar wrapping:
typedef enum{tf_none,
typedef enum
{
tf_none,
tf_frmtxlrtb, //frmtxlrtb Frame box flows from left to right and top to bottom (default).
tf_frmtxtbrl, //frmtxtbrl Frame box flows right to left and top to bottom.
tf_frmtxbtlr, //frmtxbtlr Frame box flows left to right and bottom to top.
......@@ -2695,7 +2699,7 @@ public:
int m_bStyleSECell; //\tscsecell SE cell.
RtfCharProperty m_oCharProperty;
//--------------------------------------------------------------------------------------------------------------
RtfParagraphProperty()
{
SetDefault();
......
......@@ -520,14 +520,19 @@ public:
{
return TYPE_RTF_PROPERTY_SECTION;
}
void SetDefaultRtf()
{
SetDefault();
m_nColumnSpace = 720;
DEFAULT_PROPERTY_DEF( m_eSectionBreak, sb_sbkpage )
DEFAULT_PROPERTY_DEF( m_nColumnSpace, 720);
}
void SetDefaultOOX()
{
SetDefault();
m_nPageWidth = 11906;
m_nPageHeight = 16838;
......@@ -544,72 +549,73 @@ public:
}
void SetDefault()
{
DEFAULT_PROPERTY( m_bBidi )
DEFAULT_PROPERTY( m_nPaperSourceFirst )
DEFAULT_PROPERTY( m_nPaperSourceOther )
DEFAULT_PROPERTY( m_bRtlGutter )
DEFAULT_PROPERTY( m_bEndnotes )
DEFAULT_PROPERTY( m_nStyle )
DEFAULT_PROPERTY ( m_bBidi )
DEFAULT_PROPERTY ( m_nPaperSourceFirst )
DEFAULT_PROPERTY ( m_nPaperSourceOther )
DEFAULT_PROPERTY ( m_bRtlGutter )
DEFAULT_PROPERTY ( m_bEndnotes )
DEFAULT_PROPERTY ( m_nStyle )
DEFAULT_PROPERTY_DEF( m_eSectionBreak, sb_none )
//Columns
m_nColumnNumber = 1;
DEFAULT_PROPERTY( m_nColumnSpace )
DEFAULT_PROPERTY( m_bColumnLineBetween )
DEFAULT_PROPERTY ( m_nColumnSpace )
DEFAULT_PROPERTY ( m_bColumnLineBetween )
m_oCollumnProperty.m_aCollumnProperty.resize( m_nColumnNumber );
//Footnotes and Endnotes
DEFAULT_PROPERTY_DEF( m_eFootnotesJust, fj_none )
DEFAULT_PROPERTY( m_nFootnotesStart )
DEFAULT_PROPERTY ( m_nFootnotesStart )
DEFAULT_PROPERTY_DEF( m_eFootnotesRestart, fr_none )
DEFAULT_PROPERTY_DEF( m_eFootnotesFormat, ff_none )
DEFAULT_PROPERTY( m_nEndnotesStart )
DEFAULT_PROPERTY ( m_nEndnotesStart )
DEFAULT_PROPERTY_DEF( m_eEndnotesRestart, er_none )
DEFAULT_PROPERTY_DEF( m_eEndnotesFormat, ef_none )
//Line Numbering
DEFAULT_PROPERTY( m_nLineModulus )
DEFAULT_PROPERTY( m_nLineX )
DEFAULT_PROPERTY( m_nLineStart )
DEFAULT_PROPERTY ( m_nLineModulus )
DEFAULT_PROPERTY ( m_nLineX )
DEFAULT_PROPERTY ( m_nLineStart )
DEFAULT_PROPERTY_DEF( m_eLineNumberRestart, lnr_none )
//Page Information
DEFAULT_PROPERTY( m_nPageWidth )
DEFAULT_PROPERTY( m_nPageHeight )
DEFAULT_PROPERTY( m_nMarginLeft )
DEFAULT_PROPERTY( m_nMarginRight )
DEFAULT_PROPERTY( m_nMarginTop )
DEFAULT_PROPERTY( m_nMarginBottom )
DEFAULT_PROPERTY( m_nGutterMarginWidth )
DEFAULT_PROPERTY( m_bSwitchMargin )
DEFAULT_PROPERTY( m_bLandscapeFormat )
DEFAULT_PROPERTY( m_bTitlePage )
DEFAULT_PROPERTY ( m_nPageWidth )
DEFAULT_PROPERTY ( m_nPageHeight )
DEFAULT_PROPERTY ( m_nMarginLeft )
DEFAULT_PROPERTY ( m_nMarginRight )
DEFAULT_PROPERTY ( m_nMarginTop )
DEFAULT_PROPERTY ( m_nMarginBottom )
DEFAULT_PROPERTY ( m_nGutterMarginWidth )
DEFAULT_PROPERTY ( m_bSwitchMargin )
DEFAULT_PROPERTY ( m_bLandscapeFormat )
DEFAULT_PROPERTY ( m_bTitlePage )
DEFAULT_PROPERTY_DEF( m_nHeaderTop, 720 )
DEFAULT_PROPERTY_DEF( m_nFooterBottom, 720 )
//Page Numbers
DEFAULT_PROPERTY( m_nPageNumberStart )
DEFAULT_PROPERTY( m_bPageNumberContinuos )
DEFAULT_PROPERTY( m_bPageNumberRestart )
DEFAULT_PROPERTY( m_nPageNumberX )
DEFAULT_PROPERTY( m_nPageNumberY )
DEFAULT_PROPERTY ( m_nPageNumberStart )
DEFAULT_PROPERTY ( m_bPageNumberContinuos )
DEFAULT_PROPERTY ( m_bPageNumberRestart )
DEFAULT_PROPERTY ( m_nPageNumberX )
DEFAULT_PROPERTY ( m_nPageNumberY )
DEFAULT_PROPERTY_DEF( m_ePageNumberFormat, pnf_none )
//Vertical Alignment
DEFAULT_PROPERTY_DEF( m_eVerticalAlignment, va_none )
//Text Flow
DEFAULT_PROPERTY( m_nTextFollow )
DEFAULT_PROPERTY ( m_nTextFollow )
//Page Borders
m_oBorderLeft.SetDefault();
m_oBorderTop.SetDefault();
m_oBorderRight.SetDefault();
m_oBorderBottom.SetDefault();
DEFAULT_PROPERTY( m_nBorderArt )
DEFAULT_PROPERTY( m_nBorderMeasure )
DEFAULT_PROPERTY( m_nBorderAlign )
DEFAULT_PROPERTY ( m_nBorderArt )
DEFAULT_PROPERTY ( m_nBorderMeasure )
DEFAULT_PROPERTY ( m_nBorderAlign )
//footer - header надо обнулять вручную
//m_oHeaderLeft = TextItemContainerPtr();
......@@ -660,6 +666,7 @@ public:
CString RenderToOOX(RenderParameter oRenderParameter)
{
if (!m_bFinalize) return L"";
m_bFinalize = false; // тут .. чтобы не повторилось при конвертации колонтитулов
RenderParameter oNewParam = oRenderParameter;
......
......@@ -225,40 +225,42 @@ bool OOXDocumentWriter::SaveByItem()
if( m_oDocument.GetCount() > 1)//если что-то есть в следующей секции значит предыдущая закончилась
{
if( m_oDocument[1].props->GetCount() > 0 )
{
CString sSectPr = m_oDocument[0].props->m_oProperty.RenderToOOX(oNewParam);
CString sXml = m_oDocument[1].props->operator[](0)->RenderToOOX(oNewParam);
std::wstring sXml, sectPr;
int nIndexP = sXml.Find( _T("<w:p>") );
_section section;
if (m_oDocument.GetItem(section, 0))
{
sectPr = section.props->RenderToOOX(oNewParam).GetBuffer();
}
if (nIndexP == 0) //элемент параграф
if( m_oDocument[0].props->GetCount() > 0 )
{
int nIndexpPr = sXml.Find( _T("</w:pPr>") );
if( -1 != nIndexpPr )
sXml = m_oDocument[0].props->operator[](0)->RenderToOOX(oNewParam).GetBuffer();
int nFind = sXml.rfind(L"</w:pPr>");
if( -1 != nFind )
{
sXml.Insert( nIndexpPr, sSectPr );
sXml.insert( nFind, sectPr );
}
else
{
sSectPr = _T("<w:pPr>") + sSectPr + _T("</w:pPr>");
sXml.Insert( 5, sSectPr );
int Find = sXml.rfind( L"<w:p>" );
if( -1 != nFind )
sXml.insert( nFind + 5, L"<w:pPr>" + sectPr + L"</w:pPr>" );
}
}
else
{
sXml = _T("<w:p><w:pPr>") + sSectPr + _T("</w:pPr></w:p>") + sXml;
//генерация ???
sXml = _T("<w:p><w:pPr>") + sectPr + _T("</w:pPr></w:p>");
}
std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml.GetBuffer());
std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml);
m_oFileWriter->Write((BYTE*)sXmlUTF.c_str(), sXmlUTF.length());
m_oDocument[1].props->RemoveItem( 0 ); //удаляем первый параграф
m_oDocument.RemoveItem( 0 ); //удаляем секцию
}
}
else if( m_oDocument.GetCount() > 0 && m_oDocument[0].props->GetCount() > 0 )//пишем параграф
else if( m_oDocument.GetCount() > 0 && m_oDocument[0].props->GetCount() > 1 )//пишем параграф - один всегда "прозапас для секций"
{
CString sXml = m_oDocument[0].props->operator[](0)->RenderToOOX(oNewParam);
std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml.GetBuffer());
......
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