Correct computation of math font size

Move math style to FontInfo and compute the font sizes for scriptstyle and
scriptscriptstyle according to standard proportions: 0.73 and 0.55.

This is simpler and more accurate. It also fixes the font size of
${\scriptscriptstyle {\textstyle A}}A$ which exposed the limitations of the
previous approach.
This commit is contained in:
Guillaume Munch 2016-11-19 21:25:34 +01:00
parent cb6c40a07b
commit a9eb87a89d
22 changed files with 154 additions and 105 deletions

View File

@ -198,10 +198,10 @@ hspace* space none
hspace space none hspace space none
# styles # styles
displaystyle style 0 displaystyle style 3
textstyle style 1 textstyle style 2
scriptstyle style 2 scriptstyle style 1
scriptscriptstyle style 3 scriptscriptstyle style 0
# misc # misc
# The commented lines in this block get misparsed as MathSymbolInset because # The commented lines in this block get misparsed as MathSymbolInset because

View File

@ -142,5 +142,21 @@ enum FontState {
FONT_IGNORE FONT_IGNORE
}; };
/// Math styles
enum MathStyle {
///
LM_ST_SCRIPTSCRIPT = 0,
///
LM_ST_SCRIPT,
///
LM_ST_TEXT,
///
LM_ST_DISPLAY,
///
NUM_STYLE = LM_ST_DISPLAY
};
} // namespace lyx } // namespace lyx
#endif #endif

View File

@ -17,7 +17,9 @@
#include "ColorSet.h" #include "ColorSet.h"
#include "FontInfo.h" #include "FontInfo.h"
#include "Lexer.h" #include "Lexer.h"
#include "LyXRC.h"
#include "support/convert.h"
#include "support/debug.h" #include "support/debug.h"
#include "support/docstring.h" #include "support/docstring.h"
#include "support/lstrings.h" #include "support/lstrings.h"
@ -168,6 +170,29 @@ FontInfo & FontInfo::incSize()
} }
double FontInfo::realSize() const
{
double d = convert<double>(lyxrc.font_sizes[size()]);
// The following is according to the average of the values in the
// definitions of \defaultscriptratio and \defaultscriptscriptratio in LaTeX
// font packages. No attempt is made to implement the actual values from
// \DefineMathSizes.
switch (style()) {
case LM_ST_DISPLAY:
case LM_ST_TEXT:
break;
case LM_ST_SCRIPT:
d *= .73;
break;
case LM_ST_SCRIPTSCRIPT:
d *= .55;
break;
}
// Never go below the smallest size
return max(d, convert<double>(lyxrc.font_sizes[FONT_SIZE_TINY]));
}
/// Reduce font to fall back to template where possible /// Reduce font to fall back to template where possible
void FontInfo::reduce(FontInfo const & tmplt) void FontInfo::reduce(FontInfo const & tmplt)
{ {
@ -258,6 +283,12 @@ Changer FontInfo::changeShape(FontShape const shape, bool cond)
} }
Changer FontInfo::changeStyle(MathStyle const new_style, bool cond)
{
return make_change(style_, new_style, cond);
}
Changer FontInfo::change(FontInfo font, bool realiz, bool cond) Changer FontInfo::change(FontInfo font, bool realiz, bool cond)
{ {
if (realiz) if (realiz)

View File

@ -49,7 +49,7 @@ public:
FontState noun, FontState noun,
FontState number) FontState number)
: family_(family), series_(series), shape_(shape), size_(size), : family_(family), series_(series), shape_(shape), size_(size),
color_(color), background_(background), paint_color_(), emph_(emph), style_(LM_ST_TEXT), color_(color), background_(background), emph_(emph),
underbar_(underbar), strikeout_(strikeout), uuline_(uuline), underbar_(underbar), strikeout_(strikeout), uuline_(uuline),
uwave_(uwave), noun_(noun), number_(number) uwave_(uwave), noun_(noun), number_(number)
{} {}
@ -69,6 +69,8 @@ public:
void setShape(FontShape s) { shape_ = s; } void setShape(FontShape s) { shape_ = s; }
FontSize size() const { return size_; } FontSize size() const { return size_; }
void setSize(FontSize s) { size_ = s; } void setSize(FontSize s) { size_ = s; }
MathStyle style() const {return style_; }
void setStyle(MathStyle s) { style_ = s; }
FontState emph() const { return emph_; } FontState emph() const { return emph_; }
void setEmph(FontState e) { emph_ = e; } void setEmph(FontState e) { emph_ = e; }
FontState underbar() const { return underbar_; } FontState underbar() const { return underbar_; }
@ -107,6 +109,9 @@ public:
/// Sets the color which is used during painting /// Sets the color which is used during painting
void setPaintColor(Color c) { paint_color_ = c; } void setPaintColor(Color c) { paint_color_ = c; }
/// Compute the font size, taking size and math style into account.
double realSize() const;
/// ///
docstring asCSS() const; docstring asCSS() const;
@ -143,6 +148,8 @@ public:
Changer changeColor(ColorCode const color, bool cond = true); Changer changeColor(ColorCode const color, bool cond = true);
/// Temporarily replace the shape with \param shape. /// Temporarily replace the shape with \param shape.
Changer changeShape(FontShape const shape, bool cond = true); Changer changeShape(FontShape const shape, bool cond = true);
/// Temporarily replace the style
Changer changeStyle(MathStyle style, bool cond = true);
/// Temporarily replace the FontInfo with \param font, and optionally /// Temporarily replace the FontInfo with \param font, and optionally
/// \param realize the \param font against the current FontInfo. /// \param realize the \param font against the current FontInfo.
Changer change(FontInfo font, bool realize = false, bool cond = true); Changer change(FontInfo font, bool realize = false, bool cond = true);
@ -159,6 +166,8 @@ private:
/// ///
FontSize size_; FontSize size_;
/// ///
MathStyle style_;
///
ColorCode color_; ColorCode color_;
/// ///
ColorCode background_; ColorCode background_;

