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

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


Author: dburrows
Date: Sat Jun 25 21:02:08 2005
New Revision: 3434

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

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sat Jun 25 21:02:08 2005
@@ -2,6 +2,10 @@
 
 	* src/vscreen/fragment.cc:
 
+	  Rewrite the fill algorithm to handle wide characters.
+
+	* src/vscreen/fragment.cc:
+
 	  Rewrite the main flow algorithm to handle wide characters (i.e.,
 	  separate the concepts of "visible width" and "character count").
 

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:02:08 2005
@@ -563,6 +563,11 @@
   fragment_contents layout(size_t firstw, size_t restw,
 			   const style &st)
   {
+    // As far as I know, this is valid everywhere...but it would be
+    // rather tricky to write this algorithm without making this
+    // assumption.
+    assert(wcwidth(L' ')==1);
+
     if(restw==0)
       return fragment_contents();
 
@@ -609,17 +614,34 @@
 	    // As long as adding the *next* word doesn't put us
 	    // past the right edge, add it.
 	    while(word_start+nwords < words.size() &&
-		  curwidth+words[word_start+nwords].size()+nwords <= firstw)
+		  curwidth+words[word_start+nwords].width()+nwords <= firstw)
 	      {
-		curwidth=curwidth+words[word_start+nwords].size();
+		curwidth+=words[word_start+nwords].width();
 		++nwords;
 	      }
 
 	    if(nwords==0)
 	      {
 		// Split a single word: just chop the beginning off.
-		rval.push_back(fragment_line(words[word_start], 0, firstw));
-		words[word_start]=fragment_line(words[word_start], firstw);
+		size_t chars=0;
+		fragment_line &word=words[word_start];
+		while(chars<word.size() && curwidth<firstw)
+		  {
+		    curwidth+=word[chars];
+		    ++chars;
+		  }
+
+		while(chars>0 && curwidth>firstw)
+		  {
+		    --chars;
+		    curwidth-=word[chars];
+		  }
+
+		if(chars==0)
+		  chars=1;
+
+		rval.push_back(fragment_line(words[word_start], 0, chars));
+		words[word_start]=fragment_line(words[word_start], chars);
 		firstw=restw;
 		output_something=true;
 	      }
@@ -630,7 +652,7 @@
 		if(word_start+nwords<words.size())
 		  diff=firstw-(curwidth+nwords-1);
 		else
-		  // Cheat to disable fililng on the last line of the
+		  // Cheat to disable filling on the last line of the
 		  // paragraph.
 		  diff=0;