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>
35 FontList::iterator FontList::fontIterator(pos_type pos)
38 FontTable search_elem(pos, dummy);
39 return lower_bound(list_.begin(), list_.end(), search_elem,
44 FontList::const_iterator FontList::fontIterator(pos_type pos) const
47 FontTable search_elem(pos, dummy);
48 return lower_bound(list_.begin(), list_.end(), search_elem,
53 Font & FontList::get(pos_type pos)
55 iterator end = list_.end();
56 iterator it = fontIterator(pos);
57 if (it != end && it->pos == pos)
64 void FontList::erase(pos_type pos)
66 // Erase entries in the tables.
67 iterator it = fontIterator(pos);
68 iterator beg = list_.begin();
69 if (it != list_.end() && it->pos() == pos
71 || (it != beg && boost::prior(it)->pos() == pos - 1))) {
73 // If it is a multi-character font
74 // entry, we just make it smaller
75 // (see update below), otherwise we
77 unsigned int const i = it - beg;
80 if (i > 0 && i < list_.size() &&
81 list_[i - 1].font() == list_[i].font()) {
82 list_.erase(beg + i - 1);
87 // Update all other entries
88 iterator end = list_.end();
89 for (; it != end; ++it)
90 it->pos(it->pos() - 1);
93 void FontList::increasePosAfterPos(pos_type pos)
95 List::iterator end = list_.end();
96 List::iterator it = fontIterator(pos);
97 for (; it != end; ++it)
102 void FontList::decreasePosAfterPos(pos_type pos)
104 List::iterator end = list_.end();
105 List::iterator it = fontIterator(pos);
106 for (; it != end; ++it)
111 void FontList::set(pos_type pos, Font const & font)
113 // No need to simplify this because it will disappear
114 // in a new kernel. (Asger)
115 // Next search font table
117 iterator beg = list_.begin();
119 iterator endit = list_.end();
120 for (; it != endit; ++it) {
121 if (it->pos() >= pos)
124 size_t const i = distance(beg, it);
125 bool notfound = (it == endit);
127 if (!notfound && list_[i].font() == font)
130 bool begin = pos == 0 || notfound ||
131 (i > 0 && list_[i - 1].pos() == pos - 1);
132 // Is position pos is a beginning of a font block?
133 bool end = !notfound && list_[i].pos() == pos;
134 // Is position pos is the end of a font block?
135 if (begin && end) { // A single char block
136 if (i + 1 < list_.size() &&
137 list_[i + 1].font() == font) {
138 // Merge the singleton block with the next block
139 list_.erase(list_.begin() + i);
140 if (i > 0 && list_[i - 1].font() == font)
141 list_.erase(list_.begin() + i - 1);
142 } else if (i > 0 && list_[i - 1].font() == font) {
143 // Merge the singleton block with the previous block
144 list_[i - 1].pos(pos);
145 list_.erase(list_.begin() + i);
149 if (i > 0 && list_[i - 1].font() == font)
150 list_[i - 1].pos(pos);
152 list_.insert(list_.begin() + i,
153 FontTable(pos, font));
155 list_[i].pos(pos - 1);
156 if (!(i + 1 < list_.size() &&
157 list_[i + 1].font() == font))
158 list_.insert(list_.begin() + i + 1,
159 FontTable(pos, font));
160 } else { // The general case. The block is splitted into 3 blocks
161 list_.insert(list_.begin() + i,
162 FontTable(pos - 1, list_[i].font()));
163 list_.insert(list_.begin() + i + 1,
164 FontTable(pos, font));