]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Introducing Font::validate().
[lyx.git] / src / Paragraph.cpp
index ba03df5b29b25ca614e3f400b669f116d745e9a6..f20a92bd6d847f8e2d4df522ccf85b7d8fa0761a 100644 (file)
 #include "support/convert.h"
 #include "support/unicode.h"
 
-#include <boost/bind.hpp>
-#include <boost/next_prior.hpp>
-
-#include <algorithm>
 #include <sstream>
 
-using std::distance;
 using std::endl;
 using std::string;
 using std::ostream;
@@ -605,17 +600,7 @@ bool Paragraph::Private::isTextAt(string const & str, pos_type pos) const
                        return false;
        }
 
-       // is there a font change in middle of the word?
-       FontList::const_iterator cit = fontlist_.begin();
-       FontList::const_iterator end = fontlist_.end();
-       for (; cit != end; ++cit) {
-               if (cit->pos() >= pos)
-                       break;
-       }
-       if (cit != end && pos + len - 1 > cit->pos())
-               return false;
-
-       return true;
+       return fontlist_.hasChangeInRange(pos, len);
 }
 
 
@@ -944,8 +929,6 @@ void Paragraph::Private::simpleTeXSpecialChars(Buffer const & buf,
 void Paragraph::Private::validate(LaTeXFeatures & features,
                                Layout const & layout) const
 {
-       BufferParams const & bparams = features.bufferParams();
-
        // check the params.
        if (!params_.spacing().isDefault())
                features.require("setspace");
@@ -954,47 +937,9 @@ void Paragraph::Private::validate(LaTeXFeatures & features,
        features.useLayout(layout.name());
 
        // then the fonts
-       Language const * doc_language = bparams.language;
-
-       FontList::const_iterator fcit = fontlist_.begin();
-       FontList::const_iterator fend = fontlist_.end();
-       for (; fcit != fend; ++fcit) {
-               if (fcit->font().noun() == Font::ON) {
-                       LYXERR(Debug::LATEX) << "font.noun: "
-                                            << fcit->font().noun()
-                                            << endl;
-                       features.require("noun");
-                       LYXERR(Debug::LATEX) << "Noun enabled. Font: "
-                                            << to_utf8(fcit->font().stateText(0))
-                                            << endl;
-               }
-               switch (fcit->font().color()) {
-               case Color::none:
-               case Color::inherit:
-               case Color::ignore:
-                       // probably we should put here all interface colors used for
-                       // font displaying! For now I just add this ones I know of (Jug)
-               case Color::latex:
-               case Color::note:
-                       break;
-               default:
-                       features.require("color");
-                       LYXERR(Debug::LATEX) << "Color enabled. Font: "
-                                            << to_utf8(fcit->font().stateText(0))
-                                            << endl;
-               }
-
-               Language const * language = fcit->font().language();
-               if (language->babel() != doc_language->babel() &&
-                   language != ignore_language &&
-                   language != latex_language)
-               {
-                       features.useLanguage(language);
-                       LYXERR(Debug::LATEX) << "Found language "
-                                            << language->lang() << endl;
-               }
-       }
+       fontlist_.validate(features);
 
+       // then the indentation
        if (!params_.leftIndent().zero())
                features.require("ParagraphLeftIndent");
 
@@ -1239,13 +1184,8 @@ Font const Paragraph::getFontSettings(BufferParams const & bparams,
                BOOST_ASSERT(pos <= size());
        }
 
-       FontList::const_iterator cit = d->fontlist_.begin();
-       FontList::const_iterator end = d->fontlist_.end();
-       for (; cit != end; ++cit)
-               if (cit->pos() >= pos)
-                       break;
-
-       if (cit != end)
+       FontList::const_iterator cit = d->fontlist_.fontIterator(pos);
+       if (cit != d->fontlist_.end())
                return cit->font();
 
        if (pos == size() && !empty())
@@ -1343,34 +1283,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);
 }