Changeset 643 for libcaca/trunk
- Timestamp:
- Mar 17, 2006, 2:32:58 PM (15 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 5 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/driver_conio.c
r631 r643 34 34 #include "cucul.h" 35 35 #include "cucul_internals.h" 36 37 static uint8_t conio_utf32_to_cp437(uint32_t);38 36 39 37 struct driver_private … … 107 105 for(n = kk->qq->height * kk->qq->width; n--; ) 108 106 { 109 *screen++ = conio_utf32_to_cp437(*chars++);107 *screen++ = _cucul_utf32_to_cp437(*chars++); 110 108 *screen++ = *attr++; 111 109 } … … 137 135 138 136 /* 139 * XXX: following functions are local140 */141 142 static uint8_t conio_utf32_to_cp437(uint32_t c)143 {144 static uint32_t const lookup1[] =145 {146 /* 0x01 - 0x0f: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ */147 0x263a, 0x263b, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022,148 0x25d8, 0x25cb, 0x25d9, 0x2642, 0x2640, 0x266a, 0x266b, 0x263c,149 /* 0x10 - 0x1f: ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼ */150 0x25ba, 0x25c4, 0x2195, 0x203c, 0xb6, 0xa7, 0x25ac, 0x21a8,151 0x2191, 0x2193, 0x2192, 0x2190, 0x221f, 0x2194, 0x25b2, 0x25bc152 };153 154 static uint32_t const lookup2[] =155 {156 /* 0x7f: ⌂ */157 0x2302,158 /* 0x80 - 0x8f: Ç ü é â ä à å ç ê ë è ï î ì Ä Å */159 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7,160 0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5,161 /* 0x90 - 0x9f: É æ Æ ô ö ò û ù ÿ Ö Ü ¢ £ ¥ ₧ ƒ */162 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9,163 0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0x20a7, 0x192,164 /* 0xa0 - 0xaf: á í ó ú ñ Ñ ª º ¿ ⌐ ¬ ½ ¼ ¡ « » */165 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba,166 0xbf, 0x2310, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb,167 /* 0xb0 - 0xbf: ░ ▒ ▓ │ ┤ ╡ ╢ ╖ ╕ ╣ ║ ╗ ╝ ╜ ╛ ┐ */168 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,169 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,170 /* 0xc0 - 0xcf: └ ┴ ┬ ├ ─ ┼ ╞ ╟ ╚ ╔ ╩ ╦ ╠ ═ ╬ ╧ */171 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,172 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,173 /* 0xd0 - 0xdf: ╨ ╤ ╥ ╙ ╘ ╒ ╓ ╫ ╪ ┘ ┌ █ ▄ ▌ ▐ ▀ */174 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b,175 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580,176 /* 0xe0 - 0xef: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ */177 0x3b1, 0xdf, 0x393, 0x3c0, 0x3a3, 0x3c3, 0xb5, 0x3c4,178 0x3a6, 0x398, 0x3a9, 0x3b4, 0x221e, 0x3c6, 0x3b5, 0x2229,179 /* 0xf0 - 0xff: ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■ <nbsp> */180 0x2261, 0xb1, 0x2265, 0x2264, 0x2320, 0x2321, 0xf7, 0x2248,181 0xb0, 0x2219, 0xb7, 0x221a, 0x207f, 0xb2, 0x25a0, 0xa0182 };183 184 unsigned int i;185 186 if(c < 0x00000020)187 return '?';188 189 if(c < 0x00000080)190 return c;191 192 for(i = 0; i < sizeof(lookup1) / sizeof(*lookup1); i++)193 if(lookup1[i] == c)194 return 0x01 + i;195 196 for(i = 0; i < sizeof(lookup2) / sizeof(*lookup2); i++)197 if(lookup2[i] == c)198 return 0x7f + i;199 200 return '?';201 }202 203 /*204 137 * Driver initialisation 205 138 */ -
libcaca/trunk/caca/driver_vga.c
r631 r643 26 26 #include "cucul.h" 27 27 #include "cucul_internals.h" 28 29 static uint8_t vga_utf32_to_cp437(uint32_t);30 28 31 29 /* Address of the VGA screen */ … … 125 123 for(n = kk->qq->height * kk->qq->width; n--; ) 126 124 { 127 *screen++ = vga_utf32_to_cp437(*chars++);125 *screen++ = _cucul_utf32_to_cp437(*chars++); 128 126 *screen++ = *attr++; 129 127 } … … 141 139 /* FIXME */ 142 140 return CACA_EVENT_NONE; 143 }144 145 /*146 * XXX: following functions are local147 */148 149 static uint8_t vga_utf32_to_cp437(uint32_t c)150 {151 static uint32_t const lookup1[] =152 {153 /* 0x01 - 0x0f: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ */154 0x263a, 0x263b, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022,155 0x25d8, 0x25cb, 0x25d9, 0x2642, 0x2640, 0x266a, 0x266b, 0x263c,156 /* 0x10 - 0x1f: ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼ */157 0x25ba, 0x25c4, 0x2195, 0x203c, 0xb6, 0xa7, 0x25ac, 0x21a8,158 0x2191, 0x2193, 0x2192, 0x2190, 0x221f, 0x2194, 0x25b2, 0x25bc159 };160 161 static uint32_t const lookup2[] =162 {163 /* 0x7f: ⌂ */164 0x2302,165 /* 0x80 - 0x8f: Ç ü é â ä à å ç ê ë è ï î ì Ä Å */166 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7,167 0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5,168 /* 0x90 - 0x9f: É æ Æ ô ö ò û ù ÿ Ö Ü ¢ £ ¥ ₧ ƒ */169 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9,170 0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0x20a7, 0x192,171 /* 0xa0 - 0xaf: á í ó ú ñ Ñ ª º ¿ ⌐ ¬ ½ ¼ ¡ « » */172 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba,173 0xbf, 0x2310, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb,174 /* 0xb0 - 0xbf: ░ ▒ ▓ │ ┤ ╡ ╢ ╖ ╕ ╣ ║ ╗ ╝ ╜ ╛ ┐ */175 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,176 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,177 /* 0xc0 - 0xcf: └ ┴ ┬ ├ ─ ┼ ╞ ╟ ╚ ╔ ╩ ╦ ╠ ═ ╬ ╧ */178 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,179 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,180 /* 0xd0 - 0xdf: ╨ ╤ ╥ ╙ ╘ ╒ ╓ ╫ ╪ ┘ ┌ █ ▄ ▌ ▐ ▀ */181 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b,182 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580,183 /* 0xe0 - 0xef: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ */184 0x3b1, 0xdf, 0x393, 0x3c0, 0x3a3, 0x3c3, 0xb5, 0x3c4,185 0x3a6, 0x398, 0x3a9, 0x3b4, 0x221e, 0x3c6, 0x3b5, 0x2229,186 /* 0xf0 - 0xff: ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■ <nbsp> */187 0x2261, 0xb1, 0x2265, 0x2264, 0x2320, 0x2321, 0xf7, 0x2248,188 0xb0, 0x2219, 0xb7, 0x221a, 0x207f, 0xb2, 0x25a0, 0xa0189 };190 191 unsigned int i;192 193 if(c < 0x00000020)194 return '?';195 196 if(c < 0x00000080)197 return c;198 199 for(i = 0; i < sizeof(lookup1) / sizeof(*lookup1); i++)200 if(lookup1[i] == c)201 return 0x01 + i;202 203 for(i = 0; i < sizeof(lookup2) / sizeof(*lookup2); i++)204 if(lookup2[i] == c)205 return 0x7f + i;206 207 return '?';208 141 } 209 142 -
libcaca/trunk/cucul/Makefile.am
r620 r643 10 10 cucul_internals.h \ 11 11 char.c \ 12 charset.c \ 12 13 math.c \ 13 14 line.c \ -
libcaca/trunk/cucul/char.c
r583 r643 39 39 #include "cucul_internals.h" 40 40 41 size_t utf8_strlen(const char *s);42 const char *utf8_skip(const char *s, size_t x);43 uint32_t utf8_to_utf32(const char *s);44 45 41 /** \brief Set the default colour pair. 46 42 * … … 158 154 return; 159 155 160 len = utf8_strlen(s);156 len = _cucul_strlen_utf8(s); 161 157 162 158 if(x < 0) … … 165 161 return; 166 162 len -= -x; 167 s = utf8_skip(s, -x);163 s = _cucul_skip_utf8(s, -x); 168 164 x = 0; 169 165 } … … 177 173 while(len) 178 174 { 179 *chars++ = utf8_to_utf32(s);175 *chars++ = _cucul_utf8_to_utf32(s); 180 176 *attr++ = (qq->bgcolor << 4) | qq->fgcolor; 181 177 182 s = utf8_skip(s, 1);178 s = _cucul_skip_utf8(s, 1); 183 179 len--; 184 180 } … … 262 258 } 263 259 264 /*265 * XXX: The following functions are local.266 */267 268 static const char trailing[256] =269 {270 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,271 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,272 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,273 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,274 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,275 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,276 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,277 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5278 };279 280 static const uint32_t offsets[6] =281 {282 0x00000000UL, 0x00003080UL, 0x000E2080UL,283 0x03C82080UL, 0xFA082080UL, 0x82082080UL284 };285 286 size_t utf8_strlen(const char *s)287 {288 int len = 0;289 const char *parser = s;290 291 while(*parser)292 {293 int i;294 int bytes = 1 + trailing[(int)(unsigned char)*parser];295 296 for(i = 1; i < bytes; i++)297 if(!parser[i])298 return len;299 parser += bytes;300 len++;301 }302 303 return len;304 }305 306 const char *utf8_skip(const char *s, size_t x)307 {308 const char *parser = s;309 310 while(x)311 {312 int i;313 int bytes = 1 + trailing[(int)(unsigned char)*parser];314 315 for(i = 1; i < bytes; i++)316 if(!parser[i])317 return parser;318 parser += bytes;319 x--;320 }321 322 return parser;323 }324 325 uint32_t utf8_to_utf32(const char *s)326 {327 int bytes = trailing[(int)(unsigned char)*s];328 uint32_t ret = 0;329 330 switch(bytes)331 {332 /* FIXME: do something for invalid sequences (4 and 5) */333 case 3: ret += (uint8_t)*s++; ret <<= 6;334 case 2: ret += (uint8_t)*s++; ret <<= 6;335 case 1: ret += (uint8_t)*s++; ret <<= 6;336 case 0: ret += (uint8_t)*s++;337 }338 339 ret -= offsets[bytes];340 341 return ret;342 }343 -
libcaca/trunk/cucul/charset.c
r639 r643 10 10 */ 11 11 12 /** \file char .c12 /** \file charset.c 13 13 * \version \$Id$ 14 14 * \author Sam Hocevar <sam@zoy.org> 15 * \brief Character drawing15 * \brief Character set conversions 16 16 * 17 * This file contains character and string drawing functions. 17 * This file contains functions for converting characters between 18 * various character sets. 18 19 */ 19 20 … … 21 22 22 23 #if !defined(__KERNEL__) 23 # include <stdio.h> /* BUFSIZ */24 24 # include <string.h> 25 # include <stdlib.h>26 # include <stdarg.h>27 # if defined(HAVE_UNISTD_H)28 # include <unistd.h>29 # endif30 # if defined(HAVE_SIGNAL_H)31 # include <signal.h>32 # endif33 # if defined(HAVE_SYS_IOCTL_H)34 # include <sys/ioctl.h>35 # endif36 25 #endif 37 26 … … 39 28 #include "cucul_internals.h" 40 29 41 size_t utf8_strlen(const char *s); 42 const char *utf8_skip(const char *s, size_t x); 43 uint32_t utf8_to_utf32(const char *s); 44 45 /** \brief Set the default colour pair. 46 * 47 * This function sets the default colour pair. String functions such as 48 * caca_printf() and graphical primitive functions such as caca_draw_line() 49 * will use these colour pairs. 50 * 51 * \param fgcolor The requested foreground colour. 52 * \param bgcolor The requested background colour. 53 */ 54 void cucul_set_color(cucul_t *qq, enum cucul_color fgcolor, enum cucul_color bgcolor) 55 { 56 if(fgcolor < 0 || fgcolor > 15 || bgcolor < 0 || bgcolor > 15) 57 return; 58 59 qq->fgcolor = fgcolor; 60 qq->bgcolor = bgcolor; 61 } 62 63 /** \brief Get the current foreground colour. 64 * 65 * This function returns the current foreground colour that was set with 66 * cucul_set_color(). 67 * 68 * \return The current foreground colour. 69 */ 70 enum cucul_color cucul_get_fg_color(cucul_t *qq) 71 { 72 return qq->fgcolor; 73 } 74 75 /** \brief Get the current background colour. 76 * 77 * This function returns the current background colour that was set with 78 * cucul_set_color(). 79 * 80 * \return The current background colour. 81 */ 82 enum cucul_color cucul_get_bg_color(cucul_t *qq) 83 { 84 return qq->bgcolor; 85 } 86 87 /** \brief Print an ASCII character. 88 * 89 * This function prints an ASCII character at the given coordinates, using 90 * the default foreground and background values. If the coordinates are 91 * outside the screen boundaries, nothing is printed. If the character 92 * value is a non-printable character or is outside the ASCII range, it is 93 * replaced with a space. To print a sequence of bytes forming an UTF-8 94 * character, use cucul_putstr() instead. 95 * 96 * \param x X coordinate. 97 * \param y Y coordinate. 98 * \param c The character to print. 99 */ 100 void cucul_putchar(cucul_t *qq, int x, int y, char c) 101 { 102 if(x < 0 || x >= (int)qq->width || 103 y < 0 || y >= (int)qq->height) 104 return; 105 106 if((unsigned char)c < 0x20 || (unsigned char)c > 0x7f) 107 c = 0x20; 108 109 qq->chars[x + y * qq->width] = c; 110 qq->attr[x + y * qq->width] = (qq->bgcolor << 4) | qq->fgcolor; 111 } 112 113 /** \brief Print a Unicode character. 114 * 115 * FIXME: do we really want this function? 116 * 117 * This function prints a Unicode character (native-endian, 32 bits UCS-4, 118 * also known as UTF-32) at the given coordinates, using the default 119 * foreground and background values. If the coordinates are outside the 120 * screen boundaries, nothing is printed. If the character is an invalid 121 * Unicode character, it is replaced with a space. 122 * 123 * \param x X coordinate. 124 * \param y Y coordinate. 125 * \param c The character to print. 126 */ 127 void cucul_putchar32(cucul_t *qq, int x, int y, unsigned long int c) 128 { 129 if(x < 0 || x >= (int)qq->width || 130 y < 0 || y >= (int)qq->height) 131 return; 132 133 if(c < 0x20 || c > 0x7f) 134 c = 0x20; 135 136 qq->chars[x + y * qq->width] = c; 137 qq->attr[x + y * qq->width] = (qq->bgcolor << 4) | qq->fgcolor; 138 } 139 140 /** \brief Print a string. 141 * 142 * This function prints an UTF-8 string at the given coordinates, using the 143 * default foreground and background values. The coordinates may be outside 144 * the screen boundaries (eg. a negative Y coordinate) and the string will 145 * be cropped accordingly if it is too long. 146 * 147 * \param x X coordinate. 148 * \param y Y coordinate. 149 * \param s The string to print. 150 */ 151 void cucul_putstr(cucul_t *qq, int x, int y, char const *s) 152 { 153 uint32_t *chars; 154 uint8_t *attr; 155 unsigned int len; 156 157 if(y < 0 || y >= (int)qq->height || x >= (int)qq->width) 158 return; 159 160 len = utf8_strlen(s); 161 162 if(x < 0) 163 { 164 if(len < (unsigned int)-x) 165 return; 166 len -= -x; 167 s = utf8_skip(s, -x); 168 x = 0; 169 } 170 171 chars = qq->chars + x + y * qq->width; 172 attr = qq->attr + x + y * qq->width; 173 174 if(x + len >= qq->width) 175 len = qq->width - x; 176 177 while(len) 178 { 179 *chars++ = utf8_to_utf32(s); 180 *attr++ = (qq->bgcolor << 4) | qq->fgcolor; 181 182 s = utf8_skip(s, 1); 183 len--; 184 } 185 } 186 187 /** \brief Format a string. 188 * 189 * This function formats a string at the given coordinates, using the 190 * default foreground and background values. The coordinates may be outside 191 * the screen boundaries (eg. a negative Y coordinate) and the string will 192 * be cropped accordingly if it is too long. The syntax of the format 193 * string is the same as for the C printf() function. 194 * 195 * \param x X coordinate. 196 * \param y Y coordinate. 197 * \param format The format string to print. 198 * \param ... Arguments to the format string. 199 */ 200 void cucul_printf(cucul_t *qq, int x, int y, char const *format, ...) 201 { 202 char tmp[BUFSIZ]; 203 char *buf = tmp; 204 va_list args; 205 206 if(y < 0 || y >= (int)qq->height || x >= (int)qq->width) 207 return; 208 209 if(qq->width - x + 1 > BUFSIZ) 210 buf = malloc(qq->width - x + 1); 211 212 va_start(args, format); 213 #if defined(HAVE_VSNPRINTF) 214 vsnprintf(buf, qq->width - x + 1, format, args); 215 #else 216 vsprintf(buf, format, args); 217 #endif 218 buf[qq->width - x] = '\0'; 219 va_end(args); 220 221 cucul_putstr(qq, x, y, buf); 222 223 if(buf != tmp) 224 free(buf); 225 } 226 227 /** \brief Get the screen. 228 * 229 * This function fills a byte array with the character values. 230 */ 231 void cucul_get_screen(cucul_t *qq, char *buffer) 232 { 233 unsigned int x, y; 234 235 for(y = 0; y < qq->height; y++) 236 { 237 for(x = 0; x < qq->width; x++) 238 { 239 *buffer++ = qq->attr[x + y * qq->width]; 240 *buffer++ = qq->chars[x + y * qq->width] & 0x7f; /* FIXME: ASCII */ 241 } 242 } 243 } 244 245 /** \brief Clear the screen. 246 * 247 * This function clears the screen using a black background. 248 */ 249 void cucul_clear(cucul_t *qq) 250 { 251 enum cucul_color oldfg = cucul_get_fg_color(qq); 252 enum cucul_color oldbg = cucul_get_bg_color(qq); 253 int y = qq->height; 254 255 cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); 256 257 /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */ 258 while(y--) 259 cucul_putstr(qq, 0, y, qq->empty_line); 260 261 cucul_set_color(qq, oldfg, oldbg); 262 } 263 264 /* 265 * XXX: The following functions are local. 266 */ 267 268 static const char trailing[256] = 30 static char const trailing[256] = 269 31 { 270 32 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, … … 278 40 }; 279 41 280 static const uint32_t offsets[6] =42 static uint32_t const offsets[6] = 281 43 { 282 44 0x00000000UL, 0x00003080UL, 0x000E2080UL, … … 284 46 }; 285 47 286 size_t utf8_strlen(const char*s)48 unsigned int _cucul_strlen_utf8(char const *s) 287 49 { 288 50 int len = 0; 289 c onst char*parser = s;51 char const *parser = s; 290 52 291 53 while(*parser) … … 304 66 } 305 67 306 c onst char *utf8_skip(const char *s, size_t x)68 char const *_cucul_skip_utf8(char const *s, unsigned int x) 307 69 { 308 c onst char*parser = s;70 char const *parser = s; 309 71 310 72 while(x) … … 323 85 } 324 86 325 uint32_t utf8_to_utf32(const char*s)87 uint32_t _cucul_utf8_to_utf32(char const *s) 326 88 { 327 89 int bytes = trailing[(int)(unsigned char)*s]; … … 342 104 } 343 105 106 /* 107 * CP437 handling 108 */ 109 110 static uint32_t const cp437_lookup1[] = 111 { 112 /* 0x01 - 0x0f: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ */ 113 0x263a, 0x263b, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, 114 0x25d8, 0x25cb, 0x25d9, 0x2642, 0x2640, 0x266a, 0x266b, 0x263c, 115 /* 0x10 - 0x1f: ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼ */ 116 0x25ba, 0x25c4, 0x2195, 0x203c, 0xb6, 0xa7, 0x25ac, 0x21a8, 117 0x2191, 0x2193, 0x2192, 0x2190, 0x221f, 0x2194, 0x25b2, 0x25bc 118 }; 119 120 static uint32_t const cp437_lookup2[] = 121 { 122 /* 0x7f: ⌂ */ 123 0x2302, 124 /* 0x80 - 0x8f: Ç ü é â ä à å ç ê ë è ï î ì Ä Å */ 125 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7, 126 0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5, 127 /* 0x90 - 0x9f: É æ Æ ô ö ò û ù ÿ Ö Ü ¢ £ ¥ ₧ ƒ */ 128 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9, 129 0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0x20a7, 0x192, 130 /* 0xa0 - 0xaf: á í ó ú ñ Ñ ª º ¿ ⌐ ¬ ½ ¼ ¡ « » */ 131 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba, 132 0xbf, 0x2310, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb, 133 /* 0xb0 - 0xbf: ░ ▒ ▓ │ ┤ ╡ ╢ ╖ ╕ ╣ ║ ╗ ╝ ╜ ╛ ┐ */ 134 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 135 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, 136 /* 0xc0 - 0xcf: └ ┴ ┬ ├ ─ ┼ ╞ ╟ ╚ ╔ ╩ ╦ ╠ ═ ╬ ╧ */ 137 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 138 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, 139 /* 0xd0 - 0xdf: ╨ ╤ ╥ ╙ ╘ ╒ ╓ ╫ ╪ ┘ ┌ █ ▄ ▌ ▐ ▀ */ 140 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 141 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, 142 /* 0xe0 - 0xef: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ */ 143 0x3b1, 0xdf, 0x393, 0x3c0, 0x3a3, 0x3c3, 0xb5, 0x3c4, 144 0x3a6, 0x398, 0x3a9, 0x3b4, 0x221e, 0x3c6, 0x3b5, 0x2229, 145 /* 0xf0 - 0xff: ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■ <nbsp> */ 146 0x2261, 0xb1, 0x2265, 0x2264, 0x2320, 0x2321, 0xf7, 0x2248, 147 0xb0, 0x2219, 0xb7, 0x221a, 0x207f, 0xb2, 0x25a0, 0xa0 148 }; 149 150 uint8_t _cucul_utf32_to_cp437(uint32_t c) 151 { 152 unsigned int i; 153 154 if(c < 0x00000020) 155 return '?'; 156 157 if(c < 0x00000080) 158 return c; 159 160 for(i = 0; i < sizeof(cp437_lookup1) / sizeof(*cp437_lookup1); i++) 161 if(cp437_lookup1[i] == c) 162 return 0x01 + i; 163 164 for(i = 0; i < sizeof(cp437_lookup2) / sizeof(*cp437_lookup2); i++) 165 if(cp437_lookup2[i] == c) 166 return 0x7f + i; 167 168 return '?'; 169 } 170 171 uint32_t _cucul_cp437_to_utf32(uint8_t c) 172 { 173 if(c > 0x7f) 174 return cp437_lookup2[c - 0x7f]; 175 176 if(c >= 0x20) 177 return (uint32_t)c; 178 179 if(c > 0) 180 return cp437_lookup1[c - 0x01]; 181 182 return 0x00000000; 183 } 184 -
libcaca/trunk/cucul/cucul_internals.h
r609 r643 55 55 void _cucul_set_size(cucul_t *qq, unsigned int width, unsigned int height); 56 56 57 /* Charset functions */ 58 unsigned int _cucul_strlen_utf8(char const *s); 59 char const *_cucul_skip_utf8(char const *s, unsigned int x); 60 uint32_t _cucul_utf8_to_utf32(char const *s); 61 uint8_t _cucul_utf32_to_cp437(uint32_t c); 62 uint32_t _cucul_cp437_to_utf32(uint8_t c); 63 64 /* Export functions */ 65 void _cucul_get_ansi(cucul_t *qq, struct cucul_buffer *ex); 66 void _cucul_get_html(cucul_t *qq, struct cucul_buffer *ex); 67 void _cucul_get_html3(cucul_t *qq, struct cucul_buffer *ex); 68 void _cucul_get_irc(cucul_t *qq, struct cucul_buffer *ex); 69 void _cucul_get_ps(cucul_t *qq, struct cucul_buffer *ex); 70 void _cucul_get_svg(cucul_t *qq, struct cucul_buffer *ex); 57 71 58 72 #endif /* __CUCUL_INTERNALS_H__ */
Note: See TracChangeset
for help on using the changeset viewer.