Bläddra i källkod

* More characters for the wide rotations.

* Updated test/text to show what the wide rotations now do.
tags/v0.99.beta14
Sam Hocevar sam 17 år sedan
förälder
incheckning
64e11f119b
2 ändrade filer med 114 tillägg och 19 borttagningar
  1. +91
    -10
      cucul/transform.c
  2. +23
    -9
      test/text.c

+ 91
- 10
cucul/transform.c Visa fil

@@ -31,6 +31,8 @@ static uint32_t flopchar(uint32_t ch);
static uint32_t rotatechar(uint32_t ch);
static uint32_t leftchar(uint32_t ch);
static uint32_t rightchar(uint32_t ch);
static void leftpair(uint32_t pair[2]);
static void rightpair(uint32_t pair[2]);

/** \brief Invert a canvas' colours.
*
@@ -363,16 +365,18 @@ int cucul_rotate_left_wide(cucul_canvas_t *cv)
{
for(x = 0; x < subwidth; x++)
{
uint32_t ch1, ch2, attr1, attr2;
uint32_t pair[2], attr1, attr2;

ch1 = cv->chars[(subwidth * y + x) * 2];
pair[0] = cv->chars[(subwidth * y + x) * 2];
attr1 = cv->attrs[(subwidth * y + x) * 2];
ch2 = cv->chars[(subwidth * y + x) * 2 + 1];
pair[1] = cv->chars[(subwidth * y + x) * 2 + 1];
attr2 = cv->attrs[(subwidth * y + x) * 2 + 1];

newchars[(subheight * (subwidth - 1 - x) + y) * 2] = ch1;
leftpair(pair);

newchars[(subheight * (subwidth - 1 - x) + y) * 2] = pair[0];
newattrs[(subheight * (subwidth - 1 - x) + y) * 2] = attr1;
newchars[(subheight * (subwidth - 1 - x) + y) * 2 + 1] = ch2;
newchars[(subheight * (subwidth - 1 - x) + y) * 2 + 1] = pair[1];
newattrs[(subheight * (subwidth - 1 - x) + y) * 2 + 1] = attr2;
}
}
@@ -553,16 +557,18 @@ int cucul_rotate_right_wide(cucul_canvas_t *cv)
{
for(x = 0; x < subwidth; x++)
{
uint32_t ch1, ch2, attr1, attr2;
uint32_t pair[2], attr1, attr2;

ch1 = cv->chars[(subwidth * y + x) * 2];
pair[0] = cv->chars[(subwidth * y + x) * 2];
attr1 = cv->attrs[(subwidth * y + x) * 2];
ch2 = cv->chars[(subwidth * y + x) * 2 + 1];
pair[1] = cv->chars[(subwidth * y + x) * 2 + 1];
attr2 = cv->attrs[(subwidth * y + x) * 2 + 1];

newchars[(subheight * x + subheight - 1 - y) * 2] = ch1;
rightpair(pair);

newchars[(subheight * x + subheight - 1 - y) * 2] = pair[0];
newattrs[(subheight * x + subheight - 1 - y) * 2] = attr1;
newchars[(subheight * x + subheight - 1 - y) * 2 + 1] = ch2;
newchars[(subheight * x + subheight - 1 - y) * 2 + 1] = pair[1];
newattrs[(subheight * x + subheight - 1 - y) * 2 + 1] = attr2;
}
}
@@ -901,6 +907,8 @@ static uint32_t const leftright4[] =
/* ASCII */
'<', 'v', '>', '^',
',', '.', '\'', '`',
/* ASCII / Unicode */
'(', 0x203f, ')', 0x2040, /* ( ‿ ) ⁀ */
/* Misc Unicode */
0x256d, 0x2570, 0x256f, 0x256e, /* ╭ ╰ ╯ ╮ */
/* CP437 */
@@ -953,3 +961,76 @@ static uint32_t rightchar(uint32_t ch)
return ch;
}

static uint32_t const leftright2x2[] =
{
/* ASCII / Unicode */
'-', '-', 0x4e28, CUCUL_MAGIC_FULLWIDTH, /* -- 丨 */
0, 0, 0, 0
};

