LibreOffice Module sw (master) 1
chrfmt.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 <libxml/xmlwriter.h>
21
22#include <charfmt.hxx>
23#include <charformats.hxx>
24#include <doc.hxx>
25
27{
28 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwCharFormat"));
29 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("name"),
30 BAD_CAST(GetName().toUtf8().getStr()));
31
33 {
34 (void)xmlTextWriterWriteAttribute(
35 pWriter, BAD_CAST("linked"), BAD_CAST(mpLinkedParaFormat->GetName().toUtf8().getStr()));
36 }
37
38 GetAttrSet().dumpAsXml(pWriter);
39 (void)xmlTextWriterEndElement(pWriter);
40}
41
43
45
47{
48 if (GetDoc()->IsInDtor())
49 {
50 return;
51 }
52
53 for (const auto& pTextFormat : *GetDoc()->GetTextFormatColls())
54 {
55 if (pTextFormat->GetLinkedCharFormat() == this)
56 {
57 pTextFormat->SetLinkedCharFormat(nullptr);
58 }
59 }
60}
61
63{
64 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwCharFormats"));
65 for (size_t i = 0; i < size(); ++i)
66 GetFormat(i)->dumpAsXml(pWriter);
67 (void)xmlTextWriterEndElement(pWriter);
68}
69
71 : m_PosIndex(m_Array.get<0>())
72 , m_NameIndex(m_Array.get<1>())
73{
74}
75
77{
78 // default char format is owned by SwDoc
80}
81
83{
84 ByName::iterator it
85 = m_NameIndex.find(std::make_tuple(x->GetName(), const_cast<SwCharFormat*>(x)));
86 return m_Array.project<0>(it);
87}
88
89SwCharFormats::ByName::const_iterator SwCharFormats::findByName(const OUString& name) const
90{
91 return m_NameIndex.find(std::make_tuple(name));
92}
93
94SwCharFormat* SwCharFormats::FindFormatByName(const OUString& rName) const
95{
96 auto it = findByName(rName);
97 if (it != m_NameIndex.end())
98 return *it;
99 return nullptr;
100}
101
103{
104 if (empty())
105 return;
106 const int _offset = keepDefault ? 1 : 0;
107 for (const_iterator it = begin() + _offset; it != end(); ++it)
108 {
109 assert(!(*it)->HasName(u"Character style"));
110 delete *it;
111 }
112 if (_offset)
113 m_PosIndex.erase(begin() + _offset, end());
114 else
115 m_Array.clear();
116}
117
119{
120 assert(!ContainsFormat(x));
121 m_PosIndex.push_back(x);
122}
123
125
126bool SwCharFormats::ContainsFormat(const SwCharFormat* x) const { return find(x) != end(); }
127
129void SwCharFormats::SetFormatNameAndReindex(SwCharFormat* v, const OUString& sNewName)
130{
131 auto it = find(v);
132 erase(it);
133 v->SetFormatName(sNewName);
134 insert(v);
135}
136
138{
139 auto it = find(p);
140 return it == end() ? SIZE_MAX : it - begin();
141}
142
143/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
void dumpAsXml(xmlTextWriterPtr pWriter) const
Represents the style of a text portion.
Definition: charfmt.hxx:27
SwTextFormatColl * mpLinkedParaFormat
Definition: charfmt.hxx:31
void SetLinkedParaFormat(SwTextFormatColl *pLink)
Definition: chrfmt.cxx:42
~SwCharFormat()
Definition: chrfmt.cxx:46
const SwTextFormatColl * GetLinkedParaFormat() const
Definition: chrfmt.cxx:44
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: chrfmt.cxx:26
bool ContainsFormat(const SwCharFormat *pFormat) const
fast check if given format is contained here @precond pFormat must not have been deleted
Definition: chrfmt.cxx:126
void insert(SwCharFormat *x)
Definition: chrfmt.cxx:118
ByPos & m_PosIndex
Definition: charformats.hxx:58
virtual ~SwCharFormats() override
Definition: chrfmt.cxx:76
const_iterator find(const SwCharFormat *x) const
Definition: chrfmt.cxx:82
virtual SwCharFormat * GetFormat(size_t idx) const override
Definition: charformats.hxx:95
size_t GetPos(const SwCharFormat *p) const
Definition: chrfmt.cxx:137
SwCharFormatsBase m_Array
Definition: charformats.hxx:57
size_t size() const
Definition: charformats.hxx:71
ByPos::const_iterator const_iterator
Definition: charformats.hxx:62
ByName::const_iterator findByName(const OUString &name) const
Definition: chrfmt.cxx:89
void DeleteAndDestroyAll(bool keepDefault=false)
Definition: chrfmt.cxx:102
const_iterator begin() const
Definition: charformats.hxx:89
virtual SwCharFormat * FindFormatByName(const OUString &rName) const override
Definition: chrfmt.cxx:94
ByName & m_NameIndex
Definition: charformats.hxx:59
bool empty() const
Definition: charformats.hxx:70
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: chrfmt.cxx:62
void erase(const_iterator const &position)
Definition: chrfmt.cxx:124
const_iterator end() const
Definition: charformats.hxx:90
void SetFormatNameAndReindex(SwCharFormat *v, const OUString &sNewName)
Need to call this when the format name changes.
Definition: chrfmt.cxx:129
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:139
const OUString & GetName() const
Definition: format.hxx:131
const SwAttrSet & GetAttrSet() const
For querying the attribute array.
Definition: format.hxx:136
Represents the style of a paragraph.
Definition: fmtcol.hxx:59
float v
float u
float x
const char * name
void * p
SvBaseLink * pLink
def position(n=-1)
int i
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)