Changeset 624


Ignore:
Timestamp:
Mar 15, 2006, 7:41:29 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Unicode support in the HTML exporter.
File:
1 edited

Legend:

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

    r620 r624  
    4949    unsigned int x, y, len;
    5050
    51     /* 13000 -> css palette
    52      * 40 -> max size used for a pixel (plus 10, never know)*/
    53     /* FIXME: Check this value */
    54     ex->size = 13000 + (qq->width * qq->height * 40);
     51    /* The CSS palette: roughly 13000 bytes
     52     * A line: 7 chars for "<br />\n"
     53     * A glyph: 18 chars for "<span class='bxx'>"
     54     *          up to 9 chars for "&#xxxxxx;", far less for pure ASCII
     55     *          7 chars for "</span>" */
     56    ex->size = 13000 + qq->height * (7 + qq->width * (18 + 9 + 7));
    5557    ex->buffer = malloc(ex->size);
    5658
     
    8688                len++)
    8789            {
    88                 if(linechar[x + len] == (uint32_t)' ')
     90                if(linechar[x + len] <= 0x00000020)
    8991                    cur += sprintf(cur, "&nbsp;");
     92                else if(linechar[x + len] < 0x00000080)
     93                    cur += sprintf(cur, "%c", linechar[x + len]);
    9094                else
    91                     cur += sprintf(cur, "%c", linechar[x] & 0x7f);
     95                    cur += sprintf(cur, "&#%i;", linechar[x + len]);
    9296            }
    9397            cur += sprintf(cur, "</span>");
     
    126130    unsigned int x, y, len;
    127131
    128     /* 13000 -> css palette
    129      * 40 -> max size used for a pixel (plus 10, never know) */
    130     ex->size = 13000 + (qq->width * qq->height * 40);
     132    /* The CSS palette: roughly 13000 bytes
     133     * A line: 10 chars for "<tr></tr>\n"
     134     * A glyph: 40 chars for "<td bgcolor=#xxxxxx><font color=#xxxxxx>"
     135     *          up to 9 chars for "&#xxxxxx;", far less for pure ASCII
     136     *          12 chars for "</font></td>" */
     137    ex->size = 13000 + qq->height * (10 + qq->width * (40 + 9 + 12));
    131138    ex->buffer = malloc(ex->size);
    132139
     
    164171            for(i = 0; i < len; i++)
    165172            {
    166                 if(linechar[x + i] == (uint32_t)' ')
     173                if(linechar[x + i] <= 0x00000020)
    167174                    cur += sprintf(cur, "&nbsp;");
     175                else if(linechar[x + i] < 0x00000080)
     176                    cur += sprintf(cur, "%c", linechar[x + i]);
    168177                else
    169                     cur += sprintf(cur, "%c", linechar[x + i] & 0x7f);
     178                    cur += sprintf(cur, "&#%i;", linechar[x + i]);
    170179            }
    171180
Note: See TracChangeset for help on using the changeset viewer.