[776] in BarnOwl Developers
[D-O-H] r782 - branches/barnowl_unicode/owl
daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:09:35 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: Mon, 24 Dec 2007 10:14:09 -0500 (EST)
Author: asedeno
Date: 2007-12-24 10:14:09 -0500 (Mon, 24 Dec 2007)
New Revision: 782
Modified:
branches/barnowl_unicode/owl/fmtext.c
branches/barnowl_unicode/owl/owl.h
branches/barnowl_unicode/owl/text.c
Log:
Unicode / Glib branch:
* include wchar.h
* replace hand-rolled width detection with wcswidth.
* pad with space if we end up halfway into a character at the start of a line.
WARNING: Still not safe.
Modified: branches/barnowl_unicode/owl/fmtext.c
===================================================================
--- branches/barnowl_unicode/owl/fmtext.c 2007-12-24 08:10:38 UTC (rev 781)
+++ branches/barnowl_unicode/owl/fmtext.c 2007-12-24 15:14:09 UTC (rev 782)
@@ -315,7 +315,7 @@
void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
{
char *ptr_s, *ptr_e, *ptr_c, *last;
- int col, cnt;
+ int col, cnt, padding;
last=in->textbuff+in->textlen-1;
ptr_s=in->textbuff;
@@ -334,26 +334,32 @@
col = 0;
cnt = 0;
+ padding = 0;
ptr_c = ptr_s;
while(col < bcol && ptr_c < ptr_e) {
gunichar c = g_utf8_get_char(ptr_c);
- if (g_unichar_iswide(c)) {
- if (col + 2 > bcol) break;
- else col += 2;
+ if (col + wcwidth(c) > bcol) break;
+ col += wcwidth(c);
+ ptr_c = g_utf8_next_char(ptr_c);
+ if (col >= acol) {
+ if (cnt == 0) {
+ ptr_s = ptr_c;
+ padding = col - acol;
+ }
+ ++cnt;
}
- else if (g_unichar_type(c) == G_UNICODE_NON_SPACING_MARK) ; /*do nothing*/
- /* We may need more special cases here... unicode spacing is hard. */
- else {
- if (col + 1 > bcol) break;
- else ++col;
+ }
+ if (cnt) {
+ while(padding-- > 0) {
+ owl_fmtext_append_normal(out, " ");
}
- ptr_c = g_utf8_next_char(ptr_c);
- if (col >= acol) ++cnt;
- if (col <= acol) ptr_s = ptr_c;
+ _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
}
- _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
+ else {
+ owl_fmtext_append_normal(out, "\n");
+ }
ptr_s=ptr_e+1;
-
+
#if 0
/* we need to check that we won't run over here */
len=bcol-acol;
Modified: branches/barnowl_unicode/owl/owl.h
===================================================================
--- branches/barnowl_unicode/owl/owl.h 2007-12-24 08:10:38 UTC (rev 781)
+++ branches/barnowl_unicode/owl/owl.h 2007-12-24 15:14:09 UTC (rev 782)
@@ -51,6 +51,7 @@
#include <signal.h>
#include <termios.h>
#include <libfaim/aim.h>
+#include <wchar.h>
#include "config.h"
#include "glib.h"
#ifdef HAVE_LIBZEPHYR
Modified: branches/barnowl_unicode/owl/text.c
===================================================================
--- branches/barnowl_unicode/owl/text.c 2007-12-24 08:10:38 UTC (rev 781)
+++ branches/barnowl_unicode/owl/text.c 2007-12-24 15:14:09 UTC (rev 782)
@@ -50,7 +50,7 @@
void owl_text_truncate_cols(char *out, char *in, int acol, int bcol)
{
char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last;
- int col, cnt;
+ int col, cnt, padding;
tmpbuff=owl_malloc(strlen(in)+20);
@@ -72,24 +72,27 @@
col = 0;
cnt = 0;
+ padding = 0;
ptr_c = ptr_s;
while(col < bcol && ptr_c < ptr_e) {
gunichar c = g_utf8_get_char(ptr_c);
- if (g_unichar_iswide(c)) {
- if (col + 2 > bcol) break;
- else col += 2;
+ if (col + wcwidth(c) > bcol) break;
+ col += wcwidth(c);
+ ptr_c = g_utf8_next_char(ptr_c);
+ if (col >= acol) {
+ if (cnt == 0) {
+ ptr_s = ptr_c;
+ padding = col - acol;
+ }
+ ++cnt;
}
- else if (g_unichar_type(c) == G_UNICODE_NON_SPACING_MARK) ; /*do nothing*/
- /* We may need more special cases here... unicode spacing is hard. */
- else {
- if (col + 1 > bcol) break;
- else ++col;
+ }
+ if (cnt) {
+ while(padding-- > 0) {
+ strcat(tmpbuff, " ");
}
- ptr_c = g_utf8_next_char(ptr_c);
- if (col >= acol) ++cnt;
- if (col <= acol) ptr_s = ptr_c;
+ strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1);
}
- strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1);
strcat(tmpbuff, "\n");
ptr_s = ptr_e + 1;
#if 0