mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-26 22:17:41 +00:00
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:
parent
2f78aab340
commit
a92a5e20e6
@ -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>
|
||||
|
||||
|
50
src/FontIterator.C
Normal file
50
src/FontIterator.C
Normal 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
50
src/FontIterator.h
Normal 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
|
@ -77,6 +77,8 @@ lyx_SOURCES = \
|
||||
FloatList.h \
|
||||
Floating.C \
|
||||
Floating.h \
|
||||
FontIterator.C \
|
||||
FontIterator.h \
|
||||
FuncStatus.C \
|
||||
FuncStatus.h \
|
||||
InsetList.C \
|
||||
|
@ -464,24 +464,4 @@ std::string expandLabel(LyXTextClass const & textclass,
|
||||
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
|
||||
|
32
src/text.C
32
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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user