11#include <ooxml/resourceids.hxx>
13#include <rtl/strbuf.hxx>
20 : m_nKeyword(nKeyword)
41 OStringBuffer
aBuf(
"RTFSprm");
46 if (sResult.length() == 0)
49 aBuf.append(sResult.c_str());
52 return std::string(
aBuf);
63 RTFSprms_compare(
Id keyword)
67 bool operator()(
const std::pair<Id, RTFValue::Pointer_t>& raPair)
const
79 RTFSprms_compare cmp{ nKeyword };
107 std::remove_if(
m_pSprms->begin(),
m_pSprms->end(), RTFSprms_compare{ nKeyword }),
115 = std::find_if(
m_pSprms->begin(),
m_pSprms->end(), RTFSprms_compare{ nKeyword });
119 m_pSprms->emplace_back(nKeyword, pValue);
124 if (std::none_of(
m_pSprms->cbegin(),
m_pSprms->cend(), RTFSprms_compare{ nKeyword }))
125 m_pSprms->emplace_back(nKeyword, pValue);
130 m_pSprms->emplace_back(nKeyword, pValue);
140 auto i = std::find_if(
m_pSprms->begin(),
m_pSprms->end(), RTFSprms_compare{ nKeyword });
153 auto i = std::find_if(
m_pSprms->rbegin(),
m_pSprms->rend(), RTFSprms_compare{ nKeyword });
160 if (nStyleType == NS_ooxml::LN_Value_ST_StyleType_character)
164 case NS_ooxml::LN_EG_RPrBase_szCs:
165 case NS_ooxml::LN_EG_RPrBase_sz:
167 case NS_ooxml::LN_CT_Color_val:
169 case NS_ooxml::LN_EG_RPrBase_b:
170 case NS_ooxml::LN_EG_RPrBase_i:
172 case NS_ooxml::LN_CT_Underline_val:
173 return new RTFValue(NS_ooxml::LN_Value_ST_Underline_none);
174 case NS_ooxml::LN_CT_Fonts_ascii:
175 case NS_ooxml::LN_CT_Fonts_eastAsia:
176 case NS_ooxml::LN_CT_Fonts_cs:
177 return new RTFValue(
"Times New Roman");
183 if (!nStyleType || nStyleType == NS_ooxml::LN_Value_ST_StyleType_paragraph)
187 case NS_ooxml::LN_CT_Spacing_before:
188 case NS_ooxml::LN_CT_Spacing_after:
189 case NS_ooxml::LN_CT_Ind_left:
190 case NS_ooxml::LN_CT_Ind_right:
191 case NS_ooxml::LN_CT_Ind_firstLine:
193 case NS_ooxml::LN_CT_Spacing_lineRule:
194 return new RTFValue(NS_ooxml::LN_Value_doc_ST_LineSpacingRule_auto);
195 case NS_ooxml::LN_CT_Spacing_line:
198 case NS_ooxml::LN_CT_NumPr_numId:
200 case NS_ooxml::LN_CT_PrBase_pBdr:
204 for (
int i = 0;
i < 4; ++
i)
209 aAttributes.
set(NS_ooxml::LN_CT_Border_val,
210 new RTFValue(NS_ooxml::LN_Value_ST_Border_none));
213 return new RTFValue(attributes, sprms);
231 case NS_ooxml::LN_CT_TabStop_val:
232 case NS_ooxml::LN_CT_TabStop_leader:
233 case NS_ooxml::LN_CT_TabStop_pos:
236 case NS_ooxml::LN_CT_Spacing_beforeAutospacing:
237 case NS_ooxml::LN_CT_Spacing_afterAutospacing:
243 case NS_ooxml::LN_CT_Border_sz:
244 case NS_ooxml::LN_CT_Border_val:
245 case NS_ooxml::LN_CT_Border_color:
246 case NS_ooxml::LN_CT_Border_space:
247 case NS_ooxml::LN_CT_Border_shadow:
248 case NS_ooxml::LN_CT_Border_frame:
249 case NS_ooxml::LN_CT_Border_themeTint:
250 case NS_ooxml::LN_CT_Border_themeColor:
254 case NS_ooxml::LN_CT_Ind_firstLine:
255 case NS_ooxml::LN_CT_Ind_left:
256 return pDirect && pDirect->
find(NS_ooxml::LN_CT_PPrBase_numPr);
268 case NS_ooxml::LN_CT_PBdr_top:
269 case NS_ooxml::LN_CT_PBdr_left:
270 case NS_ooxml::LN_CT_PBdr_bottom:
271 case NS_ooxml::LN_CT_PBdr_right:
273 case NS_ooxml::LN_CT_PrBase_shd:
275 case NS_ooxml::LN_CT_PPrBase_ind:
291 if (rSprm.second->equals(*pValue))
295 ret.
erase(rSprm.first);
298 else if (!rSprm.second->getSprms().empty() || !rSprm.second->getAttributes().empty())
300 RTFSprms const sprms(pValue->getSprms().cloneAndDeduplicate(
301 rSprm.second->getSprms(), nStyleType,
false, pDirect));
302 RTFSprms const attributes(pValue->getAttributes().cloneAndDeduplicate(
303 rSprm.second->getAttributes(), nStyleType,
false, pDirect));
316 ret.
set(rSprm.first, pDefault);
318 else if (!rSprm.second->getSprms().empty() || !rSprm.second->getAttributes().empty())
321 RTFSprms().cloneAndDeduplicate(rSprm.second->getSprms(), nStyleType));
323 RTFSprms().cloneAndDeduplicate(rSprm.second->getAttributes(), nStyleType));
326 ret.
set(rSprm.first,
new RTFValue(attributes, sprms));
335 for (
const auto& rPair : pAbstract->getSprms())
337 if (rPair.first != NS_ooxml::LN_CT_AbstractNum_lvl)
344 if (pLevel->getInt() != nLevel)
357 =
getNestedSprm(*
this, NS_ooxml::LN_CT_PPrBase_numPr, NS_ooxml::LN_CT_NumPr_ilvl);
359 nLevel = pLevelId->getInt();
361 auto it = rInvalidListLevelFirstIndents.find(nLevel);
362 if (it == rInvalidListLevelFirstIndents.end())
365 int nListValue = it->second;
368 =
getNestedAttribute(*
this, NS_ooxml::LN_CT_PPrBase_ind, NS_ooxml::LN_CT_Ind_firstLine);
369 if (!pParagraphValue)
382 =
getNestedSprm(*
this, NS_ooxml::LN_CT_PPrBase_numPr, NS_ooxml::LN_CT_NumPr_ilvl);
384 nLevel = pLevelId->getInt();
394 for (
const auto& rListLevelPair : pLevelInd->getAttributes())
396 switch (rListLevelPair.first)
398 case NS_ooxml::LN_CT_Ind_left:
399 case NS_ooxml::LN_CT_Ind_right:
400 case NS_ooxml::LN_CT_Ind_firstLine:
403 if (!pParagraphValue)
413 bool const bImplicitPPr,
RTFSprms* pDirect)
const
420 for (
auto& rSprm : rReference)
426 if (bImplicitPPr && rSprm.first == NS_ooxml::LN_CT_Style_pPr)
428 for (
const auto&
i : rSprm.second->getSprms())
440 [&](
const std::pair<Id, RTFValue::Pointer_t>& raPair) ->
bool {
441 return raPair.second->equals(rOther);
tools::SvRef< Value > Pointer_t
Pointer to a value.
RTFValue::Pointer_t & m_pValue
writerfilter::Reference< Properties >::Pointer_t getProps() override
Returns reference to properties contained in the SPRM.
std::string getName() const override
Returns name of sprm.
Value::Pointer_t getValue() override
Returns value of the SPRM.
sal_uInt32 getId() const override
Returns id of the SPRM.
std::string toString() const override
Returns string representation of sprm.
RTFSprm(Id nKeyword, RTFValue::Pointer_t &pValue)
The payload of RTFSprms which is only copied on write.
A list of RTFSprm with a copy constructor that performs a deep copy.
RTFValue::Pointer_t find(Id nKeyword, bool bFirst=true, bool bForWrite=false)
bool equals(const RTFValue &rOther) const
void deduplicateList(const std::map< int, int > &rInvalidListLevelFirstIndents)
Removes duplicated values based on in-list properties.
void set(Id nKeyword, const RTFValue::Pointer_t &pValue, RTFOverwrite eOverwrite=RTFOverwrite::YES)
Does the same as ->push_back(), except that it can overwrite or ignore existing entries.
tools::SvRef< RTFSprmsImpl > m_pSprms
void eraseLast(Id nKeyword)
RTFSprms cloneAndDeduplicate(RTFSprms &rReference, Id nStyleType, bool bImplicitPPr=false, RTFSprms *pDirect=nullptr) const
Removes elements which are already in the reference set.
void ensureCopyBeforeWrite()
void duplicateList(const RTFValue::Pointer_t &pAbstract)
Inserts default values to override attributes of pAbstract.
tools::SvRef< RTFValue > Pointer_t
ParagraphAdjust nParagraphValue
tools::Long const nBorder
static bool isSPRMDeduplicateDenylist(Id nId, RTFSprms *pDirect)
Is it problematic to deduplicate this SPRM?
static bool isSPRMChildrenExpected(Id nId)
Should this SPRM be removed if all its children are removed?
RTFValue::Pointer_t getNestedAttribute(RTFSprms &rSprms, Id nParent, Id nId)
Looks up the nParent then the nested nId attribute in rSprms.
static void cloneAndDeduplicateSprm(std::pair< Id, RTFValue::Pointer_t > const &rSprm, RTFSprms &ret, Id nStyleType, RTFSprms *pDirect=nullptr)
Does the clone / deduplication of a single sprm.
void putNestedAttribute(RTFSprms &rSprms, Id nParent, Id nId, const RTFValue::Pointer_t &pValue, RTFOverwrite eOverwrite, bool bAttribute)
bool eraseNestedAttribute(RTFSprms &rSprms, Id nParent, Id nId)
@ NO_IGNORE
No, if the key is already in the list, then ignore, otherwise append.
@ NO_APPEND
No, always append the value to the end of the list.
@ YES_PREPEND
Yes, always prepend the value to the start of the list and remove existing entries.
@ YES
Yes, if an existing key is found, overwrite it.
RTFValue::Pointer_t getNestedSprm(RTFSprms &rSprms, Id nParent, Id nId)
Looks up the nParent then the nested nId sprm in rSprms.
Id getParagraphBorder(sal_uInt32 nIndex)
static RTFValue::Pointer_t getDefaultSPRM(Id const id, Id nStyleType)
static RTFValue::Pointer_t getListLevel(const RTFValue::Pointer_t &pAbstract, int nLevel)
Extracts the list level matching nLevel from pAbstract.
std::string QNameToString(Id)