]> git.lyx.org Git - features.git/blobdiff - src/mathed/math_delim.C
apply the ostream changes to mathed, some other small related things
[features.git] / src / mathed / math_delim.C
index acc7687bccf1d70f4a17af58a02b64ad0f32f7d8..9f09cb3511c7d5e4adc73c3023ae7df9000a9e02 100644 (file)
@@ -21,6 +21,8 @@
 #include <cstdlib>
 #include "symbol_def.h"
 #include "math_inset.h"
+#include "LColor.h"
+#include "Painter.h"
 
 /* 
  * Internal struct of a drawing: code n x1 y1 ... xn yn, where code is:
@@ -223,28 +225,28 @@ static struct math_deco_struct {
 };
 
 
-inline int odd(int x) { return ((x) & 1); }
+inline
+int odd(int x) { return ((x) & 1); }
 
 typedef float matriz_data[2][2];
 
-const matriz_data MATIDEN={ {1,0}, {0,1}};
+const matriz_data MATIDEN= { {1, 0}, {0, 1}};
 
-extern void mathed_set_font(short type, int style);
 extern int mathed_char_width(short type, int style, byte c);
-extern int mathed_char_height(short, int, byte, int&, int&);
+extern int mathed_char_height(short, int, byte, int &, int &);
 
-#define mateq(m1,m2)  memcpy(m1,m2,sizeof(matriz_data))
+#define mateq(m1, m2)  memcpy(m1, m2, sizeof(matriz_data))
 
 class Matriz {
  public: 
-   Matriz() { mateq(m,MATIDEN); }
+   Matriz() { mateq(m, MATIDEN); }
    void rota(int);
    void escala(float, float);
-   void transf(float, float, float&, float&);
+   void transf(float, float, float &, float &);
    
  protected:
    matriz_data m;
-   void matmat(matriz_data& a);
+   void matmat(matriz_data & a);
 };
 
 
@@ -253,7 +255,7 @@ void Matriz::rota(int code)
    float cs, sn;
    
    matriz_data r;
-   mateq(r,MATIDEN);
+   mateq(r, MATIDEN);
    cs = (odd(code)) ? 0: 1 - code;
    sn = (odd(code)) ? 2 - code: 0;
    r[0][0] = cs;         r[0][1] = sn;
@@ -264,127 +266,128 @@ void Matriz::rota(int code)
 void Matriz::escala(float x, float y)
 {
    matriz_data s;
-   mateq(s,MATIDEN);
+   mateq(s, MATIDEN);
    s[0][0] = x;  s[1][1] = y;
    matmat(s);
 }
 
 
-void Matriz::matmat(matriz_data& a)
+void Matriz::matmat(matriz_data & a)
 {
-   int i;
    matriz_data c;   
-   for (i=0;i<2; i++) {
-      c[0][i] = a[0][0]*m[0][i] + a[0][1]*m[1][i];
-      c[1][i] = a[1][0]*m[0][i] + a[1][1]*m[1][i];
+   for (int i = 0;i < 2; ++i) {
+      c[0][i] = a[0][0] * m[0][i] + a[0][1] * m[1][i];
+      c[1][i] = a[1][0] * m[0][i] + a[1][1] * m[1][i];
    }
    mateq(m, c);
 }
 
-void Matriz::transf(float xp, float yp, float &x, float &y)
+void Matriz::transf(float xp, float yp, float & x, float & y)
 {
-   x = m[0][0]*xp + m[0][1]*yp;
-   y = m[1][0]*xp + m[1][1]*yp;
+   x = m[0][0] * xp + m[0][1] * yp;
+   y = m[1][0] * xp + m[1][1] * yp;
 }
 
-extern GC latexGC, mathGC, mathLineGC, cursorGC;
 
-static int search_deco(int code)
+static
+int search_deco(int code)
 {
-   int i=0;
+   int i = 0;
    
-   while (math_deco_table[i].code &&  math_deco_table[i].code!=code) i++;
+   while (math_deco_table[i].code &&  math_deco_table[i].code != code) ++i;
    if (!math_deco_table[i].code) i = -1;
    return i;
 }
-      
-void mathed_draw_deco(Window win, 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)
 {
-   Matriz mt, sqmt;
-   XPoint p[32];
-   float *d, xx, yy, x2, y2;
-   int i=0,j, n, r;
+       Matriz mt, sqmt;
+       float xx, yy, x2, y2;
+       int i = 0;
    
-   j = search_deco(code);   
-   if (j<0) return;
+       int j = search_deco(code);   
+       if (j < 0) return;
    
-   r = math_deco_table[j].angle;
-   d = math_deco_table[j].data;
-   
-   if (h > 70 && (math_deco_table[j].code == (int) '(' || math_deco_table[j].code == (int) ')'))
-      d = parenthHigh;
-    
-   mt.rota(r);
-   mt.escala(w, h);
+       int r = math_deco_table[j].angle;
+       float * d = math_deco_table[j].data;
+       
+       if (h > 70 && (math_deco_table[j].code == int('(')
+                      || math_deco_table[j].code == int(')')))
+               d = parenthHigh;
+       
+       mt.rota(r);
+       mt.escala(w, h);
    
-   n = (w < h) ? w: h;
-   sqmt.rota(r);
-   sqmt.escala(n, n);
-   if (r> 0 && r< 3) y += h;   
-   if (r>=2) x += w;   
-   do {
-      code = (int)d[i++];
-      switch (code) {
-       case 0: break;
-       case 1: 
-       case 3:
-       {
-         xx = d[i++]; yy = d[i++];
-         x2 = d[i++]; y2 = d[i++];
-         if (code==3) 
-           sqmt.transf(xx, yy, xx, yy);
-         else
-           mt.transf(xx, yy, xx, yy);
-         mt.transf(x2, y2, x2, y2);
-         XDrawLine(fl_display, win, mathGC, x+(int)xx, y+(int)yy,
-                   x+(int)x2, y+(int)y2);
-         XFlush(fl_display);
-         break;
-       }        
-       case 2: 
-       case 4:
-       {
-         n = (int)d[i++];
-         for (j=0; j<n; j++) {
-            xx = d[i++]; yy = d[i++];
+       int n = (w < h) ? w: h;
+       sqmt.rota(r);
+       sqmt.escala(n, n);
+       if (r > 0 && r < 3) y += h;   
+       if (r >= 2) x += w;   
+       do {
+               code = int(d[i++]);
+               switch (code) {
+               case 0: break;
+               case 1: 
+               case 3:
+               {
+                       xx = d[i++]; yy = d[i++];
+                       x2 = d[i++]; y2 = d[i++];
+                       if (code == 3) 
+                               sqmt.transf(xx, yy, xx, yy);
+                       else
+                               mt.transf(xx, yy, xx, yy);
+                       mt.transf(x2, y2, x2, y2);
+                       pain.line(x + int(xx), y + int(yy),
+                                 x + int(x2), y + int(y2),
+                                 LColor::mathline);
+                       break;
+               }        
+               case 2: 
+               case 4:
+               {
+                       int xp[32], yp[32];
+                       n = int(d[i++]);
+                       for (j = 0; j < n; ++j) {
+                               xx = d[i++]; yy = d[i++];
 //          lyxerr << " " << xx << " " << yy << " ";
-            if (code==4) 
-              sqmt.transf(xx, yy, xx, yy);
-            else
-              mt.transf(xx, yy, xx, yy);
-            p[j].x = x+(int)xx;
-            p[j].y = y+(int)yy;
-            //  lyxerr << "P[" << j " " << xx << " " << yy << " " << x << " " << y << "]";
-         }
-         XDrawLines(fl_display, win, mathLineGC, p, n, CoordModeOrigin);
-         XFlush(fl_display);
-       }
-      }
-   } while (code);
+                               if (code == 4) 
+                                       sqmt.transf(xx, yy, xx, yy);
+                               else
+                                       mt.transf(xx, yy, xx, yy);
+                               xp[j] = x + int(xx);
+                               yp[j] = y + int(yy);
+                               //  lyxerr << "P[" << j " " << xx << " " << yy << " " << x << " " << y << "]";
+                       }
+                       pain.lines(xp, yp, n, LColor::mathline);
+               }
+               }
+       } while (code);
 }
 
+
 void
-MathDelimInset::Draw(int x, int y)
+MathDelimInset::draw(Painter & pain, int x, int y)
 { 
-   xo = x;  yo = y; 
-   MathParInset::Draw(x+dw+2, y-dh); 
-   //int h=Height(), hg=descent-1;  
-
-   if (left=='.') {
-     XDrawLine(fl_display, pm, cursorGC, x+4, yo-ascent, x+4, yo+descent);
-     XFlush(fl_display);
-   }
-   else
-     mathed_draw_deco(pm, x, y-ascent, dw, Height(), left);
-   x += Width()-dw-2;
-   if (right=='.') {
-     XDrawLine(fl_display, pm, cursorGC, x+4, yo-ascent, x+4, yo+descent);
-     XFlush(fl_display);
-   }
-   else
-     mathed_draw_deco(pm, x, y-ascent, dw, Height(), right);
+       xo = x;  yo = y; 
+       MathParInset::draw(pain, x + dw + 2, y - dh); 
+       
+       if (left == '.') {
+               pain.line(x + 4, yo - ascent,
+                         x + 4, yo + descent,
+                         LColor::mathcursor);
+       } else
+               mathed_draw_deco(pain, x, y - ascent, dw, Height(), left);
+       x += Width()-dw-2;
+       if (right == '.') {
+               pain.line(x + 4, yo - ascent,
+                         x + 4, yo + descent,
+                         LColor::mathcursor);
+       } else
+               mathed_draw_deco(pain, x, y-ascent, dw, Height(), right);
 }
 
+
 void
 MathDelimInset::Metrics()
 {
@@ -403,10 +406,10 @@ MathDelimInset::Metrics()
 
 
 void
-MathDecorationInset::Draw(int x, int y)
+MathDecorationInset::draw(Painter & pain, int x, int y)
 { 
-   MathParInset::Draw(x+(width-dw)/2, y);
-   mathed_draw_deco(pm, x, y+dy, width, dh, deco);
+   MathParInset::draw(pain, x + (width - dw) / 2, y);
+   mathed_draw_deco(pain, x, y + dy, width, dh, deco);
 }
 
 
@@ -431,30 +434,22 @@ MathDecorationInset::Metrics()
    width = w;
 }
 
+
 void
-MathAccentInset::Draw(int x, int y)
+MathAccentInset::draw(Painter & pain, int x, int y)
 {
-    int dw = width-2;
-/*    char s[8];
-    mathed_set_font(fn, size);
-    if (MathIsBinary(fn)) {
-       s[0] = s[2] = ' '; 
-       s[1] = (char)c;
-       ns = 3;
-       dw = mathed_char_width(fn, size, c);
-    } else
-      s[0] = (char)c;
-*/
+    int dw = width - 2;
+
     if (inset) {
-       inset->Draw(x, y);
+       inset->draw(pain, x, y);
     } else {
-       drawStr(fn, size, x, y, &c, 1);
-       XFlush(fl_display);
+       drawStr(pain, fn, size, x, y, &c, 1);
     }
