summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>2022-08-18 11:13:31 +0200
committerSamuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>2022-08-22 08:49:05 +0200
commitf1adf4e4672b805fbda5682f4e0e6f08aed5ce79 (patch)
treeaafafc0a534ffbadc8f13ce41ab56d9439c7d90d /writerfilter
parent1e589375228b4dcee4a38122b34aea0720f888c0 (diff)
tdf#150267 RTF: Import/Export unused document variables
Previously document variables were only imported when there was a field in the document using them. This adds import/export for the RTF `docvar` group. Change-Id: I25099e037594f4b4c5530ba3a28c64aaa2927918 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138482 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> Tested-by: Jenkins
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/rtftok/rtfcontrolwords.hxx1
-rw-r--r--writerfilter/source/rtftok/rtfdispatchdestination.cxx3
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx26
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.hxx9
4 files changed, 39 insertions, 0 deletions
diff --git a/writerfilter/source/rtftok/rtfcontrolwords.hxx b/writerfilter/source/rtftok/rtfcontrolwords.hxx
index e79f4f39559f..c1480ffb0231 100644
--- a/writerfilter/source/rtftok/rtfcontrolwords.hxx
+++ b/writerfilter/source/rtftok/rtfcontrolwords.hxx
@@ -156,6 +156,7 @@ enum class Destination
PROPNAME,
STATICVAL,
GENERATOR,
+ DOCVAR,
};
enum class RTFKeyword
diff --git a/writerfilter/source/rtftok/rtfdispatchdestination.cxx b/writerfilter/source/rtftok/rtfdispatchdestination.cxx
index 3e71cfcc91ca..8789c3f858a8 100644
--- a/writerfilter/source/rtftok/rtfdispatchdestination.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchdestination.cxx
@@ -65,6 +65,9 @@ RTFError RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
m_aStates.top().setDestination(Destination::FIELD);
m_aStates.top().setFieldLocked(false);
break;
+ case RTFKeyword::DOCVAR:
+ m_aStates.top().setDestination(Destination::DOCVAR);
+ break;
case RTFKeyword::FLDINST:
{
// Look for the field type
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index c7e10a7f2284..4a5961f19355 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1483,6 +1483,11 @@ void RTFDocumentImpl::text(OUString& rString)
}
}
break;
+ case Destination::DOCVAR:
+ {
+ m_aStates.top().setDocVar(rString);
+ }
+ break;
case Destination::FONTTABLE:
case Destination::FONTENTRY:
case Destination::LEVELTEXT:
@@ -3457,6 +3462,27 @@ void RTFDocumentImpl::afterPopState(RTFParserState& rState)
if (rState.getFieldStatus() == RTFFieldStatus::INSTRUCTION)
singleChar(cFieldEnd);
break;
+ case Destination::DOCVAR:
+ if (!m_aStates.empty())
+ {
+ OUString docvar(rState.getDocVar());
+ if (m_aStates.top().getDocVarName().isEmpty())
+ {
+ m_aStates.top().setDocVarName(docvar);
+ }
+ else
+ {
+ uno::Reference<beans::XPropertySet> xMasterProperties(
+ m_xModelFactory->createInstance("com.sun.star.text.FieldMaster.User"),
+ uno::UNO_QUERY_THROW);
+ xMasterProperties->setPropertyValue("Name",
+ uno::Any(m_aStates.top().getDocVarName()));
+ xMasterProperties->setPropertyValue("Value", uno::Any(docvar));
+
+ m_aStates.top().clearDocVarName();
+ }
+ }
+ break;
case Destination::SHAPEPROPERTYVALUEPICT:
if (!m_aStates.empty())
{
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 48738135542a..208812fd4237 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -523,6 +523,11 @@ public:
void setInternalState(RTFInternalState nInternalState) { m_nInternalState = nInternalState; }
RTFInternalState getInternalState() const { return m_nInternalState; }
RTFDocumentImpl* getDocumentImpl() { return m_pDocumentImpl; }
+ OUString getDocVar() { return m_aDocVar; }
+ void setDocVar(OUString& aDocVar) { m_aDocVar = aDocVar; };
+ OUString getDocVarName() { return m_aDocVarName; }
+ void setDocVarName(OUString& aDocVarName) { m_aDocVarName = aDocVarName; }
+ void clearDocVarName() { m_aDocVarName = ""; }
private:
RTFDocumentImpl* m_pDocumentImpl;
@@ -622,6 +627,10 @@ private:
/// Width of invisible cell at the end of the row.
int m_nTableRowWidthAfter;
+
+ /// For importing document variables which are not referenced in the document
+ OUString m_aDocVar;
+ OUString m_aDocVarName;
};
/// An RTF stack is similar to std::stack, except that it has an operator[].