mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 20:33:46 +01:00
Get and free pdf page
This commit is contained in:
parent
f5fabb01ba
commit
43727a597b
@ -196,7 +196,7 @@ zathura_document_attachments_free(zathura_list_t* list)
|
||||
zathura_page_t*
|
||||
zathura_page_get(zathura_document_t* document, unsigned int page)
|
||||
{
|
||||
if(!document || !page) {
|
||||
if(!document) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,8 @@ typedef struct zathura_form_s
|
||||
|
||||
typedef struct zathura_page_s
|
||||
{
|
||||
unsigned int height;
|
||||
unsigned int width;
|
||||
double height;
|
||||
double width;
|
||||
zathura_document_t* document;
|
||||
void* data;
|
||||
} zathura_page_t;
|
||||
|
58
ft/pdf/pdf.c
58
ft/pdf/pdf.c
@ -38,7 +38,7 @@ pdf_document_open(zathura_document_t* document)
|
||||
}
|
||||
|
||||
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
|
||||
pdf_document->document = poppler_document_new_from_file(file_uri, document->password, &error);
|
||||
pdf_document->document = poppler_document_new_from_file(file_uri, document->password, &error);
|
||||
|
||||
if(!pdf_document->document) {
|
||||
fprintf(stderr, "error: could not open file: %s\n", error->message);
|
||||
@ -47,6 +47,8 @@ pdf_document_open(zathura_document_t* document)
|
||||
return false;
|
||||
}
|
||||
|
||||
document->number_of_pages = poppler_document_get_n_pages(pdf_document->document);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -58,6 +60,8 @@ pdf_document_free(zathura_document_t* document)
|
||||
}
|
||||
|
||||
if(document->data) {
|
||||
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
|
||||
g_object_unref(pdf_document->document);
|
||||
free(document->data);
|
||||
}
|
||||
|
||||
@ -73,6 +77,16 @@ pdf_document_index_generate(zathura_document_t* document)
|
||||
bool
|
||||
pdf_document_save_as(zathura_document_t* document, const char* path)
|
||||
{
|
||||
if(!document || !document->data || !path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
|
||||
|
||||
char* file_path = g_strdup_printf("file://%s", path);
|
||||
poppler_document_save(pdf_document->document, file_path, NULL);
|
||||
g_free(file_path);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -85,7 +99,41 @@ pdf_document_attachments_get(zathura_document_t* document)
|
||||
zathura_page_t*
|
||||
pdf_page_get(zathura_document_t* document, unsigned int page)
|
||||
{
|
||||
return NULL;
|
||||
if(!document || !document->data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
|
||||
zathura_page_t* document_page = malloc(sizeof(zathura_page_t));
|
||||
|
||||
if(!document_page) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
document_page->document = document;
|
||||
document_page->data = poppler_document_get_page(pdf_document->document, page);
|
||||
|
||||
if(!document_page->data) {
|
||||
free(document_page);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
poppler_page_get_size(document_page->data, &(document_page->width), &(document_page->height));
|
||||
|
||||
return document_page;
|
||||
}
|
||||
|
||||
bool
|
||||
pdf_page_free(zathura_page_t* page)
|
||||
{
|
||||
if(!page) {
|
||||
return false;
|
||||
}
|
||||
|
||||
g_object_unref(page->data);
|
||||
free(page);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
zathura_list_t*
|
||||
@ -111,9 +159,3 @@ pdf_page_render(zathura_page_t* page)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
pdf_page_free(zathura_page_t* page)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
24
zathura.c
24
zathura.c
@ -44,22 +44,32 @@ int main(int argc, char* argv[])
|
||||
gdk_threads_init();
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
/*if(!init_zathura()) {*/
|
||||
/*printf("error: coult not initialize zathura\n");*/
|
||||
/*return -1;*/
|
||||
/*}*/
|
||||
if(!init_zathura()) {
|
||||
printf("error: coult not initialize zathura\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(argc > 1) {
|
||||
zathura_document_t* document = zathura_document_open(argv[1], NULL);
|
||||
|
||||
if(!document) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
zathura_page_t* page = zathura_page_get(document, 0);
|
||||
|
||||
if(!page) {
|
||||
zathura_document_free(document);
|
||||
return -2;
|
||||
}
|
||||
|
||||
zathura_page_free(page);
|
||||
zathura_document_free(document);
|
||||
}
|
||||
|
||||
/*gdk_threads_enter();*/
|
||||
/*gtk_main();*/
|
||||
/*gdk_threads_leave();*/
|
||||
gdk_threads_enter();
|
||||
gtk_main();
|
||||
gdk_threads_leave();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user