1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
2002-09-11 08:26:02 +00:00
|
|
|
|
/**
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* \file math_data.h
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-09-11 08:26:02 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
2002-08-02 14:29:42 +00:00
|
|
|
|
|
2001-12-10 10:09:00 +00:00
|
|
|
|
#ifndef MATH_DATA_H
|
|
|
|
|
#define MATH_DATA_H
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
2001-12-11 10:14:51 +00:00
|
|
|
|
#include <iosfwd>
|
2001-02-09 17:17:08 +00:00
|
|
|
|
#include <vector>
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
#include "math_atom.h"
|
2002-08-02 14:29:42 +00:00
|
|
|
|
#include "dimension.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
|
class MathMacro;
|
2001-11-08 12:06:56 +00:00
|
|
|
|
class LaTeXFeatures;
|
2001-11-16 09:55:37 +00:00
|
|
|
|
class ReplaceData;
|
2003-03-21 14:20:48 +00:00
|
|
|
|
class MetricsInfo;
|
|
|
|
|
class PainterInfo;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
class TextMetricsInfo;
|
|
|
|
|
class TextPainter;
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
class MathArray : private std::vector<MathAtom> {
|
2001-08-09 08:53:16 +00:00
|
|
|
|
public:
|
2002-07-30 13:56:02 +00:00
|
|
|
|
/// re-use inhertited stuff
|
|
|
|
|
typedef std::vector<MathAtom> base_type;
|
|
|
|
|
using base_type::const_iterator;
|
|
|
|
|
using base_type::iterator;
|
|
|
|
|
using base_type::size_type;
|
|
|
|
|
using base_type::difference_type;
|
|
|
|
|
using base_type::size;
|
|
|
|
|
using base_type::empty;
|
|
|
|
|
using base_type::clear;
|
|
|
|
|
using base_type::begin;
|
|
|
|
|
using base_type::end;
|
|
|
|
|
using base_type::push_back;
|
|
|
|
|
using base_type::pop_back;
|
|
|
|
|
using base_type::back;
|
|
|
|
|
using base_type::front;
|
|
|
|
|
using base_type::swap;
|
|
|
|
|
///
|
|
|
|
|
typedef size_type idx_type;
|
|
|
|
|
typedef size_type pos_type;
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
public:
|
2001-02-09 17:17:08 +00:00
|
|
|
|
///
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray();
|
2001-02-19 14:16:57 +00:00
|
|
|
|
///
|
2002-07-30 13:56:02 +00:00
|
|
|
|
MathArray(const_iterator from, const_iterator to);
|
2001-11-09 10:44:24 +00:00
|
|
|
|
///
|
2002-07-30 13:56:02 +00:00
|
|
|
|
void append(MathArray const & ar);
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
/// inserts single atom at position pos
|
|
|
|
|
void insert(size_type pos, MathAtom const & at);
|
|
|
|
|
/// inserts multiple atoms at position pos
|
|
|
|
|
void insert(size_type pos, MathArray const & ar);
|
2001-02-14 17:50:58 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
/// erase range from pos1 to pos2
|
2001-11-09 10:44:24 +00:00
|
|
|
|
void erase(iterator pos1, iterator pos2);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
/// erase single atom
|
2001-11-09 10:44:24 +00:00
|
|
|
|
void erase(iterator pos);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
/// erase range from pos1 to pos2
|
2001-09-14 14:05:57 +00:00
|
|
|
|
void erase(size_type pos1, size_type pos2);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
/// erase single atom
|
2001-09-14 14:05:57 +00:00
|
|
|
|
void erase(size_type pos);
|
2001-11-09 16:27:44 +00:00
|
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
|
///
|
2001-11-08 12:06:56 +00:00
|
|
|
|
void dump() const;
|
2001-02-12 08:55:14 +00:00
|
|
|
|
///
|
2001-11-08 12:06:56 +00:00
|
|
|
|
void dump2() const;
|
2001-02-12 08:55:14 +00:00
|
|
|
|
///
|
2002-06-18 15:44:30 +00:00
|
|
|
|
void substitute(MathMacro const & macro);
|
2001-11-16 09:55:37 +00:00
|
|
|
|
///
|
|
|
|
|
void replace(ReplaceData &);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
/// looks for exact match
|
|
|
|
|
bool match(MathArray const & ar) const;
|
|
|
|
|
/// looks for inclusion match starting at pos
|
|
|
|
|
bool matchpart(MathArray const & ar, pos_type pos) const;
|
|
|
|
|
/// looks for containment, return == size mean not found
|
|
|
|
|
size_type find(MathArray const & ar) const;
|
|
|
|
|
/// looks for containment, return == size mean not found
|
|
|
|
|
size_type find_last(MathArray const & ar) const;
|
2001-02-12 08:55:14 +00:00
|
|
|
|
///
|
2002-06-18 15:44:30 +00:00
|
|
|
|
bool contains(MathArray const & ar) const;
|
|
|
|
|
///
|
|
|
|
|
void validate(LaTeXFeatures &) const;
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
/// checked write access
|
|
|
|
|
MathAtom & operator[](pos_type);
|
|
|
|
|
/// checked read access
|
|
|
|
|
MathAtom const & operator[](pos_type) const;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// rebuild cached metrics information
|
2003-05-28 13:22:36 +00:00
|
|
|
|
void metrics(MetricsInfo & mi) const;
|
|
|
|
|
/// rebuild cached metrics information
|
|
|
|
|
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// redraw cell using cache metrics information
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void draw(PainterInfo & pi, int x, int y) const;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// rebuild cached metrics information
|
2003-05-28 13:22:36 +00:00
|
|
|
|
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// redraw cell using cache metrics information
|
|
|
|
|
void drawT(TextPainter & pi, int x, int y) const;
|
|
|
|
|
/// mark cell for re-drawing
|
|
|
|
|
void touch() const;
|
|
|
|
|
|
|
|
|
|
/// access to cached x coordinate of last drawing
|
|
|
|
|
int xo() const { return xo_; }
|
|
|
|
|
/// access to cached y coordinate of last drawing
|
|
|
|
|
int yo() const { return yo_; }
|
|
|
|
|
/// access to cached x coordinate of mid point of last drawing
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int xm() const { return xo_ + dim_.wid / 2; }
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// access to cached y coordinate of mid point of last drawing
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int ym() const { return yo_ + (dim_.des - dim_.asc) / 2; }
|
2004-01-30 11:41:12 +00:00
|
|
|
|
///
|
|
|
|
|
bool contains(int x, int y) const;
|
2002-08-09 08:14:18 +00:00
|
|
|
|
/// write access to coordinate;
|
2002-09-11 08:26:02 +00:00
|
|
|
|
void setXY(int x, int y) const;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// returns x coordinate of given position in the array
|
|
|
|
|
int pos2x(size_type pos) const;
|
|
|
|
|
/// returns position of given x coordinate
|
2003-04-14 06:17:19 +00:00
|
|
|
|
int pos2x(size_type pos, int glue) const;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// returns position of given x coordinate
|
|
|
|
|
size_type x2pos(int pos) const;
|
|
|
|
|
/// returns position of given x coordinate fstarting from a certain pos
|
2003-04-14 06:17:19 +00:00
|
|
|
|
size_type x2pos(int targetx, int glue) const;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// returns distance of this cell to the point given by x and y
|
|
|
|
|
// assumes valid position and size cache
|
|
|
|
|
int dist(int x, int y) const;
|
|
|
|
|
|
|
|
|
|
/// ascent of this cell above the baseline
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int ascent() const { return dim_.asc; }
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// descent of this cell below the baseline
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int descent() const { return dim_.des; }
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// height of the cell
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int height() const { return dim_.asc + dim_.des; }
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// width of this cell
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int width() const { return dim_.wid; }
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// dimensions of cell
|
2003-05-28 13:22:36 +00:00
|
|
|
|
Dimension const & dim() const { return dim_; }
|
2002-08-02 14:29:42 +00:00
|
|
|
|
/// dimensions of cell
|
|
|
|
|
void setDim(Dimension const & d) const { dim_ = d; }
|
|
|
|
|
/// bounding box of this cell
|
|
|
|
|
void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
|
|
|
|
|
/// gives center coordinates
|
|
|
|
|
void center(int & x, int & y) const;
|
|
|
|
|
/// adjust (x,y) to point on boundary on a straight line from the center
|
|
|
|
|
void towards(int & x, int & y) const;
|
2002-10-29 08:23:32 +00:00
|
|
|
|
/// clean up if necessary
|
|
|
|
|
void notifyCursorLeaves();
|
2002-08-02 14:29:42 +00:00
|
|
|
|
|
2001-08-09 08:53:16 +00:00
|
|
|
|
private:
|
2002-06-18 15:44:30 +00:00
|
|
|
|
/// is this an exact match at this position?
|
|
|
|
|
bool find1(MathArray const & ar, size_type pos) const;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
|
|
|
|
|
/// cached dimensions of cell
|
|
|
|
|
mutable Dimension dim_;
|
|
|
|
|
/// cached x coordinate of last drawing
|
|
|
|
|
mutable int xo_;
|
|
|
|
|
/// cached y coordinate of last drawing
|
|
|
|
|
mutable int yo_;
|
|
|
|
|
/// cached cleaness of cell
|
|
|
|
|
mutable bool clean_;
|
|
|
|
|
/// cached draw status of cell
|
|
|
|
|
mutable bool drawn_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
2001-04-24 16:13:38 +00:00
|
|
|
|
|
2001-12-11 10:14:51 +00:00
|
|
|
|
///
|
|
|
|
|
std::ostream & operator<<(std::ostream & os, MathArray const & ar);
|
|
|
|
|
|
|
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
|
#endif
|