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

tdf#113408 RTF import style dedup: separate paragraph and character handling

The problem was that the paragraph in question had no left margin, while
it should have one. The reason for this is that the style deduplication
logic took both the current paragraph and character style, but the
direct formatting only contained character formatting, so it tried to
emit the default values for all paragraph formatting.

This started to show up after commit
657c6cc3 (tdf#104228 RTF import: fix
override of style left/right para margin, 2016-12-13), but the root
cause is much older, it was there since commit
321d7ec2 (fdo#82078 RTF import: fix bold
text spilling over to non-bold text, 2014-09-06).

Change-Id: If03240a85cc9de89afe9111c2d29de2672e407bf
Reviewed-on: https://gerrit.libreoffice.org/44097Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 4f798ed2
{\rtf1\adeflang1037\ansi\ansicpg1252\uc1\adeff1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs1025
{\fonttbl
{\f0\fbidi \froman\fcharset238\fprq2 Times New Roman;}
}
{\stylesheet
{Normal;}
{\s66\li720\ri0 List Paragraph;}
}
{\*\listtable
{\list\listtemplateid1275618250\listhybrid
{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0
\levelstartat1\levelspace0\levelindent0
{\leveltext\leveltemplateid67698703\'02\'00.;}
{\levelnumbers\'01;}
\rtlch\fcs1 \af0 \fbias0 \fi-360\li720 }
{\listname ;}
\listid1880166401}
}
{\*\listoverridetable
{\listoverride\listid1880166401\listoverridecount0\ls9}
}
\paperw12240\paperh15840\margl1440\margr1440\margt1800\margb1440\gutter0\viewkind1
\pard \s66\li720\ri0\itap0 \par
}
......@@ -743,6 +743,12 @@ DECLARE_RTFEXPORT_TEST(testPictureWrapPolygon, "picture-wrap-polygon.rtf")
CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(-67)), getProperty<sal_Int32>(getShape(1), "VertOrientPosition"));
}
DECLARE_RTFEXPORT_TEST(testTdf113408, "tdf113408.rtf")
{
// This was 0, left margin was not inherited from style properly.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin"));
}
DECLARE_RTFEXPORT_TEST(testAbi10039, "abi10039.odt")
{
// Make sure we don't just crash on export, and additionally the shape should not be inline (as it's at-page anchored originally).
......
......@@ -439,7 +439,7 @@ static void lcl_copyFlatten(RTFReferenceProperties& rProps, RTFSprms& rStyleAttr
rStyleAttributes.set(rAttribute.first, rAttribute.second);
}
writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RTFSprms& rAttributes, RTFSprms& rSprms)
writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RTFSprms& rAttributes, RTFSprms& rSprms, Id nStyleType)
{
int nStyle = 0;
if (!m_aStates.empty())
......@@ -461,13 +461,15 @@ writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RT
RTFSprms aStyleSprms;
RTFSprms aStyleAttributes;
// Ensure the paragraph style is a flat list.
lcl_copyFlatten(rProps, aStyleAttributes, aStyleSprms);
if (!nStyleType || nStyleType == NS_ooxml::LN_Value_ST_StyleType_paragraph)
lcl_copyFlatten(rProps, aStyleAttributes, aStyleSprms);
if (itChar != m_aStyleTableEntries.end())
{
// Found active character style, then update aStyleSprms/Attributes.
RTFReferenceProperties& rCharProps = *static_cast<RTFReferenceProperties*>(itChar->second.get());
lcl_copyFlatten(rCharProps, aStyleAttributes, aStyleSprms);
if (!nStyleType || nStyleType == NS_ooxml::LN_Value_ST_StyleType_character)
lcl_copyFlatten(rCharProps, aStyleAttributes, aStyleSprms);
}
// Get rid of direct formatting what is already in the style.
......@@ -491,7 +493,7 @@ void RTFDocumentImpl::checkNeedPap()
if (!m_aStates.top().pCurrentBuffer)
{
writerfilter::Reference<Properties>::Pointer_t const pParagraphProperties(
getProperties(m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms)
getProperties(m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms, NS_ooxml::LN_Value_ST_StyleType_paragraph)
);
// Writer will ignore a page break before a text frame, so guard it with empty paragraphs
......@@ -526,7 +528,7 @@ void RTFDocumentImpl::runProps()
{
if (!m_aStates.top().pCurrentBuffer)
{
writerfilter::Reference<Properties>::Pointer_t const pProperties = getProperties(m_aStates.top().aCharacterAttributes, m_aStates.top().aCharacterSprms);
Reference<Properties>::Pointer_t const pProperties = getProperties(m_aStates.top().aCharacterAttributes, m_aStates.top().aCharacterSprms, NS_ooxml::LN_Value_ST_StyleType_character);
Mapper().props(pProperties);
}
else
......@@ -1421,7 +1423,7 @@ void RTFDocumentImpl::prepareProperties(
writerfilter::Reference<Properties>::Pointer_t& o_rpTableRowProperties,
int const nCells, int const nCurrentCellX)
{
o_rpParagraphProperties = getProperties(rState.aParagraphAttributes, rState.aParagraphSprms);
o_rpParagraphProperties = getProperties(rState.aParagraphAttributes, rState.aParagraphSprms, NS_ooxml::LN_Value_ST_StyleType_paragraph);
if (rState.aFrame.hasProperties())
{
......@@ -1505,7 +1507,7 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer,
{
// Construct properties via getProperties() and not directly, to take care of deduplication.
writerfilter::Reference<Properties>::Pointer_t const pProp(
getProperties(std::get<1>(aTuple)->getAttributes(), std::get<1>(aTuple)->getSprms())
getProperties(std::get<1>(aTuple)->getAttributes(), std::get<1>(aTuple)->getSprms(), 0)
);
Mapper().props(pProp);
}
......
......@@ -476,7 +476,7 @@ private:
void runBreak();
void parBreak();
void tableBreak();
writerfilter::Reference<Properties>::Pointer_t getProperties(RTFSprms& rAttributes, RTFSprms& rSprms);
writerfilter::Reference<Properties>::Pointer_t getProperties(RTFSprms& rAttributes, RTFSprms& rSprms, Id nStyleType);
void checkNeedPap();
void sectBreak(bool bFinal = false);
void prepareProperties(
......
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