simplify code by using fontIterator()

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25665 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-07-16 12:40:10 +00:00
parent bef58b3b16
commit e1eaea3b4d

View File

@ -127,27 +127,20 @@ void FontList::set(pos_type pos, Font const & font)
// in a new kernel. (Asger) // in a new kernel. (Asger)
// Next search font table // Next search font table
iterator beg = list_.begin(); List::iterator it = fontIterator(pos);
iterator it = beg; bool const found = it != list_.end();
iterator endit = list_.end();
bool found = false;
for (; it != endit; ++it) {
if (it->pos() >= pos) {
found = true;
break;
}
}
if (found && it->font() == font) if (found && it->font() == font)
// Font is already set.
return; return;
size_t const i = distance(beg, it); size_t const i = distance(list_.begin(), it);
// Is position pos is a beginning of a font block? // Is position pos a beginning of a font block?
bool begin = pos == 0 || !found bool const begin = pos == 0 || !found
|| (i > 0 && list_[i - 1].pos() == pos - 1); || (i > 0 && list_[i - 1].pos() == pos - 1);
// Is position pos is the end of a font block? // Is position pos at the end of a font block?
bool end = found && list_[i].pos() == pos; bool const end = found && list_[i].pos() == pos;
if (!begin && !end) { if (!begin && !end) {
// The general case: The block is splitted into 3 blocks // The general case: The block is splitted into 3 blocks
@ -188,27 +181,18 @@ void FontList::set(pos_type pos, Font const & font)
} }
FontSize FontList::highestInRange FontSize FontList::highestInRange(pos_type startpos, pos_type endpos,
(pos_type startpos, pos_type endpos, FontSize def_size) const FontSize def_size) const
{ {
if (list_.empty()) if (list_.empty())
return def_size; return def_size;
const_iterator end_it = list_.begin(); List::const_iterator end_it = fontIterator(endpos);
const_iterator const end = list_.end(); const_iterator const end = list_.end();
for (; end_it != end; ++end_it) {
if (end_it->pos() >= endpos)
break;
}
if (end_it != end) if (end_it != end)
++end_it; ++end_it;
FontList::const_iterator cit = list_.begin(); List::const_iterator cit = fontIterator(startpos);
for (; cit != end; ++cit) {
if (cit->pos() >= startpos)
break;
}
FontSize maxsize = FONT_SIZE_TINY; FontSize maxsize = FONT_SIZE_TINY;
for (; cit != end_it; ++cit) { for (; cit != end_it; ++cit) {
@ -224,17 +208,8 @@ FontSize FontList::highestInRange
bool FontList::hasChangeInRange(pos_type pos, int len) const bool FontList::hasChangeInRange(pos_type pos, int len) const
{ {
// FIXME: can't we use fontIterator(pos) instead? List::const_iterator cit = fontIterator(pos);
const_iterator cit = list_.begin(); return cit == list_.end() || pos + len - 1 <= cit->pos();
const_iterator end = list_.end();
for (; cit != end; ++cit) {
if (cit->pos() >= pos)
break;
}
if (cit != end && pos + len - 1 > cit->pos())
return false;
return true;
} }