Fix bug #4071: wrong fonts in math

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@34519 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2010-05-27 07:03:09 +00:00
parent 8cbb4a451f
commit 0c71d4fb78
11 changed files with 67 additions and 15 deletions

View File

@ -232,10 +232,16 @@ FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
{
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
docstring const oldname = from_ascii(save_.fontname);
mb.fontname = name;
mb.font = sane_font;
augmentFont(mb.font, from_ascii(name));
mb.font.setSize(oldsize);
if (string(name) != "lyxtex"
&& ((isTextFont(oldname) && oldcolor != Color_foreground)
|| (isMathFont(oldname) && oldcolor != Color_math)))
mb.font.setColor(oldcolor);
}
@ -244,10 +250,16 @@ FontSetChanger::FontSetChanger(MetricsBase & mb, docstring const & name)
{
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
docstring const oldname = from_ascii(save_.fontname);
mb.fontname = to_utf8(name);
mb.font = sane_font;
augmentFont(mb.font, name);
mb.font.setSize(oldsize);
if (name != "lyxtex"
&& ((isTextFont(oldname) && oldcolor != Color_foreground)
|| (isMathFont(oldname) && oldcolor != Color_math)))
mb.font.setColor(oldcolor);
}
@ -283,17 +295,21 @@ WidthChanger::~WidthChanger()
//
/////////////////////////////////////////////////////////////////////////
ColorChanger::ColorChanger(FontInfo & font, string const & color)
: Changer<FontInfo, string>(font)
ColorChanger::ColorChanger(FontInfo & font, docstring const & color,
bool really_change_color)
: Changer<FontInfo, ColorCode>(font), change_(really_change_color)
{
save_ = lcolor.getFromLyXName(color);
font.setColor(lcolor.getFromLyXName(color));
if (change_) {
save_ = font.color();
font.setColor(lcolor.getFromLyXName(to_utf8(color)));
}
}
ColorChanger::~ColorChanger()
{
orig_.setColor(lcolor.getFromLyXName(save_));
if (change_)
orig_.setColor(save_);
}

View File

@ -216,12 +216,16 @@ public:
// temporarily change the used color
class ColorChanger : public Changer<FontInfo, std::string> {
class ColorChanger : public Changer<FontInfo, ColorCode> {
public:
///
ColorChanger(FontInfo & font, std::string const & color);
ColorChanger(FontInfo & font, docstring const & color,
bool really_change_color = true);
///
~ColorChanger();
private:
///
bool change_;
};
} // namespace lyx

View File

@ -244,12 +244,12 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
pi.pain.line(xx + dim0.wid,
y + dim.des - 2,
xx + dim0.wid + 5,
y - dim.asc + 2, Color_math);
y - dim.asc + 2, pi.base.font.color());
}
if (kind_ == FRAC || kind_ == CFRAC || kind_ == CFRACLEFT
|| kind_ == CFRACRIGHT || kind_ == OVER)
pi.pain.line(x + 1, y - 5,
x + dim.wid - 2, y - 5, Color_math);
x + dim.wid - 2, y - 5, pi.base.font.color());
drawMarkers(pi, x, y);
}

View File

@ -329,6 +329,12 @@ docstring InsetMathHull::standardFont() const
}
docstring InsetMathHull::standardColor() const
{
return from_ascii(type_ == hullNone ? "foreground" : "math");
}
bool InsetMathHull::previewState(BufferView * bv) const
{
if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
@ -413,8 +419,11 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
return;
}
bool const really_change_color = pi.base.font.color() == Color_none;
ColorChanger dummy0(pi.base.font, standardColor(), really_change_color);
FontSetChanger dummy1(pi.base, standardFont());
StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
InsetMathGrid::draw(pi, x + 1, y);
if (numberedType()) {

View File

@ -191,6 +191,8 @@ private:
void changeCols(col_type);
///
docstring standardFont() const;
///
docstring standardColor() const;
/// consistency check
void check() const;
/// can this change its number of rows?

View File

@ -60,12 +60,12 @@ void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
int xp[4];
int yp[4];
pi.pain.line(x + dim.width(), y - a + 1,
x + w + 4, y - a + 1, Color_math);
x + w + 4, y - a + 1, pi.base.font.color());
xp[0] = x + w + 4; yp[0] = y - a + 1;
xp[1] = x + w; yp[1] = y + d;
xp[2] = x + w - 2; yp[2] = y + (d - a)/2 + 2;
xp[3] = x + w - 5; yp[3] = y + (d - a)/2 + 4;
pi.pain.lines(xp, yp, 4, Color_math);
pi.pain.lines(xp, yp, 4, pi.base.font.color());
drawMarkers(pi, x, y);
}

View File

@ -49,11 +49,11 @@ void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
int xp[3];
int yp[3];
pi.pain.line(x + dim.width(), y - a + 1,
x + 8, y - a + 1, Color_math);
x + 8, y - a + 1, pi.base.font.color());
xp[0] = x + 8; yp[0] = y - a + 1;
xp[1] = x + 5; yp[1] = y + d - 1;
xp[2] = x; yp[2] = y + (d - a)/2;
pi.pain.lines(xp, yp, 3, Color_math);
pi.pain.lines(xp, yp, 3, pi.base.font.color());
drawMarkers(pi, x, y);
}

View File

@ -591,6 +591,7 @@ void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
void MathMacroTemplate::draw(PainterInfo & pi, int x, int y) const
{
ColorChanger dummy0(pi.base.font, from_ascii("math"));
FontSetChanger dummy1(pi.base, from_ascii("mathnormal"));
StyleChanger dummy2(pi.base, LM_ST_TEXT);

View File

@ -450,7 +450,7 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
pi.pain.line(
int(x + xx + 0.5), int(y + yy + 0.5),
int(x + x2 + 0.5), int(y + y2 + 0.5),
Color_math);
pi.base.font.color());
} else {
int xp[32];
int yp[32];
@ -467,7 +467,7 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
yp[j] = int(y + yy + 0.5);
// lyxerr << "P[" << j ' ' << xx << ' ' << yy << ' ' << x << ' ' << y << ']';
}
pi.pain.lines(xp, yp, n, Color_math);
pi.pain.lines(xp, yp, n, pi.base.font.color());
}
}
}
@ -635,6 +635,20 @@ bool isFontName(docstring const & name)
}
bool isMathFont(docstring const & name)
{
fontinfo * f = lookupFont(name);
return f && f->color_ == Color_math;
}
bool isTextFont(docstring const & name)
{
fontinfo * f = lookupFont(name);
return f && f->color_ == Color_foreground;
}
FontInfo getFont(docstring const & name)
{
FontInfo font;

View File

@ -49,6 +49,10 @@ void augmentFont(FontInfo & f, docstring const & cmd);
bool isFontName(docstring const & name);
bool isMathFont(docstring const & name);
bool isTextFont(docstring const & name);
// converts single cell to string
docstring asString(MathData const & ar);
// converts single inset to string

View File

@ -81,6 +81,8 @@ What's new
- Correctly handle empty custom line spacing in settings (bug 6649).
- Correctly display color changes in math formulas (bug 4071).
* DOCUMENTATION AND LOCALIZATION