-    x += (code==LM_not) ? (width-dw)/2: 2;
-    mathed_draw_deco(pm, x, y-dy, dw, dh, code);
+    x += (code == LM_not) ? (width-dw) / 2 : 2;
+    mathed_draw_deco(pain, x, y - dy, dw, dh, code);
 }
 
+
 void
 MathAccentInset::Metrics()
 {
@@ -470,7 +465,7 @@ MathAccentInset::Metrics()
        width = mathed_char_width(fn, size, c);
        dh = (width-2)/2; 
     }
-    if (code==LM_not) {
+    if (code == LM_not) {
        ascent += dh;
        descent += dh;
        dh = Height();
@@ -484,13 +479,14 @@ MathAccentInset::Metrics()
 
 
 void
-MathDotsInset::Draw(int x, int y)
+MathDotsInset::draw(Painter & pain, int x, int y)
 {
-   mathed_draw_deco(pm, x+2, y-dh, width-2, ascent, code);
-   if (code==LM_vdots||code==LM_ddots) x++; 
-   if (code!=LM_vdots) y--;
-   mathed_draw_deco(pm, x+2, y-dh, width-2, ascent, code);
-}     
+   mathed_draw_deco(pain, x + 2, y - dh, width - 2, ascent, code);
+   if (code == LM_vdots || code == LM_ddots) ++x; 
+   if (code != LM_vdots) --y;
+   mathed_draw_deco(pain, x + 2, y - dh, width - 2, ascent, code);
+}
+
 
 void
 MathDotsInset::Metrics()
@@ -500,7 +496,7 @@ MathDotsInset::Metrics()
    switch (code) {
     case LM_ldots: dh = 0; break;
     case LM_cdots: dh = ascent/2; break;
-    case LM_vdots: width /=2;
+    case LM_vdots: width /= 2;
     case LM_ddots: dh = ascent; break;
    }
 }