]> git.lyx.org Git - features.git/commitdiff
Correctly implement rule 18a in appendix G of the TeXbook
authorEnrico Forestieri <forenr@lyx.org>
Fri, 23 Mar 2007 02:12:48 +0000 (02:12 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Fri, 23 Mar 2007 02:12:48 +0000 (02:12 +0000)
* 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
src/mathed/InsetMathSymbol.C
src/mathed/InsetMathSymbol.h
src/mathed/MathData.C

index e65d9c74a494c43d44b46d19c1698f8f9e5317cd..2a76532273de16ee718c2cd4ddb0502032d1b98c 100644 (file)
@@ -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);
index 15ef723034d614bd608246d93b36bce1e162150a..259047ad49ff2750ca1860e54fb531066cb51f23 100644 (file)
@@ -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_;
index 5ac141724c2fe3062dce4ab56c29e44fd2ed451b..a64c54a5df50c231c4aaabf89dc9212a4b9cd7a8 100644 (file)
@@ -42,6 +42,8 @@ public:
 
        ///
        bool isRelOp() const;
+       ///
+       bool isOrdAlpha() const;
        /// do we take scripts?
        bool isScriptable() const;
        /// do we take \limits or \nolimits?
index babbef64b80b61cb317ab24646f124a97d5db3d1..22f2bda56df0f6915f7e7ae5efc26bd59dbe76d3 100644 (file)
@@ -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;