X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFontList.cpp;h=f6b456d9db495d4383cede00d8e38a71dbd77151;hb=1acedf11da79f509da706bc8d6d2f491c9676087;hp=a305e4f7284a7da52be7feec9b0b440d72a87a2d;hpb=3372738c6d589103b16b6d5d6b2ed07d776c9e99;p=lyx.git diff --git a/src/FontList.cpp b/src/FontList.cpp index a305e4f728..f6b456d9db 100644 --- a/src/FontList.cpp +++ b/src/FontList.cpp @@ -20,19 +20,11 @@ #include "FontList.h" -#include "BufferParams.h" -#include "debug.h" -#include "Language.h" -#include "LaTeXFeatures.h" - #include #include -using std::distance; -using std::endl; -using std::string; -using std::ostream; +using namespace std; namespace lyx { @@ -85,19 +77,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; } } @@ -125,6 +119,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 @@ -134,22 +136,36 @@ void FontList::set(pos_type pos, Font const & font) iterator beg = list_.begin(); iterator it = beg; iterator endit = list_.end(); + bool found = false; for (; it != endit; ++it) { - if (it->pos() >= pos) + if (it->pos() >= pos) { + found = true; break; + } } - size_t const i = distance(beg, it); - bool notfound = (it == endit); - - if (!notfound && list_[i].font() == font) + if (found && it->font() == font) return; - bool begin = pos == 0 || notfound || - (i > 0 && list_[i - 1].pos() == pos - 1); + size_t const i = distance(beg, it); + // Is position pos is a beginning of a font block? - bool end = !notfound && list_[i].pos() == pos; + bool begin = pos == 0 || !found + || (i > 0 && list_[i - 1].pos() == pos - 1); + // Is position pos is the end of a font block? - if (begin && end) { // A single char block + bool end = found && list_[i].pos() == pos; + + if (!begin && !end) { + // The general case: The block is splitted into 3 blocks + list_.insert(list_.begin() + i, + FontTable(pos - 1, list_[i].font())); + list_.insert(list_.begin() + i + 1, + FontTable(pos, font)); + return; + } + + if (begin && end) { + // A single char block if (i + 1 < list_.size() && list_[i + 1].font() == font) { // Merge the singleton block with the next block @@ -174,17 +190,12 @@ void FontList::set(pos_type pos, Font const & font) list_[i + 1].font() == font)) list_.insert(list_.begin() + i + 1, FontTable(pos, font)); - } else { // The general case. The block is splitted into 3 blocks - list_.insert(list_.begin() + i, - FontTable(pos - 1, list_[i].font())); - list_.insert(list_.begin() + i + 1, - FontTable(pos, font)); } } -Font_size FontList::highestInRange - (pos_type startpos, pos_type endpos, Font_size def_size) const +FontSize FontList::highestInRange + (pos_type startpos, pos_type endpos, FontSize def_size) const { if (list_.empty()) return def_size; @@ -205,12 +216,12 @@ Font_size FontList::highestInRange break; } - Font::FONT_SIZE maxsize = Font::SIZE_TINY; + FontSize maxsize = FONT_SIZE_TINY; for (; cit != end_it; ++cit) { - Font::FONT_SIZE size = cit->font().size(); - if (size == Font::INHERIT_SIZE) + FontSize size = cit->font().fontInfo().size(); + if (size == FONT_SIZE_INHERIT) size = def_size; - if (size > maxsize && size <= Font::SIZE_HUGER) + if (size > maxsize && size <= FONT_SIZE_HUGER) maxsize = size; } return maxsize; @@ -235,47 +246,10 @@ bool FontList::hasChangeInRange(pos_type pos, int len) const void FontList::validate(LaTeXFeatures & features) const { - BufferParams const & bparams = features.bufferParams(); - Language const * doc_language = bparams.language; - const_iterator fcit = list_.begin(); const_iterator fend = list_.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; - } - } + for (; fcit != fend; ++fcit) + fcit->font().validate(features); } } // namespace lyx