Changeset 1194 for toilet/trunk


Ignore:
Timestamp:
Oct 10, 2006, 1:54:40 AM (16 years ago)
Author:
Sam Hocevar
Message:
  • The mono9 driver works again. With wrapping and stdin reading.
Location:
toilet/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • toilet/trunk/src/main.c

    r1193 r1194  
    170170    }
    171171
    172 #if 0
    173     if(optind >= argc)
    174 #endif
    175 
    176 #if 0
    177     /* Render string to canvas */
    178172    if(!strcasecmp(cx->font, "mono9"))
    179     {
    180         cv = render_big(string, length);
    181         filter_autocrop(cv);
    182     }
    183     else if(!strcasecmp(cx->font, "term"))
    184         cv = render_tiny(string, length);
    185     else
    186         cv = render_figlet(cx, string, length);
    187 #endif
    188 
    189     init_tiny(cx);
     173        init_big(cx);
     174    else /* if(!strcasecmp(cx->font, "term")) */
     175        init_tiny(cx);
    190176
    191177    if(optind >= argc)
     
    230216
    231217    /* Apply optional effects to our string */
     218    if(!strcasecmp(cx->font, "mono9"))
     219        filter_autocrop(cx->cv);
    232220    if(flag_metal)
    233221        filter_metal(cx->cv);
  • toilet/trunk/src/render.c

    r1193 r1194  
    3030static int end_tiny(context_t *);
    3131
     32static int feed_big(context_t *, uint32_t);
     33static int end_big(context_t *);
     34
    3235int init_tiny(context_t *cx)
    3336{
     
    4649static int feed_tiny(context_t *cx, uint32_t ch)
    4750{
    48     if(cx->x >= cx->w)
    49         cx->w = cx->x + 1;
     51    /* Check whether we reached the end of the screen */
     52    if(cx->x && cx->x + 1 > cx->term_width)
     53    {
     54        cx->x = 0;
     55        cx->y++;
     56    }
    5057
    51     if(cx->y >= cx->h)
     58    /* Check whether the current canvas is large enough */
     59    if(cx->x + 1 > cx->w)
     60    {
     61        cx->w = cx->x + 1 < cx->term_width ? cx->x + 1 : cx->term_width;
     62        if(cx->w > cx->ew)
     63            cx->ew = cx->ew + cx->ew / 2;
     64    }
     65
     66    if(cx->y + 1 > cx->h)
     67    {
    5268        cx->h = cx->y + 1;
     69        if(cx->h > cx->eh)
     70            cx->eh = cx->eh + cx->eh / 2;
     71    }
     72
     73    cucul_set_canvas_size(cx->cv, cx->ew, cx->eh);
    5374
    5475    switch(ch)
     
    6990    }
    7091
    71     if(cx->x >= cx->term_width)
    72     {
    73         cx->x = 0;
    74         cx->y++;
    75     }
    76 
    77     if(cx->x >= cx->ew)
    78         cx->ew = cx->ew + cx->ew / 2;
    79 
    80     if(cx->y >= cx->eh)
    81         cx->eh = cx->eh + cx->eh / 2;
    82 
    83     cucul_set_canvas_size(cx->cv, cx->ew, cx->eh);
    84 
    8592    return 0;
    8693}
     
    93100}
    94101
    95 #if 0
    96 cucul_canvas_t *render_big(uint32_t const *string, unsigned int length)
     102int init_big(context_t *cx)
    97103{
    98     cucul_canvas_t *cv;
    99     cucul_font_t *f;
    100104    char const * const * fonts;
    101     unsigned char *buf;
    102     unsigned int w, h, x, y, miny, maxy;
    103 
    104     cv = cucul_create_canvas(length, 1);
    105     cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    106     for(x = 0; x < length; x++)
    107         cucul_putchar(cv, x, 0, string[x]);
    108105
    109106    fonts = cucul_get_font_list();
    110     f = cucul_load_font(fonts[0], 0);
     107    cx->f = cucul_load_font(fonts[0], 0);
     108    cx->buf = malloc(4 * cucul_get_font_width(cx->f)
     109                       * cucul_get_font_height(cx->f));
     110    cx->onechar = cucul_create_canvas(1, 1);
     111    cucul_set_color(cx->onechar, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    111112
    112     /* Create our bitmap buffer (32-bit ARGB) */
    113     w = cucul_get_canvas_width(cv) * cucul_get_font_width(f);
    114     h = cucul_get_canvas_height(cv) * cucul_get_font_height(f);
    115     buf = malloc(4 * w * h);
     113    cx->x = cx->y = 0;
     114    cx->w = cx->h = 0;
     115    cx->cv = cucul_create_canvas(1, 1);
    116116
    117     /* Render the canvas onto our image buffer */
    118     cucul_render_canvas(cv, f, buf, w, h, 4 * w);
     117    cx->feed = feed_big;
     118    cx->end = end_big;
    119119
    120     /* Free our canvas, and allocate a bigger one */
    121     cucul_free_font(f);
    122     cucul_free_canvas(cv);
    123     cv = cucul_create_canvas(w, h);
     120    return 0;
     121}
    124122
    125     /* Render the image buffer on the canvas */
    126     cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_TRANSPARENT);
    127     cucul_clear_canvas(cv);
     123static int feed_big(context_t *cx, uint32_t ch)
     124{
     125    unsigned int w = cucul_get_font_width(cx->f);
     126    unsigned int h = cucul_get_font_height(cx->f);
     127    unsigned int x, y;
    128128
    129     miny = h; maxy = 0;
     129    /* Check whether we reached the end of the screen */
     130    if(cx->x && cx->x + w > cx->term_width)
     131    {
     132        cx->x = 0;
     133        cx->y += h;
     134    }
     135
     136    /* Check whether the current canvas is large enough */
     137    if(cx->x + w > cx->w)
     138        cx->w = cx->x + w < cx->term_width ? cx->x + w : cx->term_width;
     139
     140    if(cx->y + h > cx->h)
     141        cx->h = cx->y + h;
     142
     143    cucul_set_canvas_size(cx->cv, cx->w, cx->h);
     144
     145    /* Render our char */
     146    cucul_putchar(cx->onechar, 0, 0, ch);
     147    cucul_render_canvas(cx->onechar, cx->f, cx->buf, w, h, 4 * w);
    130148
    131149    for(y = 0; y < h; y++)
    132150       for(x = 0; x < w; x++)
    133151    {
    134         unsigned char c = buf[4 * (x + y * w) + 2];
     152        unsigned char c = cx->buf[4 * (x + y * w) + 2];
    135153
    136154        if(c >= 0xa0)
    137             cucul_putstr(cv, x, y, "█");
     155            cucul_putstr(cx->cv, cx->x + x, cx->y + y, "█");
    138156        else if(c >= 0x80)
    139             cucul_putstr(cv, x, y, "▓");
     157            cucul_putstr(cx->cv, cx->x + x, cx->y + y, "▓");
    140158        else if(c >= 0x40)
    141             cucul_putstr(cv, x, y, "▒");
     159            cucul_putstr(cx->cv, cx->x + x, cx->y + y, "▒");
    142160        else if(c >= 0x20)
    143             cucul_putstr(cv, x, y, "░");
     161            cucul_putstr(cx->cv, cx->x + x, cx->y + y, "░");
    144162    }
    145163
    146     free(buf);
     164    /* Advance cursor */
     165    cx->x += w;
    147166
    148     return cv;
     167    return 0;
    149168}
    150 #endif
    151169
     170static int end_big(context_t *cx)
     171{
     172    cucul_free_canvas(cx->onechar);
     173    free(cx->buf);
     174    cucul_free_font(cx->f);
     175
     176    return 0;
     177}
     178
  • toilet/trunk/src/render.h

    r1193 r1194  
    1717
    1818extern int init_tiny(context_t *);
     19extern int init_big(context_t *);
    1920
  • toilet/trunk/src/toilet.h

    r1193 r1194  
    2727    unsigned int w, h, ew, eh, x, y;
    2828
     29    /* Methods */
    2930    int (*feed)(struct toilet_context *, uint32_t);
    3031    int (*end)(struct toilet_context *);
     32
     33    /* Used by the big driver */
     34    cucul_font_t *f;
     35    cucul_canvas_t *onechar;
     36    unsigned char *buf;
    3137};
    3238
Note: See TracChangeset for help on using the changeset viewer.