Changeset 3179
- Timestamp:
- Nov 1, 2008, 5:41:25 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/codec/export.c
r2962 r3179 460 460 char *data, *cur; 461 461 int x, y, len; 462 int maxcols; 462 463 463 464 /* The HTML table markup: less than 1000 bytes … … 465 466 * A glyph: 40 chars for "<td bgcolor=#xxxxxx><font color=#xxxxxx>" 466 467 * up to 36 chars for "<b><i><u><blink></blink></u></i></b>" 467 * up to 9 chars for "&#xxxxxx;",far less for pure ASCII468 * up to 48 chars for "&#xxxxxx;", or " " (\t); far less for pure ASCII 468 469 * 12 chars for "</font></td>" */ 469 *bytes = 1000 + cv->height * (10 + cv->width * (40 + 36 + 9+ 12));470 *bytes = 1000 + cv->height * (10 + cv->width * (40 + 36 + 48 + 12)); 470 471 cur = data = malloc(*bytes); 471 472 472 473 /* Table */ 474 maxcols = 0; 475 for(y = 0; y < cv->height; y++) 476 { 477 uint32_t *linechar = cv->chars + y * cv->width; 478 int cols = 0; 479 480 for(x = 0; x < cv->width; x++) 481 { 482 if(linechar[x] == 0x00000009) 483 while((cols + 1) % 8) 484 cols ++; 485 cols ++; 486 } 487 if (cols > maxcols) 488 maxcols = cols; 489 } 490 473 491 cur += sprintf(cur, "<table cols='%d' cellpadding='0' cellspacing='0'>\n", 474 cv->height);492 maxcols); 475 493 476 494 for(y = 0; y < cv->height; y++) … … 478 496 uint32_t *lineattr = cv->attrs + y * cv->width; 479 497 uint32_t *linechar = cv->chars + y * cv->width; 498 int taboff = 0; 480 499 481 500 cur += sprintf(cur, "<tr>"); … … 484 503 { 485 504 int i, needfont; 505 int thistab = 0; 486 506 487 507 /* Use colspan option to factor cells with same attributes 488 508 * (see below) */ 489 509 len = 1; 490 while( x + len < cv->width && lineattr[x + len] == lineattr[x])510 while((x + len < cv->width) && (lineattr[x + len] == lineattr[x])) 491 511 len++; 512 513 for(i = 0; i < len; i++) 514 if(linechar[x + i] == 0x00000009) 515 while((x + i + taboff + thistab + 1) % 8) 516 thistab ++; 492 517 493 518 cur += sprintf(cur, "<td"); … … 497 522 _caca_attr_to_rgb24bg(lineattr[x])); 498 523 499 if( len> 1)500 cur += sprintf(cur, " colspan=%d", len );524 if((len + thistab) > 1) 525 cur += sprintf(cur, " colspan=%d", len + thistab); 501 526 502 527 cur += sprintf(cur, ">"); … … 522 547 ; 523 548 else if(linechar[x + i] <= 0x00000020) 549 { 550 if(linechar[x + i] == 0x00000009) 551 { 552 while((x + i + taboff + 1) % 8) 553 { 554 cur += sprintf(cur, " "); 555 taboff ++; 556 } 557 } 524 558 cur += sprintf(cur, " "); 559 } 525 560 else if(linechar[x + i] < 0x00000080) 526 561 cur += sprintf(cur, "%c", (uint8_t)linechar[x + i]);
Note: See TracChangeset
for help on using the changeset viewer.