From 2530fdb9abf7ea668a0692e6cc337126ade6f864 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 28 Mar 2008 08:45:33 +0000 Subject: [PATCH] FontIterator is only used in TextMetrics. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24013 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/FontIterator.cpp | 55 ------------------------------------ src/FontIterator.h | 67 -------------------------------------------- src/Makefile.am | 2 -- src/Text.cpp | 1 - src/TextMetrics.cpp | 58 +++++++++++++++++++++++++++++++++++++- 5 files changed, 57 insertions(+), 126 deletions(-) delete mode 100644 src/FontIterator.cpp delete mode 100644 src/FontIterator.h diff --git a/src/FontIterator.cpp b/src/FontIterator.cpp deleted file mode 100644 index e104ca414d..0000000000 --- a/src/FontIterator.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/** - * \file src/FontIterator.cpp - * 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 "FontIterator.h" - -#include "TextMetrics.h" -#include "Paragraph.h" - - -namespace lyx { - - -FontIterator::FontIterator(TextMetrics const & tm, - Paragraph const & par, pit_type pit, pos_type pos) - : tm_(tm), par_(par), pit_(pit), pos_(pos), - font_(tm.displayFont(pit, pos)), - endspan_(par.fontSpan(pos).last), - bodypos_(par.beginOfBody()) -{} - - -Font const & FontIterator::operator*() const -{ - return font_; -} - - -Font * FontIterator::operator->() -{ - return &font_; -} - - -FontIterator & FontIterator::operator++() -{ - ++pos_; - if (pos_ > endspan_ || pos_ == bodypos_) { - font_ = tm_.displayFont(pit_, pos_); - endspan_ = par_.fontSpan(pos_).last; - } - return *this; -} - - -} // namespace lyx diff --git a/src/FontIterator.h b/src/FontIterator.h deleted file mode 100644 index ce5d9369cf..0000000000 --- a/src/FontIterator.h +++ /dev/null @@ -1,67 +0,0 @@ -// -*- 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 Text::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 "Font.h" - -#include "support/types.h" - - -namespace lyx { - -class Paragraph; -class TextMetrics; - - -class FontIterator -{ -public: - /// - FontIterator(TextMetrics const & tm, - Paragraph const & par, pit_type pit, pos_type pos); - /// - Font const & operator*() const; - /// - FontIterator & operator++(); - /// - Font * operator->(); - -private: - /// - TextMetrics const & tm_; - /// - Paragraph const & par_; - /// - pit_type pit_; - /// - pos_type pos_; - /// - Font font_; - /// - pos_type endspan_; - /// - pos_type bodypos_; -}; - - -} // namespace lyx - -#endif // FONTITERATOR_H diff --git a/src/Makefile.am b/src/Makefile.am index a8c490deca..4826fe8226 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -107,7 +107,6 @@ SOURCEFILESCORE = \ Floating.cpp \ FloatList.cpp \ FontInfo.cpp \ - FontIterator.cpp \ FontList.cpp \ Font.cpp \ Format.cpp \ @@ -207,7 +206,6 @@ HEADERFILESCORE = \ Font.h \ FontEnums.h \ FontInfo.h \ - FontIterator.h \ FontList.h \ Format.h \ FuncCode.h \ diff --git a/src/Text.cpp b/src/Text.cpp index 8db7ef65aa..8b7457108d 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -34,7 +34,6 @@ #include "ErrorList.h" #include "FuncRequest.h" #include "factory.h" -#include "FontIterator.h" #include "Language.h" #include "Length.h" #include "Lexer.h" diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index c46a8e48eb..904c7611a9 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -27,7 +27,6 @@ #include "CoordCache.h" #include "Cursor.h" #include "CutAndPaste.h" -#include "FontIterator.h" #include "FuncRequest.h" #include "InsetList.h" #include "Layout.h" @@ -694,6 +693,63 @@ int TextMetrics::labelEnd(pit_type const pit) const return leftMargin(max_width_, pit); } +namespace { + +/** + * Calling Text::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). + **/ +class FontIterator +{ +public: + /// + FontIterator(TextMetrics const & tm, + Paragraph const & par, pit_type pit, pos_type pos) + : tm_(tm), par_(par), pit_(pit), pos_(pos), + font_(tm.displayFont(pit, pos)), + endspan_(par.fontSpan(pos).last), + bodypos_(par.beginOfBody()) + {} + + /// + Font const & operator*() const { return font_; } + + /// + FontIterator & operator++() + { + ++pos_; + if (pos_ > endspan_ || pos_ == bodypos_) { + font_ = tm_.displayFont(pit_, pos_); + endspan_ = par_.fontSpan(pos_).last; + } + return *this; + } + + /// + Font * operator->() { return &font_; } + +private: + /// + TextMetrics const & tm_; + /// + Paragraph const & par_; + /// + pit_type pit_; + /// + pos_type pos_; + /// + Font font_; + /// + pos_type endspan_; + /// + pos_type bodypos_; +}; + +} // anon namespace pit_type TextMetrics::rowBreakPoint(int width, pit_type const pit, pit_type pos) const -- 2.39.2