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 "support/strfwd.h"
37 class TextMetricsInfo;
41 class MathData : private std::vector<MathAtom> {
43 /// re-use inhertited stuff
44 typedef std::vector<MathAtom> base_type;
45 using base_type::const_iterator;
46 using base_type::iterator;
47 using base_type::size_type;
48 using base_type::difference_type;
49 using base_type::size;
50 using base_type::empty;
51 using base_type::clear;
52 using base_type::begin;
54 using base_type::push_back;
55 using base_type::pop_back;
56 using base_type::back;
57 using base_type::front;
59 typedef size_type idx_type;
60 typedef size_type pos_type;
66 MathData(const_iterator from, const_iterator to);
68 void append(MathData const & ar);
70 /// inserts single atom at position pos
71 void insert(size_type pos, MathAtom const & at);
72 /// inserts multiple atoms at position pos
73 void insert(size_type pos, MathData const & ar);
75 /// erase range from pos1 to pos2
76 void erase(iterator pos1, iterator pos2);
78 void erase(iterator pos);
79 /// erase range from pos1 to pos2
80 void erase(size_type pos1, size_type pos2);
82 void erase(size_type pos);
89 void replace(ReplaceData &);
91 void substitute(MathData const & m);
93 /// looks for exact match
94 bool match(MathData const & ar) const;
95 /// looks for inclusion match starting at pos
96 bool matchpart(MathData const & ar, pos_type pos) const;
97 /// looks for containment, return == size mean not found
98 size_type find(MathData const & ar) const;
99 /// looks for containment, return == size mean not found
100 size_type find_last(MathData const & ar) const;
102 bool contains(MathData const & ar) const;
104 void validate(LaTeXFeatures &) const;
106 /// checked write access
107 MathAtom & operator[](pos_type);
108 /// checked read access
109 MathAtom const & operator[](pos_type) const;
110 /// rebuild cached metrics information
111 void metrics(MetricsInfo & mi, Dimension & dim) const;
113 Dimension const & dimension(BufferView const &) const;
115 /// redraw cell using cache metrics information
116 void draw(PainterInfo & pi, int x, int y) const;
117 /// rebuild cached metrics information
118 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
119 /// redraw cell using cache metrics information
120 void drawT(TextPainter & pi, int x, int y) const;
121 /// mark cell for re-drawing
124 /// access to cached x coordinate of last drawing
125 int xo(BufferView const & bv) const;
126 /// access to cached y coordinate of last drawing
127 int yo(BufferView const & bv) const;
128 /// access to cached x coordinate of mid point of last drawing
129 int xm(BufferView const & bv) const;
130 /// access to cached y coordinate of mid point of last drawing
131 int ym(BufferView const & bv) const;
132 /// write access to coordinate;
133 void setXY(BufferView & bv, int x, int y) const;
134 /// returns x coordinate of given position in the array
135 int pos2x(BufferView const * bv, size_type pos) const;
136 /// returns position of given x coordinate
137 int pos2x(BufferView const * bv, size_type pos, int glue) const;
138 /// returns position of given x coordinate
139 size_type x2pos(BufferView const * bv, int pos) const;
140 /// returns position of given x coordinate fstarting from a certain pos
141 size_type x2pos(BufferView const * bv, int targetx, int glue) const;
142 /// returns distance of this cell to the point given by x and y
143 // assumes valid position and size cache
144 int dist(BufferView const & bv, int x, int y) const;
146 /// minimum ascent offset for superscript
147 int minasc() const { return minasc_; }
148 /// minimum descent offset for subscript
149 int mindes() const { return mindes_; }
150 /// level above/below which super/subscript should extend
151 int slevel() const { return slevel_; }
152 /// additional super/subscript shift
153 int sshift() const { return sshift_; }
154 /// superscript kerning
155 int kerning(BufferView const *) const { return kerning_; }
157 void swap(MathData & ar) { base_type::swap(ar); }
159 /// attach/detach arguments to macros, updating the cur to
160 /// stay visually at the same position (cur==0 is allowed)
161 void updateMacros(Cursor * cur, MacroContext const & mc);
164 /// cached values for super/subscript placement
169 mutable int kerning_;
172 /// is this an exact match at this position?
173 bool find1(MathData const & ar, size_type pos) const;
176 void detachMacroParameters(Cursor * cur, const size_type macroPos);
178 void attachMacroParameters(Cursor * cur, const size_type macroPos,
179 const size_type macroNumArgs, const int macroOptionals,
180 const bool fromInitToNormalMode, const bool interactiveInit,
181 const size_t appetite);
183 void collectOptionalParameters(Cursor * cur,
184 const size_type numOptionalParams, std::vector<MathData> & params,
185 size_t & pos, MathAtom & scriptToPutAround,
186 const pos_type macroPos, const int thisPos, const int thisSlice);
188 void collectParameters(Cursor * cur,
189 const size_type numParams, std::vector<MathData> & params,
190 size_t & pos, MathAtom & scriptToPutAround,
191 const pos_type macroPos, const int thisPos, const int thisSlice,
192 const size_t appetite);
196 std::ostream & operator<<(std::ostream & os, MathData const & ar);
198 odocstream & operator<<(odocstream & os, MathData const & ar);