| verzia 1.15, 2002/10/20 14:07:23 |
verzia 1.16, 2002/10/26 06:27:52 |
|
|
| |
|
| #include "cpdf.h" |
#include "cpdf.h" |
| #include "parse.h" |
#include "parse.h" |
| |
#include "filter.h" |
| #include "utils.h" |
#include "utils.h" |
| /* function compute number of locations of char c from buffer to character c |
/* function compute number of locations of char c from buffer to character c |
| */ |
*/ |
| Riadok 235 void xref(void) |
|
| Riadok 236 void xref(void) |
|
| realloc(object, entry[0] + entry[1]); |
realloc(object, entry[0] + entry[1]); |
| obj_count = entry[0] + entry[1]; |
obj_count = entry[0] + entry[1]; |
| } |
} |
| if (!entry[0]) |
do { |
| fseek(fp, XREFLINE, SEEK_CUR); |
fget(xref, XREFLINE, fp); |
| fget(xref, XREFLINE, fp); |
if(xref[XREFLINE - 3] == 'f') |
| while (strncmp(xref, "trailer", 7)) { |
continue; |
| add_obj(&xref[0]); |
add_obj(&xref[0]); |
| fget(xref, XREFLINE, fp); |
} while (strncmp(xref, "trailer", 7)); |
| } |
|
| fseek(fp, 3, SEEK_CUR); |
fseek(fp, 3, SEEK_CUR); |
| fget(xref, XREFLINE, fp); |
fget(xref, XREFLINE, fp); |
| trailer.prev = 0; |
trailer.prev = 0; |
| Riadok 257 void xref(void) |
|
| Riadok 257 void xref(void) |
|
| if (!strncmp(xref, "/Prev", 5)) |
if (!strncmp(xref, "/Prev", 5)) |
| sscanf(xref, "/Prev %ld", |
sscanf(xref, "/Prev %ld", |
| &trailer.prev); |
&trailer.prev); |
| |
if (!strncmp(xref, "/Encrypt",8)) |
| |
sscanf(xref, |
| |
"/Encrypt %d 0 R \n", |
| |
&trailer.encrypt); |
| fget(xref, XREFLINE, fp); |
fget(xref, XREFLINE, fp); |
| } |
} |
| if (!trailer.prev) |
if (!trailer.prev) |
| Riadok 303 void fill_page(int page_num) |
|
| Riadok 307 void fill_page(int page_num) |
|
| struct page *page; |
struct page *page; |
| struct object *obj; |
struct object *obj; |
| char *p, **mediabox; |
char *p, **mediabox; |
| int contents, resources, i = 0; |
int contents, resources; |
| if (object[page_num]->type == PAGE) |
if (object[page_num]->type == PAGE) |
| return; |
return; |
| page = (struct page *) malloc(sizeof(struct page)); |
page = (struct page *) xmalloc(sizeof(struct page)); |
| obj = object[page_num]; |
obj = object[page_num]; |
| p = strstr(obj->unparsed, "/Contents "); |
p = strstr(obj->unparsed, "/Contents "); |
| if (!p) { |
if (!p) { |
| /* error */ |
/* error */ |
| return; |
return; |
| } |
} |
| sscanf(p, "/Contents %d 0 R", &contents); |
if(p[11] == '<') /* if /Contents << */ |
| |
contents = page_num; |
| |
else |
| |
sscanf(p, "/Contents %d 0 R", &contents); |
| p = strstr(obj->unparsed, "/Resources "); |
p = strstr(obj->unparsed, "/Resources "); |
| if (!p) { |
if (!p) { |
| /* error */ |
/* error */ |
| return; |
return; |
| } |
} |
| sscanf(p, "/Resources %d 0 R", &resources); |
if(p[11] == '<') /* if /Resources << */ |
| fill_contents(contents); |
resources = page_num; |
| page->contents = object[contents]->parsed; |
else |
| fill_resources(resources); |
sscanf(p, "/Resources %d 0 R", &resources); |
| page->resources = object[resources]->parsed; |
page->contents = fill_contents(contents); |
| |
page->resources = fill_resources(resources); |
| p = strstr(obj->unparsed, "/Mediabox "); |
p = strstr(obj->unparsed, "/Mediabox "); |
| if (!p) { |
if (!p) { |
| /* error */ |
/* error */ |
| Riadok 352 void fill_page(int page_num) |
|
| Riadok 360 void fill_page(int page_num) |
|
| return; |
return; |
| } |
} |
| |
|
| void fill_contents(int page_num) |
struct contents *fill_contents(int page_num) |
| { |
{ |
| struct contents *content; |
struct contents *content; |
| struct object *obj; |
struct object *obj; |
| |
struct page *page; |
| char *p; |
char *p; |
| if (object[page_num]->type == CONTENT) |
|
| return; |
|
| content = (struct content *) malloc(sizeof(struct content)); |
|
| obj = object[page_num]; |
obj = object[page_num]; |
| |
page = (struct page *) obj->parsed; |
| |
if(page->contents) |
| |
return page->contents; |
| |
content = (struct contents *) xmalloc(sizeof(struct contents)); |
| p = strstr(obj->unparsed, "/Length "); |
p = strstr(obj->unparsed, "/Length "); |
| if (!p) { |
if (!p) { |
| /* error */ |
/* error */ |
| return; |
free(content); |
| |
return NULL; |
| } |
} |
| sscanf(p, "/Length %d", &content->length); |
sscanf(p, "/Length %d", &content->length); |
| p = strstr(obj->unparsed, "/Filter "); |
p = strstr(obj->unparsed, "/Filter "); |
| if (!p) { |
if (!p) { |
| /* error */ |
/* error */ |
| return; |
free(content); |
| |
return NULL; |
| } |
} |
| content->filter = get_filternum(&p[9]); |
content->filter = get_filternum(&p[9]); |
| p = strstr(obj->unparsed, "stream"); |
p = strstr(obj->unparsed, "stream"); |
| if (!p) { |
if (!p) { |
| /* error */ |
/* error */ |
| return; |
free(content); |
| |
return NULL; |
| } |
} |
| content->stream = (char *) malloc(content->length); |
content->stream = (char *) xmalloc(content->length); |
| strncpy(content->stream, &p[7], content->length); |
strncpy(content->stream, &p[7], content->length); |
| free(obj->unparsed); |
return content; |
| obj->unparsed = NULL; |
} |
| obj->type = CONTENT; |
|
| obj->parsed = content; |
struct resources *fill_resources(int page_num) |
| return; |
{ |
| |
struct resources *resources; |
| |
struct object *obj; |
| |
struct page *page; |
| |
obj = object[page_num]; |
| |
page = obj->parsed; |
| |
if(page->resources) |
| |
return page->resources; |
| |
resources = (struct resources *) xmalloc(sizeof(struct resources)); |
| |
return resources; |
| } |
} |