}
-int InsetOld::ascent() const
-{
- return dim_.asc;
-}
-
-
-int InsetOld::descent() const
-{
- return dim_.des;
-}
-
-
-int InsetOld::width() const
-{
- return dim_.wid;
-}
-
-
void InsetOld::setPosCache(PainterInfo const & pi, int x, int y) const
{
//lyxerr << "InsetOld:: position cache to " << x << " " << y << std::endl;
///
InsetOld();
- ///
- int ascent() const;
- ///
- int descent() const;
- ///
- int width() const;
///
void setInsetName(docstring const & s) { name_ = s; }
/// reject the changes within the inset
virtual void rejectChanges(BufferParams const &) {};
- /// pretty arbitrary
- virtual int width() const { return 10; }
- /// pretty arbitrary
- virtual int ascent() const { return 10; }
- /// pretty arbitrary
- virtual int descent() const { return 10; }
+ /// inset width.
+ int width() const { return dim_.wid; }
+ /// inset ascent.
+ int ascent() const { return dim_.asc; }
+ /// inset descent.
+ int descent() const { return dim_.des; }
///
int scroll() const { return 0; }
///
///
virtual void setStatus(LCursor &, CollapseStatus) {}
protected:
- InsetBase() {}
- InsetBase(InsetBase const &) {}
+ /// pretty arbitrary dimensions
+ InsetBase(): dim_(10, 10, 10) {}
+ InsetBase(InsetBase const & i): dim_(i.dim_) {}
/** The real dispatcher.
* Gets normally called from LCursor::dispatch(). LCursor::dispatch()
* assumes the common case of 'LFUN handled, need update'.
bool InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
{
+ if (mi.base.font == font_cache_) {
+ dim = dim_;
+ return false;
+ }
+ font_cache_ = mi.base.font;
+
#if 1
if (char_ == '=' && has_math_fonts) {
FontSetChanger dummy(mi.base, "cmr");
whichFont(font_, code_, mi);
dim = theFontMetrics(font_).dimension(char_);
if (isBinaryOp(char_, code_))
- width_ += 2 * theFontMetrics(font_).width(' ');
+ dim.wid += 2 * theFontMetrics(font_).width(' ');
lyxerr << "InsetMathChar::metrics: " << dim << endl;
#endif
- width_ = dim.wid;
- if (dim_ == dim)
- return false;
dim_ = dim;
return true;
}
#include "InsetMath.h"
+#include "lyxfont.h"
namespace lyx {
///
void drawT(TextPainter &, int x, int y) const;
///
- int width() const { return width_; }
- ///
int kerning() const { return kerning_; }
///
virtual std::auto_ptr<InsetBase> doClone() const;
/// the character
char_type char_;
- /// cached width
- mutable int width_;
/// cached kerning for superscript
mutable int kerning_;
+ ///
+ mutable LyXFont font_cache_;
};
} // namespace lyx
{}
-int InsetMathDim::ascent() const
-{
- return dim_.asc;
-}
-
-
-int InsetMathDim::descent() const
-{
- return dim_.des;
-}
-
-
-int InsetMathDim::width() const
-{
- return dim_.wid;
-}
-
-
void InsetMathDim::setPosCache(PainterInfo const & pi, int x, int y) const
{
//lyxerr << "InsetMathDim: cache to " << x << " " << y << std::endl;
///
InsetMathDim();
- ///
- Dimension dimensions() const { return dim_; }
- ///
- int ascent() const;
- ///
- int descent() const;
- ///
- int width() const;
-
///
void setPosCache(PainterInfo const & pi, int x, int y) const;
};
InsetMathKern::InsetMathKern()
-{}
+{
+ dim_.asc = 0;
+ dim_.des = 0;
+}
InsetMathKern::InsetMathKern(LyXLength const & w)
: wid_(w)
-{}
+{
+ dim_.asc = 0;
+ dim_.des = 0;
+}
InsetMathKern::InsetMathKern(docstring const & s)
: wid_(to_utf8(s))
-{}
+{
+ dim_.asc = 0;
+ dim_.des = 0;
+}
auto_ptr<InsetBase> InsetMathKern::doClone() const
bool InsetMathKern::metrics(MetricsInfo & mi, Dimension & dim) const
{
- wid_pix_ = wid_.inPixels(0, mathed_char_width(mi.base.font, 'M'));
- dim.wid = wid_pix_;
- dim.asc = 0;
- dim.des = 0;
- if (dim_ == dim)
+ int wid_pixel = wid_.inPixels(0, mathed_char_width(mi.base.font, 'M'));
+ if (wid_pixel == dim_.wid)
return false;
- dim_ = dim;
+ dim_.wid = wid_pixel;
+ dim = dim_;
return true;
}
-int InsetMathKern::width() const
-{
- return wid_pix_;
-}
-
-
void InsetMathKern::draw(PainterInfo &, int, int) const
{}
void write(WriteStream & os) const;
///
void normalize(NormalStream & ns) const;
- ///
- int width() const;
private:
virtual std::auto_ptr<InsetBase> doClone() const;
/// width in em
LyXLength wid_;
- /// in pixels
- mutable int wid_pix_;
-
};
int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
+namespace {
-InsetMathSpace::InsetMathSpace(int sp)
- : space_(sp)
-{}
-
-
-InsetMathSpace::InsetMathSpace(docstring const & name)
- : space_(1)
-{
- for (int i = 0; i < nSpace; ++i)
- if (latex_mathspace[i] == name)
- space_ = i;
-}
-
-
-auto_ptr<InsetBase> InsetMathSpace::doClone() const
-{
- return auto_ptr<InsetBase>(new InsetMathSpace(*this));
-}
-
-
-int InsetMathSpace::width() const
+int spaceToWidth(int space)
{
- switch (space_) {
+ switch (space) {
case 0: return 6;
case 1: return 8;
case 2: return 10;
}
}
+} // anon namespace
+
+InsetMathSpace::InsetMathSpace(int sp)
+ : space_(sp)
+{
+ dim_.asc = 4;
+ dim_.des = 0;
+ dim_.wid = spaceToWidth(space_);
+}
+
-int InsetMathSpace::ascent() const
+InsetMathSpace::InsetMathSpace(docstring const & name)
+ : space_(1)
{
- return 4;
+ dim_.asc = 4;
+ dim_.des = 0;
+ for (int i = 0; i < nSpace; ++i)
+ if (latex_mathspace[i] == name)
+ space_ = i;
+ dim_.wid = spaceToWidth(space_);
}
-int InsetMathSpace::descent() const
+auto_ptr<InsetBase> InsetMathSpace::doClone() const
{
- return 0;
+ return auto_ptr<InsetBase>(new InsetMathSpace(*this));
}
void InsetMathSpace::incSpace()
{
space_ = (space_ + 1) % (nSpace - 2);
+ dim_.wid = spaceToWidth(space_);
}
///
void incSpace();
///
- int ascent() const;
- ///
- int descent() const;
- ///
- int width() const;
- ///
bool metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo & pi, int x, int y) const;
InsetMathSymbol::InsetMathSymbol(latexkeys const * l)
- : sym_(l), h_(0), width_(0), scriptable_(false)
+ : sym_(l), h_(0), scriptable_(false), font_cache_(LyXFont::ALL_IGNORE)
{}
InsetMathSymbol::InsetMathSymbol(char const * name)
- : sym_(in_word_set(from_ascii(name))), h_(0), width_(0), scriptable_(false)
+ : sym_(in_word_set(from_ascii(name))), h_(0), scriptable_(false),
+ font_cache_(LyXFont::ALL_IGNORE)
{}
InsetMathSymbol::InsetMathSymbol(docstring const & name)
- : sym_(in_word_set(name)), h_(0), width_(0), scriptable_(false)
+ : sym_(in_word_set(name)), h_(0), scriptable_(false), font_cache_(LyXFont::ALL_IGNORE)
{}
// << "' drawn as: '" << sym_->draw
// << "'" << std::endl;
- int const em = mathed_char_width(mi.base.font, 'M');
- FontSetChanger dummy(mi.base, sym_->inset);
- mathed_string_dim(mi.base.font, sym_->draw, dim);
- docstring::const_reverse_iterator rit = sym_->draw.rbegin();
- kerning_ = mathed_char_kerning(mi.base.font, *rit);
- // correct height for broken cmex and wasy font
- if (sym_->inset == "cmex" || sym_->inset == "wasy") {
- h_ = 4 * dim.des / 5;
- dim.asc += h_;
- dim.des -= h_;
+ bool dim_unchanged = (mi.base.font == font_cache_);
+ if (dim_unchanged)
+ dim = dim_;
+ else {
+ font_cache_ = mi.base.font;
+ int const em = mathed_char_width(mi.base.font, 'M');
+ FontSetChanger dummy(mi.base, sym_->inset);
+ mathed_string_dim(mi.base.font, sym_->draw, dim);
+ docstring::const_reverse_iterator rit = sym_->draw.rbegin();
+ kerning_ = mathed_char_kerning(mi.base.font, *rit);
+ // correct height for broken cmex and wasy font
+ if (sym_->inset == "cmex" || sym_->inset == "wasy") {
+ h_ = 4 * dim.des / 5;
+ dim.asc += h_;
+ dim.des -= h_;
+ }
+ // seperate things a bit
+ if (isRelOp())
+ dim.wid += static_cast<int>(0.5 * em + 0.5);
+ else
+ dim.wid += static_cast<int>(0.1667 * em + 0.5);
+
+ dim_ = dim;
}
- // seperate things a bit
- if (isRelOp())
- dim.wid += static_cast<int>(0.5 * em + 0.5);
- else
- dim.wid += static_cast<int>(0.1667 * em + 0.5);
-
scriptable_ = false;
if (mi.base.style == LM_ST_DISPLAY)
if (sym_->inset == "cmex" || sym_->inset == "esint" ||
sym_->extra == "funclim")
scriptable_ = true;
- width_ = dim.wid;
- if (dim_ == dim)
- return false;
- dim_ = dim;
- return true;
+ return dim_unchanged;
}
#include "InsetMath.h"
+#include "lyxfont.h"
namespace lyx {
///
void draw(PainterInfo &, int x, int y) const;
///
- int width() const { return width_; }
- ///
int kerning() const { return kerning_; }
///
latexkeys const * sym_;
///
mutable int h_;
- /// cached width
- mutable int width_;
/// cached superscript kerning
mutable int kerning_;
///
mutable bool scriptable_;
+ ///
+ mutable LyXFont font_cache_;
};
} // namespace lyx