From a92a5e20e6560ca675710b0def3703845e67737d Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Mon, 1 Mar 2004 10:46:58 +0000 Subject: [PATCH] move FontIterator to own files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8467 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 3 +++ src/FontIterator.C | 50 ++++++++++++++++++++++++++++++++++++++++++++++ src/FontIterator.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 2 ++ src/lyxtext.h | 20 ------------------- src/text.C | 32 +---------------------------- 6 files changed, 106 insertions(+), 51 deletions(-) create mode 100644 src/FontIterator.C create mode 100644 src/FontIterator.h diff --git a/src/ChangeLog b/src/ChangeLog index 0543f2e80f..86d503d67a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,6 @@ +2004-03-01 Alfredo Braunstein + + * FontIterator.[Ch]: move FontIterator from lyxtext.h/text.C to here 2004-03-01 Alfredo Braunstein diff --git a/src/FontIterator.C b/src/FontIterator.C new file mode 100644 index 0000000000..9de58e3e3b --- /dev/null +++ b/src/FontIterator.C @@ -0,0 +1,50 @@ +/** + * \file src/FontIterator.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS. + * + */ + + +#include + +#include "lyxtext.h" + +#include "FontIterator.h" +#include "paragraph.h" + + +FontIterator::FontIterator(LyXText const & text, ParagraphList::iterator pit, + lyx::pos_type pos) + : text_(text), pit_(pit), pos_(pos), + font_(text.getFont(pit, pos)), + endspan_(pit->getEndPosOfFontSpan(pos)), + bodypos_(pit->beginOfBody()) +{} + + +LyXFont FontIterator::operator*() const +{ + return font_; +} + + +LyXFont * FontIterator::operator->() +{ + return &font_; +} + + +FontIterator & FontIterator::operator++() +{ + ++pos_; + if (pos_ > endspan_ || pos_ == bodypos_) { + font_ = text_.getFont(pit_, pos_); + endspan_ = pit_->getEndPosOfFontSpan(pos_); + } + return *this; +} diff --git a/src/FontIterator.h b/src/FontIterator.h new file mode 100644 index 0000000000..f640c8a661 --- /dev/null +++ b/src/FontIterator.h @@ -0,0 +1,50 @@ +// -*- C++ -*- +/** + * \file src/FontIterator.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS. + * + * + * Calling LyXText::getFont is slow. While rebreaking we scan a + * paragraph from left to right calling getFont for every char. This + * simple class address this problem by hidding an optimization trick + * (not mine btw -AB): the font is reused in the whole font span. The + * class handles transparently the "hidden" (not part of the fontlist) + * label font (as getFont does). + */ + +#ifndef FONTITERATOR_H +#define FONTITERATOR_H + + +#include "lyxfont.h" +#include "ParagraphList_fwd.h" + +#include "support/types.h" + +class LyXText; + +class FontIterator : std::iterator +{ +public: + FontIterator(LyXText const & text, ParagraphList::iterator pit, + lyx::pos_type pos); + + LyXFont operator*() const; + FontIterator & operator++(); + LyXFont * operator->(); + +private: + LyXText const & text_; + ParagraphList::iterator pit_; + lyx::pos_type pos_; + LyXFont font_; + lyx::pos_type endspan_; + lyx::pos_type bodypos_; +}; + +#endif //FONTITERATOR_H diff --git a/src/Makefile.am b/src/Makefile.am index 1cc8e44aae..9d489999b9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -77,6 +77,8 @@ lyx_SOURCES = \ FloatList.h \ Floating.C \ Floating.h \ + FontIterator.C \ + FontIterator.h \ FuncStatus.C \ FuncStatus.h \ InsetList.C \ diff --git a/src/lyxtext.h b/src/lyxtext.h index d724b98300..3ab56aeb9c 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -464,24 +464,4 @@ std::string expandLabel(LyXTextClass const & textclass, LyXLayout_ptr const & layout, bool appendix); -class FontIterator : std::iterator -{ -public: - FontIterator(LyXText const & text, ParagraphList::iterator pit, - lyx::pos_type pos); - - LyXFont operator*() const; - FontIterator & operator++(); - LyXFont * operator->(); - -private: - LyXText const & text_; - ParagraphList::iterator pit_; - lyx::pos_type pos_; - LyXFont font_; - lyx::pos_type endspan_; - lyx::pos_type bodypos_; -}; - - #endif // LYXTEXT_H diff --git a/src/text.C b/src/text.C index d452e540d1..fcb390712d 100644 --- a/src/text.C +++ b/src/text.C @@ -27,6 +27,7 @@ #include "dispatchresult.h" #include "encoding.h" #include "funcrequest.h" +#include "FontIterator.h" #include "gettext.h" #include "language.h" #include "LColor.h" @@ -444,37 +445,6 @@ pos_type addressBreakPoint(pos_type i, Paragraph const & par) }; -FontIterator::FontIterator(LyXText const & text, ParagraphList::iterator pit, - lyx::pos_type pos) - : text_(text), pit_(pit), pos_(pos), - font_(text.getFont(pit, pos)), - endspan_(pit->getEndPosOfFontSpan(pos)), - bodypos_(pit->beginOfBody()) -{} - - -LyXFont FontIterator::operator*() const -{ - return font_; -} - - -LyXFont * FontIterator::operator->() -{ - return &font_; -} - - -FontIterator & FontIterator::operator++() -{ - ++pos_; - if (pos_ > endspan_ || pos_ == bodypos_) { - font_ = text_.getFont(pit_, pos_); - endspan_ = pit_->getEndPosOfFontSpan(pos_); - } - return *this; -} - void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const {