2016-11-16 14:07:00 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file MathRow.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MATH_ROW_H
|
|
|
|
#define MATH_ROW_H
|
|
|
|
|
2017-01-06 08:52:10 +00:00
|
|
|
#include "InsetMath.h"
|
2016-11-16 14:07:00 +00:00
|
|
|
#include "MathClass.h"
|
|
|
|
|
2016-10-04 22:25:38 +00:00
|
|
|
#include "ColorCode.h"
|
|
|
|
|
2016-11-16 14:07:00 +00:00
|
|
|
#include "support/docstring.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
class BufferView;
|
|
|
|
class Dimension;
|
|
|
|
class MetricsInfo;
|
|
|
|
class PainterInfo;
|
|
|
|
|
|
|
|
class InsetMath;
|
|
|
|
class MathData;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* While for editing purpose it is important that macros are counted
|
|
|
|
* as a single element, this is not the case for display. To get the
|
|
|
|
* spacing correct, it is necessary to dissolve all the macros that
|
|
|
|
* can be, along with their arguments. Then one obtains a
|
|
|
|
* representation of the MathData contents as a string of insets and
|
|
|
|
* then spacing can be done properly.
|
|
|
|
*
|
|
|
|
* This is the purpose of the MathRow class.
|
|
|
|
*/
|
|
|
|
class MathRow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// What row elements can be
|
|
|
|
enum Type {
|
|
|
|
INSET, // this element is a plain inset
|
2016-12-02 14:58:39 +00:00
|
|
|
BOX, // an empty box
|
2017-02-01 16:46:53 +00:00
|
|
|
BEGIN, // an inset and/or a math array begins here
|
|
|
|
END, // an inset and/or a math array ends here
|
2016-12-02 14:58:39 +00:00
|
|
|
DUMMY // a dummy element (used before or after row)
|
2016-11-16 14:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// An elements, together with its spacing
|
|
|
|
struct Element
|
|
|
|
{
|
|
|
|
///
|
2017-01-05 12:25:28 +00:00
|
|
|
Element(MetricsInfo const & mi, Type t, MathClass mc = MC_UNKNOWN);
|
2016-11-16 14:07:00 +00:00
|
|
|
|
|
|
|
/// Classifies the contents of the object
|
|
|
|
Type type;
|
2016-12-02 14:58:39 +00:00
|
|
|
/// the class of the element
|
|
|
|
MathClass mclass;
|
|
|
|
/// the spacing around the element
|
|
|
|
int before, after;
|
2017-01-05 12:25:28 +00:00
|
|
|
/// count wether the current mathdata is nested in macro(s)
|
|
|
|
int macro_nesting;
|
2017-01-06 08:52:10 +00:00
|
|
|
/// Marker type
|
|
|
|
InsetMath::marker_type marker;
|
2016-11-16 14:07:00 +00:00
|
|
|
|
|
|
|
/// When type is INSET
|
2017-02-01 16:46:53 +00:00
|
|
|
/// the math inset (also for BEGIN and END)
|
2016-11-16 14:07:00 +00:00
|
|
|
InsetMath const * inset;
|
|
|
|
// Non empty when there is a completion to draw
|
|
|
|
docstring compl_text;
|
|
|
|
// the number of characters forming the unique part.
|
|
|
|
size_t compl_unique_to;
|
|
|
|
|
2017-02-01 16:46:53 +00:00
|
|
|
// type is BEGIN, END
|
2016-11-16 14:07:00 +00:00
|
|
|
MathData const * ar;
|
2016-10-04 22:25:38 +00:00
|
|
|
|
|
|
|
// type is BOX
|
|
|
|
ColorCode color;
|
2016-11-16 14:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
2019-06-03 14:22:44 +00:00
|
|
|
MathRow(int asc = 0, int des = 0) : caret_ascent(asc), caret_descent(des) {};
|
2016-11-16 14:07:00 +00:00
|
|
|
///
|
|
|
|
typedef std::vector<Element> Elements;
|
|
|
|
///
|
|
|
|
typedef Elements::iterator iterator;
|
|
|
|
///
|
|
|
|
typedef Elements::const_iterator const_iterator;
|
|
|
|
///
|
|
|
|
iterator begin() { return elements_.begin(); }
|
|
|
|
///
|
|
|
|
iterator end() { return elements_.end(); }
|
|
|
|
///
|
|
|
|
const_iterator begin() const { return elements_.begin(); }
|
|
|
|
///
|
|
|
|
const_iterator end() const { return elements_.end(); }
|
|
|
|
//
|
|
|
|
void push_back(Element const & e) { elements_.push_back(e); }
|
|
|
|
//
|
|
|
|
Element & back() { return elements_.back(); }
|
|
|
|
|
|
|
|
// create the math row by unwinding all macros in the MathData and
|
|
|
|
// compute the spacings.
|
2016-10-04 22:25:38 +00:00
|
|
|
MathRow(MetricsInfo & mi, MathData const * ar);
|
2016-11-16 14:07:00 +00:00
|
|
|
|
2019-04-16 13:58:51 +00:00
|
|
|
//
|
|
|
|
void metrics(MetricsInfo & mi, Dimension & dim);
|
2016-11-16 14:07:00 +00:00
|
|
|
//
|
|
|
|
void draw(PainterInfo & pi, int const x, int const y) const;
|
|
|
|
|
|
|
|
/// superscript kerning
|
|
|
|
int kerning(BufferView const *) const;
|
|
|
|
|
2019-04-16 13:58:51 +00:00
|
|
|
/// useful when the caret visits this cell
|
|
|
|
int caret_ascent, caret_descent;
|
|
|
|
|
|
|
|
|
2016-11-16 14:07:00 +00:00
|
|
|
private:
|
|
|
|
// Index of the first inset element before position i
|
|
|
|
int before(int i) const;
|
|
|
|
// Index of the first inset element after position i
|
|
|
|
int after(int i) const;
|
|
|
|
|
|
|
|
///
|
|
|
|
Elements elements_;
|
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
std::ostream & operator<<(std::ostream & os, MathRow::Element const & elt);
|
|
|
|
|
|
|
|
///
|
|
|
|
std::ostream & operator<<(std::ostream & os, MathRow const & mrow);
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif
|