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)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
30 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("name"),
31 BAD_CAST(GetName().toUtf8().getStr()));
32
34 {
35 (void)xmlTextWriterWriteAttribute(
36 pWriter, BAD_CAST("linked"), BAD_CAST(mpLinkedParaFormat->GetName().toUtf8().getStr()));
37 }
38
39 GetAttrSet().dumpAsXml(pWriter);
40 (void)xmlTextWriterEndElement(pWriter);
41}
42
44
46
48{
49 if (GetDoc()->IsInDtor())
50 {
51 return;
52 }
53
54 for (const auto& pTextFormat : *GetDoc()->GetTextFormatColls())
55 {
56 if (pTextFormat->GetLinkedCharFormat() == this)
57 {
58 pTextFormat->SetLinkedCharFormat(nullptr);
59 }
60 }
61}
62
64{
65 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwCharFormats"));
66 for (size_t i = 0; i < size(); ++i)
67 GetFormat(i)->dumpAsXml(pWriter);
68 (void)xmlTextWriterEndElement(pWriter);
69}
70
72 : m_PosIndex(m_Array.get<0>())
73 , m_NameIndex(m_Array.get<1>())
74{
75}
76
78{
79 // default char format is owned by SwDoc
81}
82
84{
85 ByName::iterator it
86 = m_NameIndex.find(std::make_tuple(x->GetName(), const_cast<SwCharFormat*>(x)));
87 return m_Array.project<0>(it);
88}
89
90SwCharFormats::ByName::const_iterator SwCharFormats::findByName(const OUString& name) const
91{
92 return m_NameIndex.find(std::make_tuple(name));
93}
94
95SwCharFormat* SwCharFormats::FindFormatByName(const OUString& rName) const
96{
97 auto it = findByName(rName);
98 if (it != m_NameIndex.end())
99 return *it;
100 return nullptr;
101}
102
104{
105 if (empty())
106 return;
107 const int _offset = keepDefault ? 1 : 0;
108 for (const_iterator it = begin() + _offset; it != end(); ++it)
109 {
110 assert(!(*it)->HasName(u"Character style"));
111 delete *it;
112 }
113 if (_offset)
114 m_PosIndex.erase(begin() + _offset, end());
115 else
116 m_Array.clear();
117}
118
120{
121 assert(!ContainsFormat(x));
122 m_PosIndex.push_back(x);
123}
124
126
127bool SwCharFormats::ContainsFormat(const SwCharFormat* x) const { return find(x) != end(); }
128
130void SwCharFormats::SetFormatNameAndReindex(SwCharFormat* v, const OUString& sNewName)
131{
132 auto it = find(v);
133 erase(it);
134 v->SetFormatName(sNewName);
135 insert(v);
136}
137
139{
140 auto it = find(p);
141 return it == end() ? SIZE_MAX : it - begin();
142}
143
144/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:43
~SwCharFormat()
Definition: chrfmt.cxx:47
const SwTextFormatColl * GetLinkedParaFormat() const
Definition: chrfmt.cxx:45
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:127
void insert(SwCharFormat *x)
Definition: chrfmt.cxx:119
ByPos & m_PosIndex
Definition: charformats.hxx:58
virtual ~SwCharFormats() override
Definition: chrfmt.cxx:77
const_iterator find(const SwCharFormat *x) const
Definition: chrfmt.cxx:83
virtual SwCharFormat * GetFormat(size_t idx) const override
Definition: charformats.hxx:95
size_t GetPos(const SwCharFormat *p) const
Definition: chrfmt.cxx:138
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:90
void DeleteAndDestroyAll(bool keepDefault=false)
Definition: chrfmt.cxx:103
const_iterator begin() const
Definition: charformats.hxx:89
virtual SwCharFormat * FindFormatByName(const OUString &rName) const override
Definition: chrfmt.cxx:95
ByName & m_NameIndex
Definition: charformats.hxx:59
bool empty() const
Definition: charformats.hxx:70
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: chrfmt.cxx:63
void erase(const_iterator const &position)
Definition: chrfmt.cxx:125
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:130
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:61
struct _xmlTextWriter * xmlTextWriterPtr
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)