Summary: | Fixed width font alignment problems for Japanese (and other languages I suspect) | ||
---|---|---|---|
Product: | [Applications] konsole | Reporter: | Ken Deeter <ktdeeter> |
Component: | general | Assignee: | Konsole Developer <konsole-devel> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Gentoo Packages | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
Ken Deeter
2003-05-31 04:56:40 UTC
btw, I'm also on the konsole-devel list, so please feel free to ask me anything if clarifcation is needed. Subject: Re: [Konsole-devel] Fixed width font alignment problems for Japanese (and other languages I suspect) Does it help if you change fixed_font = true; to fixed_font = false; in TEWidget::fontChange(), in kdebase/konsole/konsole/TEWidget.cpp ? Cheers, Waldo I don't have a quick way to test this right now. I'm assuming this will let me choose a properly spaced japanese font in the font dialog? Won't this allow people to potentially choose proportional western fonts though? Subject: kdebase/konsole/konsole CVS commit by waba: CCMAIL: 59162-done@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)) Is there a reason why the same code happens in two separate places? Seems like we should isolate the rendering part in a separate inline function, to improve readability and also to make it easier for newcomers to read the code (It took me a bit to figure out the same rendering code was happening in two separate places). |