]> git.lyx.org Git - lyx.git/blob - src/mathed/MathData.h
adjust
[lyx.git] / src / mathed / MathData.h
1 // -*- C++ -*-
2 /**
3  * \file MathData.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author André Pönitz
9  * \author Lars Gullik Bjønnes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef MATH_DATA_H
15 #define MATH_DATA_H
16
17 #include <vector>
18
19 #include "MathAtom.h"
20 #include "Dimension.h"
21
22 #include "support/docstream.h"
23
24
25 namespace lyx {
26
27 class BufferView;
28 class LaTeXFeatures;
29 class ReplaceData;
30 class MetricsInfo;
31 class PainterInfo;
32 class TextMetricsInfo;
33 class TextPainter;
34
35
36 class MathData : private std::vector<MathAtom> {
37 public:
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;
48         using base_type::end;
49         using base_type::push_back;
50         using base_type::pop_back;
51         using base_type::back;
52         using base_type::front;
53         ///
54         typedef size_type idx_type;
55         typedef size_type pos_type;
56
57 public:
58         ///
59         MathData() {}
60         ///
61         MathData(const_iterator from, const_iterator to);
62         ///
63         void append(MathData const & ar);
64
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);
69
70         /// erase range from pos1 to pos2
71         void erase(iterator pos1, iterator pos2);
72         /// erase single atom
73         void erase(iterator pos);
74         /// erase range from pos1 to pos2
75         void erase(size_type pos1, size_type pos2);
76         /// erase single atom
77         void erase(size_type pos);
78
79         ///
80         void dump() const;
81         ///
82         void dump2() const;
83         ///
84         void replace(ReplaceData &);
85         ///
86         void substitute(MathData const & m);
87
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;
96         ///
97         bool contains(MathData const & ar) const;
98         ///
99         void validate(LaTeXFeatures &) const;
100
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, Dimension & dim) const;
107         ///
108         Dimension const & dimension(BufferView const &) const;
109
110         /// redraw cell using cache metrics information
111         void draw(PainterInfo & pi, int x, int y) const;
112         /// rebuild cached metrics information
113         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
114         /// redraw cell using cache metrics information
115         void drawT(TextPainter & pi, int x, int y) const;
116         /// mark cell for re-drawing
117         void touch() const;
118
119         /// access to cached x coordinate of last drawing
120         int xo(BufferView const & bv) const;
121         /// access to cached y coordinate of last drawing
122         int yo(BufferView const & bv) const;
123         /// access to cached x coordinate of mid point of last drawing
124         int xm(BufferView const & bv) const;
125         /// access to cached y coordinate of mid point of last drawing
126         int ym(BufferView const & bv) const;
127         /// write access to coordinate;
128         void setXY(BufferView & bv, int x, int y) const;
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 pos, 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(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(BufferView const & bv, int x, int y) const;
140
141         /// minimum ascent offset for superscript
142         int minasc() const { return minasc_; }
143         /// minimum descent offset for subscript
144         int mindes() const { return mindes_; }
145         /// level above/below which super/subscript should extend
146         int slevel() const { return slevel_; }
147         /// additional super/subscript shift
148         int sshift() const { return sshift_; }
149         /// superscript kerning
150         int kerning() const { return kerning_; }
151         ///
152         void swap(MathData & ar) { base_type::swap(ar); }
153
154 protected:
155         /// cached values for super/subscript placement
156         mutable int minasc_;
157         mutable int mindes_;
158         mutable int slevel_;
159         mutable int sshift_;
160         mutable int kerning_;
161
162 private:
163         /// is this an exact match at this position?
164         bool find1(MathData const & ar, size_type pos) const;
165
166         ///
167         mutable std::vector<Dimension> atom_dims_;
168 };
169
170 ///
171 std::ostream & operator<<(std::ostream & os, MathData const & ar);
172 ///
173 odocstream & operator<<(odocstream & os, MathData const & ar);
174
175
176 } // namespace lyx
177
178 #endif