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"
29 #include "LaTeXFeatures.h"
33 #include "outputparams.h"
34 #include "paragraph_funcs.h"
36 #include "rowpainter.h"
42 #include "frontends/FontMetrics.h"
44 #include "insets/InsetBibitem.h"
45 #include "insets/InsetOptArg.h"
47 #include "support/lstrings.h"
48 #include "support/textutils.h"
49 #include "support/convert.h"
50 #include "support/unicode.h"
52 #include <boost/bind.hpp>
53 #include <boost/crc.hpp>
63 using lyx::support::contains;
64 using lyx::support::rsplit;
73 using std::ostringstream;
76 ParagraphMetrics::ParagraphMetrics(Paragraph const & par): par_(&par)
81 ParagraphMetrics & ParagraphMetrics::operator=(
82 ParagraphMetrics const & pm)
91 size_type ParagraphMetrics::calculateRowSignature(Row const & row)
93 boost::crc_32_type crc;
94 for (pos_type i = row.pos(); i < row.endpos(); ++i) {
95 char_type const b[] = { par_->getChar(i) };
96 crc.process_bytes(b, 1);
98 return crc.checksum();
102 void ParagraphMetrics::updateRowChangeStatus()
104 size_t const size = rows_.size();
105 row_change_status_.resize(size);
106 row_signature_.resize(size);
108 for (size_t i = 0; i != size; ++i) {
109 // Row signature; has row changed since last update?
110 size_type const row_sig = calculateRowSignature(rows_[i]);
111 row_change_status_[i] = row_signature_[i] != row_sig;
112 row_signature_[i] = row_sig;
117 Row & ParagraphMetrics::getRow(pos_type pos, bool boundary)
119 BOOST_ASSERT(!rows().empty());
121 // If boundary is set we should return the row on which
122 // the character before is inside.
123 if (pos > 0 && boundary)
126 RowList::iterator rit = rows_.end();
127 RowList::iterator const begin = rows_.begin();
129 for (--rit; rit != begin && rit->pos() > pos; --rit)
136 Row const & ParagraphMetrics::getRow(pos_type pos, bool boundary) const
138 BOOST_ASSERT(!rows().empty());
140 // If boundary is set we should return the row on which
141 // the character before is inside.
142 if (pos > 0 && boundary)
145 RowList::const_iterator rit = rows_.end();
146 RowList::const_iterator const begin = rows_.begin();
148 for (--rit; rit != begin && rit->pos() > pos; --rit)
155 size_t ParagraphMetrics::pos2row(pos_type pos) const
157 BOOST_ASSERT(!rows().empty());
159 RowList::const_iterator rit = rows_.end();
160 RowList::const_iterator const begin = rows_.begin();
162 for (--rit; rit != begin && rit->pos() > pos; --rit)
169 void ParagraphMetrics::dump() const
171 lyxerr << "Paragraph::dump: rows.size(): " << rows_.size() << endl;
172 for (size_t i = 0; i != rows_.size(); ++i) {
173 lyxerr << " row " << i << ": ";
178 int ParagraphMetrics::rightMargin(Buffer const & buffer) const
180 BufferParams const & params = buffer.params();
181 LyXTextClass const & tclass = params.getLyXTextClass();
182 docstring trmarg = from_utf8(tclass.rightmargin());
183 docstring lrmarg = from_utf8(par_->layout()->rightmargin);
184 frontend::FontMetrics const & fm = theFontMetrics(params.getFont());
187 + fm.signedWidth(trmarg)
188 + fm.signedWidth(lrmarg)
189 * 4 / (par_->getDepth() + 4);