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