3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * \author André Pönitz
13 * \author Jürgen Vigna
15 * Full author contact details are available in file CREDITS.
20 #include "ParagraphMetrics.h"
23 #include "BufferParams.h"
24 #include "BufferView.h"
28 #include "LaTeXFeatures.h"
33 #include "OutputParams.h"
35 #include "TextClass.h"
38 #include "frontends/FontMetrics.h"
40 #include "insets/InsetBibitem.h"
41 #include "insets/InsetArgument.h"
43 #include "support/lassert.h"
44 #include "support/debug.h"
45 #include "support/ExceptionMessage.h"
46 #include "support/gettext.h"
47 #include "support/lstrings.h"
48 #include "support/textutils.h"
56 using namespace lyx::support;
61 ParagraphMetrics::ParagraphMetrics(Paragraph const & par) :
62 position_(-1), par_(&par)
66 ParagraphMetrics & ParagraphMetrics::operator=(
67 ParagraphMetrics const & pm)
72 position_ = pm.position_;
77 void ParagraphMetrics::reset(Paragraph const & par)
85 void ParagraphMetrics::setPosition(int position)
91 Row & ParagraphMetrics::getRow(pos_type pos, bool boundary)
93 LBUFERR(!rows().empty());
95 // If boundary is set we should return the row on which
96 // the character before is inside.
97 if (pos > 0 && boundary)
100 RowList::iterator rit = rows_.end();
101 RowList::iterator const begin = rows_.begin();
103 for (--rit; rit != begin && rit->pos() > pos; --rit)
110 Row const & ParagraphMetrics::getRow(pos_type pos, bool boundary) const
112 LBUFERR(!rows().empty());
114 // If boundary is set we should return the row on which
115 // the character before is inside.
116 if (pos > 0 && boundary)
119 RowList::const_iterator rit = rows_.end();
120 RowList::const_iterator const begin = rows_.begin();
122 for (--rit; rit != begin && rit->pos() > pos; --rit)
129 size_t ParagraphMetrics::pos2row(pos_type pos) const
131 LBUFERR(!rows().empty());
133 RowList::const_iterator rit = rows_.end();
134 RowList::const_iterator const begin = rows_.begin();
136 for (--rit; rit != begin && rit->pos() > pos; --rit)
143 void ParagraphMetrics::dump() const
145 lyxerr << "Paragraph::dump: rows.size(): " << rows_.size() << endl;
146 for (size_t i = 0; i != rows_.size(); ++i) {
147 lyxerr << " row " << i << ": " << rows_[i];
151 int ParagraphMetrics::rightMargin(BufferView const & bv) const
153 BufferParams const & params = bv.buffer().params();
154 DocumentClass const & tclass = params.documentClass();
155 frontend::FontMetrics const & fm = theFontMetrics(params.getFont());
158 + fm.signedWidth(tclass.rightmargin())
159 + fm.signedWidth(par_->layout().rightmargin)
160 * 4 / (par_->getDepth() + 4);
166 // FIXME: this code seems bogus. Audit and rewrite (see bug #9860).
167 bool ParagraphMetrics::hfillExpansion(Row const & row, pos_type pos) const
169 if (!par_->isHfill(pos))
172 LASSERT(pos >= row.pos() && pos < row.endpos(), return false);
174 // expand at the end of a row only if there is another hfill on the same row
175 if (pos == row.endpos() - 1) {
176 for (pos_type i = row.pos(); i < pos; i++) {
177 if (par_->isHfill(i))
183 // expand at the beginning of a row only if it is the first row of a paragraph
184 if (pos == row.pos())
187 // do not expand in some labels
188 if (par_->layout().margintype != MARGIN_MANUAL && pos < par_->beginOfBody())
191 // if there is anything between the first char of the row and
192 // the specified position that is neither a newline nor an hfill,
193 // the hfill will be expanded, otherwise it won't
194 for (pos_type i = row.pos(); i < pos; i++) {
195 if (!par_->isNewline(i) && !par_->isEnvSeparator(i) && !par_->isHfill(i))