View File

@ -37,7 +37,7 @@ namespace lyx {
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
MetricsBase::MetricsBase(BufferView * b, FontInfo f, int w) MetricsBase::MetricsBase(BufferView * b, FontInfo f, int w)
: bv(b), font(move(f)), style(LM_ST_TEXT), fontname("mathnormal"), : bv(b), font(move(f)), fontname("mathnormal"),
textwidth(w), macro_nesting(0), textwidth(w), macro_nesting(0),
solid_line_thickness_(1), solid_line_offset_(1), dotted_line_thickness_(1) solid_line_thickness_(1), solid_line_offset_(1), dotted_line_thickness_(1)
{ {
@ -71,6 +71,7 @@ Changer MetricsBase::changeFontSet(string const & name, bool cond)
font = sane_font; font = sane_font;
augmentFont(font, name); augmentFont(font, name);
font.setSize(rc->old.font.size()); font.setSize(rc->old.font.size());
font.setStyle(rc->old.font.style());
if (name != "lyxtex" if (name != "lyxtex"
&& ((isTextFont(oldname) && oldcolor != Color_foreground) && ((isTextFont(oldname) && oldcolor != Color_foreground)
|| (isMathFont(oldname) && oldcolor != Color_math))) || (isMathFont(oldname) && oldcolor != Color_math)))
@ -153,13 +154,13 @@ Color PainterInfo::textColor(Color const & color) const
Changer MetricsBase::changeScript(bool cond) Changer MetricsBase::changeScript(bool cond)
{ {
switch (style) { switch (font.style()) {
case LM_ST_DISPLAY: case LM_ST_DISPLAY:
case LM_ST_TEXT: case LM_ST_TEXT:
return changeStyle(LM_ST_SCRIPT, cond); return font.changeStyle(LM_ST_SCRIPT, cond);
case LM_ST_SCRIPT: case LM_ST_SCRIPT:
case LM_ST_SCRIPTSCRIPT: case LM_ST_SCRIPTSCRIPT:
return changeStyle(LM_ST_SCRIPTSCRIPT, cond); return font.changeStyle(LM_ST_SCRIPTSCRIPT, cond);
} }
//remove Warning //remove Warning
LASSERT(false, return Changer()); LASSERT(false, return Changer());
@ -168,42 +169,18 @@ Changer MetricsBase::changeScript(bool cond)
Changer MetricsBase::changeFrac(bool cond) Changer MetricsBase::changeFrac(bool cond)
{ {
switch (style) { switch (font.style()) {
case LM_ST_DISPLAY: case LM_ST_DISPLAY:
return changeStyle(LM_ST_TEXT, cond); return font.changeStyle(LM_ST_TEXT, cond);
case LM_ST_TEXT: case LM_ST_TEXT:
return changeStyle(LM_ST_SCRIPT, cond); return font.changeStyle(LM_ST_SCRIPT, cond);
case LM_ST_SCRIPT: case LM_ST_SCRIPT:
case LM_ST_SCRIPTSCRIPT: case LM_ST_SCRIPTSCRIPT:
return changeStyle(LM_ST_SCRIPTSCRIPT, cond); return font.changeStyle(LM_ST_SCRIPTSCRIPT, cond);
} }
//remove Warning //remove Warning
return Changer(); return Changer();
} }
Changer MetricsBase::changeStyle(Styles new_style, bool cond)
{
static const int diff[4][4] =
{ { 0, 0, -3, -5 },
{ 0, 0, -3, -5 },
{ 3, 3, 0, -2 },
{ 5, 5, 2, 0 } };
int t = diff[style][new_style];
RefChanger<MetricsBase> rc = make_save(*this);
if (!cond)
rc->keep();
else {
if (t > 0)
while (t--)
font.incSize();
else
while (t++)
font.decSize();
style = new_style;
}
return move(rc);
}
} // namespace lyx } // namespace lyx

View File

@ -32,20 +32,6 @@ class Inset;
class MacroContext; class MacroContext;
/// Standard Sizes (mode styles)
/// note: These values are hard-coded in changeStyle
enum Styles {
///
LM_ST_DISPLAY = 0,
///
LM_ST_TEXT,
///
LM_ST_SCRIPT,
///
LM_ST_SCRIPTSCRIPT
};
// //
// This is the part common to MetricsInfo and PainterInfo // This is the part common to MetricsInfo and PainterInfo
// //
@ -59,8 +45,6 @@ public:
BufferView * bv; BufferView * bv;
/// current font /// current font
FontInfo font; FontInfo font;
/// current math style (display/text/script/..)
Styles style;
/// name of current font - mathed specific /// name of current font - mathed specific
std::string fontname; std::string fontname;
/// This is the width available in pixels /// This is the width available in pixels
@ -70,8 +54,6 @@ public:
/// Temporarily change a full font. /// Temporarily change a full font.
Changer changeFontSet(std::string const & font, bool cond = true); Changer changeFontSet(std::string const & font, bool cond = true);
/// Temporarily change the font size and the math style.
Changer changeStyle(Styles style, bool cond = true);
// Temporarily change to the style suitable for use in fractions // Temporarily change to the style suitable for use in fractions
Changer changeFrac(bool cond = true); Changer changeFrac(bool cond = true);
// Temporarily change the style to (script)script style // Temporarily change the style to (script)script style

View File

@ -19,7 +19,6 @@
#include "LyXRC.h" #include "LyXRC.h"
#include "support/convert.h"
#include "support/debug.h" #include "support/debug.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/gettext.h" #include "support/gettext.h"
@ -88,7 +87,18 @@ SymbolFont symbol_fonts[] = {
size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_fonts[0]); size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_fonts[0]);
/// BUTT ugly ! /// BUTT ugly !
static GuiFontInfo * fontinfo_[NUM_FAMILIES][NUM_SERIES][NUM_SHAPE][NUM_SIZE]; static GuiFontInfo *
fontinfo_[NUM_FAMILIES][NUM_SERIES][NUM_SHAPE][NUM_SIZE][NUM_STYLE];
// returns a reference to the pointer type (GuiFontInfo *) in the
// fontinfo_ table.
GuiFontInfo * & fontinfo_ptr(FontInfo const & f)
{
// The display font and the text font are the same
size_t const style = (f.style() == LM_ST_DISPLAY) ? LM_ST_TEXT : f.style();
return fontinfo_[f.family()][f.series()][f.realShape()][f.size()][style];
}
// Get font info (font + metrics) for the given LyX font. // Get font info (font + metrics) for the given LyX font.
@ -106,16 +116,12 @@ GuiFontInfo & fontinfo(FontInfo const & f)
LYXERR0("Unrealized font!"); LYXERR0("Unrealized font!");
FontInfo f2 = f; FontInfo f2 = f;
f2.realize(sane_font); f2.realize(sane_font);
GuiFontInfo * & fi = GuiFontInfo * & fi = fontinfo_ptr(f2);
fontinfo_[f2.family()][f2.series()][f2.realShape()][f2.size()];
if (!fi) if (!fi)
fi = new GuiFontInfo(f2); fi = new GuiFontInfo(f2);
return *fi; return *fi;
} }
// fi is a reference to the pointer type (GuiFontInfo *) in the GuiFontInfo * & fi = fontinfo_ptr(f);
// fontinfo_ table.
GuiFontInfo * & fi =
fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
if (!fi) if (!fi)
fi = new GuiFontInfo(f); fi = new GuiFontInfo(f);
return *fi; return *fi;
@ -248,7 +254,8 @@ FontLoader::FontLoader()
for (int i2 = 0; i2 < NUM_SERIES; ++i2) for (int i2 = 0; i2 < NUM_SERIES; ++i2)
for (int i3 = 0; i3 < NUM_SHAPE; ++i3) for (int i3 = 0; i3 < NUM_SHAPE; ++i3)
for (int i4 = 0; i4 < NUM_SIZE; ++i4) for (int i4 = 0; i4 < NUM_SIZE; ++i4)
fontinfo_[i1][i2][i3][i4] = 0; for (int i5 = 0; i5 < NUM_STYLE; ++i5)
fontinfo_[i1][i2][i3][i4][i5] = 0;
} }
@ -257,9 +264,10 @@ void FontLoader::update()
for (int i1 = 0; i1 < NUM_FAMILIES; ++i1) for (int i1 = 0; i1 < NUM_FAMILIES; ++i1)
for (int i2 = 0; i2 < NUM_SERIES; ++i2) for (int i2 = 0; i2 < NUM_SERIES; ++i2)
for (int i3 = 0; i3 < NUM_SHAPE; ++i3) for (int i3 = 0; i3 < NUM_SHAPE; ++i3)
for (int i4 = 0; i4 < NUM_SIZE; ++i4) { for (int i4 = 0; i4 < NUM_SIZE; ++i4)
delete fontinfo_[i1][i2][i3][i4]; for (int i5 = 0; i5 < NUM_STYLE; ++i5) {
fontinfo_[i1][i2][i3][i4] = 0; delete fontinfo_[i1][i2][i3][i4][i5];
fontinfo_[i1][i2][i3][i4][i5] = 0;
} }
} }
@ -355,8 +363,7 @@ QFont makeQFont(FontInfo const & f)
LYXERR(Debug::FONT, "XFLD: " << font.rawName()); LYXERR(Debug::FONT, "XFLD: " << font.rawName());
font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()]) font.setPointSizeF(f.realSize() * lyxrc.zoom / 100.0);
* lyxrc.zoom / 100.0);
LYXERR(Debug::FONT, "The font has size: " << font.pointSizeF()); LYXERR(Debug::FONT, "The font has size: " << font.pointSizeF());

