Changeset 1400 for toilet


Ignore:
Timestamp:
Nov 15, 2006, 12:42:11 AM (16 years ago)
Author:
Sam Hocevar
Message:
  • Kerning support. We used to have:

_
\ \ / / (_) _ _ _ _ _ _ _

\ V / | | / -_) |
| \ \ / | '_ \ / _ \ | '_| / _|

\_/ |_| \_| \_,_| /_\_\ | ./ \_/ |_| \|

|_|

Now we have:

_
\ \ / /(_) _ _ _ _ _ _ _

\ V / | |/ -_)|
|\ \ / | '_ \/ _ \| '_|/ _|

\_/ |_|\_| \_,_|/_\_\ | ./\_/|_| \|

|_|

Now we just need smushing.

Location:
toilet/trunk/src
Files:
2 edited

Legend:

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

    r1385 r1400  
    4444        return -1;
    4545
     46    cx->left = malloc(cx->height * sizeof(int));
     47    cx->right = malloc(cx->height * sizeof(int));
     48
    4649    cx->feed = feed_figlet;
    4750    cx->flush = flush_figlet;
     
    5356static int feed_figlet(context_t *cx, uint32_t ch, uint32_t attr)
    5457{
    55     unsigned int c, w, h, x, y;
     58    unsigned int c, w, h, x, y, overlap, mx;
    5659
    5760    switch(ch)
     
    8487    }
    8588
     89    /* Compute how much the next character will overlap */
     90    overlap = w;
     91    for(y = 0; y < h; y++)
     92    {
     93        /* Compute how much spaces we can eat from the new glyph */
     94        for(x = 0; x < overlap; x++)
     95            if(cucul_get_char(cx->image, x, y + c * cx->height) != ' ')
     96                break;
     97
     98        /* Compute how much spaces we can eat from the previous glyph */
     99        for(mx = 0; x + mx < overlap && mx < cx->x; mx++)
     100            if(cucul_get_char(cx->cv, cx->x - 1 - mx, cx->y + y) != ' ')
     101                break;
     102
     103        if(x + mx < overlap)
     104            overlap = x + mx;
     105    }
     106
    86107    /* Check whether the current canvas is large enough */
    87     if(cx->x + w > cx->w)
    88         cx->w = cx->x + w < cx->term_width ? cx->x + w : cx->term_width;
     108    if(cx->x + w - overlap > cx->w)
     109        cx->w = cx->x + w - overlap < cx->term_width
     110              ? cx->x + w - overlap : cx->term_width;
    89111
    90112    if(cx->y + h > cx->h)
     
    101123        uint32_t tmpch = cucul_get_char(cx->image, x, y + c * cx->height);
    102124        //uint32_t tmpat = cucul_get_attr(cx->image, x, y + c * cx->height);
     125        if(tmpch == ' ')
     126            continue;
    103127        /* FIXME: this could be changed to cucul_put_attr() when the
    104128         * function is fixed in libcucul */
    105129        //cucul_set_attr(cx->cv, tmpat);
    106         cucul_put_char(cx->cv, cx->x + x, cx->y + y, tmpch);
     130        cucul_put_char(cx->cv, cx->x + x - overlap, cx->y + y, tmpch);
    107131        //cucul_put_attr(cx->cv, cx->x + x, cx->y + y, tmpat);
    108132    }
    109133
    110134    /* Advance cursor */
    111     cx->x += w;
     135    cx->x += w - overlap;
    112136
    113137    return 0;
     
    116140static int flush_figlet(context_t *cx)
    117141{
     142    unsigned int x, y;
     143
    118144    cx->torender = cx->cv;
    119145    cucul_set_canvas_size(cx->torender, cx->w, cx->h);
     146
     147    /* FIXME: do this somewhere else, or record hardblank positions */
     148    for(y = 0; y < cx->h; y++)
     149        for(x = 0; x < cx->w; x++)
     150            if(cucul_get_char(cx->torender, x, y) == 0xa0)
     151            {
     152                uint32_t attr = cucul_get_attr(cx->torender, x, y);
     153                cucul_put_char(cx->torender, x, y, ' ');
     154                cucul_put_attr(cx->torender, x, y, attr);
     155            }
    120156
    121157    cx->x = cx->y = 0;
     
    128164static int end_figlet(context_t *cx)
    129165{
     166    free(cx->left);
     167    free(cx->right);
    130168    cucul_free_canvas(cx->image);
    131169    free(cx->lookup);
     
    270308            ch = cucul_get_char(cx->image, i, j);
    271309
    272             /* TODO: Replace hardblanks with U+00A0 NO-BREAK SPACE */
     310            /* Replace hardblanks with U+00A0 NO-BREAK SPACE */
    273311            if(ch == cx->hardblank)
    274                 cucul_put_char(cx->image, i, j, ch = ' ');
    275                 //cucul_put_char(cx->image, i, j, ch = 0xa0);
     312                cucul_put_char(cx->image, i, j, ch = 0xa0);
    276313
    277314            if(oldch && ch != oldch)
  • toilet/trunk/src/toilet.h

    r1385 r1400  
    3333    int (*end)(struct toilet_context *);
    3434
    35     /* Used by the big driver */
    36     cucul_font_t *f;
    37     cucul_canvas_t *onechar;
    38     unsigned char *buf;
    39 
    4035    /* Used by the FIGlet driver */
    4136    unsigned long int hardblank;
     
    4540    unsigned int glyphs;
    4641    cucul_canvas_t *image;
     42    int *left, *right; /* Unused yet */
    4743    unsigned int *lookup;
    4844
Note: See TracChangeset for help on using the changeset viewer.