]> git.lyx.org Git - lyx.git/blobdiff - src/FontList.cpp
* Paragraph: reserve memory by chunks of 100 chars. This improve the loading of big...
[lyx.git] / src / FontList.cpp
index 24f041e84db78a7fdc1e183b94ddfbf2811f3fb4..d6e7eb15995733cb823a5ffa7706997a27af7fed 100644 (file)
@@ -66,7 +66,7 @@ Font & FontList::get(pos_type pos)
 {
        iterator end = list_.end();
        iterator it = fontIterator(pos);
-       if (it != end && it->pos == pos)
+       if (it != end && it->pos() == pos)
                return it->font_;
        static Font dummy;
        return dummy;
@@ -80,19 +80,21 @@ void FontList::erase(pos_type pos)
        iterator beg = list_.begin();
        if (it != list_.end() && it->pos() == pos
                && (pos == 0 
-                       || (it != beg && boost::prior(it)->pos() == pos - 1))) {
+                       || (it != list_.begin() && boost::prior(it)->pos() == pos - 1))) {
 
                // If it is a multi-character font
                // entry, we just make it smaller
                // (see update below), otherwise we
                // should delete it.
-               unsigned int const i = it - beg;
-               list_.erase(beg + i);
-               it = beg + i;
+               unsigned int const i = it - list_.begin();
+               list_.erase(it);
+               if (i >= list_.size())
+                       return;
+               it = list_.begin() + i;
                if (i > 0 && i < list_.size() &&
                    list_[i - 1].font() == list_[i].font()) {
                        list_.erase(beg + i - 1);
-                       it = beg + i - 1;
+                       it = list_.begin() + i - 1;
                }
        }
 
@@ -120,6 +122,14 @@ void FontList::decreasePosAfterPos(pos_type pos)
 }
 
 
+void FontList::setRange(pos_type startpos, pos_type endpos, Font const & font)
+{
+       // FIXME: Optimize!!!
+       for (pos_type pos = startpos; pos != endpos; ++pos)
+               set(pos, font);
+}
+
+
 void FontList::set(pos_type pos, Font const & font)
 {
        // No need to simplify this because it will disappear
@@ -177,4 +187,63 @@ void FontList::set(pos_type pos, Font const & font)
        }
 }
 
+
+Font_size FontList::highestInRange
+       (pos_type startpos, pos_type endpos, Font_size def_size) const
+{
+       if (list_.empty())
+               return def_size;
+
+       const_iterator end_it = list_.begin();
+       const_iterator const end = list_.end();
+       for (; end_it != end; ++end_it) {
+               if (end_it->pos() >= endpos)
+                       break;
+       }
+
+       if (end_it != end)
+               ++end_it;
+
+       FontList::const_iterator cit = list_.begin();
+       for (; cit != end; ++cit) {
+               if (cit->pos() >= startpos)
+                       break;
+       }
+
+       Font::FONT_SIZE maxsize = Font::SIZE_TINY;
+       for (; cit != end_it; ++cit) {
+               Font::FONT_SIZE size = cit->font().size();
+               if (size == Font::INHERIT_SIZE)
+                       size = def_size;
+               if (size > maxsize && size <= Font::SIZE_HUGER)
+                       maxsize = size;
+       }
+       return maxsize;
+}
+
+
+bool FontList::hasChangeInRange(pos_type pos, int len) const
+{
+       // FIXME: can't we use fontIterator(pos) instead?
+       const_iterator cit = list_.begin();
+       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;
+}
+
+
+void FontList::validate(LaTeXFeatures & features) const
+{
+       const_iterator fcit = list_.begin();
+       const_iterator fend = list_.end();
+       for (; fcit != fend; ++fcit)
+               fcit->font().validate(features);
+}
+
 } // namespace lyx