X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFontList.cpp;h=e5a86dbb29249b9fe81d2306d47f9bf5137098a8;hb=27f1f8a94857b147fcd5097351ec2fb070c2966e;hp=5c7ea5b0debab2cc67c6759de7c4fb9083e868ac;hpb=4d9007bd61e41bad94b182e806702b6bbe5ea28c;p=lyx.git diff --git a/src/FontList.cpp b/src/FontList.cpp index 5c7ea5b0de..e5a86dbb29 100644 --- a/src/FontList.cpp +++ b/src/FontList.cpp @@ -4,13 +4,13 @@ * Licence details can be found in the file COPYING. * * \author Asger Alstrup - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * \author Jean-Marc Lasgouttes * \author Angus Leeming * \author John Levon - * \author André Pönitz + * \author André Pönitz * \author Dekel Tsur - * \author Jürgen Vigna + * \author Jürgen Vigna * \author Abdelrazak Younes * * Full author contact details are available in file CREDITS. @@ -20,43 +20,45 @@ #include "FontList.h" -#include +#include "support/lyxalgo.h" -#include - -using std::distance; -using std::endl; -using std::string; -using std::ostream; +using namespace std; namespace lyx { FontList::iterator FontList::fontIterator(pos_type pos) { - static Font dummy; - FontTable search_elem(pos, dummy); - return lower_bound(list_.begin(), list_.end(), search_elem, - matchFT()); + FontList::iterator it = list_.begin(); + FontList::iterator end = list_.end(); + for (; it != end; ++it) { + if (it->pos() >= pos) + break; + } + return it; } FontList::const_iterator FontList::fontIterator(pos_type pos) const { - static Font dummy; - FontTable search_elem(pos, dummy); - return lower_bound(list_.begin(), list_.end(), search_elem, - matchFT()); + FontList::const_iterator it = list_.begin(); + FontList::const_iterator end = list_.end(); + for (; it != end; ++it) { + if (it->pos() >= pos) + break; + } + return it; } -Font & FontList::get(pos_type pos) +Font const & 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; + + static Font const dummy; return dummy; } @@ -68,19 +70,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() && prev(it, 1)->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; } } @@ -108,31 +112,46 @@ 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 // in a new kernel. (Asger) // Next search font table - iterator beg = list_.begin(); - iterator it = beg; - iterator endit = list_.end(); - for (; it != endit; ++it) { - if (it->pos() >= pos) - break; - } - size_t const i = distance(beg, it); - bool notfound = (it == endit); + List::iterator it = fontIterator(pos); + bool const found = it != list_.end(); + if (found && it->font() == font) + // Font is already set. + return; + + size_t const i = distance(list_.begin(), it); + + // Is position pos a beginning of a font block? + bool const begin = pos == 0 || !found + || (i > 0 && list_[i - 1].pos() == pos - 1); - if (!notfound && list_[i].font() == font) + // Is position pos at the end of a font block? + bool const end = found && list_[i].pos() == pos; + + if (!begin && !end) { + // The general case: The block is split into 3 blocks + list_.insert(list_.begin() + i, + FontTable(pos - 1, list_[i].font())); + list_.insert(list_.begin() + i + 1, + FontTable(pos, font)); return; + } - bool begin = pos == 0 || notfound || - (i > 0 && list_[i - 1].pos() == pos - 1); - // Is position pos is a beginning of a font block? - bool end = !notfound && list_[i].pos() == pos; - // Is position pos is the end of a font block? - if (begin && end) { // A single char block + 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 @@ -157,12 +176,41 @@ 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)); } } + +FontSize FontList::highestInRange(pos_type startpos, pos_type endpos, + FontSize def_size) const +{ + if (list_.empty()) + return def_size; + + List::const_iterator end_it = fontIterator(endpos); + const_iterator const end = list_.end(); + if (end_it != end) + ++end_it; + + List::const_iterator cit = fontIterator(startpos); + + FontSize maxsize = FONT_SIZE_TINY; + for (; cit != end_it; ++cit) { + FontSize size = cit->font().fontInfo().size(); + if (size == FONT_SIZE_INHERIT) + size = def_size; + if (size > maxsize && size <= FONT_SIZE_HUGER) + maxsize = size; + } + return maxsize; +} + + +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