4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
15 #include "MathClass.h"
17 #include "ColorCode.h"
19 #include "support/docstring.h"
35 * While for editing purpose it is important that macros are counted
36 * as a single element, this is not the case for display. To get the
37 * spacing correct, it is necessary to dissolve all the macros that
38 * can be, along with their arguments. Then one obtains a
39 * representation of the MathData contents as a string of insets and
40 * then spacing can be done properly.
42 * This is the purpose of the MathRow class.
47 // What row elements can be
49 INSET, // this element is a plain inset
50 BEG_MACRO, // a macro begins here
51 END_MACRO, // a macro ends here
52 BEG_ARG, // a macro argument begins here
53 END_ARG, // a macro argument ends here
54 BEGIN, // dummy element before row
55 END, // dummy element after row
59 // An elements, together with its spacing
63 Element(Type t, MetricsInfo & mi);
65 /// Classifies the contents of the object
67 /// count wether the current mathdata is nested in macro(s)
70 /// When type is INSET
72 InsetMath const * inset;
73 /// the class of the inset
75 /// the spacing around the inset
77 // Non empty when there is a completion to draw
79 // the number of characters forming the unique part.
80 size_t compl_unique_to;
82 /// When type is BEG_MACRO, END_MACRO, BEG_ARG, END_ARG
84 MathMacro const * macro;
86 // type is BEG_ARG, END_ARG
96 typedef std::vector<Element> Elements;
98 typedef Elements::iterator iterator;
100 typedef Elements::const_iterator const_iterator;
102 iterator begin() { return elements_.begin(); }
104 iterator end() { return elements_.end(); }
106 const_iterator begin() const { return elements_.begin(); }
108 const_iterator end() const { return elements_.end(); }
110 void push_back(Element const & e) { elements_.push_back(e); }
112 Element & back() { return elements_.back(); }
114 // create the math row by unwinding all macros in the MathData and
115 // compute the spacings.
116 MathRow(MetricsInfo & mi, MathData const * ar);
119 void metrics(MetricsInfo & mi, Dimension & dim) const;
121 void draw(PainterInfo & pi, int const x, int const y) const;
123 /// superscript kerning
124 int kerning(BufferView const *) const;
127 // Index of the first inset element before position i
128 int before(int i) const;
129 // Index of the first inset element after position i
130 int after(int i) const;
137 std::ostream & operator<<(std::ostream & os, MathRow::Element const & elt);
140 std::ostream & operator<<(std::ostream & os, MathRow const & mrow);