Changeset 2102 for libcaca/trunk/cucul/export.c
- Timestamp:
- Dec 1, 2007, 12:48:46 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/export.c
r2074 r2102 51 51 static void *export_html(cucul_canvas_t const *, unsigned long int *); 52 52 static void *export_html3(cucul_canvas_t const *, unsigned long int *); 53 static void *export_bbfr(cucul_canvas_t const *, unsigned long int *); 53 54 static void *export_irc(cucul_canvas_t const *, unsigned long int *); 54 55 static void *export_ps(cucul_canvas_t const *, unsigned long int *); … … 104 105 return export_html3(cv, bytes); 105 106 107 if(!strcasecmp("bbfr", format)) 108 return export_bbfr(cv, bytes); 109 106 110 if(!strcasecmp("irc", format)) 107 111 return export_irc(cv, bytes); … … 141 145 "html", "HTML", 142 146 "html3", "backwards-compatible HTML", 147 "bbfr", "BBCode (French)", 143 148 "irc", "IRC with mIRC colours", 144 149 "ps", "PostScript document", … … 540 545 /* Crop to really used size */ 541 546 debug("html3 export: alloc %lu bytes, realloc %lu", 547 (unsigned long int)*bytes, (unsigned long int)(cur - data)); 548 *bytes = (uintptr_t)(cur - data); 549 data = realloc(data, *bytes); 550 551 return data; 552 } 553 554 static void *export_bbfr(cucul_canvas_t const *cv, unsigned long int *bytes) 555 { 556 char *data, *cur; 557 unsigned int x, y, len; 558 559 /* The font markup: less than 100 bytes 560 * A line: 1 char for "\n" 561 * A glyph: 22 chars for "[f=#xxxxxx][c=#xxxxxx]" 562 * up to 21 chars for "[g][i][s][/s][/i][/g]" 563 * up to 6 chars for the UTF-8 glyph 564 * 8 chars for "[/c][/f]" */ 565 *bytes = 100 + cv->height * (1 + cv->width * (22 + 21 + 6 + 8)); 566 cur = data = malloc(*bytes); 567 568 /* Table */ 569 cur += sprintf(cur, "[font=Courier New]"); 570 571 for(y = 0; y < cv->height; y++) 572 { 573 uint32_t *lineattr = cv->attrs + y * cv->width; 574 uint32_t *linechar = cv->chars + y * cv->width; 575 576 for(x = 0; x < cv->width; x += len) 577 { 578 unsigned int i, needback, needfront; 579 580 /* Use colspan option to factor cells with same attributes 581 * (see below) */ 582 len = 1; 583 if(linechar[x] == ' ') 584 while(x + len < cv->width && lineattr[x + len] == lineattr[x] 585 && linechar[x] == ' ') 586 len++; 587 else 588 while(x + len < cv->width && lineattr[x + len] == lineattr[x] 589 && linechar[x] != ' ') 590 len++; 591 592 needback = cucul_attr_to_ansi_bg(lineattr[x]) < 0x10; 593 needfront = cucul_attr_to_ansi_fg(lineattr[x]) < 0x10; 594 595 if(needback) 596 cur += sprintf(cur, "[f=#%.06lx]", (unsigned long int) 597 _cucul_attr_to_rgb24bg(lineattr[x])); 598 599 if(linechar[x] == ' ') 600 cur += sprintf(cur, "[c=#%.06lx]", (unsigned long int) 601 _cucul_attr_to_rgb24bg(lineattr[x])); 602 else if(needfront) 603 cur += sprintf(cur, "[c=#%.06lx]", (unsigned long int) 604 _cucul_attr_to_rgb24fg(lineattr[x])); 605 606 if(lineattr[x] & CUCUL_BOLD) 607 cur += sprintf(cur, "[g]"); 608 if(lineattr[x] & CUCUL_ITALICS) 609 cur += sprintf(cur, "[i]"); 610 if(lineattr[x] & CUCUL_UNDERLINE) 611 cur += sprintf(cur, "[s]"); 612 if(lineattr[x] & CUCUL_BLINK) 613 ; /* FIXME */ 614 615 for(i = 0; i < len; i++) 616 { 617 if(linechar[x + i] == CUCUL_MAGIC_FULLWIDTH) 618 ; 619 else if(linechar[x + i] == ' ') 620 *cur++ = '_'; 621 else 622 cur += cucul_utf32_to_utf8(cur, linechar[x + i]); 623 } 624 625 if(lineattr[x] & CUCUL_BLINK) 626 ; /* FIXME */ 627 if(lineattr[x] & CUCUL_UNDERLINE) 628 cur += sprintf(cur, "[/s]"); 629 if(lineattr[x] & CUCUL_ITALICS) 630 cur += sprintf(cur, "[/i]"); 631 if(lineattr[x] & CUCUL_BOLD) 632 cur += sprintf(cur, "[/g]"); 633 634 if(linechar[x] == ' ' || needfront) 635 cur += sprintf(cur, "[/c]"); 636 if(needback) 637 cur += sprintf(cur, "[/f]"); 638 } 639 cur += sprintf(cur, "\n"); 640 } 641 642 /* Footer */ 643 cur += sprintf(cur, "[/font]\n"); 644 645 /* Crop to really used size */ 646 debug("bbfr export: alloc %lu bytes, realloc %lu", 542 647 (unsigned long int)*bytes, (unsigned long int)(cur - data)); 543 648 *bytes = (uintptr_t)(cur - data);
Note: See TracChangeset
for help on using the changeset viewer.