simplify writeBitmapObject
[LibreOffice.git] / sw / source / core / txtnode / txatbase.cxx
blob7d02de606184a20fb5307486ec9be8307e41f099
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <optional>
21 #include <libxml/xmlwriter.h>
22 #include <svl/itempool.hxx>
23 #include <txatbase.hxx>
24 #include <fmtfld.hxx>
26 SwTextAttr::SwTextAttr( const SfxPoolItemHolder& rAttr, sal_Int32 nStart )
27 : m_aAttr( 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 )
42 assert(!m_aAttr.getItem()->isStaticDefault());
45 SwTextAttr::~SwTextAttr() COVERITY_NOEXCEPT_FALSE
49 const sal_Int32* SwTextAttr::GetEnd() const
51 return nullptr;
54 void SwTextAttr::SetEnd(sal_Int32 )
56 assert(false);
59 void SwTextAttr::Destroy( SwTextAttr * pToDestroy )
61 if (!pToDestroy) return;
62 delete pToDestroy;
65 bool SwTextAttr::operator==( const SwTextAttr& rAttr ) const
67 return GetAttr() == rAttr.GetAttr();
70 SwTextAttrEnd::SwTextAttrEnd(
71 const SfxPoolItemHolder& rAttr,
72 sal_Int32 nStart,
73 sal_Int32 nEnd ) :
74 SwTextAttr( rAttr, nStart ), m_nEnd( nEnd )
78 const sal_Int32* SwTextAttrEnd::GetEnd() const
80 return & m_nEnd;
83 void SwTextAttrEnd::SetEnd(sal_Int32 n)
85 if (m_nEnd != n)
87 sal_Int32 nOldEndPos = m_nEnd;
88 m_nEnd = n;
89 if (m_pHints)
90 m_pHints->EndPosChanged(Which(), GetStart(), nOldEndPos, m_nEnd);
94 void SwTextAttr::dumpAsXml(xmlTextWriterPtr pWriter) const
96 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextAttr"));
97 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
98 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s",
99 BAD_CAST(typeid(*this).name()));
101 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("start"), BAD_CAST(OString::number(m_nStart).getStr()));
102 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("dont-expand"),
103 BAD_CAST(OString::boolean(m_bDontExpand).getStr()));
104 if (End())
105 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("end"), BAD_CAST(OString::number(*End()).getStr()));
106 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
107 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("attr-item"), "%p", m_aAttr.getItem());
108 const char* pWhich = nullptr;
109 std::optional<OString> oValue;
110 switch (Which())
112 case RES_TXTATR_AUTOFMT:
113 pWhich = "autofmt";
114 break;
115 case RES_TXTATR_ANNOTATION:
116 pWhich = "annotation";
117 break;
118 case RES_TXTATR_FLYCNT:
119 pWhich = "fly content";
120 break;
121 case RES_TXTATR_CJK_RUBY:
123 pWhich = "ruby";
124 const SwFormatRuby& rFormat = GetRuby();
125 oValue = OString("rubytext: " + rFormat.GetText().toUtf8());
126 break;
128 case RES_TXTATR_META:
130 pWhich = "meta";
131 break;
133 case RES_TXTATR_FIELD:
135 pWhich = "field";
136 break;
138 default:
139 break;
141 if (pWhich)
142 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("which"), BAD_CAST(pWhich));
143 if (oValue)
144 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(oValue->getStr()));
145 switch (Which())
147 case RES_TXTATR_AUTOFMT:
148 GetAutoFormat().dumpAsXml(pWriter);
149 break;
150 case RES_TXTATR_FIELD:
151 case RES_TXTATR_ANNOTATION:
152 case RES_TXTATR_INPUTFIELD:
153 GetFormatField().dumpAsXml(pWriter);
154 break;
155 case RES_TXTATR_FTN:
156 GetFootnote().dumpAsXml(pWriter);
157 break;
158 case RES_TXTATR_LINEBREAK:
159 GetLineBreak().dumpAsXml(pWriter);
160 break;
161 case RES_TXTATR_META:
162 break;
163 case RES_TXTATR_CONTENTCONTROL:
164 GetContentControl().dumpAsXml(pWriter);
165 break;
166 case RES_TXTATR_FLYCNT:
167 GetFlyCnt().dumpAsXml(pWriter);
168 break;
169 case RES_TXTATR_CHARFMT:
170 GetCharFormat().dumpAsXml(pWriter);
171 break;
172 case RES_TXTATR_REFMARK:
173 GetRefMark().dumpAsXml(pWriter);
174 break;
175 case RES_TXTATR_INETFMT:
176 GetINetFormat().dumpAsXml(pWriter);
177 break;
178 case RES_TXTATR_CJK_RUBY:
179 GetRuby().dumpAsXml(pWriter);
180 break;
181 default:
182 SAL_WARN("sw.core", "Unhandled TXTATR: " << Which());
183 break;
186 (void)xmlTextWriterEndElement(pWriter);
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */