move FontIterator to own files

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8467 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Alfredo Braunstein 2004-03-01 10:46:58 +00:00
parent 2f78aab340
commit a92a5e20e6
6 changed files with 106 additions and 51 deletions

View File

@ -1,3 +1,6 @@
2004-03-01 Alfredo Braunstein <abraunst@lyx.org>
* FontIterator.[Ch]: move FontIterator from lyxtext.h/text.C to here
2004-03-01 Alfredo Braunstein <abraunst@lyx.org> 2004-03-01 Alfredo Braunstein <abraunst@lyx.org>

50
src/FontIterator.C Normal file
View File

@ -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 <config.h>
#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;
}

50
src/FontIterator.h Normal file
View File

@ -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<std::forward_iterator_tag, LyXFont>
{
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

View File

@ -77,6 +77,8 @@ lyx_SOURCES = \
FloatList.h \ FloatList.h \
Floating.C \ Floating.C \
Floating.h \ Floating.h \
FontIterator.C \
FontIterator.h \
FuncStatus.C \ FuncStatus.C \
FuncStatus.h \ FuncStatus.h \
InsetList.C \ InsetList.C \

View File

@ -464,24 +464,4 @@ std::string expandLabel(LyXTextClass const & textclass,
LyXLayout_ptr const & layout, bool appendix); LyXLayout_ptr const & layout, bool appendix);
class FontIterator : std::iterator<std::forward_iterator_tag, LyXFont>
{
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 #endif // LYXTEXT_H

View File

@ -27,6 +27,7 @@
#include "dispatchresult.h" #include "dispatchresult.h"
#include "encoding.h" #include "encoding.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "FontIterator.h"
#include "gettext.h" #include "gettext.h"
#include "language.h" #include "language.h"
#include "LColor.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 void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
{ {