View File

@ -85,8 +85,8 @@ char const * InsetMathAMSArray::name_right() const
void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
Changer dummy = FontInfo & f = mi.base.font;
mi.base.changeStyle(LM_ST_TEXT, mi.base.style == LM_ST_DISPLAY); Changer dummy = f.changeStyle(LM_ST_TEXT, f.style() == LM_ST_DISPLAY);
InsetMathGrid::metrics(mi, dim); InsetMathGrid::metrics(mi, dim);
} }
@ -98,8 +98,8 @@ void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
// Drawing the deco after changeStyle does not work // Drawing the deco after changeStyle does not work
mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left())); mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right())); mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
Changer dummy = FontInfo & f = pi.base.font;
pi.base.changeStyle(LM_ST_TEXT, pi.base.style == LM_ST_DISPLAY); Changer dummy = f.changeStyle(LM_ST_TEXT, f.style() == LM_ST_DISPLAY);
InsetMathGrid::draw(pi, x, y); InsetMathGrid::draw(pi, x, y);
} }

View File

@ -74,8 +74,8 @@ Inset * InsetMathArray::clone() const
void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
Changer dummy = FontInfo & f = mi.base.font;
mi.base.changeStyle(LM_ST_TEXT, mi.base.style == LM_ST_DISPLAY); Changer dummy = f.changeStyle(LM_ST_TEXT, f.style() == LM_ST_DISPLAY);
InsetMathGrid::metrics(mi, dim); InsetMathGrid::metrics(mi, dim);
} }
@ -83,8 +83,8 @@ void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathArray::draw(PainterInfo & pi, int x, int y) const void InsetMathArray::draw(PainterInfo & pi, int x, int y) const
{ {
setPosCache(pi, x, y); setPosCache(pi, x, y);
Changer dummy = FontInfo & f = pi.base.font;
pi.base.changeStyle(LM_ST_TEXT, pi.base.style == LM_ST_DISPLAY); Changer dummy = f.changeStyle(LM_ST_TEXT, f.style() == LM_ST_DISPLAY);
InsetMathGrid::draw(pi, x, y); InsetMathGrid::draw(pi, x, y);
} }

