Changeset 603 for libcaca/trunk
- Timestamp:
- Mar 14, 2006, 5:51:38 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/export_ps.c
r602 r603 31 31 32 32 33 char ps_header[] = {"%%! \n \ 34 %%%% libcaca PDF export \n \ 35 %%%%LanguageLevel: 2 \n \ 36 %%%%Pages: 1 \n \ 37 %%%%DocumentData: Clean7Bit \n \ 38 /csquare { \n \ 39 newpath \n \ 40 0 0 moveto \n \ 41 0 1 rlineto \n \ 42 1 0 rlineto \n \ 43 0 -1 rlineto \n \ 44 closepath \n \ 45 setrgbcolor \n \ 46 fill \n \ 47 } def \n \ 48 /S { \n \ 49 Show \n \ 50 } bind def \n \ 51 \n \ 52 \n \ 53 /Times-Roman findfont \n \ 54 8 scalefont \n \ 55 setfont\n \ 56 6 10 scale \n"}; 57 58 33 char ps_header[] = {"%%! \n " 34 "%%%% libcaca PDF export \n " 35 "%%%%LanguageLevel: 2 \n " 36 "%%%%Pages: 1 \n " 37 "%%%%DocumentData: Clean7Bit \n " 38 "/csquare { \n " 39 " newpath \n " 40 " 0 0 moveto \n " 41 " 0 1 rlineto \n " 42 " 1 0 rlineto \n " 43 " 0 -1 rlineto \n " 44 " closepath \n " 45 " setrgbcolor \n " 46 " fill \n " 47 "} def \n " 48 "/S { \n " 49 " Show \n " 50 "} bind def \n " 51 " \n " 52 " \n " 53 "/Courier-Bold findfont \n " 54 "8 scalefont \n " 55 "setfont\n " 56 "gsave \n " 57 "6 10 scale \n"}; 59 58 60 59 … … 66 65 char* cucul_get_ps(cucul_t *qq, int *size) 67 66 { 67 char *cur; 68 int x, y; 68 69 69 70 static float const paletteR[] = 70 71 72 73 74 75 71 { 72 0, 0, 0, 0, 73 0.5, 0.5, 0.5, 0.5, 74 0.5, 0.5, 0.5, 0.5, 75 1.0, 1.0, 1.0, 1.0, 76 }; 76 77 static float const paletteG[] = 77 78 79 80 81 82 78 { 79 0, 0, 0.5, 0.5, 80 0, 0, 0.5, 0.5, 81 0, 0, 1.0, 1.0, 82 0, 0, 1.0, 1.0, 83 }; 83 84 static float const paletteB[] = 84 85 86 87 88 89 85 { 86 0, 0.5, 0, 0.5, 87 0, 0.5, 0, 0.5, 88 0, 1.0, 0.5, 1.0, 89 0, 1.0, 0, 1.0, 90 }; 90 91 91 92 char *cur;93 unsigned int x, y;94 92 95 93 if(qq->ps_buffer) 96 94 free(qq->ps_buffer); 97 95 98 /* 400 is arbitrary and needs to be precised*/99 qq->ps_buffer = malloc((strlen(ps_header) + (qq->height*qq->width)* 400) * sizeof(char));96 /* 200 is arbitrary but should be ok */ 97 qq->ps_buffer = malloc((strlen(ps_header) + (qq->height*qq->width)*200) * sizeof(char)); 100 98 cur = qq->ps_buffer; 101 99 … … 105 103 106 104 /* Background, drawn using csquare macro defined in header */ 107 for(y= 0;y<qq->height; y++) {105 for(y=(int)(qq->height-1);y>=0; y--) { 108 106 uint8_t *lineattr = qq->attr + y * qq->width; 109 107 110 for(x = 0; x < qq->width; x++) {108 for(x = 0; x < (int)qq->width; x++) { 111 109 float bgR = paletteR[lineattr[x] >> 4]; 112 110 float bgG = paletteG[lineattr[x] >> 4]; … … 123 121 } 124 122 125 /* Text. FIXME, doesn't work yet */ 126 cur += sprintf(cur, "1 1 scale\n"); 127 cur += sprintf(cur, "newpath\n0 0 moveto\n"); 128 for(y=0;y<qq->height; y++) { 129 uint8_t *lineattr = qq->attr + y * qq->width; 123 cur += sprintf(cur, "grestore\n"); // Restore normal transformation matrix 124 for(y=(int)(qq->height-1);y>=0; y--) { 125 uint8_t *lineattr = qq->attr + y * qq->width; 130 126 uint32_t *linechar = qq->chars + y * qq->width; 131 127 132 for(x = 0; x < qq->width; x++) {128 for(x = 0; x < (int)qq->width; x++) { 133 129 uint32_t cR = linechar[x]; 134 130 float fgR = paletteR[lineattr[x] & 0x0f]; … … 136 132 float fgB = paletteB[lineattr[x] & 0x0f]; 137 133 134 cur += sprintf(cur, "newpath\n%d %d moveto\n", (x+1)*6, (y)*10); 138 135 cur += sprintf(cur, "%f %f %f setrgbcolor\n", fgR, fgG, fgB); 139 cur += sprintf(cur, "1 0 translate\n"); 140 cur += sprintf(cur, "{%c} \n", cR); 136 cur += sprintf(cur, "(%c) show\n", cR); 141 137 142 138 } 143 cur += sprintf(cur, "%d 1 translate \n", -qq->width);144 139 } 145 140 … … 149 144 /* Crop to really used size */ 150 145 *size = (strlen(qq->ps_buffer) + 1) * sizeof(char); 146 151 147 qq->ps_buffer = realloc(qq->ps_buffer, *size); 152 148
Note: See TracChangeset
for help on using the changeset viewer.