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>
39 /// used by lower_bound and upper_bound
40 int operator()(FontTable const & a, FontTable const & b) const {
41 return a.pos() < b.pos();
47 FontList::iterator FontList::fontIterator(pos_type pos)
50 FontTable search_elem(pos, dummy);
51 return lower_bound(list_.begin(), list_.end(), search_elem,
56 FontList::const_iterator FontList::fontIterator(pos_type pos) const
59 FontTable search_elem(pos, dummy);
60 return lower_bound(list_.begin(), list_.end(), search_elem,
65 Font & FontList::get(pos_type pos)
67 iterator end = list_.end();
68 iterator it = fontIterator(pos);
69 if (it != end && it->pos() == pos)
76 void FontList::erase(pos_type pos)
78 // Erase entries in the tables.
79 iterator it = fontIterator(pos);
80 iterator beg = list_.begin();
81 if (it != list_.end() && it->pos() == pos
83 || (it != list_.begin() && boost::prior(it)->pos() == pos - 1))) {
85 // If it is a multi-character font
86 // entry, we just make it smaller
87 // (see update below), otherwise we
89 unsigned int const i = it - list_.begin();
91 if (i >= list_.size())
93 it = list_.begin() + i;
94 if (i > 0 && i < list_.size() &&
95 list_[i - 1].font() == list_[i].font()) {
96 list_.erase(beg + i - 1);
97 it = list_.begin() + i - 1;
101 // Update all other entries
102 iterator end = list_.end();
103 for (; it != end; ++it)
104 it->pos(it->pos() - 1);
107 void FontList::increasePosAfterPos(pos_type pos)
109 List::iterator end = list_.end();
110 List::iterator it = fontIterator(pos);
111 for (; it != end; ++it)
116 void FontList::decreasePosAfterPos(pos_type pos)
118 List::iterator end = list_.end();
119 List::iterator it = fontIterator(pos);
120 for (; it != end; ++it)
125 void FontList::setRange(pos_type startpos, pos_type endpos, Font const & font)
127 // FIXME: Optimize!!!
128 for (pos_type pos = startpos; pos != endpos; ++pos)
133 void FontList::set(pos_type pos, Font const & font)
135 // No need to simplify this because it will disappear
136 // in a new kernel. (Asger)
137 // Next search font table
139 iterator beg = list_.begin();
141 iterator endit = list_.end();
142 for (; it != endit; ++it) {
143 if (it->pos() >= pos)
146 size_t const i = distance(beg, it);
147 bool notfound = (it == endit);
149 if (!notfound && list_[i].font() == font)
152 bool begin = pos == 0 || notfound ||
153 (i > 0 && list_[i - 1].pos() == pos - 1);
154 // Is position pos is a beginning of a font block?
155 bool end = !notfound && list_[i].pos() == pos;
156 // Is position pos is the end of a font block?
157 if (begin && end) { // A single char block
158 if (i + 1 < list_.size() &&
159 list_[i + 1].font() == font) {
160 // Merge the singleton block with the next block
161 list_.erase(list_.begin() + i);
162 if (i > 0 && list_[i - 1].font() == font)
163 list_.erase(list_.begin() + i - 1);
164 } else if (i > 0 && list_[i - 1].font() == font) {
165 // Merge the singleton block with the previous block
166 list_[i - 1].pos(pos);
167 list_.erase(list_.begin() + i);
171 if (i > 0 && list_[i - 1].font() == font)
172 list_[i - 1].pos(pos);
174 list_.insert(list_.begin() + i,
175 FontTable(pos, font));
177 list_[i].pos(pos - 1);
178 if (!(i + 1 < list_.size() &&
179 list_[i + 1].font() == font))
180 list_.insert(list_.begin() + i + 1,
181 FontTable(pos, font));
182 } else { // The general case. The block is splitted into 3 blocks
183 list_.insert(list_.begin() + i,
184 FontTable(pos - 1, list_[i].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);