Kaydet (Commit) aaa6a520 authored tarafından Miklos Vajna's avatar Miklos Vajna

tdf#109790 RTF import: keep remembering paragraph style between \cell and \row

This is the opposite situation as tdf#44715, where the problem was that
style was not reset between in-cell paragraphs.

Here we don't want to reset the paragraph style too early, so that
direct (character) formatting isn't lost just because the theoretical
end-of-row character would not have the same direct formatting.

Change-Id: I9bb54f37804f5889fb10504ae890362a2e42122c
Reviewed-on: https://gerrit.libreoffice.org/40609Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst d99cc336
{\rtf1\adeflang1037\ansi\ansicpg1252\uc1\adeff0\deff0
\noqfpromote
{\stylesheet
{\ql \li0\ri0\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \afs20\alang1037 \ltrch\fcs0
\fs20\lang1033\langfe1033\loch\f0\hich\dbch\cgrid\langnp1033\langfenp1033 \snext0 \sqformat \spriority0 Normal;}
{\s26\fs44 \sbasedon0 \snext26 \slink27 \sqformat Subtitle;}
}
\paperw12240\paperh15840
\pard\plain Start.\par
\trowd\cellx2310\pard\plain\s26\intbl
{\fs20 XXXX}
{\fs20 \cell }
\pard
{\row }
\pard\plain End.\par
}
...@@ -1231,6 +1231,14 @@ DECLARE_RTFEXPORT_TEST(testWatermark, "watermark.rtf") ...@@ -1231,6 +1231,14 @@ DECLARE_RTFEXPORT_TEST(testWatermark, "watermark.rtf")
CPPUNIT_ASSERT_EQUAL((float)66, nFontSize); CPPUNIT_ASSERT_EQUAL((float)66, nFontSize);
} }
DECLARE_RTFEXPORT_TEST(testTdf109790, "tdf109790.rtf")
{
uno::Reference<text::XTextTable> xTable(getParagraphOrTable(2), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
// Style information was reset, which caused character height to be 22.
CPPUNIT_ASSERT_EQUAL(10.f, getProperty<float>(getRun(getParagraphOfText(1, xCell->getText()), 1), "CharHeight"));
}
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -461,9 +461,12 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) ...@@ -461,9 +461,12 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
} }
break; break;
case RTF_PARD: case RTF_PARD:
{
if (m_bHadPicture) if (m_bHadPicture)
dispatchSymbol(RTF_PAR); dispatchSymbol(RTF_PAR);
// \pard is allowed between \cell and \row, but in that case it should not reset the fact that we're inside a table. // \pard is allowed between \cell and \row, but in that case it should not reset the fact that we're inside a table.
// It should not reset the paragraph style, either, so remember the old paragraph style.
RTFValue::Pointer_t pOldStyle = m_aStates.top().aParagraphSprms.find(NS_ooxml::LN_CT_PPrBase_pStyle);
m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms; m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms;
m_aStates.top().aParagraphAttributes = m_aDefaultState.aParagraphAttributes; m_aStates.top().aParagraphAttributes = m_aDefaultState.aParagraphAttributes;
...@@ -476,13 +479,17 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) ...@@ -476,13 +479,17 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
{ {
// We are still in a table. // We are still in a table.
m_aStates.top().aParagraphSprms.set(NS_ooxml::LN_inTbl, std::make_shared<RTFValue>(1)); m_aStates.top().aParagraphSprms.set(NS_ooxml::LN_inTbl, std::make_shared<RTFValue>(1));
if (m_bAfterCellBeforeRow && pOldStyle)
// And we still have the same paragraph style.
m_aStates.top().aParagraphSprms.set(NS_ooxml::LN_CT_PPrBase_pStyle, pOldStyle);
// Ideally getDefaultSPRM() would take care of this, but it would not when we're buffering. // Ideally getDefaultSPRM() would take care of this, but it would not when we're buffering.
m_aStates.top().aParagraphSprms.set(NS_ooxml::LN_CT_PPrBase_tabs, std::make_shared<RTFValue>()); m_aStates.top().aParagraphSprms.set(NS_ooxml::LN_CT_PPrBase_tabs, std::make_shared<RTFValue>());
} }
resetFrame(); resetFrame();
// Reset currently selected paragraph style as well. // Reset currently selected paragraph style as well, unless we are in the special "after \cell, before \row" state.
// By default the style with index 0 is applied. // By default the style with index 0 is applied.
if (!m_bAfterCellBeforeRow)
{ {
OUString const aName = getStyleName(0); OUString const aName = getStyleName(0);
// But only in case it's not a character style. // But only in case it's not a character style.
...@@ -499,6 +506,7 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) ...@@ -499,6 +506,7 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
// Need to send paragraph properties again, if there will be any. // Need to send paragraph properties again, if there will be any.
m_bNeedPap = true; m_bNeedPap = true;
break; break;
}
case RTF_SECTD: case RTF_SECTD:
{ {
m_aStates.top().aSectionSprms = m_aDefaultState.aSectionSprms; m_aStates.top().aSectionSprms = m_aDefaultState.aSectionSprms;
......
...@@ -174,6 +174,9 @@ RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) ...@@ -174,6 +174,9 @@ RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
case RTF_CELL: case RTF_CELL:
case RTF_NESTCELL: case RTF_NESTCELL:
{ {
if (nKeyword == RTF_CELL)
m_bAfterCellBeforeRow = true;
checkFirstRun(); checkFirstRun();
if (m_bNeedPap) if (m_bNeedPap)
{ {
...@@ -230,6 +233,7 @@ RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) ...@@ -230,6 +233,7 @@ RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
break; break;
case RTF_ROW: case RTF_ROW:
{ {
m_bAfterCellBeforeRow = false;
if (m_aStates.top().nTableRowWidthAfter > 0) if (m_aStates.top().nTableRowWidthAfter > 0)
{ {
// Add fake cellx / cell, RTF equivalent of // Add fake cellx / cell, RTF equivalent of
......
...@@ -291,7 +291,8 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x ...@@ -291,7 +291,8 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
m_hasFHeader(false), m_hasFHeader(false),
m_hasLFooter(false), m_hasLFooter(false),
m_hasRFooter(false), m_hasRFooter(false),
m_hasFFooter(false) m_hasFFooter(false),
m_bAfterCellBeforeRow(false)
{ {
OSL_ASSERT(xInputStream.is()); OSL_ASSERT(xInputStream.is());
m_pInStream.reset(utl::UcbStreamHelper::CreateStream(xInputStream, true)); m_pInStream.reset(utl::UcbStreamHelper::CreateStream(xInputStream, true));
......
...@@ -667,6 +667,9 @@ private: ...@@ -667,6 +667,9 @@ private:
bool m_hasLFooter; bool m_hasLFooter;
bool m_hasRFooter; bool m_hasRFooter;
bool m_hasFFooter; bool m_hasFFooter;
/// Are we after a \cell, but before a \row?
bool m_bAfterCellBeforeRow;
}; };
} // namespace rtftok } // namespace rtftok
} // namespace writerfilter } // namespace writerfilter
......
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