some support for TeX's \kern primitive in the parser.

use \kern instead of yesterday's home grown CheatInset


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2569 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-08-21 14:20:50 +00:00
parent 517dbda135
commit 50a865b664
10 changed files with 97 additions and 61 deletions

View File

@ -26,8 +26,6 @@ libmathed_la_SOURCES = \
math_bigopinset.h \
math_binominset.C \
math_binominset.h \
math_cheatinset.C \
math_cheatinset.h \
math_charinset.C \
math_charinset.h \
math_cursor.C \
@ -56,6 +54,8 @@ libmathed_la_SOURCES = \
math_hash.C \
math_inset.C \
math_inset.h \
math_kerninset.C \
math_kerninset.h \
math_macro.C \
math_macro.h \
math_macroarg.C \

View File

@ -1,39 +0,0 @@
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_cheatinset.h"
#include "support.h"
#include "support/LOstream.h"
MathCheatInset::MathCheatInset(double w)
: wid_(w)
{}
MathInset * MathCheatInset::clone() const
{
return new MathCheatInset(*this);
}
void MathCheatInset::draw(Painter &, int, int) const
{}
void MathCheatInset::write(std::ostream &, bool) const
{}
void MathCheatInset::writeNormal(std::ostream &) const
{}
void MathCheatInset::metrics(MathStyles st) const
{
// mimic -.1em
mathed_char_dim(LM_TC_CONST, st, 'm', ascent_, descent_, width_);
width_ *= wid_;
}

View File

@ -8,6 +8,7 @@
#include "math_funcinset.h"
#include "math_funcliminset.h"
#include "math_fracinset.h"
#include "math_kerninset.h"
#include "math_macro.h"
#include "math_macrotable.h"
#include "math_noglyphinset.h"
@ -33,6 +34,8 @@ MathInset * createMathInset(latexkeys const * l)
return new MathSymbolInset(l);
case LM_TK_STACK:
return new MathStackrelInset;
case LM_TK_KERN:
return new MathKernInset;
case LM_TK_BINOM:
case LM_TK_CHOOSE:
return new MathBinomInset;

View File

@ -27,7 +27,7 @@ MathGridInset::RowInfo::RowInfo()
int MathGridInset::RowInfo::skipPixels() const
{
#ifdef WITH_WARNINGS
#warning fix this once the interface to LyXLength has oimproved
#warning fix this once the interface to LyXLength has improved
#endif
return int(skip_.value());
}

View File

@ -153,6 +153,7 @@ latexkeys wordlist[] =
{"jmath", LM_TK_NOGLYPH, 0, LMB_NONE},
{"kappa", LM_TK_SYM, LM_kappa, LMB_NONE},
{"ker", LM_TK_FUNC, 0, LMB_NONE},
{"kern", LM_TK_KERN, 0, LMB_NONE},
{"label", LM_TK_LABEL, 0, LMB_NONE},
{"lambda", LM_TK_SYM, LM_lambda, LMB_NONE},
{"langle", LM_TK_SYM, LM_langle, LMB_NONE},

View File

@ -0,0 +1,54 @@
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_kerninset.h"
#include "support.h"
#include "support/LOstream.h"
MathKernInset::MathKernInset()
{}
MathKernInset::MathKernInset(LyXLength const & w)
: wid_(w)
{}
MathKernInset::MathKernInset(string const & s)
: wid_(s)
{}
MathInset * MathKernInset::clone() const
{
return new MathKernInset(*this);
}
void MathKernInset::draw(Painter &, int, int) const
{}
void MathKernInset::write(std::ostream & os, bool) const
{
os << "\\kern" << wid_.asLatexString() << " ";
}
void MathKernInset::writeNormal(std::ostream & os) const
{
os << "[kern " << wid_.asLatexString() << "]";
}
void MathKernInset::metrics(MathStyles) const
{
ascent_ = 0;
descent_ = 0;
#ifdef WITH_WARNINGS
#warning fix this once the interface to LyXLength has improved
#endif
width_ = static_cast<int>(wid_.value());
}

View File

@ -3,17 +3,23 @@
#define MATH_CHEATINSET_H
#include "math_diminset.h"
#include "vspace.h"
#include "LString.h"
#ifdef __GNUG__
#pragma interface
#endif
/// Some cheating for displaying things like \ll etc
/// The \kern primitive
class MathCheatInset : public MathDimInset {
class MathKernInset : public MathDimInset {
public:
///
explicit MathCheatInset(double wid);
MathKernInset();
///
explicit MathKernInset(LyXLength const & wid);
///
explicit MathKernInset(string const & wid);
///
MathInset * clone() const;
///
@ -26,6 +32,6 @@ public:
void metrics(MathStyles st) const;
private:
/// width in em
double wid_;
LyXLength wid_;
};
#endif

View File

@ -10,9 +10,6 @@
#include "math_macro.h"
#include "math_macrotemplate.h"
#include "math_parser.h"
#include "math_fracinset.h"
#include "math_cheatinset.h"
#include "math_charinset.h"
#include "debug.h"
@ -99,19 +96,12 @@ void MathMacroTable::builtinMacros()
createTemplate("perp", 0, "\\bot");
createTemplate("owns", 0, "\\ni");
createTemplate("to", 0, "\\rightarrow");
#ifdef WITH_WARNINGS
#warning 9em looks like too much but it is somehow working on screen..
#endif WITH_WARNINGS
createTemplate("ll", 0, "<\\kern-9em<");
createTemplate("gg", 0, ">\\kern-9em>");
//createTemplate("lint", 4, "\\int_#1^#2#3 d#4");
//createTemplate("silentmult", 0, "\\cdot");
//createTemplate("binom", 2, "\\left(\\frac#1#2\\right)");
MathMacroTemplate ll("ll", 0);
ll.cell(0).push_back(new MathCharInset('<', LM_TC_CONST));
ll.cell(0).push_back(new MathCheatInset(-0.9));
ll.cell(0).push_back(new MathCharInset('<', LM_TC_CONST));
insertTemplate(ll);
MathMacroTemplate gg("gg", 0);
gg.cell(0).push_back(new MathCharInset('>', LM_TC_CONST));
gg.cell(0).push_back(new MathCheatInset(-0.9));
gg.cell(0).push_back(new MathCharInset('>', LM_TC_CONST));
insertTemplate(gg);
}

View File

@ -31,6 +31,7 @@
#include "math_deliminset.h"
#include "math_factory.h"
#include "math_funcinset.h"
#include "math_kerninset.h"
#include "math_macro.h"
#include "math_macrotable.h"
#include "math_macrotemplate.h"
@ -812,6 +813,24 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
lyxerr[Debug::MATHED] << "unknow math inset begin '" << name << "'\n";
}
else if (t.cs() == "kern") {
#ifdef WITH_WARNINGS
#warning A hack...
#endif
string s;
while (1) {
Token const & t = getToken();
if (!good()) {
putback();
break;
}
s += t.character();
if (isValidLength(s))
break;
}
array.push_back(new MathKernInset(s));
}
else if (t.cs() == "label") {
//MathArray ar;
//parse_into(ar, FLAG_ITEM);

View File

@ -105,6 +105,8 @@ enum MathTokenEnum
///
LM_TK_NOT,
///
LM_TK_KERN,
///
LM_TK_STACK
};