1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
17 #include <tools/ref.hxx>
18 #include "rtfvalue.hxx"
20 namespace writerfilter::rtftok
22 using RTFSprmsImplBase
= std::vector
<std::pair
<Id
, RTFValue::Pointer_t
>>;
24 /// The payload of RTFSprms which is only copied on write.
25 class RTFSprmsImpl
: public RTFSprmsImplBase
, public virtual SvRefBase
29 enum class RTFOverwrite
31 YES
, ///< Yes, if an existing key is found, overwrite it.
32 NO_APPEND
, ///< No, always append the value to the end of the list.
33 NO_IGNORE
, ///< No, if the key is already in the list, then ignore, otherwise append.
34 YES_PREPEND
///< Yes, always prepend the value to the start of the list and remove existing entries.
37 /// A list of RTFSprm with a copy constructor that performs a deep copy.
38 class RTFSprms
: public virtual SvRefBase
41 using Pointer_t
= tools::SvRef
<RTFSprms
>;
42 using Entry_t
= std::pair
<Id
, RTFValue::Pointer_t
>;
43 using Iterator_t
= std::vector
<Entry_t
>::iterator
;
44 using ReverseIterator_t
= std::vector
<Entry_t
>::reverse_iterator
;
48 RTFSprms(RTFSprms
const&) = default;
49 RTFSprms(RTFSprms
&&) = default;
50 RTFSprms
& operator=(RTFSprms
const&) = default;
51 RTFSprms
& operator=(RTFSprms
&&) = default;
53 RTFValue::Pointer_t
find(Id nKeyword
, bool bFirst
= true, bool bForWrite
= false);
54 /// Does the same as ->push_back(), except that it can overwrite or ignore existing entries.
55 void set(Id nKeyword
, const RTFValue::Pointer_t
& pValue
,
56 RTFOverwrite eOverwrite
= RTFOverwrite::YES
);
57 bool erase(Id nKeyword
);
58 void eraseLast(Id nKeyword
);
59 /// Removes elements which are already in the reference set.
60 /// Also insert default values to override attributes of style
61 /// (yes, really; that's what Word does).
62 /// @param bImplicitPPr implicit dereference of top-level pPr SPRM
63 /// @param pDirect pointer to the root of the direct formatting SPRM tree, if any
64 RTFSprms
cloneAndDeduplicate(RTFSprms
& rReference
, Id nStyleType
, bool bImplicitPPr
= false,
65 RTFSprms
* pDirect
= nullptr) const;
66 /// Inserts default values to override attributes of pAbstract.
67 void duplicateList(const RTFValue::Pointer_t
& pAbstract
);
68 /// Removes duplicated values based on in-list properties.
69 void deduplicateList(const std::map
<int, int>& rInvalidListLevelFirstIndents
);
70 std::size_t size() const { return m_pSprms
->size(); }
71 bool empty() const { return m_pSprms
->empty(); }
72 Entry_t
& back() { return m_pSprms
->back(); }
73 Iterator_t
begin() { return m_pSprms
->begin(); }
74 Iterator_t
end() { return m_pSprms
->end(); }
76 bool equals(const RTFSprms
& rOther
) const;
79 void ensureCopyBeforeWrite();
80 tools::SvRef
<RTFSprmsImpl
> m_pSprms
;
83 /// RTF keyword with a parameter
84 class RTFSprm
: public Sprm
87 RTFSprm(Id nKeyword
, RTFValue::Pointer_t
& pValue
);
88 sal_uInt32
getId() const override
;
89 Value::Pointer_t
getValue() override
;
90 writerfilter::Reference
<Properties
>::Pointer_t
getProps() override
;
92 std::string
getName() const override
;
93 std::string
toString() const override
;
97 RTFValue::Pointer_t
& m_pValue
;
99 } // namespace writerfilter::rtftok
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */