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) : minasc_(0), mindes_(0), slevel_(0),
70 sshift_(0), kerning_(0), buffer_(buf) {}
72 MathData(Buffer * buf, const_iterator from, const_iterator to);
74 Buffer * buffer() { return buffer_; }
76 Buffer const * buffer() const { return buffer_; }
78 void append(MathData const & ar);
80 /// inserts single atom at position pos
81 void insert(size_type pos, MathAtom const & at);
82 /// inserts multiple atoms at position pos
83 void insert(size_type pos, MathData const & ar);
85 /// erase range from pos1 to pos2
86 void erase(iterator pos1, iterator pos2);
88 void erase(iterator pos);
89 /// erase range from pos1 to pos2
90 void erase(size_type pos1, size_type pos2);
92 void erase(size_type pos);
99 void replace(ReplaceData &);
101 void substitute(MathData const & m);
103 /// looks for exact match
104 bool match(MathData const & ar) const;
105 /// looks for inclusion match starting at pos
106 bool matchpart(MathData const & ar, pos_type pos) const;
107 /// looks for containment, return == size mean not found
108 size_type find(MathData const & ar) const;
109 /// looks for containment, return == size mean not found
110 size_type find_last(MathData const & ar) const;
112 bool contains(MathData const & ar) const;
114 void validate(LaTeXFeatures &) const;
116 /// checked write access
117 MathAtom & operator[](pos_type);
118 /// checked read access
119 MathAtom const & operator[](pos_type) const;
120 /// rebuild cached metrics information
121 void metrics(MetricsInfo & mi, Dimension & dim) const;
123 Dimension const & dimension(BufferView const &) const;
125 /// redraw cell using cache metrics information
126 void draw(PainterInfo & pi, int x, int y) const;
127 /// rebuild cached metrics information
128 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
129 /// redraw cell using cache metrics information
130 void drawT(TextPainter & pi, int x, int y) const;
131 /// mark cell for re-drawing
134 /// access to cached x coordinate of last drawing
135 int xo(BufferView const & bv) const;
136 /// access to cached y coordinate of last drawing
137 int yo(BufferView const & bv) const;
138 /// access to cached x coordinate of mid point of last drawing
139 int xm(BufferView const & bv) const;
140 /// access to cached y coordinate of mid point of last drawing
141 int ym(BufferView const & bv) const;
142 /// write access to coordinate;
143 void setXY(BufferView & bv, int x, int y) const;
144 /// returns x coordinate of given position in the array
145 int pos2x(BufferView const * bv, size_type pos) const;
146 /// returns position of given x coordinate
147 int pos2x(BufferView const * bv, size_type pos, int glue) const;
148 /// returns position of given x coordinate
149 size_type x2pos(BufferView const * bv, int targetx) const;
150 /// returns position of given x coordinate starting from a certain pos
151 size_type x2pos(BufferView const * bv, int targetx, int glue) const;
152 /// returns distance of this cell to the point given by x and y
153 // assumes valid position and size cache
154 int dist(BufferView const & bv, int x, int y) const;
156 /// minimum ascent offset for superscript
157 int minasc() const { return minasc_; }
158 /// minimum descent offset for subscript
159 int mindes() const { return mindes_; }
160 /// level above/below which super/subscript should extend
161 int slevel() const { return slevel_; }
162 /// additional super/subscript shift
163 int sshift() const { return sshift_; }
164 /// superscript kerning
165 int kerning(BufferView const *) const { return kerning_; }
167 void swap(MathData & ar) { base_type::swap(ar); }
169 /// attach/detach arguments to macros, updating the cur to
170 /// stay visually at the same position (cur==0 is allowed)
171 void updateMacros(Cursor * cur, MacroContext const & mc, UpdateType);
173 void updateBuffer(ParIterator const &, UpdateType);
176 /// cached values for super/subscript placement
181 mutable int kerning_;
185 /// is this an exact match at this position?
186 bool find1(MathData const & ar, size_type pos) const;
189 void detachMacroParameters(DocIterator * dit, const size_type macroPos);
191 void attachMacroParameters(Cursor * cur, const size_type macroPos,
192 const size_type macroNumArgs, const int macroOptionals,
193 const bool fromInitToNormalMode, const bool interactiveInit,
194 const size_t appetite);
196 void collectOptionalParameters(Cursor * cur,
197 const size_type numOptionalParams, std::vector<MathData> & params,
198 size_t & pos, MathAtom & scriptToPutAround,
199 const pos_type macroPos, const int thisPos, const int thisSlice);
201 void collectParameters(Cursor * cur,
202 const size_type numParams, std::vector<MathData> & params,
203 size_t & pos, MathAtom & scriptToPutAround,
204 const pos_type macroPos, const int thisPos, const int thisSlice,
205 const size_t appetite);
209 std::ostream & operator<<(std::ostream & os, MathData const & ar);
211 odocstream & operator<<(odocstream & os, MathData const & ar);