3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * \author André Pönitz
13 * \author Jürgen Vigna
14 * \author Abdelrazak Younes
16 * Full author contact details are available in file CREDITS.
23 #include "support/lyxalgo.h"
30 FontList::iterator FontList::fontIterator(pos_type pos)
32 FontList::iterator it = list_.begin();
33 FontList::iterator end = list_.end();
34 for (; it != end; ++it) {
42 FontList::const_iterator FontList::fontIterator(pos_type pos) const
44 FontList::const_iterator it = list_.begin();
45 FontList::const_iterator end = list_.end();
46 for (; it != end; ++it) {
54 Font const & FontList::get(pos_type pos)
56 iterator end = list_.end();
57 iterator it = fontIterator(pos);
58 if (it != end && it->pos() == pos)
61 static Font const dummy;
66 void FontList::erase(pos_type pos)
68 // Erase entries in the tables.
69 iterator it = fontIterator(pos);
70 iterator beg = list_.begin();
71 if (it != list_.end() && it->pos() == pos
73 || (it != list_.begin() && prev(it, 1)->pos() == pos - 1))) {
75 // If it is a multi-character font
76 // entry, we just make it smaller
77 // (see update below), otherwise we
79 unsigned int const i = it - list_.begin();
81 if (i >= list_.size())
83 it = list_.begin() + i;
84 if (i > 0 && i < list_.size() &&
85 list_[i - 1].font() == list_[i].font()) {
86 list_.erase(beg + i - 1);
87 it = list_.begin() + i - 1;
91 // Update all other entries
92 iterator end = list_.end();
93 for (; it != end; ++it)
94 it->pos(it->pos() - 1);
97 void FontList::increasePosAfterPos(pos_type pos)
99 List::iterator end = list_.end();
100 List::iterator it = fontIterator(pos);
101 for (; it != end; ++it)
106 void FontList::decreasePosAfterPos(pos_type pos)
108 List::iterator end = list_.end();
109 List::iterator it = fontIterator(pos);
110 for (; it != end; ++it)
115 void FontList::set(pos_type pos, Font const & font)
117 // No need to simplify this because it will disappear
118 // in a new kernel. (Asger)
119 // Next search font table
121 List::iterator it = fontIterator(pos);
122 bool const found = it != list_.end();
123 if (found && it->font() == font)
124 // Font is already set.
127 size_t const i = distance(list_.begin(), it);
129 // Is position pos a beginning of a font block?
130 bool const begin = pos == 0 || !found
131 || (i > 0 && list_[i - 1].pos() == pos - 1);
133 // Is position pos at the end of a font block?
134 bool const end = found && list_[i].pos() == pos;
136 if (!begin && !end) {
137 // The general case: The block is split into 3 blocks
138 list_.insert(list_.begin() + i,
139 FontTable(pos - 1, list_[i].font()));
140 list_.insert(list_.begin() + i + 1,
141 FontTable(pos, font));
146 // A single char block
147 if (i + 1 < list_.size() &&
148 list_[i + 1].font() == font) {
149 // Merge the singleton block with the next block
150 list_.erase(list_.begin() + i);
151 if (i > 0 && list_[i - 1].font() == font)
152 list_.erase(list_.begin() + i - 1);
153 } else if (i > 0 && list_[i - 1].font() == font) {
154 // Merge the singleton block with the previous block
155 list_[i - 1].pos(pos);
156 list_.erase(list_.begin() + i);
160 if (i > 0 && list_[i - 1].font() == font)
161 list_[i - 1].pos(pos);
163 list_.insert(list_.begin() + i,
164 FontTable(pos, font));
166 list_[i].pos(pos - 1);
167 if (!(i + 1 < list_.size() &&
168 list_[i + 1].font() == font))
169 list_.insert(list_.begin() + i + 1,
170 FontTable(pos, font));
175 void FontList::validate(LaTeXFeatures & features) const
177 const_iterator fcit = list_.begin();
178 const_iterator fend = list_.end();
179 for (; fcit != fend; ++fcit)
180 fcit->font().validate(features);