Fix Angus' drawing bug + cosmetics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2234 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-07-13 11:32:22 +00:00
parent 67de3b29bc
commit 747cd76667
9 changed files with 70 additions and 69 deletions

View File

@ -106,7 +106,7 @@ MathInset * MathArray::prevInset(int pos) const
return nextInset(pos); return nextInset(pos);
} }
byte MathArray::GetChar(int pos) const unsigned char MathArray::GetChar(int pos) const
{ {
return pos < size() ? bf_[pos + 1] : '\0'; return pos < size() ? bf_[pos + 1] : '\0';
} }
@ -151,7 +151,7 @@ void MathArray::replace(int pos, MathInset * p)
memcpy(&bf_[pos + 1], &p, sizeof(p)); memcpy(&bf_[pos + 1], &p, sizeof(p));
} }
void MathArray::insert(int pos, byte b, MathTextCodes t) void MathArray::insert(int pos, unsigned char b, MathTextCodes t)
{ {
bf_.insert(bf_.begin() + pos, 3, t); bf_.insert(bf_.begin() + pos, 3, t);
bf_[pos + 1] = b; bf_[pos + 1] = b;
@ -172,7 +172,7 @@ void MathArray::push_back(MathInset * p)
insert(size(), p); insert(size(), p);
} }
void MathArray::push_back(byte b, MathTextCodes c) void MathArray::push_back(unsigned char b, MathTextCodes c)
{ {
insert(size(), b, c); insert(size(), b, c);
} }
@ -284,7 +284,7 @@ void MathArray::Write(ostream & os, bool fragile) const
} else { } else {
MathTextCodes fcode = GetCode(pos); MathTextCodes fcode = GetCode(pos);
byte c = GetChar(pos); unsigned char c = GetChar(pos);
if (MathIsSymbol(fcode)) { if (MathIsSymbol(fcode)) {
latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM); latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);

View File

@ -62,7 +62,7 @@ public:
/// ///
void insert(int pos, MathInset * inset); void insert(int pos, MathInset * inset);
/// ///
void insert(int pos, byte, MathTextCodes); void insert(int pos, unsigned char, MathTextCodes);
/// ///
void insert(int pos, MathArray const &); void insert(int pos, MathArray const &);
@ -83,7 +83,7 @@ public:
/// ///
void push_back(MathInset * inset); void push_back(MathInset * inset);
/// ///
void push_back(byte, MathTextCodes); void push_back(unsigned char, MathTextCodes);
/// ///
void push_back(MathArray const &); void push_back(MathArray const &);
/// ///
@ -102,7 +102,7 @@ public:
/// ///
MathInset * prevInset(int pos) const; MathInset * prevInset(int pos) const;
/// ///
byte GetChar(int pos) const; unsigned char GetChar(int pos) const;
/// read subsequent chars of the same kind. /// read subsequent chars of the same kind.
// pos is afterwards one behind the last char belonging to the string // pos is afterwards one behind the last char belonging to the string
string GetString(int & pos) const; string GetString(int & pos) const;
@ -118,9 +118,9 @@ public:
void WriteNormal(std::ostream &) const; void WriteNormal(std::ostream &) const;
private: private:
/// ///
typedef std::vector<byte> buffer_type; typedef std::vector<unsigned char> buffer_type;
/// ///
typedef byte value_type; typedef unsigned char value_type;
/// ///
int item_size(int pos) const; int item_size(int pos) const;

View File

@ -69,6 +69,7 @@ InsetFormula::InsetFormula(string const & s)
{ {
istringstream is(s.c_str()); istringstream is(s.c_str());
par(mathed_parse(is)); par(mathed_parse(is));
Metrics();
} }
@ -114,6 +115,7 @@ int InsetFormula::docBook(ostream & os) const
void InsetFormula::read(LyXLex & lex) void InsetFormula::read(LyXLex & lex)
{ {
par(mathed_parse(lex)); par(mathed_parse(lex));
Metrics();
} }
@ -131,7 +133,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const &,
pain.fillRectangle(int(x), y - a, w, h, LColor::mathbg); pain.fillRectangle(int(x), y - a, w, h, LColor::mathbg);
if (mathcursor) { if (mathcursor) {
par()->Metrics(LM_ST_TEXT); Metrics();
if (mathcursor->formula() == this) { if (mathcursor->formula() == this) {
if (mathcursor->Selection()) { if (mathcursor->Selection()) {
@ -152,6 +154,11 @@ void InsetFormula::draw(BufferView * bv, LyXFont const &,
} }
void InsetFormula::Metrics() const
{
const_cast<MathInset *>(par_)->Metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
}
vector<string> const InsetFormula::getLabelList() const vector<string> const InsetFormula::getLabelList() const
{ {
return par()->getLabelList(); return par()->getLabelList();
@ -295,6 +302,7 @@ void InsetFormula::handleExtern(const string & arg, BufferView *)
ifstream is(outfile.c_str()); ifstream is(outfile.c_str());
par(mathed_parse(is)); par(mathed_parse(is));
Metrics();
} }
bool InsetFormula::display() const bool InsetFormula::display() const
@ -329,7 +337,7 @@ void InsetFormula::validate(LaTeXFeatures & features) const
int InsetFormula::ascent(BufferView *, LyXFont const &) const int InsetFormula::ascent(BufferView *, LyXFont const &) const
{ {
return par()->ascent() + 4; return par()->ascent();
} }
@ -341,6 +349,5 @@ int InsetFormula::descent(BufferView *, LyXFont const &) const
int InsetFormula::width(BufferView *, LyXFont const &) const int InsetFormula::width(BufferView *, LyXFont const &) const
{ {
par()->Metrics(LM_ST_TEXT);
return par()->width(); return par()->width();
} }

View File

@ -43,6 +43,8 @@ public:
int width(BufferView *, LyXFont const &) const; int width(BufferView *, LyXFont const &) const;
/// ///
void draw(BufferView *, LyXFont const &, int, float &, bool) const; void draw(BufferView *, LyXFont const &, int, float &, bool) const;
///
void Metrics() const;
/// ///
void write(std::ostream &) const; void write(std::ostream &) const;

View File

@ -614,14 +614,10 @@ in_word_set(s) << " \n";
break; break;
case LM_TK_SYM: case LM_TK_SYM:
if (l->id < 255) { if (l->id < 255)
insert(static_cast<byte>(l->id), insert(l->id, MathIsBOPS(l->id) ? LM_TC_BOPS : LM_TC_SYMB);
MathIsBOPS(l->id) ? else
LM_TC_BOPS : LM_TC_SYMB);
} else {
p = new MathFuncInset(l->name); p = new MathFuncInset(l->name);
}
break; break;
case LM_TK_STACK: case LM_TK_STACK:

View File

@ -331,7 +331,7 @@ void MathInset::dump() const
} }
void MathInset::push_back(byte ch, MathTextCodes fcode) void MathInset::push_back(unsigned char ch, MathTextCodes fcode)
{ {
if (nargs()) if (nargs())
cells_.back().data_.push_back(ch, fcode); cells_.back().data_.push_back(ch, fcode);

View File

@ -182,7 +182,7 @@ public:
/// ///
void push_back(MathInset *); void push_back(MathInset *);
/// ///
void push_back(byte ch, MathTextCodes fcode); void push_back(unsigned char ch, MathTextCodes fcode);
/// ///
void dump() const; void dump() const;

View File

@ -17,6 +17,38 @@ using std::lower_bound;
using std::endl; using std::endl;
using std::max; using std::max;
bool MathIsInset(short x)
{
return LM_TC_INSET == x;
}
bool MathIsAlphaFont(short x)
{
return LM_TC_VAR <= x && x <= LM_TC_TEXTRM;
}
bool MathIsBOPS(short x)
{
return MathLookupBOP(x) > LMB_NONE;
}
bool MathIsBinary(short x)
{
return x == LM_TC_BOP || x == LM_TC_BOPS;
}
bool MathIsSymbol(short x)
{
return x == LM_TC_SYMB || x == LM_TC_BOPS || x == LM_TC_BSYM;
}
/// ///
class Matrix { class Matrix {
public: public:
@ -375,7 +407,8 @@ static init_deco_table idt;
} // namespace anon } // namespace anon
void mathed_char_dim (short type, int size, byte c, int & asc, int & des, int & wid) void mathed_char_dim (short type, int size, unsigned char c,
int & asc, int & des, int & wid)
{ {
LyXFont const font = WhichFont(type, size); LyXFont const font = WhichFont(type, size);
des = lyxfont::descent(c, font); des = lyxfont::descent(c, font);
@ -383,7 +416,8 @@ void mathed_char_dim (short type, int size, byte c, int & asc, int & des, int &
wid = mathed_char_width(type, size, c); wid = mathed_char_width(type, size, c);
} }
int mathed_char_height(short type, int size, byte c, int & asc, int & des) int mathed_char_height(short type, int size, unsigned char c,
int & asc, int & des)
{ {
LyXFont const font = WhichFont(type, size); LyXFont const font = WhichFont(type, size);
des = lyxfont::descent(c, font); des = lyxfont::descent(c, font);
@ -392,7 +426,7 @@ int mathed_char_height(short type, int size, byte c, int & asc, int & des)
} }
int mathed_char_width(short type, int size, byte c) int mathed_char_width(short type, int size, unsigned char c)
{ {
if (MathIsBinary(type)) { if (MathIsBinary(type)) {
string s; string s;
@ -546,41 +580,6 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h, int code)
bool MathIsInset(short x)
{
return LM_TC_INSET == x;
}
bool MathIsAlphaFont(short x)
{
return LM_TC_VAR <= x && x <= LM_TC_TEXTRM;
}
bool MathIsBOPS(short x)
{
return MathLookupBOP(x) > LMB_NONE;
}
bool MathIsBinary(short x)
{
return x == LM_TC_BOP || x == LM_TC_BOPS;
}
bool MathIsSymbol(short x)
{
return x == LM_TC_SYMB || x == LM_TC_BOPS || x == LM_TC_BSYM;
}
bool is_matrix_type(short int type)
{
return type == LM_OT_MATRIX;
}
// In a near future maybe we use a better fonts renderer // In a near future maybe we use a better fonts renderer
void drawStr(Painter & pain, short type, int siz, void drawStr(Painter & pain, short type, int siz,
int x, int y, string const & s) int x, int y, string const & s)
@ -629,7 +628,7 @@ MathStyles smallerStyleFrac(MathStyles st)
return st; return st;
} }
bool MathIsRelOp(byte c, MathTextCodes f) bool MathIsRelOp(unsigned char c, MathTextCodes f)
{ {
if (f == LM_TC_BOP && (c == '=' || c == '<' || c == '>')) if (f == LM_TC_BOP && (c == '=' || c == '<' || c == '>'))
return true; return true;

View File

@ -6,10 +6,6 @@
#include "lyxfont.h" #include "lyxfont.h"
#include "math_defs.h" #include "math_defs.h"
#ifndef byte
#define byte unsigned char
#endif
class Painter; class Painter;
class MathArray; class MathArray;
class MathMatrixInset; class MathMatrixInset;
@ -17,9 +13,11 @@ class MathMatrixInset;
extern char const * math_font_name[]; extern char const * math_font_name[];
extern char const * latex_mathspace[]; extern char const * latex_mathspace[];
int mathed_char_height(short type, int size, byte c, int & asc, int & des); int mathed_char_height(short type, int size, unsigned char c,
int mathed_char_width(short type, int size, byte c); int & asc, int & des);
void mathed_char_dim(short type, int size, byte c, int & asc, int & des, int & wid); int mathed_char_width(short type, int size, unsigned char c);
void mathed_char_dim(short type, int size, unsigned char c,
int & asc, int & des, int & wid);
void mathed_draw_deco(Painter & pain, int x, int y, int w, int h, int code); void mathed_draw_deco(Painter & pain, int x, int y, int w, int h, int code);
@ -34,9 +32,8 @@ int mathed_string_width(short type, int size, string const & s);
bool MathIsInset(short x); bool MathIsInset(short x);
bool MathIsAlphaFont(short x); bool MathIsAlphaFont(short x);
bool MathIsBOPS(short x); bool MathIsBOPS(short x);
bool MathIsBinary(short x);
bool MathIsSymbol(short x); bool MathIsSymbol(short x);
bool MathIsRelOp(byte c, MathTextCodes f); bool MathIsRelOp(unsigned char c, MathTextCodes f);
void drawStr(Painter & pain, short type, int siz, void drawStr(Painter & pain, short type, int siz,
int x, int y, string const & s); int x, int y, string const & s);