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 "Dimension.h"
22 #include "support/docstream.h"
32 class TextMetricsInfo;
36 class MathData : private std::vector<MathAtom> {
38 /// re-use inhertited stuff
39 typedef std::vector<MathAtom> base_type;
40 using base_type::const_iterator;
41 using base_type::iterator;
42 using base_type::size_type;
43 using base_type::difference_type;
44 using base_type::size;
45 using base_type::empty;
46 using base_type::clear;
47 using base_type::begin;
49 using base_type::push_back;
50 using base_type::pop_back;
51 using base_type::back;
52 using base_type::front;
54 typedef size_type idx_type;
55 typedef size_type pos_type;
61 MathData(const_iterator from, const_iterator to);
63 void append(MathData const & ar);
65 /// inserts single atom at position pos
66 void insert(size_type pos, MathAtom const & at);
67 /// inserts multiple atoms at position pos
68 void insert(size_type pos, MathData const & ar);
70 /// erase range from pos1 to pos2
71 void erase(iterator pos1, iterator pos2);
73 void erase(iterator pos);
74 /// erase range from pos1 to pos2
75 void erase(size_type pos1, size_type pos2);
77 void erase(size_type pos);
84 void replace(ReplaceData &);
86 void substitute(MathData const & m);
88 /// looks for exact match
89 bool match(MathData const & ar) const;
90 /// looks for inclusion match starting at pos
91 bool matchpart(MathData const & ar, pos_type pos) const;
92 /// looks for containment, return == size mean not found
93 size_type find(MathData const & ar) const;
94 /// looks for containment, return == size mean not found
95 size_type find_last(MathData const & ar) const;
97 bool contains(MathData const & ar) const;
99 void validate(LaTeXFeatures &) const;
101 /// checked write access
102 MathAtom & operator[](pos_type);
103 /// checked read access
104 MathAtom const & operator[](pos_type) const;
105 /// rebuild cached metrics information
106 void metrics(MetricsInfo & mi) const;
107 /// rebuild cached metrics information
108 void metrics(MetricsInfo & mi, Dimension & dim) const;
110 Dimension const & dimension(BufferView const &) const { return dim_; };
112 /// redraw cell using cache metrics information
113 void draw(PainterInfo & pi, int x, int y) const;
114 /// rebuild cached metrics information
115 void metricsT(TextMetricsInfo const & mi, Dimension & dim) 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(BufferView const & bv) const;
123 /// access to cached y coordinate of last drawing
124 int yo(BufferView const & bv) const;
125 /// access to cached x coordinate of mid point of last drawing
126 int xm(BufferView const & bv) const { return xo(bv) + dim_.wid / 2; }
127 /// access to cached y coordinate of mid point of last drawing
128 int ym(BufferView const & bv) const { return yo(bv) + (dim_.des - dim_.asc) / 2; }
129 /// write access to coordinate;
130 void setXY(BufferView & bv, 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 pos, 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(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(BufferView const & bv, int x, int y) const;
143 /// ascent of this cell above the baseline
144 int ascent() const { return dim_.asc; }
145 /// descent of this cell below the baseline
146 int descent() const { return dim_.des; }
147 /// height of the cell
148 int height() const { return dim_.asc + dim_.des; }
149 /// width of this cell
150 int width() const { return dim_.wid; }
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 /// minimum ascent offset for superscript
156 int minasc() const { return minasc_; }
157 /// minimum descent offset for subscript
158 int mindes() const { return mindes_; }
159 /// level above/below which super/subscript should extend
160 int slevel() const { return slevel_; }
161 /// additional super/subscript shift
162 int sshift() const { return sshift_; }
163 /// superscript kerning
164 int kerning() const { return kerning_; }
166 void swap(MathData & ar) { base_type::swap(ar); }
169 /// cached dimensions of cell
170 mutable Dimension dim_;
171 /// cached values for super/subscript placement
176 mutable int kerning_;
179 /// is this an exact match at this position?
180 bool find1(MathData const & ar, size_type pos) const;
183 mutable std::vector<Dimension> atom_dims_;
187 std::ostream & operator<<(std::ostream & os, MathData const & ar);
189 odocstream & operator<<(odocstream & os, MathData const & ar);