View File

@ -36,7 +36,6 @@ extern bool has_math_fonts;
namespace { namespace {
latexkeys const * makeSubstitute(char_type c) latexkeys const * makeSubstitute(char_type c)
{ {
std::string name; std::string name;

View File

@ -48,12 +48,21 @@ int InsetMathDiagram::rowsep() const
void InsetMathDiagram::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathDiagram::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
if (mi.base.style == LM_ST_DISPLAY) FontInfo & f = mi.base.font;
mi.base.style = LM_ST_TEXT; Changer dummy = f.changeStyle(LM_ST_TEXT, f.style() == LM_ST_DISPLAY);
InsetMathGrid::metrics(mi, dim); InsetMathGrid::metrics(mi, dim);
} }
void InsetMathDiagram::draw(PainterInfo & pi, int x, int y) const
{
setPosCache(pi, x, y);
FontInfo & f = pi.base.font;
Changer dummy = f.changeStyle(LM_ST_TEXT, f.style() == LM_ST_DISPLAY);
InsetMathGrid::draw(pi, x, y);
}
void InsetMathDiagram::write(WriteStream & os) const void InsetMathDiagram::write(WriteStream & os) const
{ {
MathEnsurer ensurer(os); MathEnsurer ensurer(os);

View File

@ -26,6 +26,8 @@ public:
/// ///
void metrics(MetricsInfo &, Dimension &) const; void metrics(MetricsInfo &, Dimension &) const;
/// ///
void draw(PainterInfo & pi, int x, int y) const;
///
InsetMathDiagram const * asDiagramInset() const { return this; } InsetMathDiagram const * asDiagramInset() const { return this; }
/// ///
virtual int colsep() const; virtual int colsep() const;

View File

@ -181,6 +181,7 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
} else { } else {
// general cell metrics used for \frac // general cell metrics used for \frac
Changer dummy = mi.base.changeFrac(); Changer dummy = mi.base.changeFrac();
// FIXME: Exponential blowup
cell(0).metrics(mi, dim0); cell(0).metrics(mi, dim0);
cell(1).metrics(mi, dim1); cell(1).metrics(mi, dim1);
if (nargs() == 3) if (nargs() == 3)
@ -196,9 +197,9 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
|| kind_ == DFRAC || kind_ == TFRAC) { || kind_ == DFRAC || kind_ == TFRAC) {
// \cfrac and \dfrac are always in display size // \cfrac and \dfrac are always in display size
// \tfrac is in always in text size // \tfrac is in always in text size
Changer dummy2 = mi.base.changeStyle((kind_ == TFRAC) Changer dummy2 = mi.base.font.changeStyle((kind_ == TFRAC)
? LM_ST_SCRIPT ? LM_ST_SCRIPT
: LM_ST_DISPLAY); : LM_ST_DISPLAY);
cell(0).metrics(mi, dim0); cell(0).metrics(mi, dim0);
cell(1).metrics(mi, dim1); cell(1).metrics(mi, dim1);
} }
@ -252,12 +253,13 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
} else if (kind_ == FRAC || kind_ == ATOP || kind_ == OVER } else if (kind_ == FRAC || kind_ == ATOP || kind_ == OVER
|| kind_ == TFRAC) { || kind_ == TFRAC) {
// tfrac is in always in text size // tfrac is in always in text size
Changer dummy2 = pi.base.changeStyle(LM_ST_SCRIPT, kind_ == TFRAC); Changer dummy2 = pi.base.font.changeStyle(LM_ST_SCRIPT,
kind_ == TFRAC);
cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5); cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
} else { } else {
// \cfrac and \dfrac are always in display size // \cfrac and \dfrac are always in display size
Changer dummy2 = pi.base.changeStyle(LM_ST_DISPLAY); Changer dummy2 = pi.base.font.changeStyle(LM_ST_DISPLAY);
if (kind_ == CFRAC || kind_ == DFRAC) if (kind_ == CFRAC || kind_ == DFRAC)
cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5); cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
else if (kind_ == CFRACLEFT) else if (kind_ == CFRACLEFT)
@ -574,8 +576,8 @@ void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
Dimension dim0, dim1; Dimension dim0, dim1;
Changer dummy = Changer dummy =
(kind_ == DBINOM) ? mi.base.changeStyle(LM_ST_DISPLAY) : (kind_ == DBINOM) ? mi.base.font.changeStyle(LM_ST_DISPLAY) :
(kind_ == TBINOM) ? mi.base.changeStyle(LM_ST_SCRIPT) : (kind_ == TBINOM) ? mi.base.font.changeStyle(LM_ST_SCRIPT) :
mi.base.changeFrac(); mi.base.changeFrac();
cell(0).metrics(mi, dim0); cell(0).metrics(mi, dim0);
cell(1).metrics(mi, dim1); cell(1).metrics(mi, dim1);
@ -600,8 +602,8 @@ void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
int m = x + dim.width() / 2; int m = x + dim.width() / 2;
{ {
Changer dummy = Changer dummy =
(kind_ == DBINOM) ? pi.base.changeStyle(LM_ST_DISPLAY) : (kind_ == DBINOM) ? pi.base.font.changeStyle(LM_ST_DISPLAY) :
(kind_ == TBINOM) ? pi.base.changeStyle(LM_ST_SCRIPT) : (kind_ == TBINOM) ? pi.base.font.changeStyle(LM_ST_SCRIPT) :
pi.base.changeFrac(); pi.base.changeFrac();
cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 3 - 5); cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 3 - 5);
cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5);

