mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-25 17:44:59 +00:00
- reduce sizeof(MathCharInset) by 20 by better font caching
(lots of subsequent changes) - ascii art drawing for \frac and \sqrt git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3780 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
a16b2c3ba9
commit
858355fb69
@ -43,6 +43,7 @@
|
|||||||
#include "math_hullinset.h"
|
#include "math_hullinset.h"
|
||||||
#include "math_support.h"
|
#include "math_support.h"
|
||||||
#include "math_mathmlstream.h"
|
#include "math_mathmlstream.h"
|
||||||
|
#include "textpainter.h"
|
||||||
|
|
||||||
using std::ostream;
|
using std::ostream;
|
||||||
using std::ifstream;
|
using std::ifstream;
|
||||||
@ -294,9 +295,20 @@ int InsetFormula::latex(Buffer const *, ostream & os, bool fragil, bool) const
|
|||||||
|
|
||||||
int InsetFormula::ascii(Buffer const *, ostream & os, int) const
|
int InsetFormula::ascii(Buffer const *, ostream & os, int) const
|
||||||
{
|
{
|
||||||
|
#if 1
|
||||||
|
TextMetricsInfo mi;
|
||||||
|
par()->metrics(mi);
|
||||||
|
TextPainter tpain(par()->width(), par()->height());
|
||||||
|
par()->draw(tpain, 0, par()->ascent());
|
||||||
|
tpain.show(os);
|
||||||
|
// reset metrics cache to "real" values
|
||||||
|
metrics();
|
||||||
|
return tpain.textheight();
|
||||||
|
#else
|
||||||
WriteStream wi(os, false);
|
WriteStream wi(os, false);
|
||||||
par_->write(wi);
|
par_->write(wi);
|
||||||
return wi.line();
|
return wi.line();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "Lsstream.h"
|
#include "Lsstream.h"
|
||||||
#include "math_arrayinset.h"
|
#include "math_arrayinset.h"
|
||||||
|
#include "math_charinset.h"
|
||||||
#include "math_cursor.h"
|
#include "math_cursor.h"
|
||||||
#include "math_factory.h"
|
#include "math_factory.h"
|
||||||
#include "math_hullinset.h"
|
#include "math_hullinset.h"
|
||||||
@ -100,6 +101,8 @@ InsetFormulaBase::InsetFormulaBase()
|
|||||||
// This is needed as long the math parser is not re-entrant
|
// This is needed as long the math parser is not re-entrant
|
||||||
MathMacroTable::builtinMacros();
|
MathMacroTable::builtinMacros();
|
||||||
//lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
|
//lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
|
||||||
|
lyxerr << "sizeof(MathMetricsInfo): " << sizeof(MathMetricsInfo) << "\n";
|
||||||
|
lyxerr << "sizeof(MathCharInset): " << sizeof(MathCharInset) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -219,8 +222,7 @@ void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
|
|||||||
y -= yo_;
|
y -= yo_;
|
||||||
int asc = 0;
|
int asc = 0;
|
||||||
int des = 0;
|
int des = 0;
|
||||||
MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
|
math_font_max_dim(font_, asc, des);
|
||||||
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
|
|
||||||
bv->showLockedInsetCursor(x, y, asc, des);
|
bv->showLockedInsetCursor(x, y, asc, des);
|
||||||
//lyxerr << "toggleInsetCursor: " << x << " " << y << "\n";
|
//lyxerr << "toggleInsetCursor: " << x << " " << y << "\n";
|
||||||
}
|
}
|
||||||
@ -241,8 +243,7 @@ void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
|
|||||||
y -= yo_;
|
y -= yo_;
|
||||||
int asc = 0;
|
int asc = 0;
|
||||||
int des = 0;
|
int des = 0;
|
||||||
MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
|
math_font_max_dim(font_, asc, des);
|
||||||
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
|
|
||||||
bv->fitLockedInsetCursor(x, y, asc, des);
|
bv->fitLockedInsetCursor(x, y, asc, des);
|
||||||
//lyxerr << "showInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << "\n";
|
//lyxerr << "showInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << "\n";
|
||||||
}
|
}
|
||||||
@ -461,12 +462,6 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_TAB:
|
case LFUN_TAB:
|
||||||
if (0) {
|
|
||||||
TextMetricsInfo mi;
|
|
||||||
par()->metrics(mi);
|
|
||||||
TextPainter tpain(par()->width(), par()->height());
|
|
||||||
par()->draw(tpain, 0, par()->ascent());
|
|
||||||
}
|
|
||||||
mathcursor->idxNext();
|
mathcursor->idxNext();
|
||||||
updateLocal(bv, false);
|
updateLocal(bv, false);
|
||||||
break;
|
break;
|
||||||
|
@ -42,7 +42,9 @@ double MathBigInset::increase() const
|
|||||||
|
|
||||||
void MathBigInset::metrics(MathMetricsInfo const & mi) const
|
void MathBigInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
double h = mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
|
LyXFont font;
|
||||||
|
whichFont(font, LM_TC_VAR, mi);
|
||||||
|
double h = mathed_char_height(font, 'I', ascent_, descent_);
|
||||||
double f = increase();
|
double f = increase();
|
||||||
width_ = 6;
|
width_ = 6;
|
||||||
ascent_ = int(h + f * h);
|
ascent_ = int(h + f * h);
|
||||||
|
@ -28,7 +28,8 @@ void MathBraceInset::metrics(MathMetricsInfo const & mi) const
|
|||||||
{
|
{
|
||||||
xcell(0).metrics(mi);
|
xcell(0).metrics(mi);
|
||||||
int a, d;
|
int a, d;
|
||||||
mathed_char_dim(LM_TC_TEX, mi, '{', a, d, wid_);
|
whichFont(font_, LM_TC_TEX, mi);
|
||||||
|
mathed_char_dim(font_, '{', a, d, wid_);
|
||||||
ascent_ = max(xcell(0).ascent(), a);
|
ascent_ = max(xcell(0).ascent(), a);
|
||||||
descent_ = max(xcell(0).descent(), a);
|
descent_ = max(xcell(0).descent(), a);
|
||||||
width_ = xcell(0).width() + 2 * wid_;
|
width_ = xcell(0).width() + 2 * wid_;
|
||||||
@ -37,9 +38,9 @@ void MathBraceInset::metrics(MathMetricsInfo const & mi) const
|
|||||||
|
|
||||||
void MathBraceInset::draw(Painter & pain, int x, int y) const
|
void MathBraceInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
drawChar(pain, LM_TC_TEX, mi_, x, y, '{');
|
drawChar(pain, font_, x, y, '{');
|
||||||
xcell(0).draw(pain, x + wid_, y);
|
xcell(0).draw(pain, x + wid_, y);
|
||||||
drawChar(pain, LM_TC_TEX, mi_, x + width_ - wid_, y, '}');
|
drawChar(pain, font_, x + width_ - wid_, y, '}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ private:
|
|||||||
/// width of brace character
|
/// width of brace character
|
||||||
mutable int wid_;
|
mutable int wid_;
|
||||||
///
|
///
|
||||||
MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -40,7 +40,7 @@ void MathCasesInset::write(WriteStream & os) const
|
|||||||
{
|
{
|
||||||
if (os.fragile())
|
if (os.fragile())
|
||||||
os << "\\protect";
|
os << "\\protect";
|
||||||
os << "\\begin{cases}";
|
os << "\\begin{cases}\n";
|
||||||
MathGridInset::write(os);
|
MathGridInset::write(os);
|
||||||
if (os.fragile())
|
if (os.fragile())
|
||||||
os << "\\protect";
|
os << "\\protect";
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "math_mathmlstream.h"
|
#include "math_mathmlstream.h"
|
||||||
#include "LaTeXFeatures.h"
|
#include "LaTeXFeatures.h"
|
||||||
|
#include "textpainter.h"
|
||||||
|
|
||||||
|
|
||||||
using std::ostream;
|
using std::ostream;
|
||||||
@ -51,15 +52,30 @@ MathInset * MathCharInset::clone() const
|
|||||||
|
|
||||||
void MathCharInset::metrics(MathMetricsInfo const & mi) const
|
void MathCharInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
whichFont(font_, code_, mi);
|
||||||
mathed_char_dim(code_, mi_, char_, ascent_, descent_, width_);
|
mathed_char_dim(font_, char_, ascent_, descent_, width_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathCharInset::draw(Painter & pain, int x, int y) const
|
void MathCharInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
//lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
|
//lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
|
||||||
drawChar(pain, code_, mi_, x, y, char_);
|
drawChar(pain, font_, x, y, char_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathCharInset::metrics(TextMetricsInfo const &) const
|
||||||
|
{
|
||||||
|
width_ = 1;
|
||||||
|
ascent_ = 1;
|
||||||
|
descent_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathCharInset::draw(TextPainter & pain, int x, int y) const
|
||||||
|
{
|
||||||
|
lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
|
||||||
|
pain.draw(x, y, char_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,10 @@ public:
|
|||||||
///
|
///
|
||||||
void draw(Painter &, int x, int y) const;
|
void draw(Painter &, int x, int y) const;
|
||||||
///
|
///
|
||||||
|
void metrics(TextMetricsInfo const & st) const;
|
||||||
|
///
|
||||||
|
void draw(TextPainter &, int x, int y) const;
|
||||||
|
///
|
||||||
void write(WriteStream & os) const;
|
void write(WriteStream & os) const;
|
||||||
///
|
///
|
||||||
void writeHeader(std::ostream &) const;
|
void writeHeader(std::ostream &) const;
|
||||||
@ -59,6 +63,6 @@ private:
|
|||||||
/// the font to be used on screen
|
/// the font to be used on screen
|
||||||
MathTextCodes code_;
|
MathTextCodes code_;
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -74,15 +74,15 @@ bool MathDecorationInset::wide() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathDecorationInset::metrics(MathMetricsInfo const & st) const
|
void MathDecorationInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
xcell(0).metrics(st);
|
xcell(0).metrics(mi);
|
||||||
size_ = st;
|
|
||||||
width_ = xcell(0).width();
|
width_ = xcell(0).width();
|
||||||
ascent_ = xcell(0).ascent();
|
ascent_ = xcell(0).ascent();
|
||||||
descent_ = xcell(0).descent();
|
descent_ = xcell(0).descent();
|
||||||
|
|
||||||
dh_ = 6; //mathed_char_height(LM_TC_VAR, size(), 'I', ascent_, descent_);
|
dh_ = 6; //mathed_char_height(LM_TC_VAR, mi(), 'I', ascent_, descent_);
|
||||||
|
dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
|
||||||
|
|
||||||
if (upper()) {
|
if (upper()) {
|
||||||
dy_ = -ascent_ - dh_;
|
dy_ = -ascent_ - dh_;
|
||||||
@ -99,10 +99,8 @@ void MathDecorationInset::draw(Painter & pain, int x, int y) const
|
|||||||
xcell(0).draw(pain, x, y);
|
xcell(0).draw(pain, x, y);
|
||||||
if (wide())
|
if (wide())
|
||||||
mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
|
mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
|
||||||
else {
|
else
|
||||||
int w = mathed_char_width(LM_TC_VAR, size_, 'x');
|
mathed_draw_deco(pain, x + (width_ - dw_) / 2, y + dy_, dw_, dh_, name_);
|
||||||
mathed_draw_deco(pain, x + (width_ - w) / 2, y + dy_, w, dh_, name_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ private:
|
|||||||
mutable int dh_;
|
mutable int dh_;
|
||||||
/// vertical offset cache of deco
|
/// vertical offset cache of deco
|
||||||
mutable int dy_;
|
mutable int dy_;
|
||||||
///
|
/// width for non-wide deco
|
||||||
mutable MathMetricsInfo size_;
|
mutable int dw_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -55,7 +55,9 @@ void MathDelimInset::metrics(MathMetricsInfo const & mi) const
|
|||||||
{
|
{
|
||||||
xcell(0).metrics(mi);
|
xcell(0).metrics(mi);
|
||||||
int a, d, w;
|
int a, d, w;
|
||||||
mathed_char_dim(LM_TC_VAR, mi, 'I', a, d, w);
|
LyXFont font;
|
||||||
|
whichFont(font, LM_TC_VAR, mi);
|
||||||
|
mathed_char_dim(font, 'I', a, d, w);
|
||||||
int h0 = (a + d) / 2;
|
int h0 = (a + d) / 2;
|
||||||
int a0 = max(xcell(0).ascent(), a) - h0;
|
int a0 = max(xcell(0).ascent(), a) - h0;
|
||||||
int d0 = max(xcell(0).descent(), d) + h0;
|
int d0 = max(xcell(0).descent(), d) + h0;
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
#include "math_diminset.h"
|
||||||
|
#include "Lsstream.h"
|
||||||
|
#include "textpainter.h"
|
||||||
|
|
||||||
|
|
||||||
|
void MathDimInset::metrics(TextMetricsInfo const &) const
|
||||||
|
{
|
||||||
|
std::ostringstream os;
|
||||||
|
os << *this;
|
||||||
|
width_ = int(os.str().size());
|
||||||
|
ascent_ = 1;
|
||||||
|
descent_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathDimInset::draw(TextPainter & pain, int x, int y) const
|
||||||
|
{
|
||||||
|
std::ostringstream os;
|
||||||
|
os << *this;
|
||||||
|
pain.draw(x, y, os.str().c_str());
|
||||||
|
}
|
@ -16,6 +16,10 @@ public:
|
|||||||
int descent() const { return descent_; }
|
int descent() const { return descent_; }
|
||||||
/// read width
|
/// read width
|
||||||
int width() const { return width_; }
|
int width() const { return width_; }
|
||||||
|
///
|
||||||
|
void metrics(TextMetricsInfo const &) const;
|
||||||
|
///
|
||||||
|
void draw(TextPainter & pain, int x, int y) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
|
@ -21,6 +21,20 @@ MathInset * MathDotsInset::clone() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathDotsInset::metrics(MathMetricsInfo const & mi) const
|
||||||
|
{
|
||||||
|
LyXFont font;
|
||||||
|
whichFont(font, LM_TC_VAR, mi);
|
||||||
|
mathed_char_dim(font, 'M', ascent_, descent_, width_);
|
||||||
|
switch (name_[0]) {
|
||||||
|
case 'l': dh_ = 0; break;
|
||||||
|
case 'c': dh_ = ascent_ / 2; break;
|
||||||
|
case 'v': width_ /= 2;
|
||||||
|
case 'd': dh_ = ascent_; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathDotsInset::draw(Painter & pain, int x, int y) const
|
void MathDotsInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, name_);
|
mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, name_);
|
||||||
@ -33,18 +47,6 @@ void MathDotsInset::draw(Painter & pain, int x, int y) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathDotsInset::metrics(MathMetricsInfo const & mi) const
|
|
||||||
{
|
|
||||||
mathed_char_dim(LM_TC_VAR, mi, 'M', ascent_, descent_, width_);
|
|
||||||
switch (name_[0]) {
|
|
||||||
case 'l': dh_ = 0; break;
|
|
||||||
case 'c': dh_ = ascent_ / 2; break;
|
|
||||||
case 'v': width_ /= 2;
|
|
||||||
case 'd': dh_ = ascent_; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MathDotsInset::write(WriteStream & os) const
|
void MathDotsInset::write(WriteStream & os) const
|
||||||
{
|
{
|
||||||
os << '\\' << name_ << ' ';
|
os << '\\' << name_ << ' ';
|
||||||
|
@ -19,14 +19,14 @@ MathInset * MathExFuncInset::clone() const
|
|||||||
|
|
||||||
void MathExFuncInset::metrics(MathMetricsInfo const & mi) const
|
void MathExFuncInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
whichFont(font_, LM_TC_TEXTRM, mi);
|
||||||
mathed_string_dim(LM_TC_TEXTRM, mi_, name_, ascent_, descent_, width_);
|
mathed_string_dim(font_, name_, ascent_, descent_, width_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathExFuncInset::draw(Painter & pain, int x, int y) const
|
void MathExFuncInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
drawStr(pain, LM_TC_TEXTRM, mi_, x, y, name_);
|
drawStr(pain, font_, x, y, name_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +33,6 @@ private:
|
|||||||
///
|
///
|
||||||
string const name_;
|
string const name_;
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "math_support.h"
|
#include "math_support.h"
|
||||||
#include "Painter.h"
|
#include "Painter.h"
|
||||||
#include "math_mathmlstream.h"
|
#include "math_mathmlstream.h"
|
||||||
|
#include "textpainter.h"
|
||||||
|
|
||||||
|
|
||||||
using std::max;
|
using std::max;
|
||||||
@ -50,6 +51,26 @@ void MathFracInset::draw(Painter & pain, int x, int y) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathFracInset::metrics(TextMetricsInfo const & mi) const
|
||||||
|
{
|
||||||
|
xcell(0).metrics(mi);
|
||||||
|
xcell(1).metrics(mi);
|
||||||
|
width_ = max(xcell(0).width(), xcell(1).width());
|
||||||
|
ascent_ = xcell(0).height() + 1;
|
||||||
|
descent_ = xcell(1).height();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathFracInset::draw(TextPainter & pain, int x, int y) const
|
||||||
|
{
|
||||||
|
int m = x + width() / 2;
|
||||||
|
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 1);
|
||||||
|
xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent());
|
||||||
|
if (!atop_)
|
||||||
|
pain.horizontalLine(x, y, width());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathFracInset::write(WriteStream & os) const
|
void MathFracInset::write(WriteStream & os) const
|
||||||
{
|
{
|
||||||
if (atop_)
|
if (atop_)
|
||||||
|
@ -18,10 +18,14 @@ public:
|
|||||||
///
|
///
|
||||||
MathInset * clone() const;
|
MathInset * clone() const;
|
||||||
///
|
///
|
||||||
void metrics(MathMetricsInfo const & st) const;
|
void metrics(MathMetricsInfo const & mi) const;
|
||||||
///
|
///
|
||||||
void draw(Painter &, int x, int y) const;
|
void draw(Painter &, int x, int y) const;
|
||||||
///
|
///
|
||||||
|
void metrics(TextMetricsInfo const & mi) const;
|
||||||
|
///
|
||||||
|
void draw(TextPainter &, int x, int y) const;
|
||||||
|
///
|
||||||
MathFracInset * asFracInset();
|
MathFracInset * asFracInset();
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -40,14 +40,14 @@ void MathFuncInset::setName(string const & n)
|
|||||||
|
|
||||||
void MathFuncInset::metrics(MathMetricsInfo const & mi) const
|
void MathFuncInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
whichFont(font_, LM_TC_TEXTRM, mi);
|
||||||
mathed_string_dim(LM_TC_TEXTRM, mi_, name_, ascent_, descent_, width_);
|
mathed_string_dim(font_, name_, ascent_, descent_, width_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathFuncInset::draw(Painter & pain, int x, int y) const
|
void MathFuncInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
drawStr(pain, LM_TC_TEXTRM, mi_, x, y, name_);
|
drawStr(pain, font_, x, y, name_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +45,6 @@ private:
|
|||||||
///
|
///
|
||||||
string name_;
|
string name_;
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,7 +19,8 @@ MathInset * MathFuncLimInset::clone() const
|
|||||||
|
|
||||||
bool MathFuncLimInset::isScriptable() const
|
bool MathFuncLimInset::isScriptable() const
|
||||||
{
|
{
|
||||||
return mi_.style == LM_ST_DISPLAY;
|
//return mi_.style == LM_ST_DISPLAY;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -37,12 +38,12 @@ void MathFuncLimInset::normalize(NormalStream & os) const
|
|||||||
|
|
||||||
void MathFuncLimInset::metrics(MathMetricsInfo const & mi) const
|
void MathFuncLimInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
whichFont(font_, LM_TC_TEXTRM, mi);
|
||||||
mathed_string_dim(LM_TC_TEXTRM, mi_, name_, ascent_, descent_, width_);
|
mathed_string_dim(font_, name_, ascent_, descent_, width_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathFuncLimInset::draw(Painter & pain, int x, int y) const
|
void MathFuncLimInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
drawStr(pain, LM_TC_TEXTRM, mi_, x, y, name_);
|
drawStr(pain, font_, x, y, name_);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ private:
|
|||||||
///
|
///
|
||||||
string const name_;
|
string const name_;
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -376,6 +376,103 @@ void MathGridInset::draw(Painter & pain, int x, int y) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathGridInset::metrics(TextMetricsInfo const & mi) const
|
||||||
|
{
|
||||||
|
// let the cells adjust themselves
|
||||||
|
//MathNestInset::metrics(mi);
|
||||||
|
for (idx_type i = 0; i < nargs(); ++i)
|
||||||
|
xcell(i).metrics(mi);
|
||||||
|
|
||||||
|
// compute absolute sizes of vertical structure
|
||||||
|
for (row_type row = 0; row < nrows(); ++row) {
|
||||||
|
int asc = 0;
|
||||||
|
int desc = 0;
|
||||||
|
for (col_type col = 0; col < ncols(); ++col) {
|
||||||
|
MathXArray const & c = xcell(index(row, col));
|
||||||
|
asc = max(asc, c.ascent());
|
||||||
|
desc = max(desc, c.descent());
|
||||||
|
}
|
||||||
|
rowinfo_[row].ascent_ = asc;
|
||||||
|
rowinfo_[row].descent_ = desc;
|
||||||
|
}
|
||||||
|
//rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
|
||||||
|
rowinfo_[nrows()].ascent_ = 0;
|
||||||
|
rowinfo_[nrows()].descent_ = 0;
|
||||||
|
|
||||||
|
// compute vertical offsets
|
||||||
|
rowinfo_[0].offset_ = 0;
|
||||||
|
for (row_type row = 1; row <= nrows(); ++row) {
|
||||||
|
rowinfo_[row].offset_ =
|
||||||
|
rowinfo_[row - 1].offset_ +
|
||||||
|
rowinfo_[row - 1].descent_ +
|
||||||
|
//rowinfo_[row - 1].skipPixels() +
|
||||||
|
1 + //rowsep() +
|
||||||
|
//rowinfo_[row].lines_ * hlinesep() +
|
||||||
|
rowinfo_[row].ascent_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// adjust vertical offset
|
||||||
|
int h = 0;
|
||||||
|
switch (v_align_) {
|
||||||
|
case 't':
|
||||||
|
h = 0;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
h = rowinfo_[nrows() - 1].offset_;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
h = rowinfo_[nrows() - 1].offset_ / 2;
|
||||||
|
}
|
||||||
|
for (row_type row = 0; row <= nrows(); ++row)
|
||||||
|
rowinfo_[row].offset_ -= h;
|
||||||
|
|
||||||
|
|
||||||
|
// compute absolute sizes of horizontal structure
|
||||||
|
for (col_type col = 0; col < ncols(); ++col) {
|
||||||
|
int wid = 0;
|
||||||
|
for (row_type row = 0; row < nrows(); ++row)
|
||||||
|
wid = max(wid, xcell(index(row, col)).width());
|
||||||
|
colinfo_[col].width_ = wid;
|
||||||
|
}
|
||||||
|
colinfo_[ncols()].width_ = 0;
|
||||||
|
|
||||||
|
// compute horizontal offsets
|
||||||
|
colinfo_[0].offset_ = border();
|
||||||
|
for (col_type col = 1; col <= ncols(); ++col) {
|
||||||
|
colinfo_[col].offset_ =
|
||||||
|
colinfo_[col - 1].offset_ +
|
||||||
|
colinfo_[col - 1].width_ +
|
||||||
|
colinfo_[col - 1].skip_ +
|
||||||
|
1 ; //colsep() +
|
||||||
|
//colinfo_[col].lines_ * vlinesep();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
width_ = colinfo_[ncols() - 1].offset_
|
||||||
|
+ colinfo_[ncols() - 1].width_
|
||||||
|
//+ vlinesep() * colinfo_[ncols()].lines_
|
||||||
|
+ 2;
|
||||||
|
|
||||||
|
ascent_ = - rowinfo_[0].offset_
|
||||||
|
+ rowinfo_[0].ascent_
|
||||||
|
//+ hlinesep() * rowinfo_[0].lines_
|
||||||
|
+ 1;
|
||||||
|
|
||||||
|
descent_ = rowinfo_[nrows() - 1].offset_
|
||||||
|
+ rowinfo_[nrows() - 1].descent_
|
||||||
|
//+ hlinesep() * rowinfo_[nrows()].lines_
|
||||||
|
+ 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathGridInset::draw(TextPainter & pain, int x, int y) const
|
||||||
|
{
|
||||||
|
for (idx_type idx = 0; idx < nargs(); ++idx)
|
||||||
|
xcell(idx).draw(pain, x + cellXOffset(idx), y + cellYOffset(idx));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
string MathGridInset::eolString(row_type row) const
|
string MathGridInset::eolString(row_type row) const
|
||||||
{
|
{
|
||||||
string eol;
|
string eol;
|
||||||
|
@ -74,6 +74,10 @@ public:
|
|||||||
///
|
///
|
||||||
void draw(Painter &, int x, int y) const;
|
void draw(Painter &, int x, int y) const;
|
||||||
///
|
///
|
||||||
|
void metrics(TextMetricsInfo const & st) const;
|
||||||
|
///
|
||||||
|
void draw(TextPainter &, int x, int y) const;
|
||||||
|
///
|
||||||
void halign(string const &);
|
void halign(string const &);
|
||||||
///
|
///
|
||||||
void halign(char c, col_type col);
|
void halign(char c, col_type col);
|
||||||
|
@ -168,9 +168,10 @@ void MathHullInset::metrics(MathMetricsInfo const & mi) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (numberedType()) {
|
if (numberedType()) {
|
||||||
|
whichFont(mi_.font, LM_TC_BF, mi_);
|
||||||
int l = 0;
|
int l = 0;
|
||||||
for (row_type row = 0; row < nrows(); ++row)
|
for (row_type row = 0; row < nrows(); ++row)
|
||||||
l = max(l, mathed_string_width(LM_TC_BF, mi_, nicelabel(row)));
|
l = max(l, mathed_string_width(mi_.font, nicelabel(row)));
|
||||||
|
|
||||||
if (l)
|
if (l)
|
||||||
width_ += 30 + l;
|
width_ += 30 + l;
|
||||||
@ -179,7 +180,7 @@ void MathHullInset::metrics(MathMetricsInfo const & mi) const
|
|||||||
// make it at least as high as the current font
|
// make it at least as high as the current font
|
||||||
int asc = 0;
|
int asc = 0;
|
||||||
int des = 0;
|
int des = 0;
|
||||||
math_font_max_dim(LM_TC_TEXTRM, mi_, asc, des);
|
math_font_max_dim(mi_.font, asc, des);
|
||||||
ascent_ = max(ascent_, asc);
|
ascent_ = max(ascent_, asc);
|
||||||
descent_ = max(descent_, des);
|
descent_ = max(descent_, des);
|
||||||
}
|
}
|
||||||
@ -193,13 +194,13 @@ void MathHullInset::draw(Painter & pain, int x, int y) const
|
|||||||
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
|
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
|
||||||
for (row_type row = 0; row < nrows(); ++row) {
|
for (row_type row = 0; row < nrows(); ++row) {
|
||||||
int const yy = y + rowinfo_[row].offset_;
|
int const yy = y + rowinfo_[row].offset_;
|
||||||
drawStr(pain, LM_TC_BF, mi_, xx, yy, nicelabel(row));
|
drawStr(pain, mi_.font, xx, yy, nicelabel(row));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void MathHullInset::metrics(TextMetricsInfo const &) const
|
void MathHullInset::metrics(TextMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
ascent_ = 1;
|
ascent_ = 1;
|
||||||
descent_ = 0;
|
descent_ = 0;
|
||||||
@ -210,7 +211,9 @@ void MathHullInset::metrics(TextMetricsInfo const &) const
|
|||||||
void MathHullInset::draw(TextPainter & pain, int x, int y) const
|
void MathHullInset::draw(TextPainter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
pain.draw(x, y, normalName(objtype_).c_str());
|
pain.draw(x, y, normalName(objtype_).c_str());
|
||||||
|
MathGridInset::draw(pain, x, y);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
string MathHullInset::label(row_type row) const
|
string MathHullInset::label(row_type row) const
|
||||||
|
@ -31,9 +31,9 @@ public:
|
|||||||
///
|
///
|
||||||
void draw(Painter &, int x, int y) const;
|
void draw(Painter &, int x, int y) const;
|
||||||
///
|
///
|
||||||
void metrics(TextMetricsInfo const & st) const;
|
//void metrics(TextMetricsInfo const & st) const;
|
||||||
///
|
///
|
||||||
void draw(TextPainter &, int x, int y) const;
|
//void draw(TextPainter &, int x, int y) const;
|
||||||
///
|
///
|
||||||
string label(row_type row) const;
|
string label(row_type row) const;
|
||||||
///
|
///
|
||||||
|
@ -68,10 +68,11 @@ bool MathMacro::defining() const
|
|||||||
|
|
||||||
void MathMacro::metrics(MathMetricsInfo const & mi) const
|
void MathMacro::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
|
whichFont(font_, LM_TC_TEX, mi);
|
||||||
mi_ = mi;
|
mi_ = mi;
|
||||||
|
|
||||||
if (defining()) {
|
if (defining()) {
|
||||||
mathed_string_dim(LM_TC_TEX, mi_, name(), ascent_, descent_, width_);
|
mathed_string_dim(font_, name(), ascent_, descent_, width_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,12 +83,12 @@ void MathMacro::metrics(MathMetricsInfo const & mi) const
|
|||||||
ascent_ = expanded_.ascent() + 2;
|
ascent_ = expanded_.ascent() + 2;
|
||||||
descent_ = expanded_.descent() + 2;
|
descent_ = expanded_.descent() + 2;
|
||||||
|
|
||||||
width_ += mathed_string_width(LM_TC_TEXTRM, mi_, name()) + 10;
|
width_ += mathed_string_width(font_, name()) + 10;
|
||||||
|
|
||||||
int lasc;
|
int lasc;
|
||||||
int ldes;
|
int ldes;
|
||||||
int lwid;
|
int lwid;
|
||||||
mathed_string_dim(LM_TC_TEXTRM, mi_, "#1: ", lasc, ldes, lwid);
|
mathed_string_dim(font_, "#1: ", lasc, ldes, lwid);
|
||||||
|
|
||||||
for (idx_type i = 0; i < nargs(); ++i) {
|
for (idx_type i = 0; i < nargs(); ++i) {
|
||||||
MathXArray const & c = xcell(i);
|
MathXArray const & c = xcell(i);
|
||||||
@ -112,23 +113,26 @@ void MathMacro::draw(Painter & pain, int x, int y) const
|
|||||||
{
|
{
|
||||||
metrics(mi_);
|
metrics(mi_);
|
||||||
|
|
||||||
|
LyXFont texfont;
|
||||||
|
whichFont(texfont, LM_TC_TEX, mi_);
|
||||||
|
|
||||||
if (defining()) {
|
if (defining()) {
|
||||||
drawStr(pain, LM_TC_TEX, mi_, x, y, name());
|
drawStr(pain, texfont, x, y, name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editing()) {
|
if (editing()) {
|
||||||
int h = y - ascent() + 2 + expanded_.ascent();
|
int h = y - ascent() + 2 + expanded_.ascent();
|
||||||
drawStr(pain, LM_TC_TEXTRM, mi_, x + 3, h, name());
|
drawStr(pain, font_, x + 3, h, name());
|
||||||
|
|
||||||
int const w = mathed_string_width(LM_TC_TEXTRM, mi_, name());
|
int const w = mathed_string_width(font_, name());
|
||||||
expanded_.draw(pain, x + w + 12, h);
|
expanded_.draw(pain, x + w + 12, h);
|
||||||
h += expanded_.descent();
|
h += expanded_.descent();
|
||||||
|
|
||||||
int lasc;
|
int lasc;
|
||||||
int ldes;
|
int ldes;
|
||||||
int lwid;
|
int lwid;
|
||||||
mathed_string_dim(LM_TC_TEXTRM, mi_, "#1: ", lasc, ldes, lwid);
|
mathed_string_dim(font_, "#1: ", lasc, ldes, lwid);
|
||||||
|
|
||||||
for (idx_type i = 0; i < nargs(); ++i) {
|
for (idx_type i = 0; i < nargs(); ++i) {
|
||||||
MathXArray const & c = xcell(i);
|
MathXArray const & c = xcell(i);
|
||||||
@ -136,7 +140,7 @@ void MathMacro::draw(Painter & pain, int x, int y) const
|
|||||||
c.draw(pain, x + lwid, h);
|
c.draw(pain, x + lwid, h);
|
||||||
char str[] = "#1:";
|
char str[] = "#1:";
|
||||||
str[1] += static_cast<char>(i);
|
str[1] += static_cast<char>(i);
|
||||||
drawStr(pain, LM_TC_TEX, mi_, x + 3, h, str);
|
drawStr(pain, texfont, x + 3, h, str);
|
||||||
h += max(c.descent(), ldes) + 5;
|
h += max(c.descent(), ldes) + 5;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -93,6 +93,8 @@ private:
|
|||||||
mutable MathXArray expanded_;
|
mutable MathXArray expanded_;
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable MathMetricsInfo mi_;
|
||||||
|
///
|
||||||
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,14 +43,14 @@ void MathMacroArgument::write(WriteStream & os) const
|
|||||||
|
|
||||||
void MathMacroArgument::metrics(MathMetricsInfo const & mi) const
|
void MathMacroArgument::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
whichFont(font_, LM_TC_TEX, mi);
|
||||||
if (expanded_) {
|
if (expanded_) {
|
||||||
xcell(0).metrics(mi_);
|
xcell(0).metrics(mi);
|
||||||
width_ = xcell(0).width();
|
width_ = xcell(0).width();
|
||||||
ascent_ = xcell(0).ascent();
|
ascent_ = xcell(0).ascent();
|
||||||
descent_ = xcell(0).descent();
|
descent_ = xcell(0).descent();
|
||||||
} else
|
} else
|
||||||
mathed_string_dim(LM_TC_TEX, mi_, str_, ascent_, descent_, width_);
|
mathed_string_dim(font_, str_, ascent_, descent_, width_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ void MathMacroArgument::draw(Painter & pain, int x, int y) const
|
|||||||
if (expanded_)
|
if (expanded_)
|
||||||
xcell(0).draw(pain, x, y);
|
xcell(0).draw(pain, x, y);
|
||||||
else
|
else
|
||||||
drawStr(pain, LM_TC_TEX, mi_, x, y, str_);
|
drawStr(pain, font_, x, y, str_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ private:
|
|||||||
///
|
///
|
||||||
bool expanded_;
|
bool expanded_;
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
///
|
///
|
||||||
MathTextCodes code_;
|
MathTextCodes code_;
|
||||||
};
|
};
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#define MATH_METRICSINFO_H
|
#define MATH_METRICSINFO_H
|
||||||
|
|
||||||
#include "lyxfont.h"
|
#include "lyxfont.h"
|
||||||
#include "textpainter.h"
|
|
||||||
|
|
||||||
class BufferView;
|
class BufferView;
|
||||||
class MathNestInset;
|
class MathNestInset;
|
||||||
@ -24,11 +23,15 @@ enum MathStyles {
|
|||||||
struct MathMetricsInfo {
|
struct MathMetricsInfo {
|
||||||
///
|
///
|
||||||
MathMetricsInfo()
|
MathMetricsInfo()
|
||||||
: view(0), font(), style(LM_ST_TEXT), inset(0)
|
: view(0), font(), style(LM_ST_TEXT),
|
||||||
|
inset(0), idx(0),
|
||||||
|
fullredraw(false)
|
||||||
{}
|
{}
|
||||||
///
|
///
|
||||||
MathMetricsInfo(BufferView * v, LyXFont const & f, MathStyles s)
|
MathMetricsInfo(BufferView * v, LyXFont const & f, MathStyles s)
|
||||||
: view(v), font(f), style(s), inset(0)
|
: view(v), font(f), style(s),
|
||||||
|
inset(0), idx(0),
|
||||||
|
fullredraw(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -41,6 +44,8 @@ struct MathMetricsInfo {
|
|||||||
MathNestInset const * inset;
|
MathNestInset const * inset;
|
||||||
///
|
///
|
||||||
int idx;
|
int idx;
|
||||||
|
///
|
||||||
|
bool fullredraw;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,13 +61,6 @@ void MathNestInset::metrics(MathMetricsInfo const & mi) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathNestInset::draw(Painter & pain, int x, int y) const
|
|
||||||
{
|
|
||||||
for (idx_type i = 0; i < nargs(); ++i)
|
|
||||||
xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
|
bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
|
||||||
{
|
{
|
||||||
if (idx + 1 >= nargs())
|
if (idx + 1 >= nargs())
|
||||||
|
@ -22,8 +22,6 @@ public:
|
|||||||
|
|
||||||
/// the size is usuall some sort of convex hull of the cells
|
/// the size is usuall some sort of convex hull of the cells
|
||||||
void metrics(MathMetricsInfo const & st) const;
|
void metrics(MathMetricsInfo const & st) const;
|
||||||
/// draw the object, sets xo_ and yo_ cached values
|
|
||||||
void draw(Painter &, int x, int y) const;
|
|
||||||
/// appends itself with macro arguments substituted
|
/// appends itself with macro arguments substituted
|
||||||
void substitute(MathMacro const & macro);
|
void substitute(MathMacro const & macro);
|
||||||
/// identifies NestInsets
|
/// identifies NestInsets
|
||||||
|
@ -28,11 +28,14 @@ void MathNotInset::normalize(NormalStream & os) const
|
|||||||
|
|
||||||
void MathNotInset::metrics(MathMetricsInfo const & mi) const
|
void MathNotInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
if (math_font_available(LM_TC_CMSY)) {
|
||||||
if (math_font_available(LM_TC_CMSY))
|
whichFont(font_, LM_TC_CMSY, mi);
|
||||||
mathed_char_dim(LM_TC_CMSY, mi_, 54, ascent_, descent_, width_);
|
mathed_char_dim(font_, 54, ascent_, descent_, width_);
|
||||||
else
|
}
|
||||||
mathed_char_dim(LM_TC_VAR, mi_, '/', ascent_, descent_, width_);
|
else {
|
||||||
|
whichFont(font_, LM_TC_VAR, mi);
|
||||||
|
mathed_char_dim(font_, '/', ascent_, descent_, width_);
|
||||||
|
}
|
||||||
width_ = 0;
|
width_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +43,7 @@ void MathNotInset::metrics(MathMetricsInfo const & mi) const
|
|||||||
void MathNotInset::draw(Painter & pain, int x, int y) const
|
void MathNotInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
if (math_font_available(LM_TC_CMSY))
|
if (math_font_available(LM_TC_CMSY))
|
||||||
drawChar(pain, LM_TC_CMSY, mi_, x, y, 54);
|
drawChar(pain, font_, x, y, 54);
|
||||||
else
|
else
|
||||||
drawChar(pain, LM_TC_VAR, mi_, x, y, '/');
|
drawChar(pain, font_, x, y, '/');
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,13 @@ public:
|
|||||||
///
|
///
|
||||||
void write(WriteStream & os) const;
|
void write(WriteStream & os) const;
|
||||||
///
|
///
|
||||||
void normalize(NormalStream &) const;
|
void normalize(NormalStream & ns) const;
|
||||||
///
|
///
|
||||||
void metrics(MathMetricsInfo const & st) const;
|
void metrics(MathMetricsInfo const & mi) const;
|
||||||
///
|
///
|
||||||
void draw(Painter &, int x, int y) const;
|
void draw(Painter &, int x, int y) const;
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -101,7 +101,7 @@ int MathScriptInset::dy1(MathInset const * nuc) const
|
|||||||
asc += na + 2;
|
asc += na + 2;
|
||||||
else
|
else
|
||||||
asc = max(asc, na);
|
asc = max(asc, na);
|
||||||
asc = max(asc, mathed_char_ascent(LM_TC_VAR, mi_, 'I'));
|
asc = max(asc, mathed_char_ascent(font_, 'I'));
|
||||||
return asc;
|
return asc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,23 +161,19 @@ int MathScriptInset::width2(MathInset const * nuc) const
|
|||||||
|
|
||||||
int MathScriptInset::nwid(MathInset const * nuc) const
|
int MathScriptInset::nwid(MathInset const * nuc) const
|
||||||
{
|
{
|
||||||
return nuc ?
|
return nuc ? nuc->width() : mathed_char_width(font_, '.');
|
||||||
nuc->width() :
|
|
||||||
mathed_char_width(LM_TC_TEX, mi_, '.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int MathScriptInset::nasc(MathInset const * nuc) const
|
int MathScriptInset::nasc(MathInset const * nuc) const
|
||||||
{
|
{
|
||||||
return nuc ? nuc->ascent()
|
return nuc ? nuc->ascent() : mathed_char_ascent(font_, 'I');
|
||||||
: mathed_char_ascent(LM_TC_VAR, mi_, 'I');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int MathScriptInset::ndes(MathInset const * nuc) const
|
int MathScriptInset::ndes(MathInset const * nuc) const
|
||||||
{
|
{
|
||||||
return nuc ? nuc->descent()
|
return nuc ? nuc->descent() : mathed_char_descent(font_, 'I');
|
||||||
: mathed_char_descent(LM_TC_VAR, mi_, 'I');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -190,9 +186,10 @@ void MathScriptInset::metrics(MathMetricsInfo const & mi) const
|
|||||||
void MathScriptInset::metrics(MathInset const * nuc,
|
void MathScriptInset::metrics(MathInset const * nuc,
|
||||||
MathMetricsInfo const & mi) const
|
MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
MathMetricsInfo m = mi;
|
||||||
smallerStyleScript(mi_);
|
smallerStyleScript(m);
|
||||||
MathNestInset::metrics(mi_);
|
MathNestInset::metrics(m);
|
||||||
|
whichFont(font_, LM_TC_VAR, m);
|
||||||
if (nuc)
|
if (nuc)
|
||||||
nuc->metrics(mi);
|
nuc->metrics(mi);
|
||||||
ascent_ = ascent2(nuc);
|
ascent_ = ascent2(nuc);
|
||||||
@ -210,7 +207,10 @@ void MathScriptInset::metrics(TextMetricsInfo const & mi) const
|
|||||||
void MathScriptInset::metrics(MathInset const * nuc,
|
void MathScriptInset::metrics(MathInset const * nuc,
|
||||||
TextMetricsInfo const & mi) const
|
TextMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
MathNestInset::metrics(mi_);
|
if (hasUp())
|
||||||
|
up().metrics(mi);
|
||||||
|
if (hasDown())
|
||||||
|
down().metrics(mi);
|
||||||
if (nuc)
|
if (nuc)
|
||||||
nuc->metrics(mi);
|
nuc->metrics(mi);
|
||||||
//ascent_ = ascent2(nuc);
|
//ascent_ = ascent2(nuc);
|
||||||
@ -232,7 +232,7 @@ void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
|
|||||||
if (nuc)
|
if (nuc)
|
||||||
nuc->draw(pain, x + dxx(nuc), y);
|
nuc->draw(pain, x + dxx(nuc), y);
|
||||||
else // if (editing())
|
else // if (editing())
|
||||||
drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, ".");
|
drawStr(pain, font_, x + dxx(nuc), y, ".");
|
||||||
|
|
||||||
if (hasUp())
|
if (hasUp())
|
||||||
up().draw(pain, x + dx1(nuc), y - dy1(nuc));
|
up().draw(pain, x + dx1(nuc), y - dy1(nuc));
|
||||||
|
@ -120,8 +120,8 @@ private:
|
|||||||
bool script_[2];
|
bool script_[2];
|
||||||
/// 1 - "limits", -1 - "nolimits", 0 - "default"
|
/// 1 - "limits", -1 - "nolimits", 0 - "default"
|
||||||
int limits_;
|
int limits_;
|
||||||
/// cached MathMetricsInfo
|
/// cached font
|
||||||
mutable MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,31 +20,31 @@ MathInset * MathSpecialCharInset::clone() const
|
|||||||
|
|
||||||
int MathSpecialCharInset::ascent() const
|
int MathSpecialCharInset::ascent() const
|
||||||
{
|
{
|
||||||
return mathed_char_ascent(LM_TC_CONST, mi_, char_);
|
return mathed_char_ascent(font_, char_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int MathSpecialCharInset::descent() const
|
int MathSpecialCharInset::descent() const
|
||||||
{
|
{
|
||||||
return mathed_char_descent(LM_TC_CONST, mi_, char_);
|
return mathed_char_descent(font_, char_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int MathSpecialCharInset::width() const
|
int MathSpecialCharInset::width() const
|
||||||
{
|
{
|
||||||
return mathed_char_width(LM_TC_CONST, mi_, char_);
|
return mathed_char_width(font_, char_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathSpecialCharInset::metrics(MathMetricsInfo const & mi) const
|
void MathSpecialCharInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
whichFont(font_, LM_TC_CONST, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathSpecialCharInset::draw(Painter & pain, int x, int y) const
|
void MathSpecialCharInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
drawChar(pain, LM_TC_CONST, mi_, x, y, char_);
|
drawChar(pain, font_, x, y, char_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +38,6 @@ private:
|
|||||||
/// the character
|
/// the character
|
||||||
char char_;
|
char char_;
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "math_mathmlstream.h"
|
#include "math_mathmlstream.h"
|
||||||
#include "LColor.h"
|
#include "LColor.h"
|
||||||
#include "Painter.h"
|
#include "Painter.h"
|
||||||
|
#include "textpainter.h"
|
||||||
|
|
||||||
|
|
||||||
MathSqrtInset::MathSqrtInset()
|
MathSqrtInset::MathSqrtInset()
|
||||||
@ -43,6 +44,24 @@ void MathSqrtInset::draw(Painter & pain, int x, int y) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathSqrtInset::metrics(TextMetricsInfo const & mi) const
|
||||||
|
{
|
||||||
|
xcell(0).metrics(mi);
|
||||||
|
ascent_ = xcell(0).ascent() + 1;
|
||||||
|
descent_ = xcell(0).descent();
|
||||||
|
width_ = xcell(0).width() + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathSqrtInset::draw(TextPainter & pain, int x, int y) const
|
||||||
|
{
|
||||||
|
xcell(0).draw(pain, x + 2, y);
|
||||||
|
pain.horizontalLine(x + 2, y - xcell(0).ascent(), xcell(0).width(), '_');
|
||||||
|
pain.verticalLine (x + 1, y - xcell(0).ascent() + 1, xcell(0).height());
|
||||||
|
pain.draw(x, y + xcell(0).descent(), '\\');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathSqrtInset::write(WriteStream & os) const
|
void MathSqrtInset::write(WriteStream & os) const
|
||||||
{
|
{
|
||||||
os << "\\sqrt{" << cell(0) << '}';
|
os << "\\sqrt{" << cell(0) << '}';
|
||||||
|
@ -20,7 +20,11 @@ public:
|
|||||||
///
|
///
|
||||||
void draw(Painter &, int x, int y) const;
|
void draw(Painter &, int x, int y) const;
|
||||||
///
|
///
|
||||||
void metrics(MathMetricsInfo const & st) const;
|
void metrics(MathMetricsInfo const & mi) const;
|
||||||
|
///
|
||||||
|
void draw(TextPainter &, int x, int y) const;
|
||||||
|
///
|
||||||
|
void metrics(TextMetricsInfo const & mi) const;
|
||||||
|
|
||||||
///
|
///
|
||||||
void write(WriteStream & os) const;
|
void write(WriteStream & os) const;
|
||||||
|
@ -34,21 +34,22 @@ MathInset * MathStringInset::clone() const
|
|||||||
|
|
||||||
int MathStringInset::ascent() const
|
int MathStringInset::ascent() const
|
||||||
{
|
{
|
||||||
return mathed_string_ascent(code_, mi_, str_);
|
return mathed_string_ascent(font_, str_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int MathStringInset::descent() const
|
int MathStringInset::descent() const
|
||||||
{
|
{
|
||||||
return mathed_string_descent(code_, mi_, str_);
|
return mathed_string_descent(font_, str_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int MathStringInset::width() const
|
int MathStringInset::width() const
|
||||||
{
|
{
|
||||||
return mathed_string_width(code_, mi_, str_);
|
return mathed_string_width(font_, str_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathStringInset::validate(LaTeXFeatures & features) const
|
void MathStringInset::validate(LaTeXFeatures & features) const
|
||||||
{
|
{
|
||||||
//lyxerr << "stringinset amssymb" << endl;
|
//lyxerr << "stringinset amssymb" << endl;
|
||||||
@ -56,16 +57,17 @@ void MathStringInset::validate(LaTeXFeatures & features) const
|
|||||||
features.require("amssymb");
|
features.require("amssymb");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathStringInset::metrics(MathMetricsInfo const & mi) const
|
void MathStringInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
whichFont(font_, code_, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathStringInset::draw(Painter & pain, int x, int y) const
|
void MathStringInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
//lyxerr << "drawing '" << str_ << "' code: " << code_ << endl;
|
//lyxerr << "drawing '" << str_ << "' code: " << code_ << endl;
|
||||||
drawStr(pain, code_, mi_, x, y, str_);
|
drawStr(pain, font_, x, y, str_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,6 +54,6 @@ public:
|
|||||||
/// the font to be used on screen
|
/// the font to be used on screen
|
||||||
MathTextCodes code_;
|
MathTextCodes code_;
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -218,6 +218,8 @@ LyXFont const & whichFontBase(MathTextCodes type)
|
|||||||
return whichFontBaseIntern(type);
|
return whichFontBaseIntern(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
void whichFont(LyXFont & f, MathTextCodes type, MathMetricsInfo const & size)
|
void whichFont(LyXFont & f, MathTextCodes type, MathMetricsInfo const & size)
|
||||||
{
|
{
|
||||||
@ -259,8 +261,6 @@ void whichFont(LyXFont & f, MathTextCodes type, MathMetricsInfo const & size)
|
|||||||
f.setColor(LColor::latex);
|
f.setColor(LColor::latex);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
|
|
||||||
bool math_font_available(MathTextCodes type)
|
bool math_font_available(MathTextCodes type)
|
||||||
{
|
{
|
||||||
@ -553,79 +553,64 @@ deco_struct const * search_deco(string const & name)
|
|||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
void mathed_char_dim(MathTextCodes type, MathMetricsInfo const & size,
|
void mathed_char_dim(LyXFont const & font,
|
||||||
unsigned char c, int & asc, int & des, int & wid)
|
unsigned char c, int & asc, int & des, int & wid)
|
||||||
{
|
{
|
||||||
LyXFont font;
|
|
||||||
whichFont(font, type, size);
|
|
||||||
des = lyxfont::descent(c, font);
|
des = lyxfont::descent(c, font);
|
||||||
asc = lyxfont::ascent(c, font);
|
asc = lyxfont::ascent(c, font);
|
||||||
wid = mathed_char_width(type, size, c);
|
wid = mathed_char_width(font, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mathed_char_height(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_char_height(LyXFont const & font,
|
||||||
unsigned char c, int & asc, int & des)
|
unsigned char c, int & asc, int & des)
|
||||||
{
|
{
|
||||||
LyXFont font;
|
|
||||||
whichFont(font, type, size);
|
|
||||||
des = lyxfont::descent(c, font);
|
des = lyxfont::descent(c, font);
|
||||||
asc = lyxfont::ascent(c, font);
|
asc = lyxfont::ascent(c, font);
|
||||||
return asc + des;
|
return asc + des;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mathed_char_height(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_char_height(LyXFont const & font, unsigned char c)
|
||||||
unsigned char c)
|
|
||||||
{
|
{
|
||||||
int asc;
|
int asc;
|
||||||
int des;
|
int des;
|
||||||
return mathed_char_height(type, size, c, asc, des);
|
return mathed_char_height(font, c, asc, des);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mathed_char_ascent(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_char_ascent(LyXFont const & font, unsigned char c)
|
||||||
unsigned char c)
|
|
||||||
{
|
{
|
||||||
LyXFont font;
|
|
||||||
whichFont(font, type, size);
|
|
||||||
return lyxfont::ascent(c, font);
|
return lyxfont::ascent(c, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mathed_char_descent(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_char_descent(LyXFont const & font, unsigned char c)
|
||||||
unsigned char c)
|
|
||||||
{
|
{
|
||||||
LyXFont font;
|
|
||||||
whichFont(font, type, size);
|
|
||||||
return lyxfont::descent(c, font);
|
return lyxfont::descent(c, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mathed_char_width(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_char_width(LyXFont const & font,
|
||||||
unsigned char c)
|
unsigned char c)
|
||||||
{
|
{
|
||||||
LyXFont font;
|
//if (isBinaryOp(c, type))
|
||||||
whichFont(font, type, size);
|
// return lyxfont::width(c, font) + 2 * lyxfont::width(' ', font);
|
||||||
if (isBinaryOp(c, type))
|
|
||||||
return lyxfont::width(c, font) + 2 * lyxfont::width(' ', font);
|
|
||||||
return lyxfont::width(c, font);
|
return lyxfont::width(c, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void mathed_string_dim(MathTextCodes type, MathMetricsInfo const & size,
|
void mathed_string_dim(LyXFont const & font,
|
||||||
string const & s, int & asc, int & des, int & wid)
|
string const & s, int & asc, int & des, int & wid)
|
||||||
{
|
{
|
||||||
mathed_string_height(type, size, s, asc, des);
|
mathed_string_height(font, s, asc, des);
|
||||||
wid = mathed_string_width(type, size, s);
|
wid = mathed_string_width(font, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mathed_string_height(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_string_height(LyXFont const & font,
|
||||||
string const & s, int & asc, int & des)
|
string const & s, int & asc, int & des)
|
||||||
{
|
{
|
||||||
LyXFont font;
|
|
||||||
whichFont(font, type, size);
|
|
||||||
asc = des = 0;
|
asc = des = 0;
|
||||||
for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||||
des = max(des, lyxfont::descent(*it, font));
|
des = max(des, lyxfont::descent(*it, font));
|
||||||
@ -635,20 +620,14 @@ int mathed_string_height(MathTextCodes type, MathMetricsInfo const & size,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mathed_string_width(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_string_width(LyXFont const & font, string const & s)
|
||||||
string const & s)
|
|
||||||
{
|
{
|
||||||
LyXFont font;
|
|
||||||
whichFont(font, type, size);
|
|
||||||
return lyxfont::width(s, font);
|
return lyxfont::width(s, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mathed_string_ascent(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_string_ascent(LyXFont const & font, string const & s)
|
||||||
string const & s)
|
|
||||||
{
|
{
|
||||||
LyXFont font;
|
|
||||||
whichFont(font, type, size);
|
|
||||||
int asc = 0;
|
int asc = 0;
|
||||||
for (string::const_iterator it = s.begin(); it != s.end(); ++it)
|
for (string::const_iterator it = s.begin(); it != s.end(); ++it)
|
||||||
asc = max(asc, lyxfont::ascent(*it, font));
|
asc = max(asc, lyxfont::ascent(*it, font));
|
||||||
@ -656,11 +635,8 @@ int mathed_string_ascent(MathTextCodes type, MathMetricsInfo const & size,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mathed_string_descent(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_string_descent(LyXFont const & font, string const & s)
|
||||||
string const & s)
|
|
||||||
{
|
{
|
||||||
LyXFont font;
|
|
||||||
whichFont(font, type, size);
|
|
||||||
int des = 0;
|
int des = 0;
|
||||||
for (string::const_iterator it = s.begin(); it != s.end(); ++it)
|
for (string::const_iterator it = s.begin(); it != s.end(); ++it)
|
||||||
des = max(des, lyxfont::descent(*it, font));
|
des = max(des, lyxfont::descent(*it, font));
|
||||||
@ -746,22 +722,17 @@ void mathed_draw_framebox(Painter & pain, int x, int y, MathInset const * p)
|
|||||||
|
|
||||||
|
|
||||||
// In the future maybe we use a better fonts renderer
|
// In the future maybe we use a better fonts renderer
|
||||||
void drawStr(Painter & pain, MathTextCodes type, MathMetricsInfo const & size,
|
void drawStr(Painter & pain, LyXFont const & font,
|
||||||
int x, int y, string const & str)
|
int x, int y, string const & str)
|
||||||
{
|
{
|
||||||
LyXFont font;
|
|
||||||
whichFont(font, type, size);
|
|
||||||
pain.text(x, y, str, font);
|
pain.text(x, y, str, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void drawChar(Painter & pain, MathTextCodes type, MathMetricsInfo const & size,
|
void drawChar(Painter & pain, LyXFont const & font, int x, int y, char c)
|
||||||
int x, int y, char c)
|
|
||||||
{
|
{
|
||||||
LyXFont font;
|
//if (isBinaryOp(c, type))
|
||||||
whichFont(font, type, size);
|
// x += lyxfont::width(' ', font);
|
||||||
if (isBinaryOp(c, type))
|
|
||||||
x += lyxfont::width(' ', font);
|
|
||||||
pain.text(x, y, c, font);
|
pain.text(x, y, c, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -788,11 +759,8 @@ void smallerStyleFrac(MathMetricsInfo & st)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void math_font_max_dim(MathTextCodes code, MathMetricsInfo const & size,
|
void math_font_max_dim(LyXFont const & font, int & asc, int & des)
|
||||||
int & asc, int & des)
|
|
||||||
{
|
{
|
||||||
LyXFont font;
|
|
||||||
whichFont(font, code, size);
|
|
||||||
asc = lyxfont::maxAscent(font);
|
asc = lyxfont::maxAscent(font);
|
||||||
des = lyxfont::maxDescent(font);
|
des = lyxfont::maxDescent(font);
|
||||||
}
|
}
|
||||||
|
@ -11,49 +11,35 @@ class TextPainter;
|
|||||||
class latexkeys;
|
class latexkeys;
|
||||||
class MathMetricsInfo;
|
class MathMetricsInfo;
|
||||||
class MathInset;
|
class MathInset;
|
||||||
|
class LyXFont;
|
||||||
|
|
||||||
extern char const * latex_mathspace[];
|
extern char const * latex_mathspace[];
|
||||||
|
|
||||||
int mathed_char_height(MathTextCodes type, MathMetricsInfo const & size,
|
void mathed_char_dim(LyXFont const &, unsigned char c,
|
||||||
unsigned char c, int & asc, int & des);
|
int & asc, int & des, int & wid);
|
||||||
void mathed_char_dim(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_char_height(LyXFont const &, unsigned char c, int & asc, int & des);
|
||||||
unsigned char c, int & asc, int & des, int & wid);
|
int mathed_char_width(LyXFont const &, unsigned char c);
|
||||||
int mathed_char_width(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_char_ascent(LyXFont const &, unsigned char c);
|
||||||
unsigned char c);
|
int mathed_char_descent(LyXFont const &, unsigned char c);
|
||||||
int mathed_char_ascent(MathTextCodes type, MathMetricsInfo const & size,
|
|
||||||
unsigned char c);
|
|
||||||
int mathed_char_descent(MathTextCodes type, MathMetricsInfo const & size,
|
|
||||||
unsigned char c);
|
|
||||||
|
|
||||||
void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
|
void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
|
||||||
string const & name);
|
string const & name);
|
||||||
|
|
||||||
void mathed_draw_framebox(Painter & pain, int x, int y, MathInset const *);
|
void mathed_draw_framebox(Painter & pain, int x, int y, MathInset const *);
|
||||||
|
|
||||||
void mathed_string_dim(MathTextCodes type, MathMetricsInfo const & size,
|
void mathed_string_dim(LyXFont const &,
|
||||||
string const & s, int & asc, int & des, int & wid);
|
string const & s, int & asc, int & des, int & wid);
|
||||||
int mathed_string_height(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_string_height(LyXFont const &,
|
||||||
string const & s, int & asc, int & des);
|
string const & s, int & asc, int & des);
|
||||||
|
|
||||||
int mathed_string_width(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_string_width(LyXFont const &, string const & s);
|
||||||
string const & s);
|
int mathed_string_ascent(LyXFont const &, string const & s);
|
||||||
int mathed_string_ascent(MathTextCodes type, MathMetricsInfo const & size,
|
int mathed_string_descent(LyXFont const &, string const & s);
|
||||||
string const & s);
|
|
||||||
int mathed_string_descent(MathTextCodes type, MathMetricsInfo const & size,
|
|
||||||
string const & s);
|
|
||||||
|
|
||||||
void drawStr(Painter & pain, MathTextCodes type, MathMetricsInfo const & siz,
|
void drawStr(Painter & pain, LyXFont const &, int x, int y, string const & s);
|
||||||
int x, int y, string const & s);
|
void drawChar(Painter & pain, LyXFont const & font, int x, int y, char c);
|
||||||
void drawChar(Painter & pain, MathTextCodes type, MathMetricsInfo const & siz,
|
|
||||||
int x, int y, char c);
|
|
||||||
|
|
||||||
void drawStr(TextPainter & p, MathTextCodes type, MathMetricsInfo const & siz,
|
void math_font_max_dim(LyXFont const &, int & asc, int & desc);
|
||||||
int x, int y, string const & s);
|
|
||||||
void drawChar(TextPainter & p, MathTextCodes type, MathMetricsInfo const & siz,
|
|
||||||
int x, int y, char c);
|
|
||||||
|
|
||||||
void math_font_max_dim(MathTextCodes code, MathMetricsInfo const & siz,
|
|
||||||
int & asc, int & desc);
|
|
||||||
|
|
||||||
bool math_font_available(MathTextCodes code);
|
bool math_font_available(MathTextCodes code);
|
||||||
|
|
||||||
@ -67,4 +53,6 @@ char const * math_font_name(MathTextCodes type);
|
|||||||
|
|
||||||
string convertDelimToLatexName(string const & name);
|
string convertDelimToLatexName(string const & name);
|
||||||
|
|
||||||
|
void whichFont(LyXFont & f, MathTextCodes type, MathMetricsInfo const & size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -72,37 +72,47 @@ string MathSymbolInset::name() const
|
|||||||
|
|
||||||
void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
|
void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
|
LyXFont font;
|
||||||
mi_ = mi;
|
mi_ = mi;
|
||||||
MathTextCodes c = code();
|
MathTextCodes c = code();
|
||||||
if (sym_->latex_font_id > 0 && math_font_available(c)) {
|
if (sym_->latex_font_id > 0 && math_font_available(c)) {
|
||||||
mathed_char_dim(c, mi_, sym_->latex_font_id, ascent_, descent_, width_);
|
whichFont(font, c, mi_);
|
||||||
|
mathed_char_dim(font, sym_->latex_font_id, ascent_, descent_, width_);
|
||||||
if (c == LM_TC_CMEX) {
|
if (c == LM_TC_CMEX) {
|
||||||
h_ = 4 * descent_ / 5;
|
h_ = 4 * descent_ / 5;
|
||||||
ascent_ += h_;
|
ascent_ += h_;
|
||||||
descent_ -= h_;
|
descent_ -= h_;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
|
if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB)) {
|
||||||
mathed_char_dim(code2(), mi_, sym_->id, ascent_, descent_, width_);
|
whichFont(font, code2(), mi_);
|
||||||
else
|
mathed_char_dim(font, sym_->id, ascent_, descent_, width_);
|
||||||
mathed_string_dim(LM_TC_TEX, mi_, sym_->name, ascent_, descent_, width_);
|
} else {
|
||||||
|
whichFont(font, LM_TC_TEX, mi_);
|
||||||
|
mathed_string_dim(font, sym_->name, ascent_, descent_, width_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isRelOp())
|
if (isRelOp())
|
||||||
width_ += mathed_char_width(LM_TC_TEX, mi_, 'I');
|
width_ += 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathSymbolInset::draw(Painter & pain, int x, int y) const
|
void MathSymbolInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
if (isRelOp())
|
if (isRelOp())
|
||||||
x += mathed_char_width(LM_TC_TEX, mi_, 'I') / 2;
|
x += 3;
|
||||||
MathTextCodes Code = code();
|
MathTextCodes Code = code();
|
||||||
if (sym_->latex_font_id > 0 && math_font_available(Code))
|
LyXFont font;
|
||||||
drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id);
|
if (sym_->latex_font_id > 0 && math_font_available(Code)) {
|
||||||
else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
|
whichFont(font, Code, mi_);
|
||||||
drawChar(pain, code2(), mi_, x, y, sym_->id);
|
drawChar(pain, font, x, y - h_, sym_->latex_font_id);
|
||||||
else
|
} else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB)){
|
||||||
drawStr(pain, LM_TC_TEX, mi_, x, y, sym_->name);
|
whichFont(font, code2(), mi_);
|
||||||
|
drawChar(pain, font, x, y, sym_->id);
|
||||||
|
} else {
|
||||||
|
whichFont(font, LM_TC_TEX, mi_);
|
||||||
|
drawStr(pain, font, x, y, sym_->name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,14 +59,14 @@ void MathUnknownInset::normalize(NormalStream & os) const
|
|||||||
|
|
||||||
void MathUnknownInset::metrics(MathMetricsInfo const & mi) const
|
void MathUnknownInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
whichFont(font_, LM_TC_TEX, mi);
|
||||||
mathed_string_dim(LM_TC_TEX, mi_, name_, ascent_, descent_, width_);
|
mathed_string_dim(font_, name_, ascent_, descent_, width_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathUnknownInset::draw(Painter & pain, int x, int y) const
|
void MathUnknownInset::draw(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
drawStr(pain, LM_TC_TEX, mi_, x, y, name_);
|
drawStr(pain, font_, x, y, name_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
class MathUnknownInset : public MathDimInset {
|
class MathUnknownInset : public MathDimInset {
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
explicit MathUnknownInset(string const & nm);
|
explicit MathUnknownInset(string const & name);
|
||||||
///
|
///
|
||||||
MathInset * clone() const;
|
MathInset * clone() const;
|
||||||
///
|
///
|
||||||
@ -45,6 +45,6 @@ private:
|
|||||||
///
|
///
|
||||||
string name_;
|
string name_;
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable LyXFont font_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,7 +41,9 @@ void MathXArray::metrics(MathMetricsInfo const & mi) const
|
|||||||
drawn_ = false;
|
drawn_ = false;
|
||||||
|
|
||||||
if (data_.empty()) {
|
if (data_.empty()) {
|
||||||
mathed_char_dim(LM_TC_VAR, mi, 'I', ascent_, descent_, width_);
|
LyXFont font;
|
||||||
|
whichFont(font, LM_TC_VAR, mi);
|
||||||
|
mathed_char_dim(font, 'I', ascent_, descent_, width_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ MathInset * MathXYArrowInset::clone() const
|
|||||||
|
|
||||||
MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
|
MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
|
||||||
{
|
{
|
||||||
return mi_.inset ? mi_.inset->asXYMatrixInset() : 0;
|
return target_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -66,11 +66,13 @@ MathXArray const & MathXYArrowInset::sourceCell() const
|
|||||||
|
|
||||||
void MathXYArrowInset::metrics(MathMetricsInfo const & mi) const
|
void MathXYArrowInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
|
||||||
MathNestInset::metrics(mi);
|
MathNestInset::metrics(mi);
|
||||||
|
mi_ = mi;
|
||||||
|
whichFont(font_, LM_TC_TEXTRM, mi);
|
||||||
|
target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
|
||||||
|
|
||||||
if (editing()) {
|
if (editing()) {
|
||||||
int w = mathed_string_width(LM_TC_TEXTRM, mi_, "target: ");
|
int w = mathed_string_width(font_, "target: ");
|
||||||
width_ = w + max(xcell(0).width(), xcell(1).width());
|
width_ = w + max(xcell(0).width(), xcell(1).width());
|
||||||
ascent_ = xcell(0).ascent();
|
ascent_ = xcell(0).ascent();
|
||||||
descent_ = xcell(0).descent() + xcell(1).height() + 10;
|
descent_ = xcell(0).descent() + xcell(1).height() + 10;
|
||||||
@ -78,7 +80,7 @@ void MathXYArrowInset::metrics(MathMetricsInfo const & mi) const
|
|||||||
width_ = 0;
|
width_ = 0;
|
||||||
ascent_ = 0;
|
ascent_ = 0;
|
||||||
descent_ = 0;
|
descent_ = 0;
|
||||||
//mathed_string_dim(LM_TC_TEXTRM, mi_, "X", ascent_, descent_, width_);
|
//mathed_string_dim(font_, "X", ascent_, descent_, width_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,19 +94,19 @@ void MathXYArrowInset::draw(Painter & pain, int x, int y) const
|
|||||||
int lasc;
|
int lasc;
|
||||||
int ldes;
|
int ldes;
|
||||||
int lwid;
|
int lwid;
|
||||||
mathed_string_dim(LM_TC_TEXTRM, mi_, "target: ", lasc, ldes, lwid);
|
mathed_string_dim(font_, "target: ", lasc, ldes, lwid);
|
||||||
|
|
||||||
xcell(0).draw(pain, x + lwid, y);
|
xcell(0).draw(pain, x + lwid, y);
|
||||||
drawStr(pain, LM_TC_TEXTRM, mi_, x + 3, y, "target");
|
drawStr(pain, font_, x + 3, y, "target");
|
||||||
y += max(xcell(0).descent(), ldes) + 5;
|
y += max(xcell(0).descent(), ldes) + 5;
|
||||||
|
|
||||||
y += max(xcell(1).ascent(), lasc) + 5;
|
y += max(xcell(1).ascent(), lasc) + 5;
|
||||||
xcell(1).draw(pain, x + lwid, y);
|
xcell(1).draw(pain, x + lwid, y);
|
||||||
drawStr(pain, LM_TC_TEXTRM, mi_, x + 3, y, "label");
|
drawStr(pain, font_, x + 3, y, "label");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//drawStr(pain, LM_TC_TEXTRM, mi_, x, y, "X");
|
//drawStr(pain, font_, x, y, "X");
|
||||||
MathXArray const & s = sourceCell();
|
MathXArray const & s = sourceCell();
|
||||||
MathXArray const & t = targetCell();
|
MathXArray const & t = targetCell();
|
||||||
pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
|
pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
|
||||||
|
@ -44,6 +44,10 @@ public:
|
|||||||
bool up_;
|
bool up_;
|
||||||
///
|
///
|
||||||
mutable MathMetricsInfo mi_;
|
mutable MathMetricsInfo mi_;
|
||||||
|
///
|
||||||
|
mutable LyXFont font_;
|
||||||
|
///
|
||||||
|
mutable MathXYMatrixInset const * target_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
#include <iostream>
|
||||||
#include "textpainter.h"
|
#include "textpainter.h"
|
||||||
|
|
||||||
|
|
||||||
TextPainter::TextPainter(int xmax, int ymax)
|
TextPainter::TextPainter(int xmax, int ymax)
|
||||||
: xmax_(xmax), ymax_(ymax), data_((xmax_ + 1) * (ymax_ + 1))
|
: xmax_(xmax), ymax_(ymax), data_(xmax_ * (ymax_ + 1), ' ')
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -20,6 +21,41 @@ char TextPainter::at(int x, int y) const
|
|||||||
|
|
||||||
void TextPainter::draw(int x, int y, char const * str)
|
void TextPainter::draw(int x, int y, char const * str)
|
||||||
{
|
{
|
||||||
for (int i = 0; *str; ++i, ++str)
|
//cerr << "drawing string '" << str << "' at " << x << "," << y << "\n";
|
||||||
|
for (int i = 0; *str && x + i < xmax_; ++i, ++str)
|
||||||
at(x + i, y) = *str;
|
at(x + i, y) = *str;
|
||||||
|
//show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TextPainter::horizontalLine(int x, int y, int n, char c)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < n && i + x < xmax_; ++i)
|
||||||
|
at(x + i, y) = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TextPainter::verticalLine(int x, int y, int n, char c)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < n && i + y < ymax_; ++i)
|
||||||
|
at(x, y + i) = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TextPainter::draw(int x, int y, char c)
|
||||||
|
{
|
||||||
|
//cerr << "drawing char '" << c << "' at " << x << "," << y << "\n";
|
||||||
|
at(x, y) = c;
|
||||||
|
//show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TextPainter::show(std::ostream & os) const
|
||||||
|
{
|
||||||
|
os << '\n';
|
||||||
|
for (int j = 0; j <= ymax_; ++j) {
|
||||||
|
for (int i = 0; i < xmax_; ++i)
|
||||||
|
os << at(i, j);
|
||||||
|
os << '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define TEXTPAINTER_H
|
#define TEXTPAINTER_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <iosfwd>
|
||||||
|
|
||||||
class TextPainter {
|
class TextPainter {
|
||||||
public:
|
public:
|
||||||
@ -9,6 +10,16 @@ class TextPainter {
|
|||||||
TextPainter(int xmax, int ymax);
|
TextPainter(int xmax, int ymax);
|
||||||
///
|
///
|
||||||
void draw(int x, int y, char const * str);
|
void draw(int x, int y, char const * str);
|
||||||
|
///
|
||||||
|
void draw(int x, int y, char c);
|
||||||
|
///
|
||||||
|
void show(std::ostream & os) const;
|
||||||
|
///
|
||||||
|
int textheight() const { return ymax_; }
|
||||||
|
///
|
||||||
|
void horizontalLine(int x, int y, int len, char c = '-');
|
||||||
|
///
|
||||||
|
void verticalLine(int x, int y, int len, char c = '|');
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
@ -18,12 +29,12 @@ class TextPainter {
|
|||||||
///
|
///
|
||||||
char & at(int x, int y);
|
char & at(int x, int y);
|
||||||
|
|
||||||
///
|
/// xsize of the painter area
|
||||||
data_type data_;
|
|
||||||
///
|
|
||||||
int xmax_;
|
int xmax_;
|
||||||
///
|
/// ysize of the painter area
|
||||||
int ymax_;
|
int ymax_;
|
||||||
|
/// the image
|
||||||
|
data_type data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user