Changeset 28ee32b for fmtext.c


Ignore:
Timestamp:
Dec 24, 2007, 2:53:11 AM (16 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:
762512d
Parents:
5bc0f68
Message:
UTF-8 - first pass

unicode changes:
* remove downstr() from text.c, replace on site with calls to g_utf8_strdown.
  In place downcasing is not a good idea, so the downstr() contract is unfulfillable.

* make owl_text_truncate_cols() and owl_fmtext_truncate_cols() understand character width.
  This may need more work. Some code duplication - see if we can refactor.

* stristr() rewritten to yse g_utf_casefold() instead of downstr(), and restructured to have a single return.

* only_whitespace() rewritten for unicode.

glib changes:
* rewrite owl_sprintf() in terms of g_strdup_vprintf()

WARNING: THIS IS NOT SAFE YET. Network data is not yet sanitized. Non
UTF-8 inputs may do horrible things to you. This phase is just
working on rendering.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    rfa3290d r28ee32b  
    315315void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
    316316{
    317   char *ptr1, *ptr2, *last;
    318   int len, offset;
     317  char *ptr_s, *ptr_e, *ptr_c, *last;
     318  int col, cnt;
    319319
    320320  last=in->textbuff+in->textlen-1;
    321   ptr1=in->textbuff;
    322   while (ptr1<=last) {
    323     ptr2=strchr(ptr1, '\n');
    324     if (!ptr2) {
     321  ptr_s=in->textbuff;
     322  while (ptr_s<=last) {
     323    ptr_e=strchr(ptr_s, '\n');
     324    if (!ptr_e) {
    325325      /* but this shouldn't happen if we end in a \n */
    326326      break;
    327327    }
    328328   
    329     if (ptr2==ptr1) {
     329    if (ptr_e==ptr_s) {
    330330      owl_fmtext_append_normal(out, "\n");
    331       ptr1++;
     331      ptr_s++;
    332332      continue;
    333333    }
    334334
     335    col = 0;
     336    cnt = 0;
     337    ptr_c = ptr_s;
     338    while(col < bcol && ptr_c < ptr_e) {
     339      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      }
     350      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);
     355    ptr_s=ptr_e+1;
     356   
     357#if 0
    335358    /* we need to check that we won't run over here */
    336359    len=bcol-acol;
    337     if (len > (ptr2-(ptr1+acol))) {
     360    if (len > (ptr_e-(ptr_s+acol))) {
    338361      /* the whole line fits with room to spare, don't take a full 'len' */
    339       len=ptr2-(ptr1+acol);
    340     }
    341     if (len>last-ptr1) {
     362      len=ptr_e-(ptr_s+acol);
     363    }
     364    if (len>last-ptr_s) {
    342365      /* the whole rest of the text fits with room to spare, adjust for it */
    343       len-=(last-ptr1);
     366      len-=(last-ptr_s);
    344367    }
    345368    if (len<=0) {
    346369      /* saftey check */
    347370      owl_fmtext_append_normal(out, "\n");
    348       ptr1=ptr2+1;
     371      ptr_s=ptr_e+1;
    349372      continue;
    350373    }
    351374
    352     offset=ptr1-in->textbuff;
     375    offset = ptr_s - in->textbuff;
    353376    _owl_fmtext_append_fmtext(out, in, offset+acol, offset+acol+len);
    354377
    355     ptr1=ptr2+1;
     378    ptr_s=ptr_e+1;
     379#endif
    356380  }
    357381}
Note: See TracChangeset for help on using the changeset viewer.