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 const & FontList::get(pos_type pos)
58 iterator end = list_.end();
59 iterator it = fontIterator(pos);
60 if (it != end && it->pos() == pos)
63 static Font const dummy;
68 void FontList::erase(pos_type pos)
70 // Erase entries in the tables.
71 iterator it = fontIterator(pos);
72 iterator beg = list_.begin();
73 if (it != list_.end() && it->pos() == pos
75 || (it != list_.begin() && boost::prior(it)->pos() == pos - 1))) {
77 // If it is a multi-character font
78 // entry, we just make it smaller
79 // (see update below), otherwise we
81 unsigned int const i = it - list_.begin();
83 if (i >= list_.size())
85 it = list_.begin() + i;
86 if (i > 0 && i < list_.size() &&
87 list_[i - 1].font() == list_[i].font()) {
88 list_.erase(beg + i - 1);
89 it = list_.begin() + i - 1;
93 // Update all other entries
94 iterator end = list_.end();
95 for (; it != end; ++it)
96 it->pos(it->pos() - 1);
99 void FontList::increasePosAfterPos(pos_type pos)
101 List::iterator end = list_.end();
102 List::iterator it = fontIterator(pos);
103 for (; it != end; ++it)
108 void FontList::decreasePosAfterPos(pos_type pos)
110 List::iterator end = list_.end();
111 List::iterator it = fontIterator(pos);
112 for (; it != end; ++it)
117 void FontList::setRange(pos_type startpos, pos_type endpos, Font const & font)
119 // FIXME: Optimize!!!
120 for (pos_type pos = startpos; pos != endpos; ++pos)
125 void FontList::set(pos_type pos, Font const & font)
127 // No need to simplify this because it will disappear
128 // in a new kernel. (Asger)
129 // Next search font table
131 List::iterator it = fontIterator(pos);
132 bool const found = it != list_.end();
133 if (found && it->font() == font)
134 // Font is already set.
137 size_t const i = distance(list_.begin(), it);
139 // Is position pos a beginning of a font block?
140 bool const begin = pos == 0 || !found
141 || (i > 0 && list_[i - 1].pos() == pos - 1);
143 // Is position pos at the end of a font block?
144 bool const end = found && list_[i].pos() == pos;
146 if (!begin && !end) {
147 // The general case: The block is split into 3 blocks
148 list_.insert(list_.begin() + i,
149 FontTable(pos - 1, list_[i].font()));
150 list_.insert(list_.begin() + i + 1,
151 FontTable(pos, font));
156 // A single char block
157 if (i + 1 < list_.size() &&
158 list_[i + 1].font() == font) {
159 // Merge the singleton block with the next block
160 list_.erase(list_.begin() + i);
161 if (i > 0 && list_[i - 1].font() == font)
162 list_.erase(list_.begin() + i - 1);
163 } else if (i > 0 && list_[i - 1].font() == font) {
164 // Merge the singleton block with the previous block
165 list_[i - 1].pos(pos);
166 list_.erase(list_.begin() + i);
170 if (i > 0 && list_[i - 1].font() == font)
171 list_[i - 1].pos(pos);
173 list_.insert(list_.begin() + i,
174 FontTable(pos, font));
176 list_[i].pos(pos - 1);
177 if (!(i + 1 < list_.size() &&
178 list_[i + 1].font() == font))
179 list_.insert(list_.begin() + i + 1,
180 FontTable(pos, font));
185 FontSize FontList::highestInRange(pos_type startpos, pos_type endpos,
186 FontSize def_size) const
191 List::const_iterator end_it = fontIterator(endpos);
192 const_iterator const end = list_.end();
196 List::const_iterator cit = fontIterator(startpos);
198 FontSize maxsize = FONT_SIZE_TINY;
199 for (; cit != end_it; ++cit) {
200 FontSize size = cit->font().fontInfo().size();
201 if (size == FONT_SIZE_INHERIT)
203 if (size > maxsize && size <= FONT_SIZE_HUGER)
210 void FontList::validate(LaTeXFeatures & features) const
212 const_iterator fcit = list_.begin();
213 const_iterator fend = list_.end();
214 for (; fcit != fend; ++fcit)
215 fcit->font().validate(features);