From 0077782724cbbef5fe8b3fe5b4535e99e0c9be0e Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 19 Oct 2007 14:55:44 +0000 Subject: [PATCH] * Paragraph::highestFontInRange(): Transfer some more code from Paragraph to FontList. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21064 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/FontList.cpp | 34 ++++++++++++++++++++++++++++++++++ src/FontList.h | 7 +++++++ src/Paragraph.cpp | 29 +---------------------------- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/FontList.cpp b/src/FontList.cpp index 24f041e84d..b512578fec 100644 --- a/src/FontList.cpp +++ b/src/FontList.cpp @@ -177,4 +177,38 @@ 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; +} + } // namespace lyx diff --git a/src/FontList.h b/src/FontList.h index d21b74c03e..57d6d72950 100644 --- a/src/FontList.h +++ b/src/FontList.h @@ -96,6 +96,13 @@ public: /// void decreasePosAfterPos(pos_type pos); + /// Returns the height of the highest font in range + Font_size highestInRange( + pos_type startpos, + pos_type endpos, + Font_size def_size + ) const; + private: /// List list_; diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 56eb185269..ce0466f017 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -1338,34 +1338,7 @@ Font const Paragraph::getLayoutFont Font_size Paragraph::highestFontInRange (pos_type startpos, pos_type endpos, Font_size def_size) const { - if (d->fontlist_.empty()) - return def_size; - - FontList::const_iterator end_it = d->fontlist_.begin(); - FontList::const_iterator const end = d->fontlist_.end(); - for (; end_it != end; ++end_it) { - if (end_it->pos() >= endpos) - break; - } - - if (end_it != end) - ++end_it; - - FontList::const_iterator cit = d->fontlist_.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; + return d->fontlist_.highestInRange(startpos, endpos, def_size); }