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
This commit is contained in:
Enrico Forestieri 2007-03-23 02:12:48 +00:00
parent 5653a3d744
commit 7fb8a4a595
4 changed files with 42 additions and 4 deletions

View File

@ -15,6 +15,7 @@
#include "MathStream.h" #include "MathStream.h"
#include "MathSupport.h" #include "MathSupport.h"
#include "InsetMathSymbol.h" #include "InsetMathSymbol.h"
#include "InsetMathFont.h"
#include "dispatchresult.h" #include "dispatchresult.h"
#include "cursor.h" #include "cursor.h"
#include "debug.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 InsetMathScript::dy01(int asc, int des, int what) const
{ {
int dasc = 0; int dasc = 0;
int slevel = 0; int slevel = 0;
bool isCharBox = nuc().size() ? isAlphaSymbol(nuc().back()) : false;
if (hasDown()) { if (hasDown()) {
dasc = down().ascent(); dasc = down().ascent();
slevel = nuc().slevel(); slevel = nuc().slevel();
int ascdrop = dasc - slevel; int ascdrop = dasc - slevel;
int desdrop = des + nuc().sshift(); int desdrop = isCharBox ? 0 : des + nuc().sshift();
int mindes = nuc().mindes(); int mindes = nuc().mindes();
des = max(desdrop, ascdrop); des = max(desdrop, ascdrop);
des = max(mindes, des); des = max(mindes, des);
} }
if (hasUp()) { if (hasUp()) {
int minasc = nuc().minasc(); int minasc = nuc().minasc();
int ascdrop = asc - up().mindes(); int ascdrop = isCharBox ? 0 : asc - up().mindes();
int udes = up().descent(); int udes = up().descent();
asc = udes + nuc().sshift(); asc = udes + nuc().sshift();
asc = max(ascdrop, asc); asc = max(ascdrop, asc);

View File

@ -116,6 +116,12 @@ bool InsetMathSymbol::isRelOp() const
} }
bool InsetMathSymbol::isOrdAlpha() const
{
return sym_->extra == "mathord" || sym_->extra == "mathalpha";
}
bool InsetMathSymbol::isScriptable() const bool InsetMathSymbol::isScriptable() const
{ {
return scriptable_; return scriptable_;

View File

@ -42,6 +42,8 @@ public:
/// ///
bool isRelOp() const; bool isRelOp() const;
///
bool isOrdAlpha() const;
/// do we take scripts? /// do we take scripts?
bool isScriptable() const; bool isScriptable() const;
/// do we take \limits or \nolimits? /// do we take \limits or \nolimits?

View File

@ -242,8 +242,11 @@ bool isInside(DocIterator const & it, MathArray const & ar,
void MathArray::metrics(MetricsInfo & mi) const void MathArray::metrics(MetricsInfo & mi) const
{ {
dim_ = theFontMetrics(mi.base.font).dimension('I'); frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
int xascent = theFontMetrics(mi.base.font).dimension('x').ascent(); dim_ = fm.dimension('I');
int xascent = fm.dimension('x').ascent();
if (xascent >= dim_.asc)
xascent = (2 * dim_.asc) / 3;
minasc_ = xascent; minasc_ = xascent;
mindes_ = (3 * xascent) / 4; mindes_ = (3 * xascent) / 4;
slevel_ = (4 * xascent) / 5; slevel_ = (4 * xascent) / 5;