mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 14:16:00 +01:00
Revised pdf/djvu open functions
This commit is contained in:
parent
876f1e9ead
commit
7c6b081984
3 changed files with 74 additions and 23 deletions
|
@ -8,7 +8,7 @@ bool
|
|||
djvu_document_open(zathura_document_t* document)
|
||||
{
|
||||
if(!document) {
|
||||
return false;
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
document->functions.document_free = djvu_document_free;
|
||||
|
@ -24,30 +24,57 @@ djvu_document_open(zathura_document_t* document)
|
|||
|
||||
document->data = malloc(sizeof(djvu_document_t));
|
||||
if(!document->data) {
|
||||
return false;
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
djvu_document_t* djvu_document = (djvu_document_t*) document->data;
|
||||
djvu_document->context = ddjvu_context_create("zathura");
|
||||
djvu_document->context = NULL;
|
||||
djvu_document->document = NULL;
|
||||
djvu_document->format = NULL;
|
||||
|
||||
if(!djvu_document->context) {
|
||||
free(document->data);
|
||||
document->data = NULL;
|
||||
return false;
|
||||
/* setup format */
|
||||
djvu_document->format = ddjvu_format_create (DDJVU_FORMAT_RGBMASK32, 0, NULL);
|
||||
|
||||
if(!djvu_document->format) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
ddjvu_format_set_row_order(djvu_document->format, TRUE);
|
||||
|
||||
/* setup context */
|
||||
djvu_document->context = ddjvu_context_create("zathura");
|
||||
|
||||
if(!djvu_document->context) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
/* setup document */
|
||||
djvu_document->document = ddjvu_document_create_by_filename(djvu_document->context, document->file_path, FALSE);
|
||||
|
||||
if(!djvu_document->document) {
|
||||
ddjvu_context_release(djvu_document->context);
|
||||
free(document->data);
|
||||
document->data = NULL;
|
||||
return false;
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
document->number_of_pages = ddjvu_document_get_pagenum(djvu_document->document);
|
||||
|
||||
return true;
|
||||
|
||||
error_free:
|
||||
|
||||
if(djvu_document->format) {
|
||||
ddjvu_format_release(djvu_document->format);
|
||||
}
|
||||
|
||||
if(djvu_document->context) {
|
||||
ddjvu_context_release(djvu_document->context);
|
||||
}
|
||||
|
||||
free(document->data);
|
||||
document->data = NULL;
|
||||
|
||||
error_out:
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -61,6 +88,7 @@ djvu_document_free(zathura_document_t* document)
|
|||
djvu_document_t* djvu_document = (djvu_document_t*) document->data;
|
||||
ddjvu_context_release(djvu_document->context);
|
||||
ddjvu_document_release(djvu_document->document);
|
||||
ddjvu_format_release(djvu_document->format);
|
||||
free(document->data);
|
||||
}
|
||||
|
||||
|
@ -80,7 +108,17 @@ djvu_document_save_as(zathura_document_t* document, const char* path)
|
|||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
djvu_document_t* djvu_document = (djvu_document_t*) document->data;
|
||||
|
||||
FILE* fp = fopen(path, "w");
|
||||
if(!fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ddjvu_document_save(djvu_document->document, fp, 0, NULL);
|
||||
fclose(fp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
zathura_list_t*
|
||||
|
|
|
@ -12,6 +12,7 @@ typedef struct djvu_document_s
|
|||
{
|
||||
ddjvu_context_t* context;
|
||||
ddjvu_document_t* document;
|
||||
ddjvu_format_t* format;
|
||||
} djvu_document_t;
|
||||
|
||||
bool djvu_document_open(zathura_document_t* document);
|
||||
|
|
34
ft/pdf/pdf.c
34
ft/pdf/pdf.c
|
@ -7,8 +7,9 @@
|
|||
bool
|
||||
pdf_document_open(zathura_document_t* document)
|
||||
{
|
||||
if(!document)
|
||||
return false;
|
||||
if(!document) {
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
document->functions.document_free = pdf_document_free;
|
||||
document->functions.document_index_generate = pdf_document_index_generate;;
|
||||
|
@ -23,7 +24,7 @@ pdf_document_open(zathura_document_t* document)
|
|||
|
||||
document->data = malloc(sizeof(pdf_document_t));
|
||||
if(!document->data) {
|
||||
return false;
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
/* format path */
|
||||
|
@ -32,10 +33,7 @@ pdf_document_open(zathura_document_t* document)
|
|||
|
||||
if(!file_uri) {
|
||||
fprintf(stderr, "error: could not open file: %s\n", error->message);
|
||||
g_error_free(error);
|
||||
free(document->data);
|
||||
document->data = NULL;
|
||||
return false;
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
|
||||
|
@ -43,15 +41,29 @@ pdf_document_open(zathura_document_t* document)
|
|||
|
||||
if(!pdf_document->document) {
|
||||
fprintf(stderr, "error: could not open file: %s\n", error->message);
|
||||
g_error_free(error);
|
||||
free(document->data);
|
||||
document->data = NULL;
|
||||
return false;
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
document->number_of_pages = poppler_document_get_n_pages(pdf_document->document);
|
||||
|
||||
return true;
|
||||
|
||||
error_free:
|
||||
|
||||
if(error) {
|
||||
g_error_free(error);
|
||||
}
|
||||
|
||||
if(file_uri) {
|
||||
g_free(file_uri);
|
||||
}
|
||||
|
||||
free(document->data);
|
||||
document->data = NULL;
|
||||
|
||||
error_out:
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
Loading…
Reference in a new issue