static uint32_t const leftright2x4[] =
{
/* ASCII */
':', ' ', '.', '.', ' ', ':', '\'', '\'',
/* ASCII / Unicode */
' ', '`', 0x00b4, ' ', 0x02ce, ' ', ' ', ',', /* ` ´ ˎ , */
' ', '`', '\'', ' ', '.', ' ', ' ', ',',
'`', ' ', ',', ' ', ' ', 0x00b4, ' ', 0x02ce, /* ` , ˎ ´ */
'`', ' ', ',', ' ', ' ', '.', ' ', '\'',
'/', ' ', '-', 0x02ce, ' ', '/', '`', '-', /* / -ˎ / `- */
'/', ' ', '-', '.', ' ', '/', '\'', '-',
'\\', ' ', ',', '-', ' ', '\\', '-', 0x00b4, /* \ ,- \ -´ */
'\\', ' ', '.', '-', ' ', '\\', '-', '\'',
'|', ' ', '_', '_', ' ', '|', 0x203e, 0x203e, /* | __ | ‾‾ */
'_', '|', 0x203e, '|', '|', 0x203e, '|', '_', /* _| ‾| |‾ |_ */
'|', '_', '_', '|', 0x203e, '|', '|', 0x203e, /* |_ _| ‾| |‾ */
'_', ' ', ' ', 0x2577, ' ', 0x203e, 0x2575, ' ', /* _ ╷ ‾ ╵ */
' ', '_', ' ', 0x2575, 0x203e, ' ', 0x2577, ' ', /* _ ╵ ‾ ╷ */
/* Not perfect, but better than nothing */
' ', '`', '\'', ' ', '.', ' ', ' ', ',',
'`', ' ', ',', ' ', ' ', '.', ' ', '\'',
0, 0, 0, 0, 0, 0, 0, 0
};

static void leftpair(uint32_t pair[2])
{
int i;

for(i = 0; leftright2x2[i]; i += 2)
if(pair[0] == leftright2x2[i] && pair[1] == leftright2x2[i + 1])
{
pair[0] = leftright2x2[(i & ~3) | ((i + 2) & 3)];
pair[1] = leftright2x2[((i & ~3) | ((i + 2) & 3)) + 1];
return;
}

for(i = 0; leftright2x4[i]; i += 2)
if(pair[0] == leftright2x4[i] && pair[1] == leftright2x4[i + 1])
{
pair[0] = leftright2x4[(i & ~7) | ((i + 2) & 7)];
pair[1] = leftright2x4[((i & ~7) | ((i + 2) & 7)) + 1];
return;
}
}

static void rightpair(uint32_t pair[2])
{
int i;

for(i = 0; leftright2x2[i]; i += 2)
if(pair[0] == leftright2x2[i] && pair[1] == leftright2x2[i + 1])
{
pair[0] = leftright2x2[(i & ~3) | ((i - 2) & 3)];
pair[1] = leftright2x2[((i & ~3) | ((i - 2) & 3)) + 1];
return;
}

for(i = 0; leftright2x4[i]; i += 2)
if(pair[0] == leftright2x4[i] && pair[1] == leftright2x4[i + 1])
{
pair[0] = leftright2x4[(i & ~7) | ((i - 2) & 7)];
pair[1] = leftright2x4[((i & ~7) | ((i - 2) & 7)) + 1];
return;
}
}


+ 23
- 9
test/text.c Visa fil

@@ -25,21 +25,22 @@
#include "cucul.h"

#define STRING \
" \n" \
" _,----._ \n" \
" (/ @ @ \\) \n" \
" | OO | \n" \
" \\ `--' / \n" \
" `----' \n" \
" \n" \
" Hello world! \n" \
" \n"
" |_| \n" \
" _,----._ | | \n" \
" (/ @ @ \\) __ \n" \
" | OO | |_ \n" \
" \\ `--' / |__ \n" \
" `----' \n" \
" |_| \n" \
" Hello world! | \n" \
" \n"

int main(int argc, char *argv[])
{
cucul_canvas_t *cv, *pig;
void *buffer;
unsigned long int len;
unsigned int i, j;

pig = cucul_create_canvas(0, 0);
cucul_import_memory(pig, STRING, strlen(STRING), "text");
@@ -64,6 +65,19 @@ int main(int argc, char *argv[])
cucul_blit(cv, cucul_get_canvas_width(pig),
cucul_get_canvas_height(pig), pig, NULL);

for(j = 0; j < cucul_get_canvas_height(cv); j++)
{
for(i = 0; i < cucul_get_canvas_width(cv); i += 2)
{
unsigned long int a;
cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE + (i + j) % 6,
CUCUL_DEFAULT);
a = cucul_get_attr(cv, -1, -1);
cucul_put_attr(cv, i, j, a);
cucul_put_attr(cv, i + 1, j, a);
}
}

buffer = cucul_export_memory(cv, "utf8", &len);
fwrite(buffer, len, 1, stdout);
free(buffer);


Laddar…
Avbryt
Spara