LibreOffice Module sw (master)  1
txatbase.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 <optional>
21 #include <libxml/xmlwriter.h>
22 #include <svl/itempool.hxx>
23 #include <txatbase.hxx>
24 #include <fmtfld.hxx>
25 
26 SwTextAttr::SwTextAttr( SfxPoolItem& rAttr, sal_Int32 nStart )
27  : m_pAttr( &rAttr )
28  , m_nStart( nStart )
29  , m_bDontExpand( false )
30  , m_bLockExpandFlag( false )
31  , m_bDontMoveAttr( false )
32  , m_bCharFormatAttr( false )
33  , m_bOverlapAllowedAttr( false )
34  , m_bPriorityAttr( false )
35  , m_bDontExpandStart( false )
36  , m_bNesting( false )
37  , m_bHasDummyChar( false )
38  , m_bFormatIgnoreStart(false)
39  , m_bFormatIgnoreEnd(false)
40  , m_bHasContent( false )
41 {
42 }
43 
44 SwTextAttr::~SwTextAttr() COVERITY_NOEXCEPT_FALSE
45 {
46 }
47 
48 const sal_Int32* SwTextAttr::GetEnd() const
49 {
50  return nullptr;
51 }
52 
53 void SwTextAttr::SetEnd(sal_Int32 )
54 {
55  assert(false);
56 }
57 
58 void SwTextAttr::Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool )
59 {
60  if (!pToDestroy) return;
61  SfxPoolItem * const pAttr = pToDestroy->m_pAttr;
62  delete pToDestroy;
63  rPool.Remove( *pAttr );
64 }
65 
66 bool SwTextAttr::operator==( const SwTextAttr& rAttr ) const
67 {
68  return GetAttr() == rAttr.GetAttr();
69 }
70 
72  sal_Int32 nStart, sal_Int32 nEnd ) :
73  SwTextAttr( rAttr, nStart ), m_nEnd( nEnd )
74 {
75 }
76 
77 const sal_Int32* SwTextAttrEnd::GetEnd() const
78 {
79  return & m_nEnd;
80 }
81 
82 void SwTextAttrEnd::SetEnd(sal_Int32 n)
83 {
84  m_nEnd = n;
85  if (m_pHints)
87 }
88 
90 {
91  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextAttr"));
92  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
93  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s",
94  BAD_CAST(typeid(*this).name()));
95 
96  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("start"), BAD_CAST(OString::number(m_nStart).getStr()));
97  if (End())
98  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("end"), BAD_CAST(OString::number(*End()).getStr()));
99  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
100  const char* pWhich = nullptr;
101  std::optional<OString> oValue;
102  switch (Which())
103  {
104  case RES_TXTATR_AUTOFMT:
105  pWhich = "autofmt";
106  break;
108  pWhich = "annotation";
109  break;
110  case RES_TXTATR_FLYCNT:
111  pWhich = "fly content";
112  break;
113  case RES_TXTATR_CHARFMT:
114  {
115  pWhich = "character format";
116  if (SwCharFormat* pCharFormat = GetCharFormat().GetCharFormat())
117  oValue = OString("name: " + OUStringToOString(pCharFormat->GetName(), RTL_TEXTENCODING_UTF8));
118  break;
119  }
120  case RES_TXTATR_INETFMT:
121  {
122  pWhich = "inet format";
123  const SwFormatINetFormat& rFormat = GetINetFormat();
124  oValue = OString("url: " + rFormat.GetValue().toUtf8());
125  break;
126  }
127  case RES_TXTATR_CJK_RUBY:
128  {
129  pWhich = "ruby";
130  const SwFormatRuby& rFormat = GetRuby();
131  oValue = OString("rubytext: " + rFormat.GetText().toUtf8());
132  break;
133  }
134  case RES_TXTATR_META:
135  {
136  pWhich = "meta";
137  break;
138  }
139  case RES_TXTATR_FIELD:
140  {
141  pWhich = "field";
142  break;
143  }
144  default:
145  break;
146  }
147  if (pWhich)
148  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("which"), BAD_CAST(pWhich));
149  if (oValue)
150  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(oValue->getStr()));
151  switch (Which())
152  {
153  case RES_TXTATR_AUTOFMT:
154  GetAutoFormat().dumpAsXml(pWriter);
155  break;
156  case RES_TXTATR_FIELD:
158  GetFormatField().dumpAsXml(pWriter);
159  break;
160  case RES_TXTATR_FTN:
161  break;
162  default:
163  SAL_WARN("sw.core", "Unhandled TXTATR");
164  break;
165  }
166 
167  (void)xmlTextWriterEndElement(pWriter);
168 }
169 
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nEnd
Definition: txatbase.hxx:134
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_META(48)
virtual const sal_Int32 * GetEnd() const
end position
Definition: txatbase.cxx:48
virtual void SetEnd(sal_Int32) override
Definition: txatbase.cxx:82
SwpHints * m_pHints
Definition: txatbase.hxx:65
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(57)
SfxPoolItem *const m_pAttr
Definition: txatbase.hxx:45
sal_uInt16 Which() const
Definition: txatbase.hxx:114
virtual const sal_Int32 * GetEnd() const override
end position
Definition: txatbase.cxx:77
void Remove(const SfxPoolItem &)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(59)
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fmtatr2.cxx:143
sal_Int32 m_nStart
Definition: txatbase.hxx:46
SwTextAttr(SwTextAttr const &)=delete
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
constexpr TypedWhichId< SwFormatRuby > RES_TXTATR_CJK_RUBY(53)
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:195
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
constexpr TypedWhichId< SwFormatAutoFormat > RES_TXTATR_AUTOFMT(50)
constexpr TypedWhichId< SwFormatFootnote > RES_TXTATR_FTN(58)
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
const OUString & GetText() const
Definition: fmtruby.hxx:61
struct _xmlTextWriter * xmlTextWriterPtr
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE
Definition: txatbase.cxx:44
Represents the style of a text portion.
Definition: charfmt.hxx:26
virtual void SetEnd(sal_Int32)
Definition: txatbase.cxx:53
SwCharFormat * GetCharFormat() const
Definition: fchrfmt.hxx:70
void EndPosChanged() const
Definition: ndhints.hxx:213
SwTextAttrEnd(SfxPoolItem &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txatbase.cxx:71
static void Destroy(SwTextAttr *pToDestroy, SfxItemPool &rPool)
destroy instance
Definition: txatbase.cxx:58
const sal_Int32 * End() const
Definition: txatbase.hxx:152
bool operator==(const SwTextAttr &) const
Definition: txatbase.cxx:66
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: txatbase.cxx:89
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:163
#define SAL_WARN(area, stream)
const SwFormatAutoFormat & GetAutoFormat() const
Definition: txatbase.hxx:189
const SwFormatCharFormat & GetCharFormat() const
Definition: txatbase.hxx:183
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:432
const SwFormatRuby & GetRuby() const
Definition: txatbase.hxx:234
const SwFormatINetFormat & GetINetFormat() const
Definition: txatbase.hxx:228
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo