]> git.lyx.org Git - lyx.git/commitdiff
the remove reinterpret_cast patch from Andre Poenitz
authorLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 8 Feb 2001 15:09:15 +0000 (15:09 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 8 Feb 2001 15:09:15 +0000 (15:09 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1463 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/formula.C
src/mathed/math_defs.h
src/mathed/math_delim.C
src/mathed/math_draw.C
src/mathed/math_iter.C
src/mathed/math_iter.h
src/mathed/math_macro.C
src/mathed/math_write.C

index 904a48b660c235d2f97886055c768060f1d1264f..d1d07033969247c6357d7ac9a21d822dc755ee1f 100644 (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>
 
        * math_parser.C (mathed_parse): I'm sure Lars has a better fix than
index 4c31c53b2a47148e1f55bf7179e238a6081fec91..ac6d2aa7529056db80c60e48afd7bb7b2863d589 100644 (file)
@@ -197,55 +197,44 @@ 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;
        if (MathIsBinary(type))
-               for (int i = 0; i < ls; ++i) {
+               for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
                        st += ' ';
-                       st += s[i];
+                       st += *it;
                        st += ' ';
                }
        else
-               st = string(reinterpret_cast<char const *>(s), ls);
+               st = s;
 
        LyXFont const f = WhichFont(type, size);
        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 t = (MathIsBinary(type)) ? mathed_string_width(type, size, &c, 1) :
-           lyxfont::width(c, WhichFont(type, size));
-    return t;
-}
-
-
-int mathed_string_height(short type, int size, byte const * s,
-                        int ls, int & asc, int & des)
-{
-   LyXFont font = WhichFont(type, size);
-   asc = des = 0;
-   for (int i = 0; i < ls; ++i) {
-      des = max(des, lyxfont::descent(s[i], font));
-      asc = max(asc, lyxfont::ascent(s[i], font));
-   }
-   return asc + des;
+       if (MathIsBinary(type)) {
+               string s;
+               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, string const & str,
+int mathed_string_height(short type, int size, string const & s,
                         int & asc, int & des)
 {
-       return mathed_string_height(type, size,
-                                   reinterpret_cast<unsigned char const *>(str.c_str()), str.length(),
-                                   asc, des);
+       LyXFont font = WhichFont(type, size);
+       asc = des = 0;
+       for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
+               des = max(des, lyxfont::descent(*it, font));
+               asc = max(asc, lyxfont::ascent(*it, font));
+       }
+       return asc + des;
 }
 
 
@@ -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
 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;
        if (MathIsBinary(type))
-               for (int i = 0; i < ls; ++i) {
+               for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
                        st += ' ';
-                       st += char(s[i]);
+                       st += *it;
                        st += ' ';
                }
        else
-               st = string(reinterpret_cast<char const *>(s), ls);
+               st = s;
 
        LyXFont const mf = mathed_get_font(type, siz);
        pain.text(x, y, st, mf);
index 06c997773ba85b078fccb359ae44a01041f2a782..10e49d0e53926191d6f99e9c599063ac515d3cc3 100644 (file)
@@ -279,7 +279,7 @@ class MathedInset  {
     ///
     static int df_width;
     /// 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;
     ///
index be58ebd343e0bcefeef05038fb0d7529d739e08d..55bd9dbeb16439b0be774eaa8c2bbde7946267d7 100644 (file)
@@ -527,15 +527,17 @@ MathDecorationInset::Metrics()
 void
 MathAccentInset::draw(Painter & pain, int x, int y)
 {
-    int dw = width - 2;
-
-    if (inset) {
-       inset->draw(pain, x, y);
-    } else {
-       drawStr(pain, fn, size, x, y, &c, 1);
-    }
-    x += (code == LM_not) ? (width-dw) / 2 : 2;
-    mathed_draw_deco(pain, x, y - dy, dw, dh, code);
+       int dw = width - 2;
+
+       if (inset) 
+               inset->draw(pain, x, y);
+       else {
+               string s;
+               s += c;
+               drawStr(pain, fn, size, x, y, s);
+       }
+       x += (code == LM_not) ? (width-dw) / 2 : 2;
+       mathed_draw_deco(pain, x, y - dy, dw, dh, code);
 }
 
 
index 620bf06b528756409c7e2dd33d43461c000d35b1..8aab09c1e707899c78fa23366ae8ab6c6076e791 100644 (file)
@@ -54,86 +54,89 @@ MathSpaceInset::draw(Painter & pain, int x, int y)
 void 
 MathParInset::draw(Painter & pain, int x, int y)
 {
-   byte cx, cxp = 0;
-   int xp = 0, ls;
-   int asc = df_asc, des = 0;
-   bool limits = false;
-    
-   xo = x;  yo = y; 
-   if (!array || array->empty()) {
-       if (array) {
-          MathedXIter data(this);
-          data.GetPos(x, y);
-       }
-       pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
-      return;
-   }  
-   MathedXIter data(this);
-   data.GoBegin();
-   while (data.OK()) {
-      data.GetPos(x, y);
-      cx = data.GetChar();
-      if (cx >= ' ') {
-        byte * s = data.GetString(ls);
-         drawStr(pain, data.FCode(), size, x, y, s, ls);
-         mathed_char_height(LM_TC_CONST, size, 'y', asc, des);
-         limits = false;
-      } else {
-         if (cx == 0) break;
-        if (MathIsInset(cx)) {
-           int yy = y;
-           MathedInset * p = data.GetInset();
-           if (cx == LM_TC_UP) {
-              if (limits) {              x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;  
-                 yy -= (asc + p->Descent()+4);
-              } else
-                 yy -= (p->Descent()>asc) ? p->Descent()+4: asc;
-           } else
-           if (cx == LM_TC_DOWN) {
-              if (limits) {
-                 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
-                 yy += des + p->Ascent() + 2;
-              } else
-                yy += des + p->Ascent()/2;
-           } else {
-              asc = p->Ascent();
-              des = p->Descent();
-           }
-           p->draw(pain, x, yy);
-           if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) {
-              limits = p->GetLimits();
-              if (limits) xp = p->Width();
-           }
-           data.Next();
-        } else 
-          if (cx == LM_TC_TAB) {
-              if ((cxp == cx || cxp == LM_TC_CR || data.IsFirst())) { // && objtype == L
-                      pain.rectangle(x, y - df_asc, df_width, df_asc,
-                                     LColor::mathline);
-              }
-             data.Next();
-             limits = false;
-          } else
-           if (cx == LM_TC_CR) {
-               if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) { //  && objtype == LM_OT_MATRIX) {
-                       pain.rectangle(x, y - df_asc, df_width, df_asc,
-                                      LColor::mathline);
+       byte cxp = 0;
+       int xp = 0;
+       int asc = df_asc, des = 0;
+       bool limits = false;
+
+       xo = x;  yo = y; 
+       if (!array || array->empty()) {
+               if (array) {
+                       MathedXIter data(this);
+                       data.GetPos(x, y);
                }
-               data.Next();
-               limits = false;
-           }
-        else {  
-                lyxerr << "GMathed Error: Unrecognized code[" << cx
-                       << "]" << endl;
-           break;
-        }
-      }
-      cxp = cx;
-   }
-   if (cxp == LM_TC_TAB || cxp == LM_TC_CR) { // && objtype == LM_OT_MATRIX) {
-      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);
+               return;
+       }  
+       MathedXIter data(this);
+       data.GoBegin();
+       while (data.OK()) {
+               data.GetPos(x, y);
+               byte cx = data.GetChar();
+               if (cx >= ' ') {
+                       string s = data.GetString();
+                       drawStr(pain, data.FCode(), size, x, y, s);
+                       mathed_char_height(LM_TC_CONST, size, 'y', asc, des);
+                       limits = false;
+               }
+               else {
+                       if (cx == 0)
+                               break;
+                       if (MathIsInset(cx)) {
+                               int yy = y;
+                               MathedInset * p = data.GetInset();
+                               if (cx == LM_TC_UP) {
+                                       if (limits) {
+                                               x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;  
+                                               yy -= (asc + p->Descent()+4);
+                                       }       
+                                       else
+                                               yy -= (p->Descent()>asc) ? p->Descent()+4: asc;
+                               }
+                               else if (cx == LM_TC_DOWN) {
+                                       if (limits) {
+                                               x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
+                                               yy += des + p->Ascent() + 2;
+                                       } else
+                                               yy += des + p->Ascent()/2;
+                               }
+                               else {
+                                       asc = p->Ascent();
+                                       des = p->Descent();
+                               }
+                               p->draw(pain, x, yy);
+                               if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) {
+                                       limits = p->GetLimits();
+                                       if (limits)
+                                               xp = p->Width();
+                               }
+                               data.Next();
+                       }
+                       else if (cx == LM_TC_TAB) {
+                               if (cxp == cx || cxp == LM_TC_CR || data.IsFirst()) {
+                                       pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
+                               }
+                               data.Next();
+                               limits = false;
+                       }
+                       else if (cx == LM_TC_CR) {
+                               if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) {
+                                       pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
+                               }
+                               data.Next();
+                               limits = false;
+                       }
+                       else {   
+                               lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
+                               break;
+                       }
+               }
+               cxp = cx;
+       }
+       if (cxp == LM_TC_TAB || cxp == LM_TC_CR) { 
+               data.GetPos(x, y);
+               pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
+       }
 }
 
 
index 5b7d4bc1e6b73d25dcdae430eb2a5536a9890fb8..0a1bff2d1755cf40a945772fcbcf2e114fcc8b10 100644 (file)
@@ -32,7 +32,7 @@ using std::endl;
 const int SizeInset = sizeof(char*) + 2;
 
 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 &);
 
 // the builtin memcpy() is broken in egcs and gcc 2.95.x on alpha