View File

@ -520,9 +520,9 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
return; return;
} }
// FIXME: Changing the same object repeatedly is inefficient.
Changer dummy1 = mi.base.changeFontSet(standardFont()); Changer dummy1 = mi.base.changeFontSet(standardFont());
Changer dummy2 = mi.base.changeStyle(display() ? LM_ST_DISPLAY : LM_ST_TEXT); Changer dummy2 = mi.base.font.changeStyle(display() ? LM_ST_DISPLAY
: LM_ST_TEXT);
// let the cells adjust themselves // let the cells adjust themselves
InsetMathGrid::metrics(mi, dim); InsetMathGrid::metrics(mi, dim);
@ -617,7 +617,8 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
bool const really_change_color = pi.base.font.color() == Color_none; bool const really_change_color = pi.base.font.color() == Color_none;
Changer dummy0 = pi.base.font.changeColor(color, really_change_color); Changer dummy0 = pi.base.font.changeColor(color, really_change_color);
Changer dummy1 = pi.base.changeFontSet(standardFont()); Changer dummy1 = pi.base.changeFontSet(standardFont());
Changer dummy2 = pi.base.changeStyle(display() ? LM_ST_DISPLAY : LM_ST_TEXT); Changer dummy2 = pi.base.font.changeStyle(display() ? LM_ST_DISPLAY
: LM_ST_TEXT);
InsetMathGrid::draw(pi, x + 1, y); InsetMathGrid::draw(pi, x + 1, y);

