From 7fb8a4a59548fd7dd3002e566fe6fb882b3ee9c2 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Fri, 23 Mar 2007 02:12:48 +0000 Subject: [PATCH] Correctly implement rule 18a in appendix G of the TeXbook * src/mathed/InsetMathScript.C (isAlphaSymbol): New. Return true if nucleus is a letter or a symbol whose type is mathord or mathalpha. (InsetMathScript::dy01): Apply rule 18a accounting for nucleus type. * src/mathed/MathData.C (MathArray::metrics): Account for the fact that some fonts (eg. mathcal) do not have a lower case x glyph. * src/mathed/InsetMathSymbol.[Ch] (InsetMathSymbol::isOrdAlpha): New. Return true if type of symbol is mathord or mathalpha. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17518 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/InsetMathScript.C | 31 +++++++++++++++++++++++++++++-- src/mathed/InsetMathSymbol.C | 6 ++++++ src/mathed/InsetMathSymbol.h | 2 ++ src/mathed/MathData.C | 7 +++++-- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/mathed/InsetMathScript.C b/src/mathed/InsetMathScript.C index e65d9c74a4..2a76532273 100644 --- a/src/mathed/InsetMathScript.C +++ b/src/mathed/InsetMathScript.C @@ -15,6 +15,7 @@ #include "MathStream.h" #include "MathSupport.h" #include "InsetMathSymbol.h" +#include "InsetMathFont.h" #include "dispatchresult.h" #include "cursor.h" #include "debug.h" @@ -146,22 +147,48 @@ MathArray & InsetMathScript::nuc() } +namespace { + +bool isAlphaSymbol(MathAtom const & at) +{ + if (at->asCharInset() || + (at->asSymbolInset() && + at->asSymbolInset()->isOrdAlpha())) + return true; + + if (at->asFontInset()) { + MathArray const & ar = at->asFontInset()->cell(0); + for (size_t i = 0; i < ar.size(); ++i) { + if (!(ar[i]->asCharInset() || + (ar[i]->asSymbolInset() && + ar[i]->asSymbolInset()->isOrdAlpha()))) + return false; + } + return true; + } + return false; +} + +} // namespace anon + + int InsetMathScript::dy01(int asc, int des, int what) const { int dasc = 0; int slevel = 0; + bool isCharBox = nuc().size() ? isAlphaSymbol(nuc().back()) : false; if (hasDown()) { dasc = down().ascent(); slevel = nuc().slevel(); int ascdrop = dasc - slevel; - int desdrop = des + nuc().sshift(); + int desdrop = isCharBox ? 0 : des + nuc().sshift(); int mindes = nuc().mindes(); des = max(desdrop, ascdrop); des = max(mindes, des); } if (hasUp()) { int minasc = nuc().minasc(); - int ascdrop = asc - up().mindes(); + int ascdrop = isCharBox ? 0 : asc - up().mindes(); int udes = up().descent(); asc = udes + nuc().sshift(); asc = max(ascdrop, asc); diff --git a/src/mathed/InsetMathSymbol.C b/src/mathed/InsetMathSymbol.C index 15ef723034..259047ad49 100644 --- a/src/mathed/InsetMathSymbol.C +++ b/src/mathed/InsetMathSymbol.C @@ -116,6 +116,12 @@ bool InsetMathSymbol::isRelOp() const } +bool InsetMathSymbol::isOrdAlpha() const +{ + return sym_->extra == "mathord" || sym_->extra == "mathalpha"; +} + + bool InsetMathSymbol::isScriptable() const { return scriptable_; diff --git a/src/mathed/InsetMathSymbol.h b/src/mathed/InsetMathSymbol.h index 5ac141724c..a64c54a5df 100644 --- a/src/mathed/InsetMathSymbol.h +++ b/src/mathed/InsetMathSymbol.h @@ -42,6 +42,8 @@ public: /// bool isRelOp() const; + /// + bool isOrdAlpha() const; /// do we take scripts? bool isScriptable() const; /// do we take \limits or \nolimits? diff --git a/src/mathed/MathData.C b/src/mathed/MathData.C index babbef64b8..22f2bda56d 100644 --- a/src/mathed/MathData.C +++ b/src/mathed/MathData.C @@ -242,8 +242,11 @@ bool isInside(DocIterator const & it, MathArray const & ar, void MathArray::metrics(MetricsInfo & mi) const { - dim_ = theFontMetrics(mi.base.font).dimension('I'); - int xascent = theFontMetrics(mi.base.font).dimension('x').ascent(); + frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); + dim_ = fm.dimension('I'); + int xascent = fm.dimension('x').ascent(); + if (xascent >= dim_.asc) + xascent = (2 * dim_.asc) / 3; minasc_ = xascent; mindes_ = (3 * xascent) / 4; slevel_ = (4 * xascent) / 5;