Kaydet (Commit) 83d51e5e authored tarafından Rohit Deshmukh's avatar Rohit Deshmukh Kaydeden (comit) Miklos Vajna

fdo#80748: Fix for file corruption due to framePr

 -For framePr Unit test is there in ooxmlexport.cxx
    -http://opengrok.libreoffice.org/xref/core/sw/qa/extras/ooxmlexport/ooxmlexport.cxx#3578

Change-Id: Ic1fd4c7a863d8ab57c6495e20bff6863eb941688
Reviewed-on: https://gerrit.libreoffice.org/10045Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 5ccb510e
...@@ -62,7 +62,7 @@ const sal_Int32 FSEND_internal = -1; // same as XML_TOKEN_INVALID ...@@ -62,7 +62,7 @@ const sal_Int32 FSEND_internal = -1; // same as XML_TOKEN_INVALID
namespace sax_fastparser { namespace sax_fastparser {
enum MergeMarksEnum { MERGE_MARKS_APPEND = 0, MERGE_MARKS_PREPEND = 1, MERGE_MARKS_POSTPONE = 2 }; enum MergeMarksEnum { MERGE_MARKS_APPEND = 0, MERGE_MARKS_PREPEND = 1, MERGE_MARKS_POSTPONE = 2, MERGE_MARKS_IGNORE = 3 };
typedef ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList > XFastAttributeListRef; typedef ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList > XFastAttributeListRef;
......
...@@ -291,7 +291,7 @@ namespace sax_fastparser { ...@@ -291,7 +291,7 @@ namespace sax_fastparser {
if ( maMarkStack.empty() ) if ( maMarkStack.empty() )
return; return;
if ( maMarkStack.size() == 1 ) if ( maMarkStack.size() == 1 && eMergeType != MERGE_MARKS_IGNORE)
{ {
mxOutputStream->writeBytes( maMarkStack.top()->getData() ); mxOutputStream->writeBytes( maMarkStack.top()->getData() );
maMarkStack.pop(); maMarkStack.pop();
...@@ -306,6 +306,8 @@ namespace sax_fastparser { ...@@ -306,6 +306,8 @@ namespace sax_fastparser {
case MERGE_MARKS_APPEND: maMarkStack.top()->append( aMerge ); break; case MERGE_MARKS_APPEND: maMarkStack.top()->append( aMerge ); break;
case MERGE_MARKS_PREPEND: maMarkStack.top()->prepend( aMerge ); break; case MERGE_MARKS_PREPEND: maMarkStack.top()->prepend( aMerge ); break;
case MERGE_MARKS_POSTPONE: maMarkStack.top()->postpone( aMerge ); break; case MERGE_MARKS_POSTPONE: maMarkStack.top()->postpone( aMerge ); break;
case MERGE_MARKS_IGNORE : break;
} }
} }
......
...@@ -329,11 +329,9 @@ void DocxAttributeOutput::PopulateFrameProperties(const SwFrmFmt* pFrmFmt, const ...@@ -329,11 +329,9 @@ void DocxAttributeOutput::PopulateFrameProperties(const SwFrmFmt* pFrmFmt, const
relativeFromV = "page"; relativeFromV = "page";
break; break;
case text::RelOrientation::FRAME: case text::RelOrientation::FRAME:
relativeFromV = "paragraph";
break;
case text::RelOrientation::TEXT_LINE: case text::RelOrientation::TEXT_LINE:
default: default:
relativeFromV = "line"; relativeFromV = "text";
break; break;
} }
...@@ -346,19 +344,31 @@ void DocxAttributeOutput::PopulateFrameProperties(const SwFrmFmt* pFrmFmt, const ...@@ -346,19 +344,31 @@ void DocxAttributeOutput::PopulateFrameProperties(const SwFrmFmt* pFrmFmt, const
relativeFromH = "page"; relativeFromH = "page";
break; break;
case text::RelOrientation::CHAR: case text::RelOrientation::CHAR:
relativeFromH = "character";
break;
case text::RelOrientation::PAGE_RIGHT: case text::RelOrientation::PAGE_RIGHT:
relativeFromH = "page";
break;
case text::RelOrientation::FRAME: case text::RelOrientation::FRAME:
default: default:
relativeFromH = "column"; relativeFromH = "text";
break; break;
} }
switch (pFrmFmt->GetSurround().GetValue())
{
case SURROUND_NONE:
attrList->add( FSNS( XML_w, XML_wrap), "none");
break;
case SURROUND_THROUGHT:
attrList->add( FSNS( XML_w, XML_wrap), "through");
break;
case SURROUND_PARALLEL:
attrList->add( FSNS( XML_w, XML_wrap), "notBeside");
break;
case SURROUND_IDEAL:
default:
attrList->add( FSNS( XML_w, XML_wrap), "auto");
break;
}
attrList->add( FSNS( XML_w, XML_vAnchor), relativeFromV); attrList->add( FSNS( XML_w, XML_vAnchor), relativeFromV);
attrList->add( FSNS( XML_w, XML_hAnchor), relativeFromH); attrList->add( FSNS( XML_w, XML_hAnchor), relativeFromH);
attrList->add( FSNS( XML_w, XML_wrap), "notBeside");
attrList->add( FSNS( XML_w, XML_hRule), "exact"); attrList->add( FSNS( XML_w, XML_hRule), "exact");
sax_fastparser::XFastAttributeListRef xAttrList(attrList); sax_fastparser::XFastAttributeListRef xAttrList(attrList);
...@@ -399,7 +409,7 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT ...@@ -399,7 +409,7 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT
{ {
// write the paragraph properties + the run, already in the correct order // write the paragraph properties + the run, already in the correct order
m_pSerializer->mergeTopMarks(); m_pSerializer->mergeTopMarks();
std::vector< boost::shared_ptr <sw::Frame> > aFramePrTextbox;
// Write the anchored frame if any // Write the anchored frame if any
// Word can't handle nested text boxes, so write them on the same level. // Word can't handle nested text boxes, so write them on the same level.
++m_nTextFrameLevel; ++m_nTextFrameLevel;
...@@ -411,12 +421,11 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT ...@@ -411,12 +421,11 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT
{ {
m_bParagraphFrameOpen = true; m_bParagraphFrameOpen = true;
sw::Frame aFrame = m_aFramesOfParagraph[nIndex]; sw::Frame aFrame = m_aFramesOfParagraph[nIndex];
m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
const SwFrmFmt& rFrmFmt = aFrame.GetFrmFmt(); const SwFrmFmt& rFrmFmt = aFrame.GetFrmFmt();
if (!TextBoxIsFramePr(rFrmFmt) || m_bWritingHeaderFooter) if (!TextBoxIsFramePr(rFrmFmt) || m_bWritingHeaderFooter)
{ {
m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
m_pSerializer->startElementNS(XML_mc, XML_AlternateContent, FSEND); m_pSerializer->startElementNS(XML_mc, XML_AlternateContent, FSEND);
m_pSerializer->startElementNS(XML_mc, XML_Choice, m_pSerializer->startElementNS(XML_mc, XML_Choice,
XML_Requires, "wps", XML_Requires, "wps",
...@@ -465,17 +474,15 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT ...@@ -465,17 +474,15 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT
m_pSerializer->endElementNS(XML_mc, XML_Fallback); m_pSerializer->endElementNS(XML_mc, XML_Fallback);
m_pSerializer->endElementNS(XML_mc, XML_AlternateContent); m_pSerializer->endElementNS(XML_mc, XML_AlternateContent);
m_pSerializer->endElementNS( XML_w, XML_r );
m_bParagraphFrameOpen = false;
} }
else else
{ {
ww8::WW8TableInfo::Pointer_t pOldTableInfo = m_rExport.mpTableInfo; ::boost::shared_ptr<sw::Frame> pFramePr;
//Reset the table infos after saving. pFramePr.reset(new sw::Frame(aFrame));
m_rExport.mpTableInfo = ww8::WW8TableInfo::Pointer_t(new ww8::WW8TableInfo()); aFramePrTextbox.push_back(pFramePr);
m_rExport.SdrExporter().writeOnlyTextOfFrame(&aFrame);
m_rExport.mpTableInfo = pOldTableInfo;
} }
m_pSerializer->endElementNS( XML_w, XML_r );
m_bParagraphFrameOpen = false;
} }
if (!m_postponedCustomShape->empty()) if (!m_postponedCustomShape->empty())
{ {
...@@ -515,8 +522,25 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT ...@@ -515,8 +522,25 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT
//sdtcontent is written so Set m_bParagraphHasDrawing to false //sdtcontent is written so Set m_bParagraphHasDrawing to false
m_rExport.SdrExporter().setParagraphHasDrawing( false ); m_rExport.SdrExporter().setParagraphHasDrawing( false );
m_bRunTextIsOn = false; m_bRunTextIsOn = false;
m_pSerializer->mergeTopMarks(); if(aFramePrTextbox.empty())
m_pSerializer->mergeTopMarks();
else
m_pSerializer->mergeTopMarks(sax_fastparser::MERGE_MARKS_IGNORE );
// Write framePr
if(!aFramePrTextbox.empty())
{
ww8::WW8TableInfo::Pointer_t pOldTableInfo = m_rExport.mpTableInfo;
for (std::vector< boost::shared_ptr<sw::Frame> > ::iterator it = aFramePrTextbox.begin() ; it != aFramePrTextbox.end(); ++it)
{
m_rExport.mpTableInfo = ww8::WW8TableInfo::Pointer_t(new ww8::WW8TableInfo());
m_pCurrentFrame = it->get();
m_rExport.SdrExporter().writeOnlyTextOfFrame(it->get());
m_pCurrentFrame = NULL;
}
m_rExport.mpTableInfo = pOldTableInfo;
aFramePrTextbox.clear();
}
// Check for end of cell, rows, tables here // Check for end of cell, rows, tables here
FinishTableRowCell( pTextNodeInfoInner ); FinishTableRowCell( pTextNodeInfoInner );
...@@ -818,20 +842,16 @@ void DocxAttributeOutput::EndParagraphProperties( const SfxItemSet* pParagraphMa ...@@ -818,20 +842,16 @@ void DocxAttributeOutput::EndParagraphProperties( const SfxItemSet* pParagraphMa
m_pSerializer->endElementNS( XML_w, XML_rPr ); m_pSerializer->endElementNS( XML_w, XML_rPr );
} }
if (!m_bWritingHeaderFooter) if (!m_bWritingHeaderFooter && m_pCurrentFrame)
{ {
//Check whether we have Frame for paragraph const SwFrmFmt& rFrmFmt = m_pCurrentFrame->GetFrmFmt();
for (size_t nIndex = 0; nIndex < m_aFramesOfParagraph.size(); ++nIndex) if (TextBoxIsFramePr(rFrmFmt))
{ {
sw::Frame aFrame = m_aFramesOfParagraph[nIndex]; const Size aSize = m_pCurrentFrame->GetSize();
const SwFrmFmt& rFrmFmt = aFrame.GetFrmFmt(); PopulateFrameProperties(&rFrmFmt, aSize);
if (TextBoxIsFramePr(rFrmFmt))
{
const Size aSize = aFrame.GetSize();
PopulateFrameProperties(&rFrmFmt, aSize);
}
} }
} }
m_pSerializer->endElementNS( XML_w, XML_pPr ); m_pSerializer->endElementNS( XML_w, XML_pPr );
if ( m_nColBreakStatus == COLBRK_WRITE ) if ( m_nColBreakStatus == COLBRK_WRITE )
...@@ -7756,6 +7776,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri ...@@ -7756,6 +7776,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri
m_nNextBookmarkId( 0 ), m_nNextBookmarkId( 0 ),
m_nNextAnnotationMarkId( 0 ), m_nNextAnnotationMarkId( 0 ),
m_pTableWrt( NULL ), m_pTableWrt( NULL ),
m_pCurrentFrame( NULL ),
m_bParagraphOpened( false ), m_bParagraphOpened( false ),
m_bParagraphFrameOpen( false ), m_bParagraphFrameOpen( false ),
m_bIsFirstParagraph( true ), m_bIsFirstParagraph( true ),
......
...@@ -770,6 +770,8 @@ private: ...@@ -770,6 +770,8 @@ private:
/// The current table helper /// The current table helper
SwWriteTable *m_pTableWrt; SwWriteTable *m_pTableWrt;
sw::Frame* m_pCurrentFrame;
bool m_bParagraphOpened; bool m_bParagraphOpened;
bool m_bParagraphFrameOpen; bool m_bParagraphFrameOpen;
bool m_bIsFirstParagraph; bool m_bIsFirstParagraph;
......
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