mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-16 21:37:52 +01:00
Get and free pdf page
This commit is contained in:
parent
f5fabb01ba
commit
43727a597b
4 changed files with 70 additions and 18 deletions
|
@ -196,7 +196,7 @@ zathura_document_attachments_free(zathura_list_t* list)
|
||||||
zathura_page_t*
|
zathura_page_t*
|
||||||
zathura_page_get(zathura_document_t* document, unsigned int page)
|
zathura_page_get(zathura_document_t* document, unsigned int page)
|
||||||
{
|
{
|
||||||
if(!document || !page) {
|
if(!document) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,8 @@ typedef struct zathura_form_s
|
||||||
|
|
||||||
typedef struct zathura_page_s
|
typedef struct zathura_page_s
|
||||||
{
|
{
|
||||||
unsigned int height;
|
double height;
|
||||||
unsigned int width;
|
double width;
|
||||||
zathura_document_t* document;
|
zathura_document_t* document;
|
||||||
void* data;
|
void* data;
|
||||||
} zathura_page_t;
|
} zathura_page_t;
|
||||||
|
|
54
ft/pdf/pdf.c
54
ft/pdf/pdf.c
|
@ -47,6 +47,8 @@ pdf_document_open(zathura_document_t* document)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document->number_of_pages = poppler_document_get_n_pages(pdf_document->document);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +60,8 @@ pdf_document_free(zathura_document_t* document)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(document->data) {
|
if(document->data) {
|
||||||
|
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
|
||||||
|
g_object_unref(pdf_document->document);
|
||||||
free(document->data);
|
free(document->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +77,16 @@ pdf_document_index_generate(zathura_document_t* document)
|
||||||
bool
|
bool
|
||||||
pdf_document_save_as(zathura_document_t* document, const char* path)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,9 +99,43 @@ pdf_document_attachments_get(zathura_document_t* document)
|
||||||
zathura_page_t*
|
zathura_page_t*
|
||||||
pdf_page_get(zathura_document_t* document, unsigned int page)
|
pdf_page_get(zathura_document_t* document, unsigned int page)
|
||||||
{
|
{
|
||||||
|
if(!document || !document->data) {
|
||||||
return NULL;
|
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*
|
zathura_list_t*
|
||||||
pdf_page_search_text(zathura_page_t* page, const char* text)
|
pdf_page_search_text(zathura_page_t* page, const char* text)
|
||||||
{
|
{
|
||||||
|
@ -111,9 +159,3 @@ pdf_page_render(zathura_page_t* page)
|
||||||
{
|
{
|
||||||
return NULL;
|
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();
|
gdk_threads_init();
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
|
|
||||||
/*if(!init_zathura()) {*/
|
if(!init_zathura()) {
|
||||||
/*printf("error: coult not initialize zathura\n");*/
|
printf("error: coult not initialize zathura\n");
|
||||||
/*return -1;*/
|
return -1;
|
||||||
/*}*/
|
}
|
||||||
|
|
||||||
if(argc > 1) {
|
if(argc > 1) {
|
||||||
zathura_document_t* document = zathura_document_open(argv[1], NULL);
|
zathura_document_t* document = zathura_document_open(argv[1], NULL);
|
||||||
|
|
||||||
if(!document) {
|
if(!document) {
|
||||||
return -1;
|
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);
|
zathura_document_free(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*gdk_threads_enter();*/
|
gdk_threads_enter();
|
||||||
/*gtk_main();*/
|
gtk_main();
|
||||||
/*gdk_threads_leave();*/
|
gdk_threads_leave();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue