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
11 * Full author contact details are available in file CREDITS.
20 #include "math_atom.h"
21 #include "dimension.h"
28 class TextMetricsInfo;
32 class MathArray : private std::vector<MathAtom> {
34 /// re-use inhertited stuff
35 typedef std::vector<MathAtom> base_type;
36 using base_type::const_iterator;
37 using base_type::iterator;
38 using base_type::size_type;
39 using base_type::difference_type;
40 using base_type::size;
41 using base_type::empty;
42 using base_type::clear;
43 using base_type::begin;
45 using base_type::push_back;
46 using base_type::pop_back;
47 using base_type::back;
48 using base_type::front;
49 using base_type::swap;
51 typedef size_type idx_type;
52 typedef size_type pos_type;
58 MathArray(const_iterator from, const_iterator to);
60 void append(MathArray const & ar);
62 /// inserts single atom at position pos
63 void insert(size_type pos, MathAtom const & at);
64 /// inserts multiple atoms at position pos
65 void insert(size_type pos, MathArray const & ar);
67 /// erase range from pos1 to pos2
68 void erase(iterator pos1, iterator pos2);
70 void erase(iterator pos);
71 /// erase range from pos1 to pos2
72 void erase(size_type pos1, size_type pos2);
74 void erase(size_type pos);
81 void substitute(MathMacro const & macro);
83 void replace(ReplaceData &);
85 /// looks for exact match
86 bool match(MathArray const & ar) const;
87 /// looks for inclusion match starting at pos
88 bool matchpart(MathArray const & ar, pos_type pos) const;
89 /// looks for containment, return == size mean not found
90 size_type find(MathArray const & ar) const;
91 /// looks for containment, return == size mean not found
92 size_type find_last(MathArray const & ar) const;
94 bool contains(MathArray const & ar) const;
96 void validate(LaTeXFeatures &) const;
98 /// checked write access
99 MathAtom & operator[](pos_type);
100 /// checked read access
101 MathAtom const & operator[](pos_type) const;
102 /// rebuild cached metrics information
103 void metrics(MetricsInfo & mi) const;
104 /// rebuild cached metrics information
105 void metrics(MetricsInfo & mi, Dimension & dim) const;
106 /// redraw cell using cache metrics information
107 void draw(PainterInfo & pi, int x, int y) const;
108 /// rebuild cached metrics information
109 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
110 /// redraw cell using cache metrics information
111 void drawT(TextPainter & pi, int x, int y) const;
112 /// mark cell for re-drawing
115 /// access to cached x coordinate of last drawing
116 int xo() const { return xo_; }
117 /// access to cached y coordinate of last drawing
118 int yo() const { return yo_; }
119 /// access to cached x coordinate of mid point of last drawing
120 int xm() const { return xo_ + dim_.wid / 2; }
121 /// access to cached y coordinate of mid point of last drawing
122 int ym() const { return yo_ + (dim_.des - dim_.asc) / 2; }
123 /// write access to coordinate;
124 void setXY(int x, int y) const;
125 /// returns x coordinate of given position in the array
126 int pos2x(size_type pos) const;
127 /// returns position of given x coordinate
128 int pos2x(size_type pos, int glue) const;
129 /// returns position of given x coordinate
130 size_type x2pos(int pos) const;
131 /// returns position of given x coordinate fstarting from a certain pos
132 size_type x2pos(int targetx, int glue) const;
133 /// returns distance of this cell to the point given by x and y
134 // assumes valid position and size cache
135 int dist(int x, int y) const;
137 /// ascent of this cell above the baseline
138 int ascent() const { return dim_.asc; }
139 /// descent of this cell below the baseline
140 int descent() const { return dim_.des; }
141 /// height of the cell
142 int height() const { return dim_.asc + dim_.des; }
143 /// width of this cell
144 int width() const { return dim_.wid; }
145 /// dimensions of cell
146 Dimension const & dim() const { return dim_; }
147 /// dimensions of cell
148 void setDim(Dimension const & d) const { dim_ = d; }
149 /// bounding box of this cell
150 void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
151 /// gives center coordinates
152 void center(int & x, int & y) const;
153 /// adjust (x,y) to point on boundary on a straight line from the center
154 void towards(int & x, int & y) const;
155 /// clean up if necessary
156 void notifyCursorLeaves();
159 /// is this an exact match at this position?
160 bool find1(MathArray const & ar, size_type pos) const;
162 /// cached dimensions of cell
163 mutable Dimension dim_;
164 /// cached x coordinate of last drawing
166 /// cached y coordinate of last drawing
168 /// cached cleaness of cell
170 /// cached draw status of cell
175 std::ostream & operator<<(std::ostream & os, MathArray const & ar);