4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alejandro Aguilar Sierra
9 * \author Lars Gullik Bjønnes
10 * \author Stefan Schimanski
12 * Full author contact details are available in file CREDITS.
18 #include "Dimension.h"
23 #include "OutputEnums.h"
25 #include "support/strfwd.h"
44 class TextMetricsInfo;
48 class MathData : private std::vector<MathAtom> {
50 /// re-use inhertited stuff
51 typedef std::vector<MathAtom> base_type;
52 using base_type::const_iterator;
53 using base_type::iterator;
54 using base_type::size_type;
55 using base_type::difference_type;
56 using base_type::size;
57 using base_type::empty;
58 using base_type::clear;
59 using base_type::begin;
61 using base_type::push_back;
62 using base_type::pop_back;
63 using base_type::back;
64 using base_type::front;
66 typedef size_type idx_type;
67 typedef size_type pos_type;
71 explicit MathData(Buffer * buf = 0) : minasc_(0), mindes_(0), slevel_(0),
72 sshift_(0), buffer_(buf) {}
74 MathData(Buffer * buf, const_iterator from, const_iterator to);
76 Buffer * buffer() { return buffer_; }
78 Buffer const * buffer() const { return buffer_; }
80 void append(MathData const & ar);
82 /// inserts single atom at position pos
83 void insert(size_type pos, MathAtom const & at);
84 /// inserts multiple atoms at position pos
85 void insert(size_type pos, MathData const & ar);
87 /// erase range from pos1 to pos2
88 void erase(iterator pos1, iterator pos2);
90 void erase(iterator pos);
91 /// erase range from pos1 to pos2
92 void erase(size_type pos1, size_type pos2);
94 void erase(size_type pos);
101 void replace(ReplaceData &);
103 void substitute(MathData const & m);
105 /// looks for exact match
106 bool match(MathData const & ar) const;
107 /// looks for inclusion match starting at pos
108 bool matchpart(MathData const & ar, pos_type pos) const;
109 /// looks for containment, return == size mean not found
110 size_type find(MathData const & ar) const;
111 /// looks for containment, return == size mean not found
112 size_type find_last(MathData const & ar) const;
114 bool contains(MathData const & ar) const;
116 void validate(LaTeXFeatures &) const;
118 /// checked write access
119 MathAtom & operator[](pos_type);
120 /// checked read access
121 MathAtom const & operator[](pos_type) const;
123 /// Add this array to a math row. Return true if contents got added
124 bool addToMathRow(MathRow &, MetricsInfo & mi) const;
126 /// rebuild cached metrics information
127 /** When \c tight is true, the height of the cell will be at least
128 * the x height of the font. Otherwise, it will be the max height
131 void metrics(MetricsInfo & mi, Dimension & dim, bool tight = true) const;
133 Dimension const & dimension(BufferView const &) const;
135 /// draw the selection over the cell
136 void drawSelection(PainterInfo & pi, int x, int y) const;
137 /// redraw cell using cache metrics information
138 void draw(PainterInfo & pi, int x, int y) const;
139 /// rebuild cached metrics information
140 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
141 /// redraw cell using cache metrics information
142 void drawT(TextPainter & pi, int x, int y) const;
143 /// approximate mathclass of the data
144 MathClass mathClass() const;
145 /// math class of last interesting element
146 MathClass lastMathClass() const;
148 /// access to cached x coordinate of last drawing
149 int xo(BufferView const & bv) const;
150 /// access to cached y coordinate of last drawing
151 int yo(BufferView const & bv) const;
152 /// access to cached x coordinate of mid point of last drawing
153 int xm(BufferView const & bv) const;
154 /// access to cached y coordinate of mid point of last drawing
155 int ym(BufferView const & bv) const;
156 /// write access to coordinate;
157 void setXY(BufferView & bv, int x, int y) const;
158 /// returns x coordinate of given position in the array
159 int pos2x(BufferView const * bv, size_type pos) const;
160 /// returns position of given x coordinate
161 size_type x2pos(BufferView const * bv, int targetx) const;
162 /// returns distance of this cell to the point given by x and y
163 // assumes valid position and size cache
164 int dist(BufferView const & bv, int x, int y) const;
166 /// minimum ascent offset for superscript
167 int minasc() const { return minasc_; }
168 /// minimum descent offset for subscript
169 int mindes() const { return mindes_; }
170 /// level above/below which super/subscript should extend
171 int slevel() const { return slevel_; }
172 /// additional super/subscript shift
173 int sshift() const { return sshift_; }
174 /// Italic correction as described in InsetMathScript.h
175 int kerning(BufferView const *) const;
177 void swap(MathData & ar) { base_type::swap(ar); }
179 /// attach/detach arguments to macros, updating the cur to
180 /// stay visually at the same position (cur==0 is allowed)
181 void updateMacros(Cursor * cur, MacroContext const & mc, UpdateType, int nesting);
183 void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false);
185 void setBuffer(Buffer & b);
188 /// cached values for super/subscript placement
196 /// is this an exact match at this position?
197 bool find1(MathData const & ar, size_type pos) const;
200 void detachMacroParameters(DocIterator * dit, const size_type macroPos);
202 void attachMacroParameters(Cursor * cur, const size_type macroPos,
203 const size_type macroNumArgs, const int macroOptionals,
204 const bool fromInitToNormalMode, const bool interactiveInit,
205 const size_t appetite);
207 void collectOptionalParameters(Cursor * cur,
208 const size_type numOptionalParams, std::vector<MathData> & params,
209 size_t & pos, MathAtom & scriptToPutAround,
210 const pos_type macroPos, const int thisPos, const int thisSlice);
212 void collectParameters(Cursor * cur,
213 const size_type numParams, std::vector<MathData> & params,
214 size_t & pos, MathAtom & scriptToPutAround,
215 const pos_type macroPos, const int thisPos, const int thisSlice,
216 const size_t appetite);
220 std::ostream & operator<<(std::ostream & os, MathData const & ar);
222 odocstream & operator<<(odocstream & os, MathData const & ar);