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
11 \author Lars Gullik Bjønnes
12 \version February 2001
21 #include "math_atom.h"
22 #include "dimension.h"
27 class MathMetricsInfo;
28 class MathPainterInfo;
29 class TextMetricsInfo;
38 class MathArray : private std::vector<MathAtom> {
40 /// re-use inhertited stuff
41 typedef std::vector<MathAtom> base_type;
42 using base_type::const_iterator;
43 using base_type::iterator;
44 using base_type::size_type;
45 using base_type::difference_type;
46 using base_type::size;
47 using base_type::empty;
48 using base_type::clear;
49 using base_type::begin;
51 using base_type::push_back;
52 using base_type::pop_back;
53 using base_type::back;
54 using base_type::front;
55 using base_type::swap;
57 typedef size_type idx_type;
58 typedef size_type pos_type;
64 MathArray(const_iterator from, const_iterator to);
66 void append(MathArray 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, MathArray 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 substitute(MathMacro const & macro);
89 void replace(ReplaceData &);
91 /// looks for exact match
92 bool match(MathArray const & ar) const;
93 /// looks for inclusion match starting at pos
94 bool matchpart(MathArray const & ar, pos_type pos) const;
95 /// looks for containment, return == size mean not found
96 size_type find(MathArray const & ar) const;
97 /// looks for containment, return == size mean not found
98 size_type find_last(MathArray const & ar) const;
100 bool contains(MathArray 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 Dimension const & metrics(MathMetricsInfo & mi) const;
110 /// redraw cell using cache metrics information
111 void draw(MathPainterInfo & pi, int x, int y) const;
112 /// rebuild cached metrics information
113 Dimension const & metricsT(TextMetricsInfo const & mi) const;
114 /// redraw cell using cache metrics information
115 void drawT(TextPainter & pi, int x, int y) const;
116 /// mark cell for re-drawing
119 /// access to cached x coordinate of last drawing
120 int xo() const { return xo_; }
121 /// access to cached y coordinate of last drawing
122 int yo() const { return yo_; }
123 /// access to cached x coordinate of mid point of last drawing
124 int xm() const { return xo_ + dim_.w / 2; }
125 /// access to cached y coordinate of mid point of last drawing
126 int ym() const { return yo_ + (dim_.d - dim_.a) / 2; }
127 /// write access to coordinate;
128 void setXY(int x, int y);
129 /// returns x coordinate of given position in the array
130 int pos2x(size_type pos) const;
131 /// returns position of given x coordinate
132 int pos2x(size_type pos1, size_type pos2, int glue) const;
133 /// returns position of given x coordinate
134 size_type x2pos(int pos) const;
135 /// returns position of given x coordinate fstarting from a certain pos
136 size_type x2pos(size_type startpos, int targetx, int glue) const;
137 /// returns distance of this cell to the point given by x and y
138 // assumes valid position and size cache
139 int dist(int x, int y) const;
141 /// ascent of this cell above the baseline
142 int ascent() const { return dim_.a; }
143 /// descent of this cell below the baseline
144 int descent() const { return dim_.d; }
145 /// height of the cell
146 int height() const { return dim_.a + dim_.d; }
147 /// width of this cell
148 int width() const { return dim_.w; }
149 /// dimensions of cell
150 Dimension const & dim() const { return dim_; }
151 /// dimensions of cell
152 void setDim(Dimension const & d) const { dim_ = d; }
153 /// bounding box of this cell
154 void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
155 /// gives center coordinates
156 void center(int & x, int & y) const;
157 /// adjust (x,y) to point on boundary on a straight line from the center
158 void towards(int & x, int & y) const;
161 /// is this an exact match at this position?
162 bool find1(MathArray const & ar, size_type pos) const;
164 /// cached dimensions of cell
165 mutable Dimension dim_;
166 /// cached x coordinate of last drawing
168 /// cached y coordinate of last drawing
170 /// cached cleaness of cell
172 /// cached draw status of cell
177 std::ostream & operator<<(std::ostream & os, MathArray const & ar);