Browse Source

* Factored more UTF32 to UTF8 conversions using _cucul_utf32_to_utf8().

tags/v0.99.beta14
Sam Hocevar sam 18 years ago
parent
commit
b2d84d524d
4 changed files with 13 additions and 85 deletions
  1. +3
    -32
      caca/driver_ncurses.c
  2. +3
    -26
      caca/driver_slang.c
  3. +1
    -0
      tools/Makefile.am
  4. +6
    -27
      tools/makefont.c

+ 3
- 32
caca/driver_ncurses.c View File

@@ -487,43 +487,14 @@ static void ncurses_check_terminal(void)
static void ncurses_write_utf32(uint32_t ch)
{
#if defined(HAVE_NCURSESW_NCURSES_H)
static const uint8_t mark[7] =
{
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
};

char buf[10], *parser;
char buf[10];
int bytes;
#endif

if(ch < 0x80)
{
addch(ch);
return;
}

#if defined(HAVE_NCURSESW_NCURSES_H)
if(ch < 0x10000)
{
addch(ch); /* FIXME: doesn't work either */
return;
}

bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4;
bytes = _cucul_utf32_to_utf8(buf, ch);
buf[bytes] = '\0';
parser = buf + bytes;

switch(bytes)
{
case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
}
*--parser = ch | mark[bytes];

addstr(buf);
#else
addch(' ');
addch(ch < 0x80 ? ch : '?');
#endif
}



+ 3
- 26
caca/driver_slang.c View File

@@ -392,37 +392,14 @@ static void slang_init_palette(void)
static void slang_write_utf32(uint32_t ch)
{
#ifdef HAVE_SLSMG_UTF8_ENABLE
static const uint8_t mark[7] =
{
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
};

char buf[10], *parser;
char buf[10];
int bytes;
#endif

if(ch < 0x80)
{
SLsmg_write_char(ch);
return;
}

#ifdef HAVE_SLSMG_UTF8_ENABLE
bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4;
bytes = _cucul_utf32_to_utf8(buf, ch);
buf[bytes] = '\0';
parser = buf + bytes;

switch(bytes)
{
case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
}
*--parser = ch | mark[bytes];

SLsmg_write_string(buf);
#else
SLsmg_write_char(' ');
SLsmg_write_char(ch < 0x80 ? ch : ' ');
#endif
}



+ 1
- 0
tools/Makefile.am View File

@@ -9,6 +9,7 @@ optipal_SOURCES = optipal.c
makefont_SOURCES = makefont.c
makefont_CFLAGS = `pkg-config --cflags pangoft2`
makefont_LDFLAGS = `pkg-config --libs pangoft2`
makefont_LDADD = ../cucul/libcucul.la

if USE_PANGO
pango_programs = makefont


+ 6
- 27
tools/makefont.c View File

@@ -27,6 +27,9 @@
# include <netinet/in.h>
#endif

#include "cucul.h"
#include "cucul_internals.h"

#include <pango/pango.h>
#include <pango/pangoft2.h>

@@ -199,35 +202,11 @@ int main(int argc, char *argv[])
for(i = blocklist[b]; i < blocklist[b + 1]; i++)
{
unsigned int ch = i;
char buf[10], *parser;
char buf[10];
int x, y, bytes;

if(ch < 0x80)
{
bytes = 1;
buf[0] = ch;
buf[1] = '\0';
}
else
{
static const unsigned char mark[7] =
{
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
};

/* FIXME: use libcucul instead of this shit */
bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4;
buf[bytes] = '\0';
parser = buf + bytes;

switch(bytes)
{
case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
}
*--parser = ch | mark[bytes];
}
bytes = _cucul_utf32_to_utf8(buf, ch);
buf[bytes] = '\0';

/* Print glyph value in comment */
printf("/* U+%.04X: \"", i);


Loading…
Cancel
Save