[Konsole-devel] [Bug 59162] Fixed width font alignment problems for Japanese (and other languages I suspect)

Waldo Bastian bastian at kde.org
Mon Jun 2 09:32:44 UTC 2003


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
     
http://bugs.kde.org/show_bug.cgi?id=59162     
bastian at kde.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From bastian at kde.org  2003-06-02 11:32 -------
Subject: kdebase/konsole/konsole

CVS commit by waba: 

CCMAIL: 59162-done at bugs.kde.org
* Fix the fixed-width with proportional-font drawing routine
* Always use it in the presence of double-width chars.
Thanks to Ken Deeter for his excellent analysis of the problem.


  M +37 -8     TEWidget.cpp   1.197


--- kdebase/konsole/konsole/TEWidget.cpp  #1.196:1.197
@@ -237,10 +237,9 @@ void TEWidget::fontChange(const QFont &)
   // "Base character width on widest ASCII character. This prevents too wide
   //  characters in the presence of double wide (e.g. Japanese) characters."
-  int fw;
   // Get the width from representative normal width characters
   font_w = qRound((double)fm.width(REPCHAR)/(double)strlen(REPCHAR));
 
   fixed_font = true;
-  fw = fm.width(REPCHAR[0]);
+  int fw = fm.width(REPCHAR[0]);
   for(unsigned int i=1; i< strlen(REPCHAR); i++){
     if (fw != fm.width(REPCHAR[i])){
@@ -456,9 +455,20 @@ void TEWidget::drawAttrStr(QPainter &pai
       // The meaning of y differs between different versions of QPainter::drawText!!
       int y = rect.y(); // top of rect
+      unsigned int nc=0;
+      int w;
       for(unsigned int i=0;i<str.length();i++)
       {
         drawstr = str.at(i);
         // Add double of the width if next c is 0;
-        int w = (attr+i+1)->c ? font_w : font_w * 2;
+        if ((attr+nc+1)->c)
+        {
+          w = font_w;
+          nc++;
+        }
+        else
+        {
+          w = font_w*2;
+          nc+=2;
+        }
         paint.drawText(x,y, w, font_h, Qt::AlignHCenter | Qt::DontClip, drawstr, -1);
         x += w;
@@ -495,9 +505,20 @@ void TEWidget::drawAttrStr(QPainter &pai
           // The meaning of y differs between different versions of QPainter::drawText!!
           int y = rect.y(); // top of rect
+          unsigned int nc=0;
+          int w;
           for(unsigned int i=0;i<str.length();i++)
           {
              drawstr = str.at(i);
              // Add double of the width if next c is 0;
-             int w = (attr+i+1)->c ? font_w : font_w * 2;
+            if ((attr+nc+1)->c)
+            {
+              w = font_w;
+              nc++;
+            }
+            else
+            {
+              w = font_w*2;
+              nc+=2;
+            }
              paint.drawText(x,y, w, font_h, Qt::AlignHCenter | Qt::DontClip, drawstr, -1);
              x += w;
@@ -610,5 +631,8 @@ HCNT("setImage");
           c = ext[x+len].c;
           if (!c)
+          {
+            fixed_font = false;
             continue; // Skip trailing part of multi-col chars.
+          }
 
           if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr ||
@@ -790,8 +814,13 @@ void TEWidget::paintContents(QPainter &p
         if (c)
           disstrU[p++] = fontMap(c);
+        else
+          fixed_font = false;
         len++;
       }
       if ((x+len < columns) && (!image[loc(x+len,y)].c))
+      {
+        fixed_font = false;
         len++; // Adjust for trailing part of multi-column char
+      }
 
       if (!isBlinkEvent || (cr & RE_BLINK))


More information about the konsole-devel mailing list