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"
23 #include "OutputEnums.h"
25 #include "support/strfwd.h"
45 class TextMetricsInfo;
49 class MathData : private std::vector<MathAtom> {
51 /// re-use inhertited stuff
52 typedef std::vector<MathAtom> base_type;
53 using base_type::const_iterator;
54 using base_type::iterator;
55 using base_type::size_type;
56 using base_type::difference_type;
57 using base_type::size;
58 using base_type::empty;
59 using base_type::clear;
60 using base_type::begin;
62 using base_type::push_back;
63 using base_type::pop_back;
64 using base_type::back;
65 using base_type::front;
67 typedef size_type idx_type;
68 typedef size_type pos_type;
72 MathData(Buffer * buf = 0) : minasc_(0), mindes_(0), slevel_(0),
73 sshift_(0), kerning_(0), buffer_(buf) {}
75 MathData(Buffer * buf, const_iterator from, const_iterator to);
77 Buffer * buffer() { return buffer_; }
79 Buffer const * buffer() const { return buffer_; }
81 void append(MathData const & ar);
83 /// inserts single atom at position pos
84 void insert(size_type pos, MathAtom const & at);
85 /// inserts multiple atoms at position pos
86 void insert(size_type pos, MathData const & ar);
88 /// erase range from pos1 to pos2
89 void erase(iterator pos1, iterator pos2);
91 void erase(iterator pos);
92 /// erase range from pos1 to pos2
93 void erase(size_type pos1, size_type pos2);
95 void erase(size_type pos);
102 void replace(ReplaceData &);
104 void substitute(MathData const & m);
106 /// looks for exact match
107 bool match(MathData const & ar) const;
108 /// looks for inclusion match starting at pos
109 bool matchpart(MathData const & ar, pos_type pos) const;
110 /// looks for containment, return == size mean not found
111 size_type find(MathData const & ar) const;
112 /// looks for containment, return == size mean not found
113 size_type find_last(MathData const & ar) const;
115 bool contains(MathData const & ar) const;
117 void validate(LaTeXFeatures &) const;
119 /// checked write access
120 MathAtom & operator[](pos_type);
121 /// checked read access
122 MathAtom const & operator[](pos_type) const;
124 /// Add this array to a math row. Return true if contents got added
125 bool addToMathRow(MathRow &, MetricsInfo & mi) const;
127 /// rebuild cached metrics information
128 void metrics(MetricsInfo & mi, Dimension & dim) const;
130 Dimension const & dimension(BufferView const &) const;
132 /// redraw cell using cache metrics information
133 void draw(PainterInfo & pi, int x, int y) const;
134 /// rebuild cached metrics information
135 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
136 /// redraw cell using cache metrics information
137 void drawT(TextPainter & pi, int x, int y) const;
138 /// mark cell for re-drawing
141 /// access to cached x coordinate of last drawing
142 int xo(BufferView const & bv) const;
143 /// access to cached y coordinate of last drawing
144 int yo(BufferView const & bv) const;
145 /// access to cached x coordinate of mid point of last drawing
146 int xm(BufferView const & bv) const;
147 /// access to cached y coordinate of mid point of last drawing
148 int ym(BufferView const & bv) const;
149 /// write access to coordinate;
150 void setXY(BufferView & bv, int x, int y) const;
151 /// returns x coordinate of given position in the array
152 int pos2x(BufferView const * bv, size_type pos) const;
153 /// returns position of given x coordinate
154 size_type x2pos(BufferView const * bv, int targetx) const;
155 /// returns distance of this cell to the point given by x and y
156 // assumes valid position and size cache
157 int dist(BufferView const & bv, int x, int y) const;
159 /// minimum ascent offset for superscript
160 int minasc() const { return minasc_; }
161 /// minimum descent offset for subscript
162 int mindes() const { return mindes_; }
163 /// level above/below which super/subscript should extend
164 int slevel() const { return slevel_; }
165 /// additional super/subscript shift
166 int sshift() const { return sshift_; }
167 /// superscript kerning
168 int kerning(BufferView const *) const { return kerning_; }
170 void swap(MathData & ar) { base_type::swap(ar); }
172 /// attach/detach arguments to macros, updating the cur to
173 /// stay visually at the same position (cur==0 is allowed)
174 void updateMacros(Cursor * cur, MacroContext const & mc, UpdateType);
176 void updateBuffer(ParIterator const &, UpdateType);
179 /// cached values for super/subscript placement
184 mutable int kerning_;
187 /// cached object that describes typeset data
188 mutable std::map<BufferView*, MathRow> mrow_cache_;
191 /// is this an exact match at this position?
192 bool find1(MathData const & ar, size_type pos) const;
195 void detachMacroParameters(DocIterator * dit, const size_type macroPos);
197 void attachMacroParameters(Cursor * cur, const size_type macroPos,
198 const size_type macroNumArgs, const int macroOptionals,
199 const bool fromInitToNormalMode, const bool interactiveInit,
200 const size_t appetite);
202 void collectOptionalParameters(Cursor * cur,
203 const size_type numOptionalParams, std::vector<MathData> & params,
204 size_t & pos, MathAtom & scriptToPutAround,
205 const pos_type macroPos, const int thisPos, const int thisSlice);
207 void collectParameters(Cursor * cur,
208 const size_type numParams, std::vector<MathData> & params,
209 size_t & pos, MathAtom & scriptToPutAround,
210 const pos_type macroPos, const int thisPos, const int thisSlice,
211 const size_t appetite);
215 std::ostream & operator<<(std::ostream & os, MathData const & ar);
217 odocstream & operator<<(odocstream & os, MathData const & ar);