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 #include <format.hxx>
31 
32 Writer& Out( const SwAttrFnTab pTab, const SfxPoolItem& rHt, Writer & rWrt )
33 {
34  sal_uInt16 nId = rHt.Which();
35  OSL_ENSURE( nId < POOLATTR_END && nId >= POOLATTR_BEGIN, "SwAttrFnTab::Out()" );
36  FnAttrOut pOut;
37  if( nullptr != ( pOut = pTab[ nId - RES_CHRATR_BEGIN] ))
38  (*pOut)( rWrt, rHt );
39  return rWrt;
40 
41 }
42 
44  const SfxItemSet& rSet, bool bDeep )
45 {
46  // at first give the own attributes out
47  const SfxItemPool& rPool = *rSet.GetPool();
48  const SfxItemSet* pSet = &rSet;
49  if( !pSet->Count() ) // Optimizing - empty Sets
50  {
51  if( !bDeep )
52  return rWrt;
53  while( nullptr != ( pSet = pSet->GetParent() ) && !pSet->Count() )
54  ;
55  if( !pSet )
56  return rWrt;
57  }
58  const SfxPoolItem* pItem(nullptr);
59  FnAttrOut pOut;
60 
61  // tdf#94088 check if any FillAttribute is used [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
62  // while processing the items
63  bool bFillItemUsed = false;
64 
65  if( !bDeep || !pSet->GetParent() )
66  {
67  OSL_ENSURE( rSet.Count(), "It has been handled already, right?" );
68  SfxItemIter aIter( *pSet );
69  pItem = aIter.GetCurItem();
70  do {
71  // pTab only covers POOLATTR_BEGIN..POOLATTR_END.
72  if( pItem->Which() <= POOLATTR_END )
73  {
74  if( nullptr != ( pOut = pTab[ pItem->Which() - RES_CHRATR_BEGIN]) )
75  {
76  (*pOut)( rWrt, *pItem );
77  }
78  }
79  else if(XATTR_FILLSTYLE == pItem->Which())
80  {
81  bFillItemUsed = true;
82  }
83  } while( !aIter.IsAtEnd() && nullptr != ( 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  if( nullptr != ( pOut = pTab[ nWhich - RES_CHRATR_BEGIN] ))
98  {
99  (*pOut)( rWrt, *pItem );
100  }
101  else if(XATTR_FILLSTYLE == pItem->Which())
102  {
103  bFillItemUsed = true;
104  }
105  }
106  nWhich = aIter.NextWhich();
107  }
108  }
109 
110  if(bFillItemUsed)
111  {
112  // tdf#94088 if used, construct a SvxBrushItem and export it using the
113  // existing mechanisms.
114  // This is the right place in the future if the adapted fill attributes
115  // may be handled more directly in HTML export to handle them.
116  const std::shared_ptr<SvxBrushItem> aSvxBrushItem(getSvxBrushItemFromSourceSet(*pSet, RES_BACKGROUND, bDeep));
117 
118  if( nullptr != ( pOut = pTab[RES_BACKGROUND - RES_CHRATR_BEGIN] ))
119  {
120  (*pOut)( rWrt, *aSvxBrushItem );
121  }
122  }
123 
124  return rWrt;
125 }
126 
127 Writer& Out( const SwNodeFnTab pTab, SwNode& rNode, Writer & rWrt )
128 {
129  // It must be a ContentNode!
130  SwContentNode * pCNd = rNode.GetContentNode();
131  if( !pCNd )
132  return rWrt;
133 
134  sal_uInt16 nId = RES_TXTNODE;
135  switch (pCNd->GetNodeType())
136  {
137  case SwNodeType::Text:
138  nId = RES_TXTNODE;
139  break;
140  case SwNodeType::Grf:
141  nId = RES_GRFNODE;
142  break;
143  case SwNodeType::Ole:
144  nId = RES_OLENODE;
145  break;
146  default:
147  OSL_FAIL("What kind of node is it now?");
148  break;
149  }
150  FnNodeOut pOut;
151  if( nullptr != ( pOut = pTab[ nId - RES_NODE_BEGIN ] ))
152  (*pOut)( rWrt, *pCNd );
153  return rWrt;
154 }
155 
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< SvxBrushItem > getSvxBrushItemFromSourceSet(const SfxItemSet &rSourceSet, sal_uInt16 nBackgroundID, bool bSearchInParents, bool bXMLImportHack)
FnNodeOut SwNodeFnTab[RES_NODE_END-RES_NODE_BEGIN]
Definition: wrt_fn.hxx:50
sal_Int16 nId
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
#define POOLATTR_END
Definition: hintids.hxx:64
SwNodeType GetNodeType() const
Definition: node.hxx:144
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:43
#define RES_BACKGROUND
Definition: hintids.hxx:210
#define POOLATTR_BEGIN
Definition: hintids.hxx:63
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
#define RES_CHRATR_BEGIN
Definition: hintids.hxx:68
Writer & Out(const SwAttrFnTab pTab, const SfxPoolItem &rHt, Writer &rWrt)
Definition: wrt_fn.cxx:32
Writer &(* FnNodeOut)(Writer &, SwContentNode &)
Definition: wrt_fn.hxx:49
#define XATTR_FILLSTYLE
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
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