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"
41 class TextMetricsInfo;
45 class MathData : private std::vector<MathAtom> {
47 /// re-use inhertited stuff
48 typedef std::vector<MathAtom> base_type;
49 using base_type::const_iterator;
50 using base_type::iterator;
51 using base_type::size_type;
52 using base_type::difference_type;
53 using base_type::size;
54 using base_type::empty;
55 using base_type::clear;
56 using base_type::begin;
58 using base_type::push_back;
59 using base_type::pop_back;
60 using base_type::back;
61 using base_type::front;
63 typedef size_type idx_type;
64 typedef size_type pos_type;
68 MathData(Buffer * buf = 0) : buffer_(buf) {}
70 MathData(Buffer * buf, const_iterator from, const_iterator to);
72 Buffer * buffer() { return buffer_; }
74 Buffer const * buffer() const { return buffer_; }
76 void append(MathData const & ar);
78 /// inserts single atom at position pos
79 void insert(size_type pos, MathAtom const & at);
80 /// inserts multiple atoms at position pos
81 void insert(size_type pos, MathData const & ar);
83 /// erase range from pos1 to pos2
84 void erase(iterator pos1, iterator pos2);
86 void erase(iterator pos);
87 /// erase range from pos1 to pos2
88 void erase(size_type pos1, size_type pos2);
90 void erase(size_type pos);
97 void replace(ReplaceData &);
99 void substitute(MathData const & m);
101 /// looks for exact match
102 bool match(MathData const & ar) const;
103 /// looks for inclusion match starting at pos
104 bool matchpart(MathData const & ar, pos_type pos) const;
105 /// looks for containment, return == size mean not found
106 size_type find(MathData const & ar) const;
107 /// looks for containment, return == size mean not found
108 size_type find_last(MathData const & ar) const;
110 bool contains(MathData const & ar) const;
112 void validate(LaTeXFeatures &) const;
114 /// checked write access
115 MathAtom & operator[](pos_type);
116 /// checked read access
117 MathAtom const & operator[](pos_type) const;
118 /// rebuild cached metrics information
119 void metrics(MetricsInfo & mi, Dimension & dim) const;
121 Dimension const & dimension(BufferView const &) const;
123 /// redraw cell using cache metrics information
124 void draw(PainterInfo & pi, int x, int y) const;
125 /// rebuild cached metrics information
126 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
127 /// redraw cell using cache metrics information
128 void drawT(TextPainter & pi, int x, int y) const;
129 /// mark cell for re-drawing
132 /// access to cached x coordinate of last drawing
133 int xo(BufferView const & bv) const;
134 /// access to cached y coordinate of last drawing
135 int yo(BufferView const & bv) const;
136 /// access to cached x coordinate of mid point of last drawing
137 int xm(BufferView const & bv) const;
138 /// access to cached y coordinate of mid point of last drawing
139 int ym(BufferView const & bv) const;
140 /// write access to coordinate;
141 void setXY(BufferView & bv, int x, int y) const;
142 /// returns x coordinate of given position in the array
143 int pos2x(BufferView const * bv, size_type pos) const;
144 /// returns position of given x coordinate
145 int pos2x(BufferView const * bv, size_type pos, int glue) const;
146 /// returns position of given x coordinate
147 size_type x2pos(BufferView const * bv, int pos) const;
148 /// returns position of given x coordinate fstarting from a certain pos
149 size_type x2pos(BufferView const * bv, int targetx, int glue) const;
150 /// returns distance of this cell to the point given by x and y
151 // assumes valid position and size cache
152 int dist(BufferView const & bv, int x, int y) const;
154 /// minimum ascent offset for superscript
155 int minasc() const { return minasc_; }
156 /// minimum descent offset for subscript
157 int mindes() const { return mindes_; }
158 /// level above/below which super/subscript should extend
159 int slevel() const { return slevel_; }
160 /// additional super/subscript shift
161 int sshift() const { return sshift_; }
162 /// superscript kerning
163 int kerning(BufferView const *) const { return kerning_; }
165 void swap(MathData & ar) { base_type::swap(ar); }
167 /// attach/detach arguments to macros, updating the cur to
168 /// stay visually at the same position (cur==0 is allowed)
169 void updateMacros(Cursor * cur, MacroContext const & mc);
171 void updateLabels(ParIterator const &, UpdateType);
174 /// cached values for super/subscript placement
179 mutable int kerning_;
183 /// is this an exact match at this position?
184 bool find1(MathData const & ar, size_type pos) const;
187 void detachMacroParameters(DocIterator * dit, const size_type macroPos);
189 void attachMacroParameters(Cursor * cur, const size_type macroPos,
190 const size_type macroNumArgs, const int macroOptionals,
191 const bool fromInitToNormalMode, const bool interactiveInit,
192 const size_t appetite);
194 void collectOptionalParameters(Cursor * cur,
195 const size_type numOptionalParams, std::vector<MathData> & params,
196 size_t & pos, MathAtom & scriptToPutAround,
197 const pos_type macroPos, const int thisPos, const int thisSlice);
199 void collectParameters(Cursor * cur,
200 const size_type numParams, std::vector<MathData> & params,
201 size_t & pos, MathAtom & scriptToPutAround,
202 const pos_type macroPos, const int thisPos, const int thisSlice,
203 const size_t appetite);
207 std::ostream & operator<<(std::ostream & os, MathData const & ar);
209 odocstream & operator<<(odocstream & os, MathData const & ar);