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"
21 #include "OutputEnums.h"
23 #include "support/strfwd.h"
42 class TextMetricsInfo;
46 class MathData : private std::vector<MathAtom> {
48 /// re-use inhertited stuff
49 typedef std::vector<MathAtom> base_type;
50 using base_type::const_iterator;
51 using base_type::iterator;
52 using base_type::size_type;
53 using base_type::difference_type;
54 using base_type::size;
55 using base_type::empty;
56 using base_type::clear;
57 using base_type::begin;
59 using base_type::push_back;
60 using base_type::pop_back;
61 using base_type::back;
62 using base_type::front;
64 typedef size_type idx_type;
65 typedef size_type pos_type;
69 MathData(Buffer * buf = 0) : buffer_(buf) {}
71 MathData(Buffer * buf, const_iterator from, const_iterator to);
73 Buffer * buffer() { return buffer_; }
75 Buffer const * buffer() const { return buffer_; }
77 void append(MathData const & ar);
79 /// inserts single atom at position pos
80 void insert(size_type pos, MathAtom const & at);
81 /// inserts multiple atoms at position pos
82 void insert(size_type pos, MathData const & ar);
84 /// erase range from pos1 to pos2
85 void erase(iterator pos1, iterator pos2);
87 void erase(iterator pos);
88 /// erase range from pos1 to pos2
89 void erase(size_type pos1, size_type pos2);
91 void erase(size_type pos);
98 void replace(ReplaceData &);
100 void substitute(MathData const & m);
102 /// looks for exact match
103 bool match(MathData const & ar) const;
104 /// looks for inclusion match starting at pos
105 bool matchpart(MathData const & ar, pos_type pos) const;
106 /// looks for containment, return == size mean not found
107 size_type find(MathData const & ar) const;
108 /// looks for containment, return == size mean not found
109 size_type find_last(MathData const & ar) const;
111 bool contains(MathData const & ar) const;
113 void validate(LaTeXFeatures &) const;
115 /// checked write access
116 MathAtom & operator[](pos_type);
117 /// checked read access
118 MathAtom const & operator[](pos_type) const;
119 /// rebuild cached metrics information
120 void metrics(MetricsInfo & mi, Dimension & dim) const;
122 Dimension const & dimension(BufferView const &) const;
124 /// redraw cell using cache metrics information
125 void draw(PainterInfo & pi, int x, int y) const;
126 /// rebuild cached metrics information
127 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
128 /// redraw cell using cache metrics information
129 void drawT(TextPainter & pi, int x, int y) const;
130 /// mark cell for re-drawing
133 /// access to cached x coordinate of last drawing
134 int xo(BufferView const & bv) const;
135 /// access to cached y coordinate of last drawing
136 int yo(BufferView const & bv) const;
137 /// access to cached x coordinate of mid point of last drawing
138 int xm(BufferView const & bv) const;
139 /// access to cached y coordinate of mid point of last drawing
140 int ym(BufferView const & bv) const;
141 /// write access to coordinate;
142 void setXY(BufferView & bv, int x, int y) const;
143 /// returns x coordinate of given position in the array
144 int pos2x(BufferView const * bv, size_type pos) const;
145 /// returns position of given x coordinate
146 int pos2x(BufferView const * bv, size_type pos, int glue) const;
147 /// returns position of given x coordinate
148 size_type x2pos(BufferView const * bv, int pos) const;
149 /// returns position of given x coordinate fstarting from a certain pos
150 size_type x2pos(BufferView const * bv, int targetx, int glue) const;
151 /// returns distance of this cell to the point given by x and y
152 // assumes valid position and size cache
153 int dist(BufferView const & bv, int x, int y) const;
155 /// minimum ascent offset for superscript
156 int minasc() const { return minasc_; }
157 /// minimum descent offset for subscript
158 int mindes() const { return mindes_; }
159 /// level above/below which super/subscript should extend
160 int slevel() const { return slevel_; }
161 /// additional super/subscript shift
162 int sshift() const { return sshift_; }
163 /// superscript kerning
164 int kerning(BufferView const *) const { return kerning_; }
166 void swap(MathData & ar) { base_type::swap(ar); }
168 /// attach/detach arguments to macros, updating the cur to
169 /// stay visually at the same position (cur==0 is allowed)
170 void updateMacros(Cursor * cur, MacroContext const & mc, UpdateType);
172 void updateBuffer(ParIterator const &, UpdateType);
175 /// cached values for super/subscript placement
180 mutable int kerning_;
184 /// is this an exact match at this position?
185 bool find1(MathData const & ar, size_type pos) const;
188 void detachMacroParameters(DocIterator * dit, const size_type macroPos);
190 void attachMacroParameters(Cursor * cur, const size_type macroPos,
191 const size_type macroNumArgs, const int macroOptionals,
192 const bool fromInitToNormalMode, const bool interactiveInit,
193 const size_t appetite);
195 void collectOptionalParameters(Cursor * cur,
196 const size_type numOptionalParams, std::vector<MathData> & params,
197 size_t & pos, MathAtom & scriptToPutAround,
198 const pos_type macroPos, const int thisPos, const int thisSlice);
200 void collectParameters(Cursor * cur,
201 const size_type numParams, std::vector<MathData> & params,
202 size_t & pos, MathAtom & scriptToPutAround,
203 const pos_type macroPos, const int thisPos, const int thisSlice,
204 const size_t appetite);
208 std::ostream & operator<<(std::ostream & os, MathData const & ar);
210 odocstream & operator<<(odocstream & os, MathData const & ar);