View File

@ -31,7 +31,8 @@ using namespace std;
namespace lyx { namespace lyx {
InsetMathSize::InsetMathSize(Buffer * buf, latexkeys const * l) InsetMathSize::InsetMathSize(Buffer * buf, latexkeys const * l)
: InsetMathNest(buf, 1), key_(l), style_(Styles(convert<int>(l->extra))) : InsetMathNest(buf, 1), key_(l),
style_(MathStyle(convert<int>(l->extra)))
{} {}
@ -43,7 +44,7 @@ Inset * InsetMathSize::clone() const
void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
Changer dummy = mi.base.changeStyle(style_); Changer dummy = mi.base.font.changeStyle(style_);
cell(0).metrics(mi, dim); cell(0).metrics(mi, dim);
metricsMarkers(mi, dim); metricsMarkers(mi, dim);
} }
@ -51,7 +52,7 @@ void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathSize::draw(PainterInfo & pi, int x, int y) const void InsetMathSize::draw(PainterInfo & pi, int x, int y) const
{ {
Changer dummy = pi.base.changeStyle(style_); Changer dummy = pi.base.font.changeStyle(style_);
cell(0).draw(pi, x + 1, y); cell(0).draw(pi, x + 1, y);
drawMarkers(pi, x, y); drawMarkers(pi, x, y);
} }

