LibreOffice Module sw (master)  1
wrt_fn.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <svl/itemiter.hxx>
21 #include <svl/whiter.hxx>
22 #include <osl/diagnose.h>
23 
24 // tdf#94088 SdrAllFillAttributesHelper needed
26 
27 #include <shellio.hxx>
28 #include <wrt_fn.hxx>
29 #include <node.hxx>
30 
31 Writer& Out( const SwAttrFnTab pTab, const SfxPoolItem& rHt, Writer & rWrt )
32 {
33  sal_uInt16 nId = rHt.Which();
34  OSL_ENSURE( nId < POOLATTR_END && nId >= POOLATTR_BEGIN, "SwAttrFnTab::Out()" );
35  FnAttrOut pOut = pTab[ nId - RES_CHRATR_BEGIN];
36  if( nullptr != pOut )
37  (*pOut)( rWrt, rHt );
38  return rWrt;
39 
40 }
41 
43  const SfxItemSet& rSet, bool bDeep )
44 {
45  // at first give the own attributes out
46  const SfxItemPool& rPool = *rSet.GetPool();
47  const SfxItemSet* pSet = &rSet;
48  if( !pSet->Count() ) // Optimizing - empty Sets
49  {
50  if( !bDeep )
51  return rWrt;
52  while( nullptr != ( pSet = pSet->GetParent() ) && !pSet->Count() )
53  ;
54  if( !pSet )
55  return rWrt;
56  }
57  const SfxPoolItem* pItem(nullptr);
59 
60  // tdf#94088 check if any FillAttribute is used [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
61  // while processing the items
62  bool bFillItemUsed = false;
63 
64  if( !bDeep || !pSet->GetParent() )
65  {
66  OSL_ENSURE( rSet.Count(), "It has been handled already, right?" );
67  SfxItemIter aIter( *pSet );
68  pItem = aIter.GetCurItem();
69  do {
70  // pTab only covers POOLATTR_BEGIN..POOLATTR_END.
71  if( pItem->Which() <= POOLATTR_END )
72  {
73  pOut = pTab[ pItem->Which() - RES_CHRATR_BEGIN];
74  if( nullptr != pOut )
75  {
76  (*pOut)( rWrt, *pItem );
77  }
78  }
79  else if(XATTR_FILLSTYLE == pItem->Which())
80  {
81  bFillItemUsed = true;
82  }
83  } while ((pItem = aIter.NextItem()));
84  }
85  else
86  {
87  SfxWhichIter aIter( *pSet );
88  sal_uInt16 nWhich = aIter.FirstWhich();
89  while( nWhich )
90  {
91  if( SfxItemState::SET == pSet->GetItemState( nWhich, bDeep, &pItem ) &&
92  ( *pItem != rPool.GetDefaultItem( nWhich )
93  || ( pSet->GetParent() &&
94  *pItem != pSet->GetParent()->Get( nWhich ))
95  ))
96  {
97  pOut = pTab[ nWhich - RES_CHRATR_BEGIN];
98  if( nullptr != pOut )
99  {
100  (*pOut)( rWrt, *pItem );
101  }
102  else if(XATTR_FILLSTYLE == pItem->Which())
103  {
104  bFillItemUsed = true;
105  }
106  }
107  nWhich = aIter.NextWhich();
108  }
109  }
110 
111  if(bFillItemUsed)
112  {
113  // tdf#94088 if used, construct a SvxBrushItem and export it using the
114  // existing mechanisms.
115  // This is the right place in the future if the adapted fill attributes
116  // may be handled more directly in HTML export to handle them.
117  const std::unique_ptr<SvxBrushItem> aSvxBrushItem(getSvxBrushItemFromSourceSet(*pSet, RES_BACKGROUND, bDeep));
118 
119  pOut = pTab[RES_BACKGROUND - RES_CHRATR_BEGIN];
120  if( nullptr != pOut )
121  {
122  (*pOut)( rWrt, *aSvxBrushItem );
123  }
124  }
125 
126  return rWrt;
127 }
128 
129 Writer& Out( const SwNodeFnTab pTab, SwNode& rNode, Writer & rWrt )
130 {
131  // It must be a ContentNode!
132  SwContentNode * pCNd = rNode.GetContentNode();
133  if( !pCNd )
134  return rWrt;
135 
136  sal_uInt16 nId = RES_TXTNODE;
137  switch (pCNd->GetNodeType())
138  {
139  case SwNodeType::Text:
140  nId = RES_TXTNODE;
141  break;
142  case SwNodeType::Grf:
143  nId = RES_GRFNODE;
144  break;
145  case SwNodeType::Ole:
146  nId = RES_OLENODE;
147  break;
148  default:
149  OSL_FAIL("What kind of node is it now?");
150  break;
151  }
152  FnNodeOut pOut = pTab[ nId - RES_NODE_BEGIN ];
153  if( nullptr != pOut )
154  (*pOut)( rWrt, *pCNd );
155  return rWrt;
156 }
157 
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< SvxBrushItem > getSvxBrushItemFromSourceSet(const SfxItemSet &rSourceSet, sal_uInt16 nBackgroundID, bool bSearchInParents, bool bXMLImportHack)
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
FnNodeOut SwNodeFnTab[RES_NODE_END-RES_NODE_BEGIN]
Definition: wrt_fn.hxx:50
sal_Int16 nId
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
SwNodeType GetNodeType() const
Definition: node.hxx:144
constexpr sal_uInt16 POOLATTR_BEGIN(HINT_BEGIN)
oslFileHandle & pOut
FnAttrOut SwAttrFnTab[POOLATTR_END-POOLATTR_BEGIN]
Definition: wrt_fn.hxx:32
Writer & Out_SfxItemSet(const SwAttrFnTab pTab, Writer &rWrt, const SfxItemSet &rSet, bool bDeep)
Definition: wrt_fn.cxx:42
const SfxItemSet * GetParent() const
Writer &(* FnAttrOut)(Writer &, const SfxPoolItem &)
Definition: wrt_fn.hxx:31
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
SwContentNode * GetContentNode()
Definition: node.hxx:615
sal_uInt16 Count() const
Writer & Out(const SwAttrFnTab pTab, const SfxPoolItem &rHt, Writer &rWrt)
Definition: wrt_fn.cxx:31
Writer &(* FnNodeOut)(Writer &, SwContentNode &)
Definition: wrt_fn.hxx:49
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
constexpr sal_uInt16 POOLATTR_END(RES_UNKNOWNATR_END)
constexpr sal_uInt16 RES_CHRATR_BEGIN(HINT_BEGIN)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
sal_uInt16 Which() const
Base class of the Writer document model elements.
Definition: node.hxx:79