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