mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 13:04:58 +00:00
write \mathrm{x}\mathrm{y} as \mathrm{xy} again
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2966 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
9c4d5b9889
commit
dff2911bda
@ -224,9 +224,11 @@ From:
|
||||
// there, because otherwise more math symbols would be ready by now..
|
||||
// just a thought.
|
||||
|
||||
- Some math symbols aren't very well supported (to my knowledge). I'm
|
||||
thinking of underbraces with extra data in them,or [] options.
|
||||
//- Some math symbols aren't very well supported (to my knowledge). I'm
|
||||
// thinking of underbraces with extra data in them
|
||||
|
||||
- Some math symbols aren't very well supported (to my knowledge). I'm
|
||||
thinking of [] options.
|
||||
|
||||
Herbert Voss:
|
||||
|
||||
|
@ -28,6 +28,8 @@ libmathed_la_SOURCES = \
|
||||
math_braceinset.h \
|
||||
math_boxinset.C \
|
||||
math_boxinset.h \
|
||||
math_binaryopinset.C \
|
||||
math_binaryopinset.h \
|
||||
math_charinset.C \
|
||||
math_charinset.h \
|
||||
math_cursor.C \
|
||||
@ -94,6 +96,8 @@ libmathed_la_SOURCES = \
|
||||
math_sqrtinset.h \
|
||||
math_stackrelinset.C \
|
||||
math_stackrelinset.h \
|
||||
math_stringinset.C \
|
||||
math_stringinset.h \
|
||||
math_symbolinset.C \
|
||||
math_symbolinset.h \
|
||||
support.C \
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "math_inset.h"
|
||||
#include "math_charinset.h"
|
||||
#include "math_scriptinset.h"
|
||||
#include "math_stringinset.h"
|
||||
#include "debug.h"
|
||||
#include "array.h"
|
||||
#include "mathed/support.h"
|
||||
@ -171,24 +172,37 @@ string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
|
||||
}
|
||||
|
||||
|
||||
MathArray MathArray::glueChars() const
|
||||
{
|
||||
MathArray ar;
|
||||
const_iterator it = begin();
|
||||
while (it != end()) {
|
||||
if (it->nucleus() && it->nucleus()->asCharInset()) {
|
||||
string s = charSequence(it, end());
|
||||
MathTextCodes c = it->nucleus()->asCharInset()->code();
|
||||
ar.push_back(MathAtom(new MathStringInset(s, c)));
|
||||
it += s.size();
|
||||
} else {
|
||||
ar.push_back(*it);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
return ar;
|
||||
}
|
||||
|
||||
|
||||
void MathArray::write(MathWriteInfo & wi) const
|
||||
{
|
||||
glueChars().write1(wi);
|
||||
}
|
||||
|
||||
|
||||
void MathArray::write1(MathWriteInfo & wi) const
|
||||
{
|
||||
for (const_iterator it = begin(); it != end(); ++it) {
|
||||
MathInset * p = it->nucleus();
|
||||
if (!p)
|
||||
continue;
|
||||
|
||||
/*
|
||||
if (p->asCharInset()) {
|
||||
MathCharInset const * c = p->asCharInset();
|
||||
// special handling for character sequences with the same code
|
||||
string s = charSequence(it, end());
|
||||
c->writeHeader(os);
|
||||
os << s;
|
||||
c->writeTrailer(os);
|
||||
it += s.size() - 1;
|
||||
} else
|
||||
*/
|
||||
if (MathScriptInset const * q = asScript(it)) {
|
||||
q->write(p, wi);
|
||||
++it;
|
||||
|
@ -97,8 +97,10 @@ public:
|
||||
MathAtom & at(size_type pos);
|
||||
///
|
||||
MathAtom const & at(size_type pos) const;
|
||||
///
|
||||
/// glue chars if necessary
|
||||
void write(MathWriteInfo & os) const;
|
||||
/// raw write
|
||||
void write1(MathWriteInfo & os) const;
|
||||
///
|
||||
void writeNormal(std::ostream &) const;
|
||||
///
|
||||
@ -113,6 +115,8 @@ public:
|
||||
iterator end();
|
||||
///
|
||||
MathScriptInset const * asScript(const_iterator it) const;
|
||||
/// glues chars with the same attributes into MathStringInsets
|
||||
MathArray glueChars() const;
|
||||
private:
|
||||
/// Buffer
|
||||
buffer_type bf_;
|
||||
|
60
src/mathed/math_binaryopinset.C
Normal file
60
src/mathed/math_binaryopinset.C
Normal file
@ -0,0 +1,60 @@
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include "math_binaryopinset.h"
|
||||
#include "Painter.h"
|
||||
#include "support/LOstream.h"
|
||||
#include "support.h"
|
||||
|
||||
|
||||
MathBinaryOpInset::MathBinaryOpInset(char op)
|
||||
: MathNestInset(2), op_(op)
|
||||
{}
|
||||
|
||||
|
||||
MathInset * MathBinaryOpInset::clone() const
|
||||
{
|
||||
return new MathBinaryOpInset(*this);
|
||||
}
|
||||
|
||||
|
||||
int MathBinaryOpInset::opwidth() const
|
||||
{
|
||||
return mathed_char_width(LM_TC_CONST, mi_, op_);
|
||||
}
|
||||
|
||||
|
||||
void MathBinaryOpInset::metrics(MathMetricsInfo const & mi) const
|
||||
{
|
||||
mi_ = mi;
|
||||
xcell(0).metrics(mi);
|
||||
xcell(1).metrics(mi);
|
||||
width_ = xcell(0).width() + xcell(1).width() + opwidth();
|
||||
ascent_ = std::max(xcell(0).ascent(), xcell(1).ascent());
|
||||
descent_ = std::max(xcell(0).descent(), xcell(1).descent());
|
||||
}
|
||||
|
||||
|
||||
void MathBinaryOpInset::draw(Painter & pain, int x, int y) const
|
||||
{
|
||||
xcell(0).draw(pain, x, y);
|
||||
drawChar(pain, LM_TC_CONST, mi_, x + xcell(0).width() , y, op_);
|
||||
xcell(1).draw(pain, x + width() - xcell(1).width(), y);
|
||||
}
|
||||
|
||||
|
||||
void MathBinaryOpInset::write(MathWriteInfo & os) const
|
||||
{
|
||||
os << '{' << cell(0) << op_ << cell(1) << '}';
|
||||
}
|
||||
|
||||
|
||||
void MathBinaryOpInset::writeNormal(std::ostream & os) const
|
||||
{
|
||||
os << "[binop " << op_ << ' ';
|
||||
cell(0).writeNormal(os);
|
||||
os << " ";
|
||||
cell(1).writeNormal(os);
|
||||
os << "]";
|
||||
}
|
37
src/mathed/math_binaryopinset.h
Normal file
37
src/mathed/math_binaryopinset.h
Normal file
@ -0,0 +1,37 @@
|
||||
// -*- C++ -*-
|
||||
#ifndef MATH_BINARYOPINSET_H
|
||||
#define MATH_BINARYOPINSET_H
|
||||
|
||||
#include "math_nestinset.h"
|
||||
#include "math_nestinset.h"
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
/** An inset for multiplication
|
||||
\author André Pönitz
|
||||
*/
|
||||
class MathBinaryOpInset : public MathNestInset {
|
||||
public:
|
||||
///
|
||||
explicit MathBinaryOpInset(char op);
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
void draw(Painter &, int x, int y) const;
|
||||
///
|
||||
void write(MathWriteInfo & os) const;
|
||||
///
|
||||
void writeNormal(std::ostream &) const;
|
||||
///
|
||||
void metrics(MathMetricsInfo const & st) const;
|
||||
private:
|
||||
///
|
||||
int opwidth() const;
|
||||
///
|
||||
char op_;
|
||||
///
|
||||
mutable MathMetricsInfo mi_;
|
||||
};
|
||||
#endif
|
@ -13,22 +13,6 @@
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
char const * math_font_name[] = {
|
||||
"mathrm",
|
||||
"mathcal",
|
||||
"mathbf",
|
||||
"mathbb",
|
||||
"mathsf",
|
||||
"mathtt",
|
||||
"mathit",
|
||||
"textrm"
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
MathCharInset::MathCharInset(char c)
|
||||
: char_(c), code_(nativeCode(c))
|
||||
{
|
||||
@ -91,14 +75,14 @@ void MathCharInset::draw(Painter & pain, int x, int y) const
|
||||
|
||||
void MathCharInset::writeHeader(std::ostream & os) const
|
||||
{
|
||||
if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
|
||||
os << '\\' << math_font_name[code_ - LM_TC_RM] << '{';
|
||||
if (math_font_name(code_))
|
||||
os << '\\' << math_font_name(code_) << '{';
|
||||
}
|
||||
|
||||
|
||||
void MathCharInset::writeTrailer(std::ostream & os) const
|
||||
{
|
||||
if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
|
||||
if (math_font_name(code_))
|
||||
os << '}';
|
||||
}
|
||||
|
||||
|
@ -243,6 +243,14 @@ bool MathMatrixInset::numbered(row_type row) const
|
||||
bool MathMatrixInset::ams() const
|
||||
{
|
||||
return true;
|
||||
|
||||
return
|
||||
objtype_ == LM_OT_ALIGN ||
|
||||
objtype_ == LM_OT_MULTLINE ||
|
||||
objtype_ == LM_OT_GATHER ||
|
||||
objtype_ == LM_OT_ALIGNAT ||
|
||||
objtype_ == LM_OT_XALIGNAT ||
|
||||
objtype_ == LM_OT_XXALIGNAT;
|
||||
}
|
||||
|
||||
|
||||
|
70
src/mathed/math_stringinset.C
Normal file
70
src/mathed/math_stringinset.C
Normal file
@ -0,0 +1,70 @@
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <cctype>
|
||||
|
||||
#include "math_stringinset.h"
|
||||
#include "LColor.h"
|
||||
#include "Painter.h"
|
||||
#include "support/LOstream.h"
|
||||
#include "support.h"
|
||||
#include "math_parser.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
MathStringInset::MathStringInset(string const & s, MathTextCodes t)
|
||||
: str_(s), code_(t)
|
||||
{}
|
||||
|
||||
|
||||
MathInset * MathStringInset::clone() const
|
||||
{
|
||||
return new MathStringInset(*this);
|
||||
}
|
||||
|
||||
|
||||
int MathStringInset::ascent() const
|
||||
{
|
||||
return mathed_string_ascent(code_, mi_, str_);
|
||||
}
|
||||
|
||||
|
||||
int MathStringInset::descent() const
|
||||
{
|
||||
return mathed_string_descent(code_, mi_, str_);
|
||||
}
|
||||
|
||||
|
||||
int MathStringInset::width() const
|
||||
{
|
||||
return mathed_string_width(code_, mi_, str_);
|
||||
}
|
||||
|
||||
|
||||
void MathStringInset::metrics(MathMetricsInfo const & mi) const
|
||||
{
|
||||
mi_ = mi;
|
||||
}
|
||||
|
||||
|
||||
void MathStringInset::draw(Painter & pain, int x, int y) const
|
||||
{
|
||||
//lyxerr << "drawing '" << str_ << "' code: " << code_ << endl;
|
||||
drawStr(pain, code_, mi_, x, y, str_);
|
||||
}
|
||||
|
||||
|
||||
void MathStringInset::write(MathWriteInfo & os) const
|
||||
{
|
||||
if (math_font_name(code_))
|
||||
os << '\\' << math_font_name(code_) << '{' << str_ << '}';
|
||||
else
|
||||
os << str_;
|
||||
}
|
||||
|
||||
|
||||
void MathStringInset::writeNormal(std::ostream & os) const
|
||||
{
|
||||
os << "[string " << str_ << " " << "mathalpha" << "]";
|
||||
}
|
46
src/mathed/math_stringinset.h
Normal file
46
src/mathed/math_stringinset.h
Normal file
@ -0,0 +1,46 @@
|
||||
// -*- C++ -*-
|
||||
#ifndef MATH_STRINGINSET_H
|
||||
#define MATH_STRINGINSET_H
|
||||
|
||||
#include "math_inset.h"
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
/** Some cllection of chars with similar properties
|
||||
\author André Pönitz
|
||||
*/
|
||||
|
||||
class MathStringInset : public MathInset {
|
||||
public:
|
||||
///
|
||||
MathStringInset(string const & s, MathTextCodes t);
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
void metrics(MathMetricsInfo const & st) const;
|
||||
///
|
||||
void draw(Painter &, int x, int y) const;
|
||||
///
|
||||
void write(MathWriteInfo & os) const;
|
||||
///
|
||||
void writeNormal(std::ostream &) const;
|
||||
///
|
||||
int ascent() const;
|
||||
///
|
||||
int descent() const;
|
||||
///
|
||||
int width() const;
|
||||
///
|
||||
string & str();
|
||||
|
||||
private:
|
||||
/// the string
|
||||
string str_;
|
||||
/// the font to be used on screen
|
||||
MathTextCodes code_;
|
||||
///
|
||||
mutable MathMetricsInfo mi_;
|
||||
};
|
||||
#endif
|
@ -591,6 +591,29 @@ int mathed_string_width(MathTextCodes type, MathMetricsInfo const & size,
|
||||
}
|
||||
|
||||
|
||||
int mathed_string_ascent(MathTextCodes type, MathMetricsInfo const & size,
|
||||
string const & s)
|
||||
{
|
||||
LyXFont const font = whichFont(type, size);
|
||||
int asc = 0;
|
||||
for (string::const_iterator it = s.begin(); it != s.end(); ++it)
|
||||
asc = max(asc, lyxfont::ascent(*it, font));
|
||||
return asc;
|
||||
}
|
||||
|
||||
|
||||
int mathed_string_descent(MathTextCodes type, MathMetricsInfo const & size,
|
||||
string const & s)
|
||||
{
|
||||
LyXFont const font = whichFont(type, size);
|
||||
int des = 0;
|
||||
for (string::const_iterator it = s.begin(); it != s.end(); ++it)
|
||||
des = max(des, lyxfont::descent(*it, font));
|
||||
return des;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
|
||||
const string & name)
|
||||
{
|
||||
@ -714,3 +737,22 @@ void math_font_max_dim(MathTextCodes code, MathMetricsInfo const & siz,
|
||||
char const * latex_mathspace[] = {
|
||||
"!", ",", ":", ";", "quad", "qquad"
|
||||
};
|
||||
|
||||
|
||||
char const * math_font_name(MathTextCodes code)
|
||||
{
|
||||
static char const * theFontNames[] = {
|
||||
"mathrm",
|
||||
"mathcal",
|
||||
"mathbf",
|
||||
"mathbb",
|
||||
"mathsf",
|
||||
"mathtt",
|
||||
"mathit",
|
||||
"textrm"
|
||||
};
|
||||
|
||||
if (code >= LM_TC_RM && code <= LM_TC_TEXTRM)
|
||||
return theFontNames[code - LM_TC_RM];
|
||||
return 0;
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ void smallerStyleScript(MathMetricsInfo &);
|
||||
// decrease math size for fractions
|
||||
void smallerStyleFrac(MathMetricsInfo & st);
|
||||
|
||||
char const * math_font_name(MathTextCodes type);
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user