Ignore:
Timestamp:
Nov 12, 2006, 7:09:54 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • Double width support in caca2tlf.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • toilet/trunk/tools/caca2tlf.c

    r1296 r1368  
    2929
    3030static void list_fonts(void);
    31 static void add_char(unsigned int);
     31static void add_char(unsigned long int);
    3232
    3333cucul_font_t *f;
     
    3535unsigned long int const *blocks;
    3636uint8_t * image;
    37 unsigned int w, h, gw, gh, iw, ih;
     37unsigned int w, h, gw, fgw, gh, iw, ih;
    3838
    3939int main(int argc, char *argv[])
     
    7979    w = cucul_get_font_width(f);
    8080    h = cucul_get_font_height(f);
    81     iw = w + 1;
     81    iw = w * 2 + 1;
    8282    ih = h + 1;
    8383    switch(mode)
     
    8585    case GRAY:
    8686        gw = w;
     87        fgw = w * 2;
    8788        gh = h;
    8889        break;
    8990    case HALFBLOCKS:
    9091        gw = w;
     92        fgw = w * 2;
    9193        gh = (h + 1) / 2;
    9294        break;
    9395    case QUARTERBLOCKS:
    9496        gw = (w + 1) / 2;
     97        fgw = (w * 2 + 1) / 2;
    9598        gh = (h + 1) / 2;
    9699        break;
     
    98101
    99102    blocks = cucul_get_font_blocks(f);
    100     onechar = cucul_create_canvas(1, 1); /* FIXME: support double width */
     103    onechar = cucul_create_canvas(0, 0);
    101104    cucul_set_color_ansi(onechar, CUCUL_WHITE, CUCUL_BLACK);
    102105    image = malloc(4 * iw * ih);
    103106
    104     out = cucul_create_canvas(gw + 2, gh);
    105     printf("tlf2a$ %u %u %u 0 4 0 0 0\n", gh, gh - 1, gw + 2);
     107    out = cucul_create_canvas(0, 0);
     108    printf("tlf2a$ %u %u %u 0 4 0 0 0\n", gh, gh - 1, fgw + 2);
    106109
    107110    printf("=============================================="
     
    164167}
    165168
    166 static void add_char(unsigned int ch)
     169static void add_char(unsigned long int ch)
    167170{
    168171    cucul_buffer_t *buf;
    169     unsigned int x, y;
    170 
     172    unsigned int x, y, myw, mygw;
     173    int full = cucul_utf32_is_fullwidth(ch);
     174
     175    cucul_set_canvas_size(onechar, full ? 2 : 1, 1);
    171176    cucul_putchar(onechar, 0, 0, ch);
    172177    cucul_render_canvas(onechar, f, image, iw, ih, 4 * iw);
    173178
     179    myw = full ? 2 * w : w;
     180    mygw = full ? fgw : gw;
     181
     182    cucul_set_canvas_size(out, (full ? fgw : gw) + 2, gh);
     183
    174184    switch(mode)
    175185    {
    176186    case GRAY:
    177187        for(y = 0; y < h; y++)
    178            for(x = 0; x < w; x++)
     188            for(x = 0; x < myw; x++)
    179189        {
    180190            uint8_t c = image[4 * (x + y * iw) + 2];
     
    194204    case HALFBLOCKS:
    195205        for(y = 0; y < gh; y++)
    196            for(x = 0; x < gw; x++)
     206            for(x = 0; x < mygw; x++)
    197207        {
    198208            static char const *str[] = { " ", "▀", "▄", "█" };
     
    201211            uint8_t p2 = image[4 * (x + (y * 2 + 1) * iw) + 2];
    202212
    203             cucul_putstr(out, x, y,
    204                          str[(p1 < 0x80 ? 0 : 1) + (p2 < 0x80 ? 0 : 2)]);
     213            cucul_putstr(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80)]);
    205214        }
    206215        break;
    207216    case QUARTERBLOCKS:
    208217        for(y = 0; y < gh; y++)
    209            for(x = 0; x < gw; x++)
     218            for(x = 0; x < mygw; x++)
    210219        {
    211220            static char const *str[] =
     
    220229            uint8_t p4 = image[4 * (x * 2 + 1 + (y * 2 + 1) * iw) + 2];
    221230
    222             cucul_putstr(out, x, y,
    223                          str[(p1 < 0x80 ? 0 : 1) + (p2 < 0x80 ? 0 : 2) +
    224                              (p3 < 0x80 ? 0 : 4) + (p4 < 0x80 ? 0 : 8)]);
    225         }
    226         break;
    227     }
    228 
    229     cucul_draw_line(out, gw, 0, gw, gh - 1, "@");
    230     cucul_putchar(out, gw + 1, gh - 1, '@');
     231            cucul_putstr(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80) +
     232                                        4 * (p3 > 0x80) + 8 * (p4 > 0x80)]);
     233        }
     234        break;
     235    }
     236
     237    cucul_draw_line(out, mygw, 0, mygw, gh - 1, '@');
     238    cucul_putchar(out, mygw + 1, gh - 1, '@');
    231239
    232240    buf = cucul_export_canvas(out, "utf8");
Note: See TracChangeset for help on using the changeset viewer.