3 * You are free to use and modify this code under the terms of
4 * the GNU General Public Licence version 2 or later.
8 \brief Low level container for math insets
9 * \author Alejandro Aguilar Sierra
10 * \author André Pönitz
11 * \author Lars Gullik Bjønnes
13 * Full author contact details are available in file CREDITS
14 \version February 2001
23 #include "math_atom.h"
24 #include "dimension.h"
29 class MathMetricsInfo;
30 class MathPainterInfo;
31 class TextMetricsInfo;
40 class MathArray : private std::vector<MathAtom> {
42 /// re-use inhertited stuff
43 typedef std::vector<MathAtom> base_type;
44 using base_type::const_iterator;
45 using base_type::iterator;
46 using base_type::size_type;
47 using base_type::difference_type;
48 using base_type::size;
49 using base_type::empty;
50 using base_type::clear;
51 using base_type::begin;
53 using base_type::push_back;
54 using base_type::pop_back;
55 using base_type::back;
56 using base_type::front;
57 using base_type::swap;
59 typedef size_type idx_type;
60 typedef size_type pos_type;
66 MathArray(const_iterator from, const_iterator to);
68 void append(MathArray 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, MathArray 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 substitute(MathMacro const & macro);
91 void replace(ReplaceData &);
93 /// looks for exact match
94 bool match(MathArray const & ar) const;
95 /// looks for inclusion match starting at pos
96 bool matchpart(MathArray const & ar, pos_type pos) const;
97 /// looks for containment, return == size mean not found
98 size_type find(MathArray const & ar) const;
99 /// looks for containment, return == size mean not found
100 size_type find_last(MathArray const & ar) const;
102 bool contains(MathArray 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 Dimension const & metrics(MathMetricsInfo & mi) const;
112 /// redraw cell using cache metrics information
113 void draw(MathPainterInfo & pi, int x, int y) const;
114 /// rebuild cached metrics information
115 Dimension const & metricsT(TextMetricsInfo const & mi) const;
116 /// redraw cell using cache metrics information
117 void drawT(TextPainter & pi, int x, int y) const;
118 /// mark cell for re-drawing
121 /// access to cached x coordinate of last drawing
122 int xo() const { return xo_; }
123 /// access to cached y coordinate of last drawing
124 int yo() const { return yo_; }
125 /// access to cached x coordinate of mid point of last drawing
126 int xm() const { return xo_ + dim_.w / 2; }
127 /// access to cached y coordinate of mid point of last drawing
128 int ym() const { return yo_ + (dim_.d - dim_.a) / 2; }
129 /// write access to coordinate;
130 void setXY(int x, int y) const;
131 /// returns x coordinate of given position in the array
132 int pos2x(size_type pos) const;
133 /// returns position of given x coordinate
134 int pos2x(size_type pos1, size_type pos2, int glue) const;
135 /// returns position of given x coordinate
136 size_type x2pos(int pos) const;
137 /// returns position of given x coordinate fstarting from a certain pos
138 size_type x2pos(size_type startpos, int targetx, int glue) const;
139 /// returns distance of this cell to the point given by x and y
140 // assumes valid position and size cache
141 int dist(int x, int y) const;
143 /// ascent of this cell above the baseline
144 int ascent() const { return dim_.a; }
145 /// descent of this cell below the baseline
146 int descent() const { return dim_.d; }
147 /// height of the cell
148 int height() const { return dim_.a + dim_.d; }
149 /// width of this cell
150 int width() const { return dim_.w; }
151 /// dimensions of cell
152 Dimension const & dim() const { return dim_; }
153 /// dimensions of cell
154 void setDim(Dimension const & d) const { dim_ = d; }
155 /// bounding box of this cell
156 void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
157 /// gives center coordinates
158 void center(int & x, int & y) const;
159 /// adjust (x,y) to point on boundary on a straight line from the center
160 void towards(int & x, int & y) const;
163 /// is this an exact match at this position?
164 bool find1(MathArray const & ar, size_type pos) const;
166 /// cached dimensions of cell
167 mutable Dimension dim_;
168 /// cached x coordinate of last drawing
170 /// cached y coordinate of last drawing
172 /// cached cleaness of cell
174 /// cached draw status of cell
179 std::ostream & operator<<(std::ostream & os, MathArray const & ar);