the remove reinterpret_cast patch from Andre Poenitz

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1463 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-02-08 15:09:15 +00:00
parent 79c4c549f4
commit 742ebe1f13
9 changed files with 166 additions and 194 deletions

View File

@ -1,3 +1,7 @@
2001-02-08 Andre Poenitz <poenitz@HTWM.De>
* several files: get rid of reinterpret_cast
2001-02-04 Allan Rae <rae@lyx.org> 2001-02-04 Allan Rae <rae@lyx.org>
* math_parser.C (mathed_parse): I'm sure Lars has a better fix than * math_parser.C (mathed_parse): I'm sure Lars has a better fix than

View File

@ -197,58 +197,47 @@ LyXFont mathed_get_font(short type, int size)
} }
int mathed_string_width(short type, int size, byte const * s, int ls) int mathed_string_width(short type, int size, string const & s)
{ {
string st; string st;
if (MathIsBinary(type)) if (MathIsBinary(type))
for (int i = 0; i < ls; ++i) { for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
st += ' '; st += ' ';
st += s[i]; st += *it;
st += ' '; st += ' ';
} }
else else
st = string(reinterpret_cast<char const *>(s), ls); st = s;
LyXFont const f = WhichFont(type, size); LyXFont const f = WhichFont(type, size);
return lyxfont::width(st, f); return lyxfont::width(st, f);
} }
int mathed_string_width(short type, int size, string const & str)
{
return mathed_string_width(type, size, reinterpret_cast<unsigned char const *>(str.c_str()), str.length());
}
int mathed_char_width(short type, int size, byte c) int mathed_char_width(short type, int size, byte c)
{ {
int t = (MathIsBinary(type)) ? mathed_string_width(type, size, &c, 1) : if (MathIsBinary(type)) {
lyxfont::width(c, WhichFont(type, size)); string s;
return t; s += c;
return mathed_string_width(type, size, s);
}
else
return lyxfont::width(c, WhichFont(type, size));
} }
int mathed_string_height(short type, int size, byte const * s, int mathed_string_height(short type, int size, string const & s,
int ls, int & asc, int & des) int & asc, int & des)
{ {
LyXFont font = WhichFont(type, size); LyXFont font = WhichFont(type, size);
asc = des = 0; asc = des = 0;
for (int i = 0; i < ls; ++i) { for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
des = max(des, lyxfont::descent(s[i], font)); des = max(des, lyxfont::descent(*it, font));
asc = max(asc, lyxfont::ascent(s[i], font)); asc = max(asc, lyxfont::ascent(*it, font));
} }
return asc + des; return asc + des;
} }
int mathed_string_height(short type, int size, string const & str,
int & asc, int & des)
{
return mathed_string_height(type, size,
reinterpret_cast<unsigned char const *>(str.c_str()), str.length(),
asc, des);
}
int mathed_char_height(short type, int size, byte c, int & asc, int & des) int mathed_char_height(short type, int size, byte c, int & asc, int & des)
{ {
LyXFont font = WhichFont(type, size); LyXFont font = WhichFont(type, size);
@ -260,17 +249,17 @@ int mathed_char_height(short type, int size, byte c, int & asc, int & des)
// In a near future maybe we use a better fonts renderer // In a near future maybe we use a better fonts renderer
void MathedInset::drawStr(Painter & pain, short type, int siz, void MathedInset::drawStr(Painter & pain, short type, int siz,
int x, int y, byte const * s, int ls) int x, int y, string const & s)
{ {
string st; string st;
if (MathIsBinary(type)) if (MathIsBinary(type))
for (int i = 0; i < ls; ++i) { for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
st += ' '; st += ' ';
st += char(s[i]); st += *it;
st += ' '; st += ' ';
} }
else else
st = string(reinterpret_cast<char const *>(s), ls); st = s;
LyXFont const mf = mathed_get_font(type, siz); LyXFont const mf = mathed_get_font(type, siz);
pain.text(x, y, st, mf); pain.text(x, y, st, mf);

View File

@ -279,7 +279,7 @@ class MathedInset {
/// ///
static int df_width; static int df_width;
/// In a near future maybe we use a better fonts renderer than X /// In a near future maybe we use a better fonts renderer than X
void drawStr(Painter &, short, int, int, int, byte const *, int); void drawStr(Painter &, short, int, int, int, string const &);
/// ///
friend class MathedCursor; friend class MathedCursor;
/// ///

View File

@ -529,10 +529,12 @@ MathAccentInset::draw(Painter & pain, int x, int y)
{ {
int dw = width - 2; int dw = width - 2;
if (inset) { if (inset)
inset->draw(pain, x, y); inset->draw(pain, x, y);
} else { else {
drawStr(pain, fn, size, x, y, &c, 1); string s;
s += c;
drawStr(pain, fn, size, x, y, s);
} }
x += (code == LM_not) ? (width-dw) / 2 : 2; x += (code == LM_not) ? (width-dw) / 2 : 2;
mathed_draw_deco(pain, x, y - dy, dw, dh, code); mathed_draw_deco(pain, x, y - dy, dw, dh, code);

View File

@ -54,8 +54,8 @@ MathSpaceInset::draw(Painter & pain, int x, int y)
void void
MathParInset::draw(Painter & pain, int x, int y) MathParInset::draw(Painter & pain, int x, int y)
{ {
byte cx, cxp = 0; byte cxp = 0;
int xp = 0, ls; int xp = 0;
int asc = df_asc, des = 0; int asc = df_asc, des = 0;
bool limits = false; bool limits = false;
@ -72,65 +72,68 @@ MathParInset::draw(Painter & pain, int x, int y)
data.GoBegin(); data.GoBegin();
while (data.OK()) { while (data.OK()) {
data.GetPos(x, y); data.GetPos(x, y);
cx = data.GetChar(); byte cx = data.GetChar();
if (cx >= ' ') { if (cx >= ' ') {
byte * s = data.GetString(ls); string s = data.GetString();
drawStr(pain, data.FCode(), size, x, y, s, ls); drawStr(pain, data.FCode(), size, x, y, s);
mathed_char_height(LM_TC_CONST, size, 'y', asc, des); mathed_char_height(LM_TC_CONST, size, 'y', asc, des);
limits = false; limits = false;
} else { }
if (cx == 0) break; else {
if (cx == 0)
break;
if (MathIsInset(cx)) { if (MathIsInset(cx)) {
int yy = y; int yy = y;
MathedInset * p = data.GetInset(); MathedInset * p = data.GetInset();
if (cx == LM_TC_UP) { if (cx == LM_TC_UP) {
if (limits) { x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp; if (limits) {
x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
yy -= (asc + p->Descent()+4); yy -= (asc + p->Descent()+4);
} else }
else
yy -= (p->Descent()>asc) ? p->Descent()+4: asc; yy -= (p->Descent()>asc) ? p->Descent()+4: asc;
} else }
if (cx == LM_TC_DOWN) { else if (cx == LM_TC_DOWN) {
if (limits) { if (limits) {
x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp; x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
yy += des + p->Ascent() + 2; yy += des + p->Ascent() + 2;
} else } else
yy += des + p->Ascent()/2; yy += des + p->Ascent()/2;
} else { }
else {
asc = p->Ascent(); asc = p->Ascent();
des = p->Descent(); des = p->Descent();
} }
p->draw(pain, x, yy); p->draw(pain, x, yy);
if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) { if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) {
limits = p->GetLimits(); limits = p->GetLimits();
if (limits) xp = p->Width(); if (limits)
xp = p->Width();
} }
data.Next(); data.Next();
} else }
if (cx == LM_TC_TAB) { else if (cx == LM_TC_TAB) {
if ((cxp == cx || cxp == LM_TC_CR || data.IsFirst())) { // && objtype == L if (cxp == cx || cxp == LM_TC_CR || data.IsFirst()) {
pain.rectangle(x, y - df_asc, df_width, df_asc, pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
LColor::mathline);
} }
data.Next(); data.Next();
limits = false; limits = false;
} else }
if (cx == LM_TC_CR) { else if (cx == LM_TC_CR) {
if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) { // && objtype == LM_OT_MATRIX) { if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) {
pain.rectangle(x, y - df_asc, df_width, df_asc, pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
LColor::mathline);
} }
data.Next(); data.Next();
limits = false; limits = false;
} }
else { else {
lyxerr << "GMathed Error: Unrecognized code[" << cx lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
<< "]" << endl;
break; break;
} }
} }
cxp = cx; cxp = cx;
} }
if (cxp == LM_TC_TAB || cxp == LM_TC_CR) { // && objtype == LM_OT_MATRIX) { if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
data.GetPos(x, y); data.GetPos(x, y);
pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline); pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
} }

View File

@ -32,7 +32,7 @@ using std::endl;
const int SizeInset = sizeof(char*) + 2; const int SizeInset = sizeof(char*) + 2;
extern int mathed_char_width(short type, int style, byte c); extern int mathed_char_width(short type, int style, byte c);
extern int mathed_string_width(short type, int style, byte const * s, int ls); extern int mathed_string_width(short type, int style, string const & s);
extern int mathed_char_height(short, int, byte, int &, int &); extern int mathed_char_height(short, int, byte, int &, int &);
// the builtin memcpy() is broken in egcs and gcc 2.95.x on alpha // the builtin memcpy() is broken in egcs and gcc 2.95.x on alpha
@ -73,28 +73,19 @@ byte MathedIter::GetChar() const
} }
byte * MathedIter::GetString(int & len) const string const MathedIter::GetString() const
{ {
if (IsFont()) { if (IsFont()) {
fcode = array->bf[++pos]; fcode = array->bf[++pos];
++pos; ++pos;
} }
byte * s = &array->bf[pos]; string s;
len = pos; for ( ; array->bf[pos] >= ' ' && pos < array->last; ++pos)
while (array->bf[pos] >= ' ' && pos < array->last) ++pos; s += array->bf[pos];
len = pos - len;
return s; return s;
} }
string const MathedIter::GetString() const
{
int ls = 0;
byte const * s = GetString(ls);
return string(reinterpret_cast<char const *>(s), ls);
}
MathedInset * MathedIter::GetInset() const MathedInset * MathedIter::GetInset() const
{ {
if (IsInset()) { if (IsInset()) {
@ -587,25 +578,11 @@ void MathedXIter::SetData(MathParInset * pp)
} }
byte * MathedXIter::GetString(int & ls) const
{
static byte s[255];
byte const * sxs = MathedIter::GetString(ls);
if (ls > 0) {
strncpy(reinterpret_cast<char*>(s),
reinterpret_cast<char const *>(sxs), ls);
x += mathed_string_width(fcode, size, s, ls);
return &s[0];
}
return 0;
}
string const MathedXIter::GetString() const string const MathedXIter::GetString() const
{ {
int ls; string s = MathedIter::GetString();
byte const * s = GetString(ls); x += mathed_string_width(fcode, size, s);
return string(reinterpret_cast<char const *>(s), ls); return s;
} }

View File

@ -68,8 +68,6 @@ class MathedIter {
/// ///
byte GetChar() const; byte GetChar() const;
/// ///
byte * GetString(int & len) const;
///
string const GetString() const; string const GetString() const;
/// ///
MathedInset * GetInset() const; MathedInset * GetInset() const;

View File

@ -49,8 +49,8 @@ ostream & operator<<(ostream & o, MathedMacroFlag mmf)
return o << int(mmf); return o << int(mmf);
} }
extern int mathed_string_width(short type, int style, byte const* s, int ls); extern int mathed_string_width(short type, int style, string const & s);
extern int mathed_string_height(short, int, byte const*, int, int&, int&); extern int mathed_string_height(short, int, string const &, int &, int &);
MathMacro::MathMacro(MathMacroTemplate* t): MathMacro::MathMacro(MathMacroTemplate* t):
@ -218,11 +218,11 @@ void MathMacroArgument::draw(Painter & pain, int x, int baseline)
{ {
if (expnd_mode) { if (expnd_mode) {
MathParInset::draw(pain, x, baseline); MathParInset::draw(pain, x, baseline);
} else { }
else {
std::ostringstream ost; std::ostringstream ost;
ost << '#' << number; ost << '#' << number;
drawStr(pain, LM_TC_TEX, size, x, baseline, drawStr(pain, LM_TC_TEX, size, x, baseline, ost.str());
reinterpret_cast<byte const *>(ost.str().c_str()), 2);
} }
} }
@ -231,14 +231,12 @@ void MathMacroArgument::Metrics()
{ {
if (expnd_mode) { if (expnd_mode) {
MathParInset::Metrics(); MathParInset::Metrics();
} else { }
else {
std::ostringstream ost; std::ostringstream ost;
ost << '#' << number; ost << '#' << number;
width = mathed_string_width(LM_TC_TEX, size, width = mathed_string_width(LM_TC_TEX, size, ost.str());
reinterpret_cast<byte const *>(ost.str().c_str()), 2); mathed_string_height(LM_TC_TEX, size, ost.str(), ascent, descent);
mathed_string_height(LM_TC_TEX, size,
reinterpret_cast<byte const *>(ost.str().c_str()),
2, ascent, descent);
} }
} }

View File

@ -192,38 +192,39 @@ void MathParInset::Write(ostream & os, bool fragile)
while (data.OK()) { while (data.OK()) {
byte cx = data.GetChar(); byte cx = data.GetChar();
if (cx >= ' ') { if (cx >= ' ') {
int ls; string str = data.GetString();
byte * s = data.GetString(ls);
if (data.FCode() >= LM_TC_RM && data.FCode() <= LM_TC_TEXTRM) { if (data.FCode() >= LM_TC_RM && data.FCode() <= LM_TC_TEXTRM) {
os << '\\' << math_font_name[data.FCode()-LM_TC_RM] << '{'; os << '\\' << math_font_name[data.FCode()-LM_TC_RM] << '{';
} }
while (ls > 0) { for (string::const_iterator s = str.begin();
s != str.end(); ++s) {
byte c = *s;
if (MathIsSymbol(data.FCode())) { if (MathIsSymbol(data.FCode())) {
l = lm_get_key_by_id(*s, (data.FCode() == LM_TC_BSYM) ? l = lm_get_key_by_id(c, (data.FCode() == LM_TC_BSYM) ?
LM_TK_BIGSYM : LM_TK_SYM); LM_TK_BIGSYM : LM_TK_SYM);
if (l) { if (l) {
os << '\\' << l->name << ' '; os << '\\' << l->name << ' ';
} else { } else {
lyxerr << "Illegal symbol code[" << *s #warning This does not compile (Lgb)
<< " " << ls << " " << data.FCode() << "]"; //lyxerr << "Illegal symbol code[" << c
// << " " << str.end() - s << " " << data.FCode() << "]";
} }
} else { } else {
// Is there a standard logical XOR? // Is there a standard logical XOR?
if ((data.FCode() == LM_TC_TEX && *s != '{' && *s != '}') || if ((data.FCode() == LM_TC_TEX && c != '{' && c != '}') ||
(data.FCode() == LM_TC_SPECIAL)) (data.FCode() == LM_TC_SPECIAL))
os << '\\'; os << '\\';
else { else {
if (*s == '{') ++brace; if (c == '{') ++brace;
if (*s == '}') --brace; if (c == '}') --brace;
} }
if (*s == '}' && data.FCode() == LM_TC_TEX && brace < 0) if (c == '}' && data.FCode() == LM_TC_TEX && brace < 0)
lyxerr <<"Math warning: Unexpected closing brace." lyxerr <<"Math warning: Unexpected closing brace."
<< endl; << endl;
else else
os << char(*s); os << char(c);
} }
++s; --ls;
} }
if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM) if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM)
os << '}'; os << '}';