]> git.lyx.org Git - features.git/commitdiff
Fix Angus' drawing bug + cosmetics
authorAndré Pönitz <poenitz@gmx.net>
Fri, 13 Jul 2001 11:32:22 +0000 (11:32 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 13 Jul 2001 11:32:22 +0000 (11:32 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2234 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/array.C
src/mathed/array.h
src/mathed/formula.C
src/mathed/formula.h
src/mathed/math_cursor.C
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/support.C
src/mathed/support.h

index afe0994684675a9555ae4ec930b24be36c59f9c7..4197abf417813238c631902e55af4f5645ad3b33 100644 (file)
@@ -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);
index 4e8a351974a020de690a1d1f346a0711f7948f77..5e17de0685bd39ad8f620537c85f112751011968 100644 (file)
@@ -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<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;
index 576769e17e0e74ad07c3ad5e67f80a487bd85cdf..61f0f9a66aabfc86c7baa04e19d734cbbb3ef4b8 100644 (file)
@@ -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<MathInset *>(par_)->Metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+}
+
 vector<string> 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();
 }
index 9a65ae5dee3fd0fa494bf0857264281ee44a0ef4..41f8bca78601985f930ee4c1344f25c9f4f9171d 100644 (file)
@@ -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;
index 51eeedf525eac21c0568fe42ea8135355639bfc5..442bb17eed43155f1ba6498d728f50da8b6d9618 100644 (file)
@@ -614,14 +614,10 @@ in_word_set(s) << " \n";
                                        break;
                                
                        case LM_TK_SYM: 
-                               if (l->id < 255) {
-                                       insert(static_cast<byte>(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:
index fece66cb1e4254640bb335f6c9004b88643b2ce6..e39af4dc2a2bde97fc4886938112080998ff0869 100644 (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())
                cells_.back().data_.push_back(ch, fcode);
index 91077fe5a08d14303e529960d1d5ec92d68b3886..bd1917c040ac37068032ba2bb4f2582e49112d7c 100644 (file)
@@ -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;
 
index cdac2c67c04cecc6c4453505eb09d5b5b1d2de74..4185742cd6f3c22b26e3ce404625c6f282f15c76 100644 (file)
@@ -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;
index cf9d4c78a6090e591a88183f3f2eeaca65d95778..9f4b811f9897ae8cb05ba805ca8d8ed49867e89b 100644 (file)
@@ -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);