Changeset 2988 for toilet/trunk/tools/caca2tlf.c
- Timestamp:
- 10/18/08 23:36:17 (5 years ago)
- File:
-
- 1 edited
-
toilet/trunk/tools/caca2tlf.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
toilet/trunk/tools/caca2tlf.c
r2415 r2988 25 25 #include <string.h> 26 26 #include <stdlib.h> 27 #include <c ucul.h>27 #include <caca.h> 28 28 29 29 enum mode { GRAY, HALFBLOCKS, QUARTERBLOCKS } mode; … … 32 32 static void add_char(unsigned long int); 33 33 34 c ucul_font_t *f;35 c ucul_canvas_t *out, *onechar;34 caca_font_t *f; 35 caca_canvas_t *out, *onechar; 36 36 uint32_t const *blocks; 37 37 uint8_t * image; … … 69 69 } 70 70 71 f = c ucul_load_font(fontname, 0);71 f = caca_load_font(fontname, 0); 72 72 73 73 if(!f) … … 78 78 } 79 79 80 w = c ucul_get_font_width(f);81 h = c ucul_get_font_height(f);80 w = caca_get_font_width(f); 81 h = caca_get_font_height(f); 82 82 iw = w * 2 + 1; 83 83 ih = h + 1; … … 101 101 } 102 102 103 blocks = c ucul_get_font_blocks(f);104 onechar = c ucul_create_canvas(0, 0);105 c ucul_set_color_ansi(onechar, CUCUL_WHITE, CUCUL_BLACK);103 blocks = caca_get_font_blocks(f); 104 onechar = caca_create_canvas(0, 0); 105 caca_set_color_ansi(onechar, CACA_WHITE, CACA_BLACK); 106 106 image = malloc(4 * iw * ih); 107 107 108 out = c ucul_create_canvas(0, 0);108 out = caca_create_canvas(0, 0); 109 109 printf("tlf2a$ %u %u %u -1 4 0 0 0\n", gh, gh - 1, fgw + 2); 110 110 … … 141 141 continue; 142 142 143 len = c ucul_utf32_to_utf8(buf, ch);143 len = caca_utf32_to_utf8(buf, ch); 144 144 buf[len] = '\0'; 145 145 printf("0x%.04lX %s\n", ch, buf); … … 148 148 } 149 149 150 c ucul_free_canvas(out);151 c ucul_free_canvas(onechar);150 caca_free_canvas(out); 151 caca_free_canvas(onechar); 152 152 free(image); 153 c ucul_free_font(f);153 caca_free_font(f); 154 154 155 155 return 0; … … 163 163 fprintf(stderr, "Available fonts:\n"); 164 164 165 fonts = c ucul_get_font_list();165 fonts = caca_get_font_list(); 166 166 for(i = 0; fonts[i]; i++) 167 167 fprintf(stderr, " \"%s\"\n", fonts[i]); … … 173 173 unsigned long int len; 174 174 unsigned int x, y, myw, mygw; 175 int full = c ucul_utf32_is_fullwidth(ch);176 177 c ucul_set_canvas_size(onechar, full ? 2 : 1, 1);178 c ucul_put_char(onechar, 0, 0, ch);179 c ucul_render_canvas(onechar, f, image, iw, ih, 4 * iw);175 int full = caca_utf32_is_fullwidth(ch); 176 177 caca_set_canvas_size(onechar, full ? 2 : 1, 1); 178 caca_put_char(onechar, 0, 0, ch); 179 caca_render_canvas(onechar, f, image, iw, ih, 4 * iw); 180 180 181 181 myw = full ? 2 * w : w; 182 182 mygw = full ? fgw : gw; 183 183 184 c ucul_set_canvas_size(out, (full ? fgw : gw) + 2, gh);184 caca_set_canvas_size(out, (full ? fgw : gw) + 2, gh); 185 185 186 186 switch(mode) … … 193 193 194 194 if(c >= 0xa0) 195 c ucul_put_str(out, x, y, "█");195 caca_put_str(out, x, y, "█"); 196 196 else if(c >= 0x80) 197 c ucul_put_str(out, x, y, "▓");197 caca_put_str(out, x, y, "▓"); 198 198 else if(c >= 0x40) 199 c ucul_put_str(out, x, y, "▒");199 caca_put_str(out, x, y, "▒"); 200 200 else if(c >= 0x20) 201 c ucul_put_str(out, x, y, "░");201 caca_put_str(out, x, y, "░"); 202 202 else 203 c ucul_put_char(out, x, y, ' ');203 caca_put_char(out, x, y, ' '); 204 204 } 205 205 break; … … 213 213 uint8_t p2 = image[4 * (x + (y * 2 + 1) * iw) + 2]; 214 214 215 c ucul_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80)]);215 caca_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80)]); 216 216 } 217 217 break; … … 231 231 uint8_t p4 = image[4 * (x * 2 + 1 + (y * 2 + 1) * iw) + 2]; 232 232 233 c ucul_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80) +233 caca_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80) + 234 234 4 * (p3 > 0x80) + 8 * (p4 > 0x80)]); 235 235 } … … 239 239 if(ch == ' ' || ch == 0xa0) 240 240 { 241 c ucul_draw_line(out, mygw - 1, 0, mygw - 1, gh - 1, '$');242 c ucul_draw_line(out, mygw / 2, 0, mygw / 2, gh - 1, '$');243 } 244 245 c ucul_draw_line(out, mygw, 0, mygw, gh - 1, '@');246 c ucul_put_char(out, mygw + 1, gh - 1, '@');247 248 buf = c ucul_export_memory(out, "utf8", &len);241 caca_draw_line(out, mygw - 1, 0, mygw - 1, gh - 1, '$'); 242 caca_draw_line(out, mygw / 2, 0, mygw / 2, gh - 1, '$'); 243 } 244 245 caca_draw_line(out, mygw, 0, mygw, gh - 1, '@'); 246 caca_put_char(out, mygw + 1, gh - 1, '@'); 247 248 buf = caca_export_memory(out, "utf8", &len); 249 249 fwrite(buf, len, 1, stdout); 250 250 free(buf);
Note: See TracChangeset
for help on using the changeset viewer.
