brush off the decoration drawing code a bit

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2747 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-09-12 16:13:31 +00:00
parent 42c8e7bff9
commit 26db643696

View File

@ -26,73 +26,32 @@ bool isBinaryOp(char c, MathTextCodes type)
class Matrix { class Matrix {
public: public:
/// ///
typedef double matriz_data[2][2]; Matrix(int, double, double);
/// ///
Matrix(); void transform(double &, double &);
///
void rotate(int);
///
void escalate(double, double);
///
void transform(double, double, double &, double &);
private: private:
/// ///
matriz_data m_; double m_[2][2];
///
void multiply(matriz_data & a);
}; };
Matrix::Matrix()
{
m_[0][0] = 1;
m_[0][1] = 0;
m_[1][0] = 0;
m_[1][1] = 1;
}
void Matrix::rotate(int code) Matrix::Matrix(int code, double x, double y)
{ {
matriz_data r;
r[0][0] = 1;
r[0][1] = 0;
r[1][0] = 0;
r[1][1] = 1;
double const cs = (code & 1) ? 0 : (1 - code); double const cs = (code & 1) ? 0 : (1 - code);
double const sn = (code & 1) ? (2 - code) : 0; double const sn = (code & 1) ? (2 - code) : 0;
r[0][0] = cs; m_[0][0] = cs * x;
r[0][1] = sn; m_[0][1] = sn * x;
r[1][0] = -r[0][1]; m_[1][0] = -sn * y;
r[1][1] = r[0][0]; m_[1][1] = cs * y;
multiply(r);
} }
void Matrix::escalate(double x, double y)
{
matriz_data s;
s[0][0] = x;
s[0][1] = 0;
s[1][0] = 0;
s[1][1] = y;
multiply(s);
}
void Matrix::multiply(matriz_data & a) void Matrix::transform(double & x, double & y)
{ {
matriz_data c; double xx = m_[0][0] * x + m_[0][1] * y;
c[0][0] = a[0][0] * m_[0][0] + a[0][1] * m_[1][0]; double yy = m_[1][0] * x + m_[1][1] * y;
c[1][0] = a[1][0] * m_[0][0] + a[1][1] * m_[1][0]; x = xx;
c[0][1] = a[0][0] * m_[0][1] + a[0][1] * m_[1][1]; y = yy;
c[1][1] = a[1][0] * m_[0][1] + a[1][1] * m_[1][1];
m_[0][0] = c[0][0];
m_[0][1] = c[0][1];
m_[1][0] = c[1][0];
m_[1][1] = c[1][1];
}
void Matrix::transform(double xp, double yp, double & x, double & y)
{
x = m_[0][0] * xp + m_[0][1] * yp;
y = m_[1][0] * xp + m_[1][1] * yp;
} }
@ -645,22 +604,15 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
return; return;
} }
int const n = (w < h) ? w : h;
int const r = mds->angle; int const r = mds->angle;
double const * d = mds->data; double const * d = mds->data;
if (h > 70 && (name == "(" || name == ")")) if (h > 70 && (name == "(" || name == ")"))
d = parenthHigh; d = parenthHigh;
Matrix mt; Matrix mt(r, w, h);
Matrix sqmt; Matrix sqmt(r, n, n);
mt.rotate(r);
mt.escalate(w, h);
int const n = (w < h) ? w : h;
sqmt.rotate(r);
sqmt.escalate(n, n);
if (r > 0 && r < 3) if (r > 0 && r < 3)
y += h; y += h;
@ -676,12 +628,11 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
double x2 = d[i++]; double x2 = d[i++];
double y2 = d[i++]; double y2 = d[i++];
if (code == 3) if (code == 3)
sqmt.transform(xx, yy, xx, yy); sqmt.transform(xx, yy);
else else
mt.transform(xx, yy, xx, yy); mt.transform(xx, yy);
mt.transform(x2, y2, x2, y2); mt.transform(x2, y2);
pain.line(x + int(xx), y + int(yy), pain.line(x + int(xx), y + int(yy), x + int(x2), y + int(y2),
x + int(x2), y + int(y2),
LColor::mathline); LColor::mathline);
} else { } else {
int xp[32]; int xp[32];
@ -692,9 +643,9 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
double yy = d[i++]; double yy = d[i++];
// lyxerr << " " << xx << " " << yy << " "; // lyxerr << " " << xx << " " << yy << " ";
if (code == 4) if (code == 4)
sqmt.transform(xx, yy, xx, yy); sqmt.transform(xx, yy);
else else
mt.transform(xx, yy, xx, yy); mt.transform(xx, yy);
xp[j] = x + int(xx); xp[j] = x + int(xx);
yp[j] = y + int(yy); yp[j] = y + int(yy);
// lyxerr << "P[" << j " " << xx << " " << yy << " " << x << " " << y << "]"; // lyxerr << "P[" << j " " << xx << " " << yy << " " << x << " " << y << "]";