]> git.lyx.org Git - lyx.git/blob - src/ParagraphMetrics.C
src/support/unlink.C: Fix an #include error
[lyx.git] / src / ParagraphMetrics.C
1 /**
2  * \file paragraph.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author Angus Leeming
10  * \author John Levon
11  * \author André Pönitz
12  * \author Dekel Tsur
13  * \author Jürgen Vigna
14  *
15  * Full author contact details are available in file CREDITS.
16  */
17
18 #include <config.h>
19
20 #include "ParagraphMetrics.h"
21
22 #include "buffer.h"
23 #include "bufferparams.h"
24 #include "counters.h"
25 #include "encoding.h"
26 #include "debug.h"
27 #include "gettext.h"
28 #include "language.h"
29 #include "LaTeXFeatures.h"
30 #include "lyxfont.h"
31 #include "lyxrc.h"
32 #include "lyxrow.h"
33 #include "outputparams.h"
34 #include "paragraph_funcs.h"
35 #include "ParagraphList_fwd.h"
36
37 #include "rowpainter.h"
38
39 #include "sgml.h"
40 #include "texrow.h"
41 #include "vspace.h"
42
43 #include "frontends/FontMetrics.h"
44
45 #include "insets/insetbibitem.h"
46 #include "insets/insetoptarg.h"
47
48 #include "support/lstrings.h"
49 #include "support/textutils.h"
50 #include "support/convert.h"
51 #include "support/unicode.h"
52
53 #include <boost/bind.hpp>
54
55 #include <algorithm>
56 #include <list>
57 #include <stack>
58 #include <sstream>
59
60
61 namespace lyx {
62
63 using lyx::support::contains;
64 using lyx::support::rsplit;
65 using support::subst;
66
67 using std::distance;
68 using std::endl;
69 using std::list;
70 using std::stack;
71 using std::string;
72 using std::ostream;
73 using std::ostringstream;
74
75
76 ParagraphMetrics::ParagraphMetrics(Paragraph const & par): par_(&par)
77 {
78 }
79
80
81 Row & ParagraphMetrics::getRow(pos_type pos, bool boundary)
82 {
83         BOOST_ASSERT(!rows().empty());
84
85         // If boundary is set we should return the row on which
86         // the character before is inside.
87         if (pos > 0 && boundary)
88                 --pos;
89
90         RowList::iterator rit = rows_.end();
91         RowList::iterator const begin = rows_.begin();
92
93         for (--rit; rit != begin && rit->pos() > pos; --rit)
94                 ;
95
96         return *rit;
97 }
98
99
100 Row const & ParagraphMetrics::getRow(pos_type pos, bool boundary) const
101 {
102         BOOST_ASSERT(!rows().empty());
103
104         // If boundary is set we should return the row on which
105         // the character before is inside.
106         if (pos > 0 && boundary)
107                 --pos;
108
109         RowList::const_iterator rit = rows_.end();
110         RowList::const_iterator const begin = rows_.begin();
111
112         for (--rit; rit != begin && rit->pos() > pos; --rit)
113                 ;
114
115         return *rit;
116 }
117
118
119 size_t ParagraphMetrics::pos2row(pos_type pos) const
120 {
121         BOOST_ASSERT(!rows().empty());
122
123         RowList::const_iterator rit = rows_.end();
124         RowList::const_iterator const begin = rows_.begin();
125
126         for (--rit; rit != begin && rit->pos() > pos; --rit)
127                 ;
128
129         return rit - begin;
130 }
131
132
133 void ParagraphMetrics::dump() const
134 {
135         lyxerr << "Paragraph::dump: rows.size(): " << rows_.size() << endl;
136         for (size_t i = 0; i != rows_.size(); ++i) {
137                 lyxerr << "  row " << i << ":   ";
138                 rows_[i].dump();
139         }
140 }
141
142 int ParagraphMetrics::rightMargin(Buffer const & buffer) const
143 {
144         BufferParams const & params = buffer.params();
145         LyXTextClass const & tclass = params.getLyXTextClass();
146         docstring trmarg = from_utf8(tclass.rightmargin());
147         docstring lrmarg = from_utf8(par_->layout()->rightmargin);
148         frontend::FontMetrics const & fm = theFontMetrics(params.getFont());
149         int const r_margin =
150                 lyx::rightMargin()
151                 + fm.signedWidth(trmarg)
152                 + fm.signedWidth(lrmarg)
153                 * 4 / (par_->getDepth() + 4);
154
155         return r_margin;
156 }
157
158 } // namespace lyx