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
|
2016-11-16 14:07:00 +00:00
|
|
|
BEG_MACRO, // a macro begins here
|
|
|
|
END_MACRO, // a macro ends here
|
|
|
|
BEG_ARG, // a macro argument begins here
|
|
|
|
END_ARG, // a macro argument 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
|
|
|
|
/// the math inset
|
|
|
|
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;
|
|
|
|
|
|
|
|
// type is BEG_ARG, END_ARG
|
|
|
|
MathData const * ar;
|
2016-10-04 22:25:38 +00:00
|
|
|
|
|
|
|
// type is BOX
|
|
|
|
ColorCode color;
|
2016-11-16 14:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
MathRow() {};
|
|
|
|
///
|
|
|
|
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
|
|
|
|
|
|
|
//
|
|
|
|
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
|
|
|
//
|
|
|
|
void draw(PainterInfo & pi, int const x, int const y) const;
|
|
|
|
|
|
|
|
/// superscript kerning
|
|
|
|
int kerning(BufferView const *) const;
|
|
|
|
|
|
|
|
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
|