#include #include #include #include #include #include #include #include "parse.h" #include "cpdf.h" #include "svga.h" #include "utils.h" #include "filter.h" int x, y; float tfs; int w0 = 0,w1 = 0,tc = 0,th = 100,tw = 0; char *strndup(const char *s, size_t n); void donothing(char *line) { return; } void text(char *line) { int n; float uno_numero; char *p = NULL,*dup; if ((p = strstr(line, "Td")) != NULL) { for(p -= 2;!isalpha(*p);p--); sscanf(p + 1,"%f %f Td",&trm[2][0],&trm[2][1]); } if ((p = strstr(line, "Tf")) != NULL) { for(p -= 2;*p != ' ';p--); sscanf(p + 1,"%f Tf",&tfs); } if ((p = strstr(line, "TJ")) != NULL) { while (*(p - 1) != '[') p--; while (strncmp(p,"]TJ",3)) { p++; n = strchr(p,')') - p; dup = strndup(p,n); dup[n] = '\0'; p = strchr(p,')'); if(*(p + 1) != ']') { n = sscanf(p, ")%f(", &uno_numero); x = ((w0 - uno_numero / 1000) * tfs + tc + tw) * th; y = (w1 - uno_numero / 1000) * tfs + tc + tw; p += n + 1; } #ifndef DEBUG gl_writen(x, y, n, dup); #endif p++; } } if ((p = strstr(line, "Tj")) != NULL) { while (*(p - 1) != '(') p--; while (strncmp(p, ")Tj", 3)) { #ifndef DEBUG gl_writen(x, y, sizeof(char), p); #endif x += 10; if (x == screen.x - 10) { x = 10; y += 10; } if (y == screen.y - 10) y = 10; p++; } } return; } void render(void) { char *content, *p, *endline, *dup; unsigned long dstlen; struct page *page; void (*fun) (char *line) = donothing; page = (struct page *) get_object(page_tree[current_page], NULL); if (!page) return; dstlen = page->contents->length << 3; content = (char *) xcalloc((int) dstlen, sizeof(char)); #ifndef DEBUG gl_setfont(8, 8, gl_font8x8); gl_setwritemode(FONT_COMPRESSED + WRITEMODE_OVERWRITE); gl_setfontcolors(0xFFFFFFFF, 0); #endif if (page->contents->filter != -1) { filter(page->contents->filter, page->contents->stream, page->contents->length, content, &dstlen); if (dstlen != page->contents->length << 3) content = (char *) realloc(content, dstlen); } write(2, content, (int) dstlen); p = content; x = y = 10; while ((endline = strchr(p, '\n')) != NULL) { dup = strndup(p, endline - p + 1); if (strstr(dup, "BT")) fun = text; if (strstr(dup, "ET")) fun = donothing; if (strstr(dup,"cm")) { tlm[2][2] = 1.0; sscanf(dup,"%f %f %f %f %f %f cm", &tlm[0][0],&tlm[0][1],&tlm[1][0], &tlm[1][1],&tlm[2][0],&tlm[2][1]); fun = donothing; } fun(dup); free(dup); p = endline + 1; } #ifndef DEBUG gl_copyscreen(physicalscreen); gl_clearscreen(0xFFFFFFFF); #endif free(content); getchar(); return; }