* for text strings, it does not give a good result with some
* characters like the \int (gyph 4) of esint.
- * Also, as a safety measure, always use QFontMetrics::width with
- * our math fonts.
+ * The metrics of some of our math fonts (eg. esint) are such that
+ * QTextLine::horizontalAdvance leads, more or less, in the middle
+ * of a symbol. This is the horizontal position where a subscript
+ * should be drawn, so that the superscript has to be moved rightward.
+ * This is done when the kerning() method of the math insets returns
+ * a positive value. The problem with this choice is that navigating
+ * a formula becomes weird. For example, a selection extends only over
+ * about half of the symbol. In order to avoid this, with our math
+ * fonts we use QTextLine::naturalTextWidth, so that a superscript can
+ * be drawn right after the symbol, and move the subscript leftward by
+ * recording a negative value for the kerning.
*/
int w = 0;
// is the string a single character from a math font ?
if (isMathFont(f) && subst_) {
// If the char has a substitute, draw the replacement symbol
// instead, but only in math mode.
- mathedSymbolDim(mi.base, dim, subst_);
- kerning_ = mathed_char_kerning(mi.base.font, *subst_->draw.rbegin());
- return;
+ kerning_ = mathedSymbolDim(mi.base, dim, subst_);
} else if (!slanted(char_) && f == "mathnormal") {
Changer dummy = mi.base.font.changeShape(UP_SHAPE);
dim = theFontMetrics(mi.base.font).dimension(char_);
void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
{
- mathedSymbolDim(mi.base, dim, sym_);
+ // set dim
+ // FIXME: this should depend on BufferView
+ // set negative kerning_ so that a subscript is moved leftward
+ kerning_ = -mathedSymbolDim(mi.base, dim, sym_);
if (sym_->draw != sym_->name) {
- // set dim
- // FIXME: this should depend on BufferView
- // set kerning_
- kerning_ = mathed_char_kerning(mi.base.font,
- mathedSymbol(mi.base, sym_).back());
-
// align character vertically
// FIXME: this should depend on BufferView
h_ = 0;
}
-void mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym)
+int mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym)
{
- LASSERT((bool)sym, return);
+ LASSERT((bool)sym, return 0);
//lyxerr << "metrics: symbol: '" << sym->name
// << "' in font: '" << sym->inset
// << "' drawn as: '" << sym->draw
std::string const font = italic_upcase_greek ? "cmm" : sym->inset;
Changer dummy = mb.changeFontSet(font);
mathed_string_dim(mb.font, mathedSymbol(mb, sym), dim);
+ return mathed_char_kerning(mb.font, mathedSymbol(mb, sym).back());
}
docstring const & mathedSymbol(MetricsBase & mb, latexkeys const * sym);
-void mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym);
+int mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym);
void mathedSymbolDraw(PainterInfo & pi, int x, int y, latexkeys const * sym);