View File

@ -53,7 +53,7 @@ private:
/// ///
latexkeys const * key_; latexkeys const * key_;
/// ///
Styles const style_; MathStyle const style_;
}; };

View File

@ -45,14 +45,16 @@ Inset * InsetMathSubstack::clone() const
void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
Changer dummy = mi.base.changeStyle(LM_ST_TEXT, mi.base.style == LM_ST_DISPLAY); FontInfo & f = mi.base.font;
Changer dummy = f.changeStyle(LM_ST_TEXT, f.style() == LM_ST_DISPLAY);
InsetMathGrid::metrics(mi, dim); InsetMathGrid::metrics(mi, dim);
} }
void InsetMathSubstack::draw(PainterInfo & pi, int x, int y) const void InsetMathSubstack::draw(PainterInfo & pi, int x, int y) const
{ {
Changer dummy = pi.base.changeStyle(LM_ST_TEXT, pi.base.style == LM_ST_DISPLAY); FontInfo & f = pi.base.font;
Changer dummy = f.changeStyle(LM_ST_TEXT, f.style() == LM_ST_DISPLAY);
InsetMathGrid::draw(pi, x + 1, y); InsetMathGrid::draw(pi, x + 1, y);
} }

View File

@ -72,7 +72,7 @@ void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
} }
// set scriptable_ // set scriptable_
scriptable_ = false; scriptable_ = false;
if (mi.base.style == LM_ST_DISPLAY) if (mi.base.font.style() == LM_ST_DISPLAY)
if (sym_->inset == "cmex" || sym_->inset == "esint" || if (sym_->inset == "cmex" || sym_->inset == "esint" ||
sym_->extra == "funclim" || sym_->extra == "funclim" ||
(sym_->inset == "stmry" && sym_->extra == "mathop")) (sym_->inset == "stmry" && sym_->extra == "mathop"))

