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 <boost/next_prior.hpp>
32 FontList::iterator FontList::fontIterator(pos_type pos)
34 FontList::iterator it = list_.begin();
35 FontList::iterator end = list_.end();
36 for (; it != end; ++it) {
44 FontList::const_iterator FontList::fontIterator(pos_type pos) const
46 FontList::const_iterator it = list_.begin();
47 FontList::const_iterator end = list_.end();
48 for (; it != end; ++it) {
56 Font & FontList::get(pos_type pos)
58 iterator end = list_.end();
59 iterator it = fontIterator(pos);
60 if (it != end && it->pos() == pos)
67 void FontList::erase(pos_type pos)
69 // Erase entries in the tables.
70 iterator it = fontIterator(pos);
71 iterator beg = list_.begin();
72 if (it != list_.end() && it->pos() == pos
74 || (it != list_.begin() && boost::prior(it)->pos() == pos - 1))) {
76 // If it is a multi-character font
77 // entry, we just make it smaller
78 // (see update below), otherwise we
80 unsigned int const i = it - list_.begin();
82 if (i >= list_.size())
84 it = list_.begin() + i;
85 if (i > 0 && i < list_.size() &&
86 list_[i - 1].font() == list_[i].font()) {
87 list_.erase(beg + i - 1);
88 it = list_.begin() + i - 1;
92 // Update all other entries
93 iterator end = list_.end();
94 for (; it != end; ++it)
95 it->pos(it->pos() - 1);
98 void FontList::increasePosAfterPos(pos_type pos)
100 List::iterator end = list_.end();
101 List::iterator it = fontIterator(pos);
102 for (; it != end; ++it)
107 void FontList::decreasePosAfterPos(pos_type pos)
109 List::iterator end = list_.end();
110 List::iterator it = fontIterator(pos);
111 for (; it != end; ++it)
116 void FontList::setRange(pos_type startpos, pos_type endpos, Font const & font)
118 // FIXME: Optimize!!!
119 for (pos_type pos = startpos; pos != endpos; ++pos)
124 void FontList::set(pos_type pos, Font const & font)
126 // No need to simplify this because it will disappear
127 // in a new kernel. (Asger)
128 // Next search font table
130 iterator beg = list_.begin();
132 iterator endit = list_.end();
134 for (; it != endit; ++it) {
135 if (it->pos() >= pos) {
140 if (found && it->font() == font)
143 size_t const i = distance(beg, it);
145 // Is position pos is a beginning of a font block?
146 bool begin = pos == 0 || !found
147 || (i > 0 && list_[i - 1].pos() == pos - 1);
149 // Is position pos is the end of a font block?
150 bool end = found && list_[i].pos() == pos;
152 if (!begin && !end) {
153 // The general case: The block is splitted into 3 blocks
154 list_.insert(list_.begin() + i,
155 FontTable(pos - 1, list_[i].font()));
156 list_.insert(list_.begin() + i + 1,
157 FontTable(pos, font));
162 // A single char block
163 if (i + 1 < list_.size() &&
164 list_[i + 1].font() == font) {
165 // Merge the singleton block with the next block
166 list_.erase(list_.begin() + i);
167 if (i > 0 && list_[i - 1].font() == font)
168 list_.erase(list_.begin() + i - 1);
169 } else if (i > 0 && list_[i - 1].font() == font) {
170 // Merge the singleton block with the previous block
171 list_[i - 1].pos(pos);
172 list_.erase(list_.begin() + i);
176 if (i > 0 && list_[i - 1].font() == font)
177 list_[i - 1].pos(pos);
179 list_.insert(list_.begin() + i,
180 FontTable(pos, font));
182 list_[i].pos(pos - 1);
183 if (!(i + 1 < list_.size() &&
184 list_[i + 1].font() == font))
185 list_.insert(list_.begin() + i + 1,
186 FontTable(pos, font));
191 FontSize FontList::highestInRange
192 (pos_type startpos, pos_type endpos, FontSize def_size) const
197 const_iterator end_it = list_.begin();
198 const_iterator const end = list_.end();
199 for (; end_it != end; ++end_it) {
200 if (end_it->pos() >= endpos)
207 FontList::const_iterator cit = list_.begin();
208 for (; cit != end; ++cit) {
209 if (cit->pos() >= startpos)
213 FontSize maxsize = FONT_SIZE_TINY;
214 for (; cit != end_it; ++cit) {
215 FontSize size = cit->font().fontInfo().size();
216 if (size == FONT_SIZE_INHERIT)
218 if (size > maxsize && size <= FONT_SIZE_HUGER)
225 bool FontList::hasChangeInRange(pos_type pos, int len) const
227 // FIXME: can't we use fontIterator(pos) instead?
228 const_iterator cit = list_.begin();
229 const_iterator end = list_.end();
230 for (; cit != end; ++cit) {
231 if (cit->pos() >= pos)
234 if (cit != end && pos + len - 1 > cit->pos())
241 void FontList::validate(LaTeXFeatures & features) const
243 const_iterator fcit = list_.begin();
244 const_iterator fend = list_.end();
245 for (; fcit != fend; ++fcit)
246 fcit->font().validate(features);