git.asbjorn.biz
/
swftools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
implemented gfxsource->destroy
[swftools.git]
/
lib
/
pdf
/
pdf.cc
diff --git
a/lib/pdf/pdf.cc
b/lib/pdf/pdf.cc
index
7d13c7b
..
ab274a5
100644
(file)
--- a/
lib/pdf/pdf.cc
+++ b/
lib/pdf/pdf.cc
@@
-34,12
+34,14
@@
typedef struct _pdf_page_info
typedef struct _pdf_doc_internal
{
int protect;
typedef struct _pdf_doc_internal
{
int protect;
+ int nocopy;
PDFDoc*doc;
Object docinfo;
InfoOutputDev*info;
CommonOutputDev*outputDev;
pdf_page_info_t*pages;
gfxdevice_t* middev;
PDFDoc*doc;
Object docinfo;
InfoOutputDev*info;
CommonOutputDev*outputDev;
pdf_page_info_t*pages;
gfxdevice_t* middev;
+ char*filename;
} pdf_doc_internal_t;
typedef struct _pdf_page_internal
} pdf_doc_internal_t;
typedef struct _pdf_page_internal
@@
-147,6
+149,10
@@
void pdf_doc_destroy(gfxdocument_t*gfx)
free(i->pages); i->pages = 0;
i->docinfo.free();
free(i->pages); i->pages = 0;
i->docinfo.free();
+
+ if(i->filename) {
+ free(i->filename);i->filename=0;
+ }
if(i->info) {
delete i->info;i->info=0;
if(i->info) {
delete i->info;i->info=0;
@@
-187,6
+193,10
@@
gfxpage_t* pdf_doc_getpage(gfxdocument_t*doc, int page)
if(page < 1 || page > doc->num_pages)
return 0;
if(page < 1 || page > doc->num_pages)
return 0;
+ if(di->nocopy) {
+ msg("<error> PDF disallows copying.");
+ return 0;
+ }
gfxpage_t* pdf_page = (gfxpage_t*)malloc(sizeof(gfxpage_t));
pdf_page_internal_t*pi= (pdf_page_internal_t*)malloc(sizeof(pdf_page_internal_t));
gfxpage_t* pdf_page = (gfxpage_t*)malloc(sizeof(gfxpage_t));
pdf_page_internal_t*pi= (pdf_page_internal_t*)malloc(sizeof(pdf_page_internal_t));
@@
-283,10
+293,21
@@
char* pdf_doc_getinfo(gfxdocument_t*doc, const char*name)
static void storeDeviceParameter(const char*name, const char*value)
{
static void storeDeviceParameter(const char*name, const char*value)
{
+ parameter_t*o = device_config;
+ while(o) {
+ if(!strcmp(name, o->name)) {
+ /* overwrite old value */
+ free(o->value);
+ o->value = strdup(value);
+ return;
+ }
+ o = o->next;
+ }
parameter_t*p = new parameter_t();
p->name = strdup(name);
p->value = strdup(value);
p->next = 0;
parameter_t*p = new parameter_t();
p->name = strdup(name);
p->value = strdup(value);
p->next = 0;
+
if(device_config_next) {
device_config_next->next = p;
device_config_next = p;
if(device_config_next) {
device_config_next->next = p;
device_config_next = p;
@@
-354,7
+375,7
@@
static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename)
pdf_doc->internal = i;
char*userPassword=0;
pdf_doc->internal = i;
char*userPassword=0;
- filename = strdup(filename);
+ i->filename = strdup(filename);
char*x = 0;
if((x = strchr(filename, '|'))) {
char*x = 0;
if((x = strchr(filename, '|'))) {
@@
-387,8
+408,7
@@
static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename)
i->protect = 0;
if (i->doc->isEncrypted()) {
if(!i->doc->okToCopy()) {
i->protect = 0;
if (i->doc->isEncrypted()) {
if(!i->doc->okToCopy()) {
- printf("PDF disallows copying.\n");
- return 0;
+ i->nocopy = 1;
}
if(!i->doc->okToChange() || !i->doc->okToAddNotes())
i->protect = 1;
}
if(!i->doc->okToChange() || !i->doc->okToAddNotes())
i->protect = 1;
@@
-422,7
+442,6
@@
static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename)
GFXOutputDev*outputDev = new GFXOutputDev(i->info, i->doc);
i->outputDev = (CommonOutputDev*)outputDev;
}
GFXOutputDev*outputDev = new GFXOutputDev(i->info, i->doc);
i->outputDev = (CommonOutputDev*)outputDev;
}
-
/* pass global parameters to PDF driver*/
parameter_t*p = device_config;
while(p) {
/* pass global parameters to PDF driver*/
parameter_t*p = device_config;
while(p) {
@@
-446,6
+465,14
@@
static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename)
return pdf_doc;
}
return pdf_doc;
}
+
+void pdf_destroy(gfxsource_t*src)
+{
+ if(!src->internal)
+ return;
+ gfxsource_internal_t*i = (gfxsource_internal_t*)src->internal;
+ free(src->internal);src->internal=0;
+}
gfxsource_t*gfxsource_pdf_create()
{
gfxsource_t*gfxsource_pdf_create()
{
@@
-453,6
+480,7
@@
gfxsource_t*gfxsource_pdf_create()
memset(src, 0, sizeof(gfxsource_t));
src->set_parameter = pdf_set_parameter;
src->open = pdf_open;
memset(src, 0, sizeof(gfxsource_t));
src->set_parameter = pdf_set_parameter;
src->open = pdf_open;
+ src->destroy = pdf_destroy;
src->internal = malloc(sizeof(gfxsource_internal_t));
memset(src->internal, 0, sizeof(gfxsource_internal_t));
src->internal = malloc(sizeof(gfxsource_internal_t));
memset(src->internal, 0, sizeof(gfxsource_internal_t));