Changeset 1136


Ignore:
Timestamp:
Sep 30, 2006, 1:34:03 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Add "utf8" import format.
  • Documented "text" import format.
File:
1 edited

Legend:

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

    r1104 r1136  
    4141static cucul_canvas_t *import_caca(void const *, unsigned int);
    4242static cucul_canvas_t *import_text(void const *, unsigned int);
    43 static cucul_canvas_t *import_ansi(void const *, unsigned int);
     43static cucul_canvas_t *import_ansi(void const *, unsigned int, int);
    4444
    4545static void ansi_parse_grcm(cucul_canvas_t *, struct ansi_grcm *,
     
    5353 *  Valid values for \c format are:
    5454 *  - \c "": attempt to autodetect the file format.
     55 *  - \c "text": import ASCII text files.
    5556 *  - \c "ansi": import ANSI files.
     57 *  - \c "utf8": import UTF-8 files with ANSI colour files.
    5658 *  - \c "caca": import native libcaca files.
    5759 *
     
    7173    if(!strcasecmp("caca", format))
    7274        return import_caca(buffer->data, buffer->size);
     75    if(!strcasecmp("utf8", format))
     76        return import_ansi(buffer->data, buffer->size, 1);
    7377    if(!strcasecmp("text", format))
    7478        return import_text(buffer->data, buffer->size);
    7579    if(!strcasecmp("ansi", format))
    76         return import_ansi(buffer->data, buffer->size);
     80        return import_ansi(buffer->data, buffer->size, 0);
    7781
    7882    /* Autodetection */
     
    8993        for(i = 0; i < buffer->size - 1; i++)
    9094            if((buf[i] == 0x1b) && (buf[i + 1] == '['))
    91                 return import_ansi(buffer->data, buffer->size);
     95                return import_ansi(buffer->data, buffer->size, 0);
    9296
    9397        /* Otherwise, import it as text */
     
    236240}
    237241
    238 static cucul_canvas_t *import_ansi(void const *data, unsigned int size)
     242static cucul_canvas_t *import_ansi(void const *data, unsigned int size,
     243                                   int utf8)
    239244{
    240245    struct ansi_grcm grcm;
     
    243248    unsigned int i, j, skip, dummy = 0;
    244249    unsigned int width = 1, height = 1;
     250    unsigned long int ch;
    245251    int x = 0, y = 0, save_x = 0, save_y = 0;
    246252
     
    412418
    413419        /* 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        }
    414430        cucul_set_color(cv, grcm.efg, grcm.ebg);
    415         cucul_putchar(cv, x, y, cucul_cp437_to_utf32(buffer[i]));
     431        cucul_putchar(cv, x, y, ch);
    416432        x++;
    417433    }
Note: See TracChangeset for help on using the changeset viewer.