@@ -73,27 +73,18 @@ byte MathedIter::GetChar() const
 }
 
 
-byte * MathedIter::GetString(int & len) const
-{
-    if (IsFont()) { 
-       fcode = array->bf[++pos];
-       ++pos;
-    }
-    byte * s = &array->bf[pos];
-    len = pos;
-    while (array->bf[pos] >= ' ' && pos < array->last) ++pos;
-    len = pos - len;
-   
-   return s;
-}
-
 string const MathedIter::GetString() const
 {
-       int ls = 0;
-       byte const * s = GetString(ls);
-       return string(reinterpret_cast<char const *>(s), ls);
-}
+       if (IsFont()) { 
+               fcode = array->bf[++pos];
+               ++pos;
+       }
+       string s;
+       for ( ; array->bf[pos] >= ' ' && pos < array->last; ++pos)
+               s += array->bf[pos];
 
+       return s;
+}
        
 MathedInset * MathedIter::GetInset() const
 {
@@ -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
 {
-       int ls;
-       byte const * s = GetString(ls);
-       return string(reinterpret_cast<char const *>(s), ls);
+       string s = MathedIter::GetString();
+       x += mathed_string_width(fcode, size, s);
+       return s;
 }
 
 
index 48e8f571215152732eec5c3cfa24ddf360e6c585..c6e89231f68e4dde4c9532001288c38df6ad84ad 100644 (file)
@@ -68,8 +68,6 @@ class MathedIter {
     ///
     byte GetChar() const;
     ///
-    byte * GetString(int & len) const;
-    ///
     string const GetString() const;
     ///
     MathedInset * GetInset() const;
index 2ddc24d13de846a5f4b7338648cc55ac955e1343..e0e77fffe41eff684b7b4c6ed2d709e622f54989 100644 (file)
@@ -49,8 +49,8 @@ ostream & operator<<(ostream & o, MathedMacroFlag mmf)
        return o << int(mmf);
 }
 
-extern int mathed_string_width(short type, int style, byte const* s, int ls);
-extern int mathed_string_height(short, int, byte const*, int, int&, int&);
+extern int mathed_string_width(short type, int style, string const & s);
+extern int mathed_string_height(short, int, string const &, int &, int &);
 
 
 MathMacro::MathMacro(MathMacroTemplate* t): 
@@ -216,30 +216,28 @@ MathMacroArgument::MathMacroArgument(int n)
 
 void MathMacroArgument::draw(Painter & pain, int x, int baseline)
 {
-    if (expnd_mode) {
-       MathParInset::draw(pain, x, baseline);
-    } else {
-           std::ostringstream ost;
-           ost << '#' << number;
-           drawStr(pain, LM_TC_TEX, size, x, baseline, 
-                   reinterpret_cast<byte const *>(ost.str().c_str()), 2);
-    }
+       if (expnd_mode) {
+               MathParInset::draw(pain, x, baseline);
+       }
+       else {
+               std::ostringstream ost;
+               ost << '#' << number;
+               drawStr(pain, LM_TC_TEX, size, x, baseline, ost.str());
+       }
 }
 
 
 void MathMacroArgument::Metrics()
 {
-    if (expnd_mode) {
-       MathParInset::Metrics();
-    } else {
-           std::ostringstream ost;
-           ost << '#' << number;
-           width = mathed_string_width(LM_TC_TEX, size, 
-                                       reinterpret_cast<byte const *>(ost.str().c_str()), 2);
-           mathed_string_height(LM_TC_TEX, size,
-                                reinterpret_cast<byte const *>(ost.str().c_str()), 
-                                2, ascent, descent);
-    }
+       if (expnd_mode) {
+               MathParInset::Metrics();
+       }
+       else {
+               std::ostringstream ost;
+               ost << '#' << number;
+               width = mathed_string_width(LM_TC_TEX, size, ost.str());
+               mathed_string_height(LM_TC_TEX, size, ost.str(), ascent, descent);
+       }
 }
 
 
index c212f1a7facb2c5f1caee4b3f92ad13327338959..e0e436924d1a61368db086706b78855a2143ef08 100644 (file)
@@ -192,38 +192,39 @@ void MathParInset::Write(ostream & os, bool fragile)
        while (data.OK()) {
                byte cx = data.GetChar();
                if (cx >= ' ') {
-                       int ls;
-                       byte * s = data.GetString(ls);
+                       string str = data.GetString();
                        
                        if (data.FCode() >= LM_TC_RM && data.FCode() <= LM_TC_TEXTRM) {
                                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())) {
-                                       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);
                                        if (l) {
                                                os << '\\' << l->name << ' ';
-                                       } else { 
-                                               lyxerr << "Illegal symbol code[" << *s
-                                                      << " " << ls << " " << data.FCode() << "]";
+                                       } else {
+#warning This does not compile (Lgb)
+                                               //lyxerr << "Illegal symbol code[" << c
+                                               //     << " " << str.end() - s << " " << data.FCode() << "]";
                                        }
                                } else {
                                        // 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))
                                                os << '\\';
                                        else {
-                                               if (*s == '{') ++brace;
-                                               if (*s == '}') --brace;
+                                               if (c == '{') ++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."
                                                       << endl;
                                        else           
-                                               os << char(*s);
+                                               os << char(c);
                                }
-                               ++s; --ls;
                        }
                        if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM)
                                os << '}';