From: André Pönitz Date: Fri, 13 Jul 2001 11:32:22 +0000 (+0000) Subject: Fix Angus' drawing bug + cosmetics X-Git-Tag: 1.6.10~21088 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=747cd76667425cffcfa55e3be5bcff3f2bbbd451;p=features.git Fix Angus' drawing bug + cosmetics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2234 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/array.C b/src/mathed/array.C index afe0994684..4197abf417 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -106,7 +106,7 @@ MathInset * MathArray::prevInset(int pos) const return nextInset(pos); } -byte MathArray::GetChar(int pos) const +unsigned char MathArray::GetChar(int pos) const { 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)); } -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_[pos + 1] = b; @@ -172,7 +172,7 @@ void MathArray::push_back(MathInset * 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); } @@ -284,7 +284,7 @@ void MathArray::Write(ostream & os, bool fragile) const } else { MathTextCodes fcode = GetCode(pos); - byte c = GetChar(pos); + unsigned char c = GetChar(pos); if (MathIsSymbol(fcode)) { latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM); diff --git a/src/mathed/array.h b/src/mathed/array.h index 4e8a351974..5e17de0685 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -62,7 +62,7 @@ public: /// 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 &); @@ -83,7 +83,7 @@ public: /// void push_back(MathInset * inset); /// - void push_back(byte, MathTextCodes); + void push_back(unsigned char, MathTextCodes); /// void push_back(MathArray const &); /// @@ -102,7 +102,7 @@ public: /// MathInset * prevInset(int pos) const; /// - byte GetChar(int pos) const; + unsigned char GetChar(int pos) const; /// read subsequent chars of the same kind. // pos is afterwards one behind the last char belonging to the string string GetString(int & pos) const; @@ -118,9 +118,9 @@ public: void WriteNormal(std::ostream &) const; private: /// - typedef std::vector buffer_type; + typedef std::vector buffer_type; /// - typedef byte value_type; + typedef unsigned char value_type; /// int item_size(int pos) const; diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 576769e17e..61f0f9a66a 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -69,6 +69,7 @@ InsetFormula::InsetFormula(string const & s) { istringstream is(s.c_str()); par(mathed_parse(is)); + Metrics(); } @@ -114,6 +115,7 @@ int InsetFormula::docBook(ostream & os) const void InsetFormula::read(LyXLex & 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); if (mathcursor) { - par()->Metrics(LM_ST_TEXT); + Metrics(); if (mathcursor->formula() == this) { if (mathcursor->Selection()) { @@ -152,6 +154,11 @@ void InsetFormula::draw(BufferView * bv, LyXFont const &, } +void InsetFormula::Metrics() const +{ + const_cast(par_)->Metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT); +} + vector const InsetFormula::getLabelList() const { return par()->getLabelList(); @@ -295,6 +302,7 @@ void InsetFormula::handleExtern(const string & arg, BufferView *) ifstream is(outfile.c_str()); par(mathed_parse(is)); + Metrics(); } bool InsetFormula::display() const @@ -329,7 +337,7 @@ void InsetFormula::validate(LaTeXFeatures & features) 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 { - par()->Metrics(LM_ST_TEXT); return par()->width(); } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 9a65ae5dee..41f8bca786 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -43,6 +43,8 @@ public: int width(BufferView *, LyXFont const &) const; /// void draw(BufferView *, LyXFont const &, int, float &, bool) const; + /// + void Metrics() const; /// void write(std::ostream &) const; diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 51eeedf525..442bb17eed 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -614,14 +614,10 @@ in_word_set(s) << " \n"; break; case LM_TK_SYM: - if (l->id < 255) { - insert(static_cast(l->id), - MathIsBOPS(l->id) ? - LM_TC_BOPS : LM_TC_SYMB); - - } else { + if (l->id < 255) + insert(l->id, MathIsBOPS(l->id) ? LM_TC_BOPS : LM_TC_SYMB); + else p = new MathFuncInset(l->name); - } break; case LM_TK_STACK: diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index fece66cb1e..e39af4dc2a 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -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()) cells_.back().data_.push_back(ch, fcode); diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 91077fe5a0..bd1917c040 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -182,7 +182,7 @@ public: /// void push_back(MathInset *); /// - void push_back(byte ch, MathTextCodes fcode); + void push_back(unsigned char ch, MathTextCodes fcode); /// void dump() const; diff --git a/src/mathed/support.C b/src/mathed/support.C index cdac2c67c0..4185742cd6 100644 --- a/src/mathed/support.C +++ b/src/mathed/support.C @@ -17,6 +17,38 @@ using std::lower_bound; using std::endl; 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 { public: @@ -375,7 +407,8 @@ static init_deco_table idt; } // 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); 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); } -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); 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)) { 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 void drawStr(Painter & pain, short type, int siz, int x, int y, string const & s) @@ -629,7 +628,7 @@ MathStyles smallerStyleFrac(MathStyles st) return st; } -bool MathIsRelOp(byte c, MathTextCodes f) +bool MathIsRelOp(unsigned char c, MathTextCodes f) { if (f == LM_TC_BOP && (c == '=' || c == '<' || c == '>')) return true; diff --git a/src/mathed/support.h b/src/mathed/support.h index cf9d4c78a6..9f4b811f98 100644 --- a/src/mathed/support.h +++ b/src/mathed/support.h @@ -6,10 +6,6 @@ #include "lyxfont.h" #include "math_defs.h" -#ifndef byte -#define byte unsigned char -#endif - class Painter; class MathArray; class MathMatrixInset; @@ -17,9 +13,11 @@ class MathMatrixInset; extern char const * math_font_name[]; extern char const * latex_mathspace[]; -int mathed_char_height(short type, int size, byte c, int & asc, int & des); -int mathed_char_width(short type, int size, byte c); -void mathed_char_dim(short type, int size, byte c, int & asc, int & des, int & wid); +int mathed_char_height(short type, int size, unsigned char c, + int & asc, int & des); +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); @@ -34,9 +32,8 @@ int mathed_string_width(short type, int size, string const & s); bool MathIsInset(short x); bool MathIsAlphaFont(short x); bool MathIsBOPS(short x); -bool MathIsBinary(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, int x, int y, string const & s);