* src/mathed/MathSupport.[Ch]
(mathed_char_kerning): New. Compute right kerning for the given
font and character as the difference between right bearing and
logical width.
* src/mathed/InsetMathScript.[Ch]
(InsetMathScript::dx1, InsetMathScript::metrics): Account for
nucleus right kerning.
(InsetMathScript::nker): New. Return the nucleus right kerning
if positive, zero otherwise.
* src/mathed/MathData.[Ch]
(MathArray::metrics): Cache the nucleus right kerning value.
(MathArray::kerning): New. Return cached right kerning.
* src/mathed/InsetMathChar.[Ch]
(InsetMathChar::metrics): Cache the character right kerning.
(InsetMathChar::kerning): New. Return cached right kerning.
* src/mathed/InsetMath.h
(InsetMath::kerning): New virtual method.
* src/mathed/InsetMathSymbol.[Ch]
(InsetMathSymbol::metrics): Cache the symbol right kerning.
(InsetMathSymbol::kerning): New. Return cached right kerning.
* src/mathed/InsetMathFont.[Ch]
(InsetMathFont::kerning): New. Return cached right kerning.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17497
a592a061-630c-0410-9148-
cb99ea01b6c8
/// math stuff usually isn't allowed in text mode
virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
+
+ /// superscript kerning
+ virtual int kerning() const { return 0; }
};
///
InsetMathChar::InsetMathChar(char_type c)
- : char_(c)
+ : char_(c), kerning_(0)
{}
ShapeChanger dummy(mi.base.font, LyXFont::UP_SHAPE);
dim = theFontMetrics(mi.base.font).dimension(char_);
} else {
- dim = theFontMetrics(mi.base.font).dimension(char_);
+ frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
+ dim = fm.dimension(char_);
+ kerning_ = fm.rbearing(char_) - dim.wid;
}
int const em = mathed_char_width(mi.base.font, 'M');
if (isBinaryOp(char_))
void drawT(TextPainter &, int x, int y) const;
///
int width() const { return width_; }
+ ///
+ int kerning() const { return kerning_; }
///
void write(WriteStream & os) const;
char_type char_;
/// cached width
mutable int width_;
+ /// cached kerning for superscript
+ mutable int kerning_;
};
} // namespace lyx
void validate(LaTeXFeatures & features) const;
///
void infoize(odocstream & os) const;
+ ///
+ int kerning() const { return cell(0).kerning(); }
private:
virtual std::auto_ptr<InsetBase> doClone() const;
int InsetMathScript::dx1() const
{
BOOST_ASSERT(hasUp());
- return hasLimits() ? (dim_.wid - up().width()) / 2 : nwid();
+ return hasLimits() ? (dim_.wid - up().width()) / 2 : nwid() + nker();
}
}
+int InsetMathScript::nker() const
+{
+ if (nuc().size()) {
+ int kerning = nuc().kerning();
+ return kerning > 0 ? kerning : 0;
+ }
+ return 0;
+}
+
+
bool InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi);
dim.wid = max(dim.wid, down().width());
} else {
if (hasUp())
- dim.wid = max(dim.wid, up().width());
+ dim.wid = max(dim.wid, nker() + up().width());
if (hasDown())
dim.wid = max(dim.wid, down().width());
dim.wid += nwid();
int nasc() const;
/// returns descent of nucleus if any
int ndes() const;
+ /// returns superscript kerning of nucleus if any
+ int nker() const;
/// where do we have to draw the scripts?
bool hasLimits() const;
/// clean up empty cells and return true if a cell has been deleted.
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;
void draw(PainterInfo &, int x, int y) const;
///
int width() const { return width_; }
+ ///
+ int kerning() const { return kerning_; }
///
bool isRelOp() const;
mutable int h_;
/// cached width
mutable int width_;
+ /// cached superscript kerning
+ mutable int kerning_;
///
mutable bool scriptable_;
};
#endif
at->metrics(mi, d);
dim_ += d;
+ if (i == n - 1)
+ kerning_ = at->kerning();
}
}
int slevel() const { return slevel_; }
/// additional super/subscript shift
int sshift() const { return sshift_; }
+ /// superscript kerning
+ int kerning() const { return kerning_; }
protected:
/// cached dimensions of cell
mutable int mindes_;
mutable int slevel_;
mutable int sshift_;
+ mutable int kerning_;
private:
/// is this an exact match at this position?
}
+int mathed_char_kerning(LyXFont const & font, char_type c)
+{
+ frontend::FontMetrics const & fm = theFontMetrics(font);
+ return fm.rbearing(c) - fm.width(c);
+}
+
+
void mathed_string_dim(LyXFont const & font,
docstring const & s,
Dimension & dim)
int mathed_char_width(LyXFont const &, char_type c);
+int mathed_char_kerning(LyXFont const &, char_type c);
+
void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
docstring const & name);