Bläddra i källkod

* Updated documentation of fullwidth-aware functions.

* Fullwidth support in all exporters.
tags/v0.99.beta14
Sam Hocevar sam 18 år sedan
förälder
incheckning
df13e2a2e1
2 ändrade filer med 35 tillägg och 7 borttagningar
  1. +10
    -3
      cucul/canvas.c
  2. +25
    -4
      cucul/export.c

+ 10
- 3
cucul/canvas.c Visa fil

@@ -53,8 +53,7 @@
*
* The behaviour when printing non-printable characters or invalid UTF-32
* characters is undefined. To print a sequence of bytes forming an UTF-8
* character instead of an UTF-32 character, use the cucul_putstr() function
* instead.
* character instead of an UTF-32 character, use the cucul_putstr() function.
*
* This function never fails.
*
@@ -132,7 +131,12 @@ int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
* as a UTF-32 value.
*
* If the coordinates are outside the canvas boundaries, a space (0x20)
* is returned. FIXME: explain CUCUL_MAGIC_FULLWIDTH
* is returned.
*
* A special exception is when CUCUL_MAGIC_FULLWIDTH is returned. This
* value is guaranteed not to be a valid Unicode character, and indicates
* that the character at the left of the requested one is a fullwidth
* character.
*
* This function never fails.
*
@@ -270,6 +274,9 @@ int cucul_clear_canvas(cucul_canvas_t *cv)
* - \c EINVAL A mask was specified but the mask size and source canvas
* size do not match.
*
* FIXME: this function may corrupt the canvas if fullwidth characters
* appear at odd places.
*
* \param dst The destination canvas.
* \param x X coordinate.
* \param y Y coordinate.


+ 25
- 4
cucul/export.c Visa fil

@@ -224,6 +224,9 @@ static void export_utf8(cucul_canvas_t *cv, cucul_buffer_t *ex)
uint32_t ch = linechar[x];
uint8_t fg, bg;

if(ch == CUCUL_MAGIC_FULLWIDTH)
continue;

fg = ((attr & 0xffff) == CUCUL_COLOR_DEFAULT) ?
0x10 : palette[_cucul_argb32_to_ansi4fg(attr)];
bg = ((attr >> 16) == CUCUL_COLOR_TRANSPARENT) ?
@@ -298,6 +301,9 @@ static void export_ansi(cucul_canvas_t *cv, cucul_buffer_t *ex)
uint8_t bg = palette[_cucul_argb32_to_ansi4bg(lineattr[x])];
uint32_t ch = linechar[x];

if(ch == CUCUL_MAGIC_FULLWIDTH)
ch = '?';

if(fg != prevfg || bg != prevbg)
{
cur += sprintf(cur, "\033[0;");
@@ -377,7 +383,9 @@ static void export_html(cucul_canvas_t *cv, cucul_buffer_t *ex)
x + len < cv->width && lineattr[x + len] == lineattr[x];
len++)
{
if(linechar[x + len] <= 0x00000020)
if(linechar[x + len] == CUCUL_MAGIC_FULLWIDTH)
;
else if(linechar[x + len] <= 0x00000020)
cur += sprintf(cur, "&nbsp;");
else if(linechar[x + len] < 0x00000080)
cur += sprintf(cur, "%c",
@@ -450,7 +458,9 @@ static void export_html3(cucul_canvas_t *cv, cucul_buffer_t *ex)

for(i = 0; i < len; i++)
{
if(linechar[x + i] <= 0x00000020)
if(linechar[x + i] == CUCUL_MAGIC_FULLWIDTH)
;
else if(linechar[x + i] <= 0x00000020)
cur += sprintf(cur, "&nbsp;");
else if(linechar[x + i] < 0x00000080)
cur += sprintf(cur, "%c", (unsigned char)linechar[x + i]);
@@ -511,6 +521,9 @@ static void export_irc(cucul_canvas_t *cv, cucul_buffer_t *ex)
uint8_t bg = palette[_cucul_argb32_to_ansi4bg(attr)];
uint32_t ch = linechar[x];

if(ch == CUCUL_MAGIC_FULLWIDTH)
continue;

if((attr & 0xffff) == CUCUL_COLOR_DEFAULT)
fg = 0x10;

@@ -697,7 +710,8 @@ static void export_svg(cucul_canvas_t *cv, cucul_buffer_t *ex)
cur += sprintf(cur, svg_header, cv->width * 6, cv->height * 10,
cv->width * 6, cv->height * 10);

cur += sprintf(cur, " <g id=\"mainlayer\" font-size=\"12\">\n");
cur += sprintf(cur, " <g id=\"mainlayer\" font-size=\"10\""
" style=\"font-family: monospace\">\n");

/* Background */
for(y = 0; y < cv->height; y++)
@@ -723,10 +737,17 @@ static void export_svg(cucul_canvas_t *cv, cucul_buffer_t *ex)
{
uint32_t ch = *linechar++;

if(ch == ' ' || ch == CUCUL_MAGIC_FULLWIDTH)
{
lineattr++;
continue;
}

cur += sprintf(cur, "<text style=\"fill:#%.03x\" "
"x=\"%d\" y=\"%d\">",
_cucul_argb32_to_rgb12fg(*lineattr++),
x * 6, (y * 10) + 10);
x * 6, (y * 10) + 8);

if(ch < 0x00000020)
*cur++ = '?';
else if(ch > 0x0000007f)


Laddar…
Avbryt
Spara