View File

@ -49,12 +49,21 @@ int InsetMathXYMatrix::rowsep() const
void InsetMathXYMatrix::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathXYMatrix::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
if (mi.base.style == LM_ST_DISPLAY) FontInfo & f = mi.base.font;
mi.base.style = LM_ST_TEXT; Changer dummy = f.changeStyle(LM_ST_TEXT, f.style() == LM_ST_DISPLAY);
InsetMathGrid::metrics(mi, dim); InsetMathGrid::metrics(mi, dim);
} }
void InsetMathXYMatrix::draw(PainterInfo & pi, int x, int y) const
{
setPosCache(pi, x, y);
FontInfo & f = pi.base.font;
Changer dummy = f.changeStyle(LM_ST_TEXT, f.style() == LM_ST_DISPLAY);
InsetMathGrid::draw(pi, x, y);
}
void InsetMathXYMatrix::write(WriteStream & os) const void InsetMathXYMatrix::write(WriteStream & os) const
{ {
MathEnsurer ensurer(os); MathEnsurer ensurer(os);

View File

@ -27,6 +27,8 @@ public:
/// ///
void metrics(MetricsInfo &, Dimension &) const; void metrics(MetricsInfo &, Dimension &) const;
/// ///
void draw(PainterInfo & pi, int x, int y) const;
///
InsetMathXYMatrix const * asXYMatrixInset() const { return this; } InsetMathXYMatrix const * asXYMatrixInset() const { return this; }
/// ///
virtual int colsep() const; virtual int colsep() const;

View File

@ -146,7 +146,7 @@ int class_spacing(MathClass const mc1, MathClass const mc2,
//lyxerr << class_to_string(mc1) << "+" << class_to_string(mc2) //lyxerr << class_to_string(mc1) << "+" << class_to_string(mc2)
// << "=" << spc_code << " @" << mb.style << endl; // << "=" << spc_code << " @" << mb.style << endl;
if (spc_code < 0) { if (spc_code < 0) {
switch (mb.style) { switch (mb.font.style()) {
case LM_ST_DISPLAY: case LM_ST_DISPLAY:
case LM_ST_TEXT: case LM_ST_TEXT:
spc_code = abs(spc_code); spc_code = abs(spc_code);

View File

@ -544,7 +544,7 @@ void MathMacroTemplate::createLook(int args) const
void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
Changer dummy1 = mi.base.changeFontSet("mathnormal"); Changer dummy1 = mi.base.changeFontSet("mathnormal");
Changer dummy2 = mi.base.changeStyle(LM_ST_TEXT); Changer dummy2 = mi.base.font.changeStyle(LM_ST_TEXT);
// valid macro? // valid macro?
MacroData const * macro = 0; MacroData const * macro = 0;
@ -588,7 +588,7 @@ void MathMacroTemplate::draw(PainterInfo & pi, int x, int y) const
// FIXME: Calling Changer on the same object repeatedly is inefficient. // FIXME: Calling Changer on the same object repeatedly is inefficient.
Changer dummy0 = pi.base.font.changeColor(Color_math); Changer dummy0 = pi.base.font.changeColor(Color_math);
Changer dummy1 = pi.base.changeFontSet("mathnormal"); Changer dummy1 = pi.base.changeFontSet("mathnormal");
Changer dummy2 = pi.base.changeStyle(LM_ST_TEXT); Changer dummy2 = pi.base.font.changeStyle(LM_ST_TEXT);
setPosCache(pi, x, y); setPosCache(pi, x, y);
Dimension const dim = dimension(*pi.base.bv); Dimension const dim = dimension(*pi.base.bv);