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.
28 FontList::iterator FontList::fontIterator(pos_type pos)
30 FontList::iterator it = list_.begin();
31 FontList::iterator end = list_.end();
32 for (; it != end; ++it) {
40 FontList::const_iterator FontList::fontIterator(pos_type pos) const
42 FontList::const_iterator it = list_.begin();
43 FontList::const_iterator end = list_.end();
44 for (; it != end; ++it) {
52 Font const & FontList::get(pos_type pos)
54 iterator end = list_.end();
55 iterator it = fontIterator(pos);
56 if (it != end && it->pos() == pos)
59 static Font const dummy;
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 != list_.begin() && prev(it, 1)->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 - list_.begin();
79 if (i >= list_.size())
81 it = list_.begin() + i;
82 if (i > 0 && i < list_.size() &&
83 list_[i - 1].font() == list_[i].font()) {
84 list_.erase(beg + i - 1);
85 it = list_.begin() + i - 1;
89 // Update all other entries
90 iterator end = list_.end();
91 for (; it != end; ++it)
92 it->pos(it->pos() - 1);
95 void FontList::increasePosAfterPos(pos_type pos)
97 List::iterator end = list_.end();
98 List::iterator it = fontIterator(pos);
99 for (; it != end; ++it)
104 void FontList::decreasePosAfterPos(pos_type pos)
106 List::iterator end = list_.end();
107 List::iterator it = fontIterator(pos);
108 for (; it != end; ++it)
113 void FontList::set(pos_type pos, Font const & font)
115 // No need to simplify this because it will disappear
116 // in a new kernel. (Asger)
117 // Next search font table
119 List::iterator it = fontIterator(pos);
120 bool const found = it != list_.end();
121 if (found && it->font() == font)
122 // Font is already set.
125 size_t const i = distance(list_.begin(), it);
127 // Is position pos a beginning of a font block?
128 bool const begin = pos == 0 || !found
129 || (i > 0 && list_[i - 1].pos() == pos - 1);
131 // Is position pos at the end of a font block?
132 bool const end = found && list_[i].pos() == pos;
134 if (!begin && !end) {
135 // The general case: The block is split into 3 blocks
136 list_.insert(list_.begin() + i,
137 FontTable(pos - 1, list_[i].font()));
138 list_.insert(list_.begin() + i + 1,
139 FontTable(pos, font));
144 // A single char block
145 if (i + 1 < list_.size() &&
146 list_[i + 1].font() == font) {
147 // Merge the singleton block with the next block
148 list_.erase(list_.begin() + i);
149 if (i > 0 && list_[i - 1].font() == font)
150 list_.erase(list_.begin() + i - 1);
151 } else if (i > 0 && list_[i - 1].font() == font) {
152 // Merge the singleton block with the previous block
153 list_[i - 1].pos(pos);
154 list_.erase(list_.begin() + i);
158 if (i > 0 && list_[i - 1].font() == font)
159 list_[i - 1].pos(pos);
161 list_.insert(list_.begin() + i,
162 FontTable(pos, font));
164 list_[i].pos(pos - 1);
165 if (!(i + 1 < list_.size() &&
166 list_[i + 1].font() == font))
167 list_.insert(list_.begin() + i + 1,
168 FontTable(pos, font));
173 void FontList::validate(LaTeXFeatures & features) const
175 const_iterator fcit = list_.begin();
176 const_iterator fend = list_.end();
177 for (; fcit != fend; ++fcit)
178 fcit->font().validate(features);