[LyX/master] Implement variable size bigops
Enrico Forestieri
forenr at lyx.org
Fri Jul 24 11:02:58 UTC 2020
On Thu, Jul 23, 2020 at 03:47:44PM +0200, Enrico Forestieri wrote:
> On Thu, Jul 23, 2020 at 03:24:13PM +0200, Jean-Marc Lasgouttes wrote:
> > Le 23/07/2020 à 15:13, Enrico Forestieri a écrit :
> > > On Thu, Jul 23, 2020 at 01:16:32PM +0200, Jean-Marc Lasgouttes wrote:
> > >
> > > > Le 23/07/2020 à 12:22, Enrico Forestieri a écrit :
> > > > > Here is an alternative patch. Please check whether the change in
> > > > > InsetMathSymbol.cpp is compatible with the corresponding change
> > > > > at e8ee0100.
> > > >
> > > > I think it is OK. What about the users of mathedSymbolDim in InsetMathFrac?
> > > > Is kerning irrelevant here?
> >
> > This looks good for master and probably branch as far as I am concerned.
>
> I am not really satisfied when navigating a formula with the cursor.
> The caret will be placed in the middle of a symbol instead of after it.
> Taking away the change to GuiFontMetrics.cpp makes navigation more
> pleasant but both scripts are placed far away the symbol.
>
> I propose the attached patch that leaves unchanged GuiFontMetrics::width()
> and makes negative the kerning for a symbol, so that the subscript is
> moved to the left instead of moving the superscript to the right.
Patch pushed at 0b3e6916.
Richard, I attach here the corresponding patch for stable.
--
Enrico
-------------- next part --------------
diff --git a/src/frontends/qt4/GuiFontMetrics.cpp b/src/frontends/qt4/GuiFontMetrics.cpp
index 67fcb2f0e4..02c5054094 100644
--- a/src/frontends/qt4/GuiFontMetrics.cpp
+++ b/src/frontends/qt4/GuiFontMetrics.cpp
@@ -212,16 +212,19 @@ int GuiFontMetrics::width(docstring const & s) const
/* For some reason QMetrics::width returns a wrong value with Qt5
* with some arabic text. OTOH, QTextLayout is broken for single
* characters with null width (like \not in mathed). Also, as a
- * safety measure, always use QMetrics::width with our math fonts.
+ * safety measure, always use QMetrics::boundingRect().width()
+ * with our math fonts.
*/
int w = 0;
if (s.length() == 1
#if QT_VERSION >= 0x040800
|| font_.styleName() == "LyX"
#endif
- )
- w = metrics_.width(toqstr(s));
- else {
+ ) {
+ // keep value 0 for math chars with null width
+ if (metrics_.width(toqstr(s)) != 0)
+ w = metrics_.boundingRect(toqstr(s)).width();
+ } else {
QTextLayout tl;
tl.setText(toqstr(s));
tl.setFont(font_);
diff --git a/src/mathed/InsetMathChar.cpp b/src/mathed/InsetMathChar.cpp
index 1137c95e75..3a9d18c5c2 100644
--- a/src/mathed/InsetMathChar.cpp
+++ b/src/mathed/InsetMathChar.cpp
@@ -113,9 +113,7 @@ void InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
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_);
diff --git a/src/mathed/InsetMathSymbol.cpp b/src/mathed/InsetMathSymbol.cpp
index 92d2573560..106780e578 100644
--- a/src/mathed/InsetMathSymbol.cpp
+++ b/src/mathed/InsetMathSymbol.cpp
@@ -60,10 +60,8 @@ docstring InsetMathSymbol::name() const
void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
{
- // set dim
- mathedSymbolDim(mi.base, dim, sym_);
- // set kerning_
- kerning_ = mathed_char_kerning(mi.base.font, *sym_->draw.rbegin());
+ // set dim and negative kerning_ to move a subscript leftward
+ kerning_ = -mathedSymbolDim(mi.base, dim, sym_);
// correct height for broken cmex and wasy font
if (sym_->inset == "cmex" || sym_->inset == "wasy") {
h_ = 4 * dim.des / 5;
diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp
index b9ea145c67..26d508f12c 100644
--- a/src/mathed/MathSupport.cpp
+++ b/src/mathed/MathSupport.cpp
@@ -673,9 +673,9 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
}
-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
@@ -687,6 +687,7 @@ void mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym)
std::string const font = italic_upcase_greek ? "cmm" : sym->inset;
Changer dummy = mb.changeFontSet(font);
mathed_string_dim(mb.font, sym->draw, dim);
+ return mathed_char_kerning(mb.font, sym->draw.back());
}
diff --git a/src/mathed/MathSupport.h b/src/mathed/MathSupport.h
index d9301453dd..7c40baa0b4 100644
--- a/src/mathed/MathSupport.h
+++ b/src/mathed/MathSupport.h
@@ -55,7 +55,7 @@ void mathed_string_dim(FontInfo const & font,
int mathed_string_width(FontInfo const &, docstring const & s);
-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);
More information about the lyx-devel
mailing list