[793] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r797 - branches/barnowl_unicode/owl

daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:09:47 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Fri,  4 Jan 2008 14:31:56 -0500 (EST)

Author: asedeno
Date: 2008-01-04 14:31:55 -0500 (Fri, 04 Jan 2008)
New Revision: 797

Modified:
   branches/barnowl_unicode/owl/fmtext.c
   branches/barnowl_unicode/owl/message.c
Log:
unicode/glib branch
* Rework some logic in fmtext's column truncating code.
* fix what appears to be an off-by-one error, though I can't explain why
  it never manifested in trunk.


Modified: branches/barnowl_unicode/owl/fmtext.c
===================================================================
--- branches/barnowl_unicode/owl/fmtext.c	2008-01-03 03:51:28 UTC (rev 796)
+++ branches/barnowl_unicode/owl/fmtext.c	2008-01-04 19:31:55 UTC (rev 797)
@@ -398,7 +398,10 @@
 /* Truncate the message so that each line begins at column 'acol' and
  * ends at 'bcol' or sooner.  The first column is number 0.  The new
  * message is placed in 'out'.  The message is * expected to end in a
- * new line for now
+ * new line for now. NOTE: This needs to be modified to deal with
+ * backing up if we find a SPACING COMBINING MARK at the end of a
+ * line. If that happens, we should back up to the last non-mark
+ * character and stop there.
  */
 void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
 {
@@ -425,13 +428,12 @@
     padding = 0;
     chwidth = 0;
     ptr_c = ptr_s;
-    while(col <= bcol && ptr_c < ptr_e) {
+    while(ptr_c < ptr_e) {
       gunichar c = g_utf8_get_char(ptr_c);
       if (!_owl_fmtext_is_format_char(c)) {
 	chwidth = mk_wcwidth(c);
-      
-	if (col + chwidth > bcol)
-	  break;
+	if (col + chwidth > bcol) break;
+	
 	if (col >= acol) {
 	  if (st == 0) {
 	    ptr_s = ptr_c;
@@ -447,14 +449,23 @@
     if (st) {
       /* lead padding */
       owl_fmtext_append_spaces(out, padding);
-      if (ptr_c[0] & 0x80) {
-	if (col + chwidth == bcol)
-	  ptr_c = g_utf8_next_char(ptr_c);
-	_owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - 1 - in->textbuff);	
-	owl_fmtext_append_normal(out, "\n");
+      if (ptr_c == ptr_e) {
+	/* We made it to the newline. */
+	owl_function_debugmsg("fmtc: reached newline");	
+	_owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
       }
       else {
-	_owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
+	if (chwidth > 1) {
+	  /* Last char is wide, truncate. */
+	  owl_function_debugmsg("fmtc: truncating.");
+	  _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1);
+	  owl_fmtext_append_normal(out, "\n");
+	}
+	else {
+	  /* Last char fits perfectly, leave alone.*/
+	  owl_function_debugmsg("fmtc: fits fine.");
+	  _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
+	}
       }
     }
     else {

Modified: branches/barnowl_unicode/owl/message.c
===================================================================
--- branches/barnowl_unicode/owl/message.c	2008-01-03 03:51:28 UTC (rev 796)
+++ branches/barnowl_unicode/owl/message.c	2008-01-04 19:31:55 UTC (rev 797)
@@ -534,7 +534,7 @@
   owl_fmtext_init_null(&a);
   owl_fmtext_init_null(&b);
   
-  owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline+1, &a);
+  owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline, &a);
   owl_fmtext_truncate_cols(&a, acol, bcol, &b);
   owl_fmtext_colorize(&b, fgcolor);
   owl_fmtext_colorizebg(&b, bgcolor);


home help back first fref pref prev next nref lref last post