? font.diff
Index: konsole/TEWidget.cpp
===================================================================
RCS file: /home/kde/kdebase/konsole/konsole/TEWidget.cpp,v
retrieving revision 1.219
diff -u -6 -p -r1.219 TEWidget.cpp
--- konsole/TEWidget.cpp	20 Dec 2004 13:38:32 -0000	1.219
+++ konsole/TEWidget.cpp	24 Jan 2005 18:47:06 -0000
@@ -203,12 +203,13 @@ unsigned short vt100_graphics[32] =
   0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,
   0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,
   0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534,
   0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7
 };
 
+
 /*
 static QChar vt100extended(QChar c)
 {
   switch (c.unicode())
   {
     case 0x25c6 : return  1;
@@ -266,15 +267,27 @@ void TEWidget::fontChange(const QFont &)
   fixed_font = true;
   int fw = fm.width(REPCHAR[0]);
   for(unsigned int i=1; i< strlen(REPCHAR); i++){
     if (fw != fm.width(REPCHAR[i])){
       fixed_font = false;
       break;
-    } else
-      fw = fm.width(REPCHAR[i]);
+    }
+  }
+  
+  //Also check the width of the line drawing chars. May fonts
+  //that have ASCII fixed don't have those the same width for the VT chars
+  //(Vera Sans Mono is a complex example)
+  //if that happens, we will have to emulate them, and fallback to manual 
+  //grid management
+  for(unsigned int i=0; i < 32; i++){
+      if (fw != fm.width(vt100_graphics[i])) {
+          fixed_font = false;
+          break;
+      }
   }
+  
 
   if (font_w>200) // don't trust unrealistic value, fallback to QFontMetrics::maxWidth()
     font_w=fm.maxWidth();
   if (font_w<1)
     font_w=1;
 
@@ -423,12 +436,198 @@ TEWidget::~TEWidget()
 /* ------------------------------------------------------------------------- */
 /*                                                                           */
 /*                             Display Operations                            */
 /*                                                                           */
 /* ------------------------------------------------------------------------- */
 
+/**
+ A table for emulating the simple (single width) unicode drawing chars.
+ It represents the 250x - 257x glyphs. If it's zero, we can't use it.
+ if it's not, the bits represent the 4 possible lines: top, bottom, left, right
+ */
+enum LineEncode
+{
+    Top   = 1,
+    Bot   = 2,
+    Left  = 4,
+    Right = 8
+};
+
+static uchar LineChars[128] =
+{
+    //250x
+  Left | Right, //0
+  0,            //1
+  Top  | Bot,   //2
+  0,            //3
+  0,            //4
+  0,            //5
+  0,            //6
+  0,            //7
+  0,            //8
+  0,            //9
+  0,            //A
+  0,            //B
+  Bot  | Right, //C
+  0,            //D
+  0,            //E
+  0,            //F
+  
+  //251x
+  Left | Bot,   //0
+  0,            //1
+  0,            //2
+  0,            //3
+  Right | Top,  //4
+  0,            //5
+  0,            //6
+  0,            //7
+  Left | Top,   //8
+  0,            //9
+  0,            //A
+  0,            //B
+  Top | Bot |Right, //C
+  0,            //D
+  0,            //E
+  0,            //F
+  
+  //252x
+  0,            //0
+  0,            //1
+  0,            //2
+  0,            //3
+  Left|Top|Bot, //4
+  0,            //5
+  0,            //6
+  0,            //7
+  0,            //8
+  0,            //9
+  0,            //A
+  0,            //B
+  Left|Right|Bot,//C
+  0,            //D
+  0,            //E
+  0,            //F
+  
+  //253x
+  0,            //0
+  0,            //1
+  0,            //2
+  0,            //3
+  Left|Right|Top,//4
+  0,            //5
+  0,            //6
+  0,            //7
+  0,            //8
+  0,            //9
+  0,            //A
+  0,            //B
+  Left|Right|Top|Bot, //C
+  0,            //D
+  0,            //E
+  0,            //F
+
+  //254x
+  0,            //0
+  0,            //1
+  0,            //2
+  0,            //3
+  0,            //4
+  0,            //5
+  0,            //6
+  0,            //7
+  0,            //8
+  0,            //9
+  0,            //A
+  0,            //B
+  0,            //C
+  0,            //D
+  0,            //E
+  0,            //F
+  
+  //255x
+  0,            //0
+  0,            //1
+  0,            //2
+  0,            //3
+  0,            //4
+  0,            //5
+  0,            //6
+  0,            //7
+  0,            //8
+  0,            //9
+  0,            //A
+  0,            //B
+  0,            //C
+  0,            //D
+  0,            //E
+  0,            //F
+
+  //256x
+  0,            //0
+  0,            //1
+  0,            //2
+  0,            //3
+  0,            //4
+  0,            //5
+  0,            //6
+  0,            //7
+  0,            //8
+  0,            //9
+  0,            //A
+  0,            //B
+  0,            //C
+  0,            //D
+  0,            //E
+  0,            //F
+
+  //257x
+  0,            //0
+  0,            //1
+  0,            //2
+  0,            //3
+  Left,         //4
+  Top,          //5
+  Right,        //6
+  Bot,          //7
+  0,            //8
+  0,            //9
+  0,            //A
+  0,            //B
+  0,            //C
+  0,            //D
+  0,            //E
+  0             //F
+};
+
+static void drawLineChar(QPainter& paint, int x, int y, int w, int h, uchar code)
+{
+    //Calculate cell midpoints, end points.
+    int cx = x + w/2;
+    int cy = y + h/2;
+    int ex = x + w - 1;
+    int ey = y + h - 1;
+    
+    /*
+    paint.save();
+    paint.setPen(Qt::yellow);
+    paint.drawRect(x, y, w, h);
+    paint.restore();
+    */
+    
+    uchar toDraw = LineChars[code];
+    if (toDraw & Left)
+        paint.drawLine(x, cy, cx, cy);
+    if (toDraw & Right)
+        paint.drawLine(cx, cy, ex, cy);
+    if (toDraw & Top)
+        paint.drawLine(cx, y, cx, cy);
+    if (toDraw & Bot)
+        paint.drawLine(cx, cy, cx, ey);
+}
+
 void TEWidget::drawTextFixed(QPainter &paint, int x, int y,
                              QString& str, const ca *attr)
 {
   QString drawstr;
   unsigned int nc=0;
   int w;
@@ -443,12 +642,25 @@ void TEWidget::drawTextFixed(QPainter &p
     }
     else
     {
       w = font_w*2;
       nc+=2;
     }
+    
+    //Check for line-drawing char
+    if ((drawstr[0].unicode() & 0xFF80) == 0x2500)
+    {
+        uchar code = drawstr[0].cell();
+        if (LineChars[code])
+        {
+            drawLineChar(paint, x, y, w, font_h, code);
+            x += w;
+            continue;
+        }
+    }
+    
     paint.drawText(x,y, w, font_h, Qt::AlignHCenter | Qt::DontClip, drawstr, -1);
     x += w;
   }
 }
 
 
@@ -462,13 +674,13 @@ void TEWidget::drawAttrStr(QPainter &pai
   int a = font_a + m_lineSpacing / 2;
   QColor fColor = printerFriendly ? Qt::black : color_table[attr->f].color;
   QString drawstr;
 
   if ((attr->r & RE_CURSOR) && !isPrinting)
     cursorRect = rect;
-
+  
   // Paint background
   if (!printerFriendly)
   {
     if (color_table[attr->b].transparent)
     {
       if (pm)
