Changeset dd24b6a


Ignore:
Timestamp:
Dec 24, 2007, 10:14:09 AM (17 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
9866c3a
Parents:
762512d
Message:
* 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.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    r28ee32b rdd24b6a  
    316316{
    317317  char *ptr_s, *ptr_e, *ptr_c, *last;
    318   int col, cnt;
     318  int col, cnt, padding;
    319319
    320320  last=in->textbuff+in->textlen-1;
     
    335335    col = 0;
    336336    cnt = 0;
     337    padding = 0;
    337338    ptr_c = ptr_s;
    338339    while(col < bcol && ptr_c < ptr_e) {
    339340      gunichar c = g_utf8_get_char(ptr_c);
    340       if (g_unichar_iswide(c)) {
    341         if (col + 2 > bcol) break;
    342         else col += 2;
    343       }
    344       else if (g_unichar_type(c) == G_UNICODE_NON_SPACING_MARK) ; /*do nothing*/
    345       /* We may need more special cases here... unicode spacing is hard. */
    346       else {
    347         if (col + 1 > bcol) break;
    348         else ++col;
    349       }
     341      if (col + wcwidth(c) > bcol) break;
     342      col += wcwidth(c);
    350343      ptr_c = g_utf8_next_char(ptr_c);
    351       if (col >= acol) ++cnt;
    352       if (col <= acol) ptr_s = ptr_c;
    353     }
    354     _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
     344      if (col >= acol) {
     345        if (cnt == 0) {
     346          ptr_s = ptr_c;
     347          padding = col - acol;
     348        }
     349        ++cnt;
     350      }
     351    }
     352    if (cnt) {
     353      while(padding-- > 0) {
     354        owl_fmtext_append_normal(out, " ");
     355      }
     356      _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
     357    }
     358    else {
     359      owl_fmtext_append_normal(out, "\n");
     360    }
    355361    ptr_s=ptr_e+1;
    356    
     362     
    357363#if 0
    358364    /* we need to check that we won't run over here */
  • owl.h

    r93ee554 rdd24b6a  
    5252#include <termios.h>
    5353#include <libfaim/aim.h>
     54#include <wchar.h>
    5455#include "config.h"
    5556#include "glib.h"
  • text.c

    r28ee32b rdd24b6a  
    5151{
    5252  char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last;
    53   int col, cnt;
     53  int col, cnt, padding;
    5454 
    5555  tmpbuff=owl_malloc(strlen(in)+20);
     
    7373    col = 0;
    7474    cnt = 0;
     75    padding = 0;
    7576    ptr_c = ptr_s;
    7677    while(col < bcol && ptr_c < ptr_e) {
    7778      gunichar c = g_utf8_get_char(ptr_c);
    78       if (g_unichar_iswide(c)) {
    79         if (col + 2 > bcol) break;
    80         else col += 2;
     79      if (col + wcwidth(c) > bcol) break;
     80      col += wcwidth(c);
     81      ptr_c = g_utf8_next_char(ptr_c);
     82      if (col >= acol) {
     83        if (cnt == 0) {
     84          ptr_s = ptr_c;
     85          padding = col - acol;
     86        }
     87        ++cnt;
    8188      }
    82       else if (g_unichar_type(c) == G_UNICODE_NON_SPACING_MARK) ; /*do nothing*/
    83       /* We may need more special cases here... unicode spacing is hard. */
    84       else {
    85         if (col + 1 > bcol) break;
    86         else ++col;
     89    }
     90    if (cnt) {
     91      while(padding-- > 0) {
     92        strcat(tmpbuff, " ");
    8793      }
    88       ptr_c = g_utf8_next_char(ptr_c);
    89       if (col >= acol) ++cnt;
    90       if (col <= acol) ptr_s = ptr_c;
    91     }
    92     strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1);
     94      strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1);
     95    }
    9396    strcat(tmpbuff, "\n");
    9497    ptr_s = ptr_e + 1;
Note: See TracChangeset for help on using the changeset viewer.