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

fdo#82078 RTF import: fix bold text spilling over to non-bold text

Regression from commit 41890bf7
(fdo#54473 fdo#57133 fix RTF import of character styles, 2012-12-04),
the problem was that the style undoing magic introduced in
1be0a3fa (n#825305: writerfilter RTF
import: override style properties like Word, 2014-06-17) was not used
for character styles.

Change-Id: Id31cfd5574a83bcf2895f0c2fd496fa60791cbb3
üst 9e6221f1
{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0
\noqfpromote
{\stylesheet
{\ql \li0\ri0\sl240\slmult0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \f40\fs18\lang1033\langfe1033\cgrid\langnp1033\langfenp1033
\snext0 \sqformat \spriority14 \styrsid11343869 Normal;}
{\*\cs73\b Strong;}
}
\pard
{before }
{\cs73
after}
\par
}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <swmodeltestbase.hxx> #include <swmodeltestbase.hxx>
#include <com/sun/star/awt/FontDescriptor.hpp> #include <com/sun/star/awt/FontDescriptor.hpp>
#include <com/sun/star/awt/FontWeight.hpp>
#include <com/sun/star/document/XFilter.hpp> #include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/document/XImporter.hpp> #include <com/sun/star/document/XImporter.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp> #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
...@@ -1919,6 +1920,12 @@ DECLARE_RTFIMPORT_TEST(testFdo79959, "fdo79959.rtf") ...@@ -1919,6 +1920,12 @@ DECLARE_RTFIMPORT_TEST(testFdo79959, "fdo79959.rtf")
CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(getStyles("ParagraphStyles")->hasByName("Test"))); CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(getStyles("ParagraphStyles")->hasByName("Test")));
} }
DECLARE_RTFIMPORT_TEST(testFdo82078, "fdo82078.rtf")
{
// This was awt::FontWeight::BOLD, i.e. the second run was bold, when it should be normal.
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, getProperty<float>(getRun(getParagraph(1), 2), "CharWeight"));
}
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -445,9 +445,29 @@ writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RT ...@@ -445,9 +445,29 @@ writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RT
if (it != m_aStyleTableEntries.end()) if (it != m_aStyleTableEntries.end())
{ {
RTFReferenceProperties& rProps = *(RTFReferenceProperties*)it->second.get(); RTFReferenceProperties& rProps = *(RTFReferenceProperties*)it->second.get();
// cloneAndDeduplicate() wants to know about only a single "style", so
// let's merge paragraph and character style properties here.
int nCharStyle = m_aStates.top().nCurrentCharacterStyleIndex;
RTFReferenceTable::Entries_t::iterator itChar = m_aStyleTableEntries.find(nCharStyle);
RTFSprms aStyleSprms = rProps.getSprms();
RTFSprms aStyleAttributes = rProps.getAttributes();
if (itChar != m_aStyleTableEntries.end())
{
// Found active character style, then update aStyleSprms/Attributes.
RTFReferenceProperties& rCharProps = *(RTFReferenceProperties*)itChar->second.get();
RTFSprms& rCharStyleSprms = rCharProps.getSprms();
for (RTFSprms::Iterator_t itSprm = rCharStyleSprms.begin(); itSprm != rCharStyleSprms.end(); ++itSprm)
aStyleSprms.set(itSprm->first, itSprm->second);
RTFSprms& rCharStyleAttributes = rCharProps.getAttributes();
for (RTFSprms::Iterator_t itAttr = rCharStyleAttributes.begin(); itAttr != rCharStyleAttributes.end(); ++itAttr)
aStyleAttributes.set(itAttr->first, itAttr->second);
}
// Get rid of direct formatting what is already in the style. // Get rid of direct formatting what is already in the style.
RTFSprms const sprms(rSprms.cloneAndDeduplicate(rProps.getSprms())); RTFSprms const sprms(rSprms.cloneAndDeduplicate(aStyleSprms));
RTFSprms const attributes(rAttributes.cloneAndDeduplicate(rProps.getAttributes())); RTFSprms const attributes(rAttributes.cloneAndDeduplicate(aStyleAttributes));
return writerfilter::Reference<Properties>::Pointer_t(new RTFReferenceProperties(attributes, sprms)); return writerfilter::Reference<Properties>::Pointer_t(new RTFReferenceProperties(attributes, sprms));
} }
writerfilter::Reference<Properties>::Pointer_t pRet(new RTFReferenceProperties(rAttributes, rSprms)); writerfilter::Reference<Properties>::Pointer_t pRet(new RTFReferenceProperties(rAttributes, rSprms));
...@@ -2807,6 +2827,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) ...@@ -2807,6 +2827,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
m_aStates.top().aCharacterSprms = getDefaultState().aCharacterSprms; m_aStates.top().aCharacterSprms = getDefaultState().aCharacterSprms;
m_aStates.top().nCurrentEncoding = getEncoding(getFontIndex(m_nDefaultFontIndex)); m_aStates.top().nCurrentEncoding = getEncoding(getFontIndex(m_nDefaultFontIndex));
m_aStates.top().aCharacterAttributes = getDefaultState().aCharacterAttributes; m_aStates.top().aCharacterAttributes = getDefaultState().aCharacterAttributes;
m_aStates.top().nCurrentCharacterStyleIndex = -1;
} }
break; break;
case RTF_PARD: case RTF_PARD:
...@@ -3692,6 +3713,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) ...@@ -3692,6 +3713,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
} }
break; break;
case RTF_CS: case RTF_CS:
m_aStates.top().nCurrentCharacterStyleIndex = nParam;
if (m_aStates.top().nDestinationState == DESTINATION_STYLESHEET || m_aStates.top().nDestinationState == DESTINATION_STYLEENTRY) if (m_aStates.top().nDestinationState == DESTINATION_STYLESHEET || m_aStates.top().nDestinationState == DESTINATION_STYLEENTRY)
{ {
m_nCurrentStyleIndex = nParam; m_nCurrentStyleIndex = nParam;
...@@ -5937,6 +5959,7 @@ RTFParserState::RTFParserState(RTFDocumentImpl* pDocumentImpl) ...@@ -5937,6 +5959,7 @@ RTFParserState::RTFParserState(RTFDocumentImpl* pDocumentImpl)
nMinute(0), nMinute(0),
pDestinationText(0), pDestinationText(0),
nCurrentStyleIndex(-1), nCurrentStyleIndex(-1),
nCurrentCharacterStyleIndex(-1),
pCurrentBuffer(0), pCurrentBuffer(0),
bInListpicture(false), bInListpicture(false),
bInBackground(false), bInBackground(false),
......
...@@ -279,6 +279,8 @@ public: ...@@ -279,6 +279,8 @@ public:
/// Index of the current style. /// Index of the current style.
int nCurrentStyleIndex; int nCurrentStyleIndex;
/// Index of the current character style.
int nCurrentCharacterStyleIndex;
/// Points to the active buffer, if there is one. /// Points to the active buffer, if there is one.
RTFBuffer_t* pCurrentBuffer; RTFBuffer_t* pCurrentBuffer;
......
...@@ -143,6 +143,7 @@ static RTFValue::Pointer_t getDefaultSPRM(Id const id) ...@@ -143,6 +143,7 @@ static RTFValue::Pointer_t getDefaultSPRM(Id const id)
{ {
case NS_ooxml::LN_CT_Spacing_before: case NS_ooxml::LN_CT_Spacing_before:
case NS_ooxml::LN_CT_Spacing_after: case NS_ooxml::LN_CT_Spacing_after:
case NS_ooxml::LN_EG_RPrBase_b:
return RTFValue::Pointer_t(new RTFValue(0)); return RTFValue::Pointer_t(new RTFValue(0));
default: default:
......
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