Changeset 841 for libcaca/trunk/cucul/import.c
- Timestamp:
- Apr 22, 2006, 9:10:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/import.c
r829 r841 28 28 29 29 static cucul_canvas_t *import_caca(void const *, unsigned int); 30 static cucul_canvas_t *import_text(void const *, unsigned int); 30 31 31 32 /** \brief Import a buffer into a canvas … … 49 50 if(!strcasecmp("caca", format)) 50 51 return import_caca(data, size); 52 if(!strcasecmp("text", format)) 53 return import_text(data, size); 51 54 52 55 /* FIXME: Try to autodetect */ … … 71 74 { 72 75 "", "autodetect", 76 "text", "plain text", 73 77 "caca", "native libcaca format", 74 78 NULL, NULL … … 128 132 } 129 133 134 static cucul_canvas_t *import_text(void const *data, unsigned int size) 135 { 136 cucul_canvas_t *cv; 137 char const *text = (char const *)data; 138 unsigned int width = 1, height = 1, x = 0, y = 0, i; 139 140 cv = cucul_create_canvas(width, height); 141 cucul_set_color(cv, CUCUL_COLOR_DEFAULT, CUCUL_COLOR_TRANSPARENT); 142 143 for(i = 0; i < size; i++) 144 { 145 unsigned char ch = *text++; 146 147 if(ch == '\r') 148 continue; 149 150 if(ch == '\n') 151 { 152 x = 0; 153 y++; 154 continue; 155 } 156 157 while(x >= width) 158 { 159 width++; 160 cucul_set_canvas_size(cv, width, height); 161 } 162 163 while(y >= height) 164 { 165 height++; 166 cucul_set_canvas_size(cv, width, height); 167 } 168 169 cucul_putchar(cv, x, y, ch); 170 x++; 171 } 172 173 return cv; 174 } 175
Note: See TracChangeset
for help on using the changeset viewer.