Changeset 1219


Ignore:
Timestamp:
Oct 22, 2006, 6:49:54 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • Support for fullwidth glyphs in the UTF-8 importer.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/import.c

    r1171 r1219  
    247247    cucul_canvas_t *cv;
    248248    unsigned int i, j, skip, dummy = 0;
    249     unsigned int width = 1, height = 1;
     249    unsigned int width = 1, height = 1, wch = 1;
    250250    unsigned long int ch;
    251251    int x = 0, y = 0, save_x = 0, save_y = 0;
     
    403403        }
    404404
    405         /* We're going to paste a character. First make sure the canvas
    406          * is big enough. */
    407         if((unsigned int)x >= width)
     405        /* Get the character we’re going to paste */
     406        if(utf8)
     407        {
     408            unsigned int bytes;
     409            ch = cucul_utf8_to_utf32((char const *)(buffer + i), &bytes);
     410            wch = cucul_utf32_is_fullwidth(ch) ? 2 : 1;
     411            skip += bytes - 1;
     412        }
     413        else
     414        {
     415            ch = cucul_cp437_to_utf32(buffer[i]);
     416        }
     417
     418        /* Make sure the canvas is big enough. */
     419        if((unsigned int)x + wch > width)
    408420        {
    409421            cucul_set_color(cv, CUCUL_COLOR_DEFAULT, CUCUL_COLOR_TRANSPARENT);
    410             cucul_set_canvas_size(cv, width = x + 1, height);
     422            cucul_set_canvas_size(cv, width = x + wch, height);
    411423        }
    412424
     
    418430
    419431        /* Now paste our character */
    420         if(utf8)
    421         {
    422             unsigned int bytes;
    423             ch = cucul_utf8_to_utf32((char const *)(buffer + i), &bytes);
    424             skip += bytes - 1;
    425         }
    426         else
    427         {
    428             ch = cucul_cp437_to_utf32(buffer[i]);
    429         }
    430432        cucul_set_color(cv, grcm.efg, grcm.ebg);
    431433        cucul_putchar(cv, x, y, ch);
    432         x++;
     434        x += wch;
    433435    }
    434436
Note: See TracChangeset for help on using the changeset viewer.