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

RTF filter: handle user-defined document properties of type bool

Next to number and string.

Change-Id: I76f78197412606f00559c1c2790b7c70117ef1c1
Reviewed-on: https://gerrit.libreoffice.org/31767Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 73131fc3
......@@ -9,5 +9,11 @@
{\propname n}
\proptype3
{\staticval 42}
{\propname by}
\proptype11
{\staticval 1}
{\propname bn}
\proptype11
{\staticval 0}
}
}
......@@ -1010,6 +1010,10 @@ DECLARE_RTFEXPORT_TEST(testCustomDocProps, "custom-doc-props.rtf")
CPPUNIT_ASSERT_EQUAL(OUString("None"), getProperty<OUString>(xUserDefinedProperties, "urn:bails:IntellectualProperty:Authorization:StopValidity"));
// Test roundtrip of numbers. This failed as getProperty() did not find "n".
CPPUNIT_ASSERT_EQUAL(42.0, getProperty<double>(xUserDefinedProperties, "n"));
// Test boolean "yes".
CPPUNIT_ASSERT(getProperty<bool>(xUserDefinedProperties, "by"));
// Test boolean "no".
CPPUNIT_ASSERT(!getProperty<bool>(xUserDefinedProperties, "bn"));
}
DECLARE_RTFEXPORT_TEST(testTdf65642, "tdf65642.rtf")
......
......@@ -469,6 +469,12 @@ void RtfExport::WriteInfo()
Strm().WriteChar('}');
}
void RtfExport::WriteUserPropType(int nType)
{
Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PROPTYPE);
OutULong(nType);
}
void RtfExport::WriteUserPropValue(const OUString& rValue)
{
Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_STATICVAL " ");
......@@ -517,17 +523,21 @@ void RtfExport::WriteUserProps()
// Property value.
OUString aValue;
double fValue;
bool bValue;
uno::Any aAny = xPropertySet->getPropertyValue(rProperty.Name);
if (aAny >>= aValue)
if (aAny >>= bValue)
{
WriteUserPropType(11);
WriteUserPropValue(OUString::number(static_cast<int>(bValue)));
}
else if (aAny >>= aValue)
{
Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PROPTYPE);
OutULong(30);
WriteUserPropType(30);
WriteUserPropValue(aValue);
}
else if (aAny >>= fValue)
{
Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PROPTYPE);
OutULong(3);
WriteUserPropType(3);
WriteUserPropValue(OUString::number(fValue));
}
}
......
......@@ -204,6 +204,8 @@ private:
void WriteFootnoteSettings();
void WriteMainText();
void WriteInfo();
/// Writes a single user property type.
void WriteUserPropType(int nType);
/// Writes a single user property value.
void WriteUserPropValue(const OUString& rValue);
/// Writes the userprops group: user defined document properties.
......
......@@ -1397,6 +1397,9 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
case 3:
m_aStates.top().aPropType = cppu::UnoType<sal_Int32>::get();
break;
case 11:
m_aStates.top().aPropType = cppu::UnoType<bool>::get();
break;
case 30:
m_aStates.top().aPropType = cppu::UnoType<OUString>::get();
break;
......
......@@ -2685,6 +2685,8 @@ RTFError RTFDocumentImpl::popState()
aAny = uno::makeAny(aStaticVal);
else if (m_aStates.top().aPropType == cppu::UnoType<sal_Int32>::get())
aAny = uno::makeAny(aStaticVal.toInt32());
else if (m_aStates.top().aPropType == cppu::UnoType<bool>::get())
aAny = uno::makeAny(aStaticVal.toBoolean());
xPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aAny);
}
......
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