Changeset 1368 for toilet/trunk/tools
- Timestamp:
- Nov 12, 2006, 7:09:54 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
toilet/trunk/tools/caca2tlf.c
r1296 r1368 29 29 30 30 static void list_fonts(void); 31 static void add_char(unsigned int);31 static void add_char(unsigned long int); 32 32 33 33 cucul_font_t *f; … … 35 35 unsigned long int const *blocks; 36 36 uint8_t * image; 37 unsigned int w, h, gw, gh, iw, ih;37 unsigned int w, h, gw, fgw, gh, iw, ih; 38 38 39 39 int main(int argc, char *argv[]) … … 79 79 w = cucul_get_font_width(f); 80 80 h = cucul_get_font_height(f); 81 iw = w + 1;81 iw = w * 2 + 1; 82 82 ih = h + 1; 83 83 switch(mode) … … 85 85 case GRAY: 86 86 gw = w; 87 fgw = w * 2; 87 88 gh = h; 88 89 break; 89 90 case HALFBLOCKS: 90 91 gw = w; 92 fgw = w * 2; 91 93 gh = (h + 1) / 2; 92 94 break; 93 95 case QUARTERBLOCKS: 94 96 gw = (w + 1) / 2; 97 fgw = (w * 2 + 1) / 2; 95 98 gh = (h + 1) / 2; 96 99 break; … … 98 101 99 102 blocks = cucul_get_font_blocks(f); 100 onechar = cucul_create_canvas( 1, 1); /* FIXME: support double width */103 onechar = cucul_create_canvas(0, 0); 101 104 cucul_set_color_ansi(onechar, CUCUL_WHITE, CUCUL_BLACK); 102 105 image = malloc(4 * iw * ih); 103 106 104 out = cucul_create_canvas( gw + 2, gh);105 printf("tlf2a$ %u %u %u 0 4 0 0 0\n", gh, gh - 1, gw + 2);107 out = cucul_create_canvas(0, 0); 108 printf("tlf2a$ %u %u %u 0 4 0 0 0\n", gh, gh - 1, fgw + 2); 106 109 107 110 printf("==============================================" … … 164 167 } 165 168 166 static void add_char(unsigned int ch)169 static void add_char(unsigned long int ch) 167 170 { 168 171 cucul_buffer_t *buf; 169 unsigned int x, y; 170 172 unsigned int x, y, myw, mygw; 173 int full = cucul_utf32_is_fullwidth(ch); 174 175 cucul_set_canvas_size(onechar, full ? 2 : 1, 1); 171 176 cucul_putchar(onechar, 0, 0, ch); 172 177 cucul_render_canvas(onechar, f, image, iw, ih, 4 * iw); 173 178 179 myw = full ? 2 * w : w; 180 mygw = full ? fgw : gw; 181 182 cucul_set_canvas_size(out, (full ? fgw : gw) + 2, gh); 183 174 184 switch(mode) 175 185 { 176 186 case GRAY: 177 187 for(y = 0; y < h; y++) 178 for(x = 0; x <w; x++)188 for(x = 0; x < myw; x++) 179 189 { 180 190 uint8_t c = image[4 * (x + y * iw) + 2]; … … 194 204 case HALFBLOCKS: 195 205 for(y = 0; y < gh; y++) 196 for(x = 0; x <gw; x++)206 for(x = 0; x < mygw; x++) 197 207 { 198 208 static char const *str[] = { " ", "▀", "▄", "█" }; … … 201 211 uint8_t p2 = image[4 * (x + (y * 2 + 1) * iw) + 2]; 202 212 203 cucul_putstr(out, x, y, 204 str[(p1 < 0x80 ? 0 : 1) + (p2 < 0x80 ? 0 : 2)]); 213 cucul_putstr(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80)]); 205 214 } 206 215 break; 207 216 case QUARTERBLOCKS: 208 217 for(y = 0; y < gh; y++) 209 for(x = 0; x <gw; x++)218 for(x = 0; x < mygw; x++) 210 219 { 211 220 static char const *str[] = … … 220 229 uint8_t p4 = image[4 * (x * 2 + 1 + (y * 2 + 1) * iw) + 2]; 221 230 222 cucul_putstr(out, x, y, 223 str[(p1 < 0x80 ? 0 : 1) + (p2 < 0x80 ? 0 : 2) + 224 (p3 < 0x80 ? 0 : 4) + (p4 < 0x80 ? 0 : 8)]); 225 } 226 break; 227 } 228 229 cucul_draw_line(out, gw, 0, gw, gh - 1, "@"); 230 cucul_putchar(out, gw + 1, gh - 1, '@'); 231 cucul_putstr(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80) + 232 4 * (p3 > 0x80) + 8 * (p4 > 0x80)]); 233 } 234 break; 235 } 236 237 cucul_draw_line(out, mygw, 0, mygw, gh - 1, '@'); 238 cucul_putchar(out, mygw + 1, gh - 1, '@'); 231 239 232 240 buf = cucul_export_canvas(out, "utf8");
Note: See TracChangeset
for help on using the changeset viewer.