[Aptitude-svn-commit] r3435 - in branches/aptitude-0.3/aptitude: . src/vscreen

Daniel Burrows dburrows@costa.debian.org
Sat, 25 Jun 2005 21:10:01 +0000


Author: dburrows
Date: Sat Jun 25 21:09:59 2005
New Revision: 3435

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc
Log:
Handle wide characters when hard-wrapping.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sat Jun 25 21:09:59 2005
@@ -2,6 +2,11 @@
 
 	* src/vscreen/fragment.cc:
 
+	  Fix the fill algorithm to compile, and rewrite the hard-wrapping
+	  algorithm to handle wide characters.
+
+	* src/vscreen/fragment.cc:
+
 	  Rewrite the fill algorithm to handle wide characters.
 
 	* src/vscreen/fragment.cc:

Modified: branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc	Sat Jun 25 21:09:59 2005
@@ -627,14 +627,14 @@
 		fragment_line &word=words[word_start];
 		while(chars<word.size() && curwidth<firstw)
 		  {
-		    curwidth+=word[chars];
+		    curwidth+=wcwidth(word[chars].ch);
 		    ++chars;
 		  }
 
 		while(chars>0 && curwidth>firstw)
 		  {
 		    --chars;
-		    curwidth-=word[chars];
+		    curwidth-=wcwidth(word[chars].ch);
 		  }
 
 		if(chars==0)
@@ -759,16 +759,24 @@
 	    fragment_line s=*i;
 	    fragment_line::size_type start=0;
 
-	    while(s.size()-start>firstw)
+	    while(start<s.size())
 	      {
-		rval.push_back(fragment_line(s, start, firstw));
-		start+=firstw;
-		firstw=restw;
-	      }
+		size_t chars=0;
+		int width=0;
 
-	    if(start<s.size())
-	      {
-		rval.push_back(fragment_line(s, start));
+		while(width<(signed) firstw && chars<s.size())
+		  {
+		    width+=wcwidth(s[start+chars].ch);
+		    ++chars;
+		  }
+
+		// If we spilled over, it's the last character that's
+		// responsible.
+		if(width>(signed) firstw && chars>1)
+		  --chars;
+
+		rval.push_back(fragment_line(s, start, chars));
+		start+=chars;
 		firstw=restw;
 	      }
 	  }