From cd7fda37cfa5a25d23196391a1d42836fb1c1c2d Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 18 Nov 2010 03:15:32 +0100 Subject: [PATCH] PDF function definitions --- ft/document.c | 19 ++++++++++--- ft/document.h | 3 +- ft/pdf/pdf.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ ft/pdf/pdf.h | 15 ++++++++++ utils.c | 20 +++++++++++++- 5 files changed, 127 insertions(+), 6 deletions(-) diff --git a/ft/document.c b/ft/document.c index 7f6b62f..387be7c 100644 --- a/ft/document.c +++ b/ft/document.c @@ -2,6 +2,7 @@ #include #include +#include #include "document.h" #include "../utils.h" @@ -43,6 +44,7 @@ zathura_document_open(const char* path, const char* password) document->number_of_pages = 0; document->scale = 100; document->rotate = 0; + document->data = NULL; document->functions.document_free = NULL; document->functions.document_index_generate = NULL; @@ -58,9 +60,17 @@ zathura_document_open(const char* path, const char* password) /* init plugin with associated file type */ for(unsigned int i = 0; i < LENGTH(zathura_document_plugins); i++) { - + if(!strcmp(file_extension, zathura_document_plugins[i].file_extension)) { + if(zathura_document_plugins[i].open_function) { + if(zathura_document_plugins[i].open_function(document)) { + return document; + } + } + } } + fprintf(stderr, "error: unknown file type\n"); + return NULL; } @@ -68,12 +78,13 @@ bool zathura_document_free(zathura_document_t* document) { if(!document) { - return NULL; + return false; } - if(!document->functions.document_free(document)) { + if(!document->functions.document_free) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); - return NULL; + free(document); + return true; } bool r = document->functions.document_free(document); diff --git a/ft/document.h b/ft/document.h index 28b18d9..9976639 100644 --- a/ft/document.h +++ b/ft/document.h @@ -13,7 +13,7 @@ typedef bool (*zathura_document_open_t)(zathura_document_t* document); typedef struct zathura_document_plugin_s { - const char* file_type; + const char* file_extension; zathura_document_open_t open_function; } zathura_document_plugin_t; @@ -76,6 +76,7 @@ struct zathura_document_s unsigned int number_of_pages; int scale; int rotate; + void* data; struct { diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 83bc422..35b0995 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -1,9 +1,85 @@ /* See LICENSE file for license and copyright information */ +#include + #include "pdf.h" bool pdf_document_open(zathura_document_t* document) { + if(!document) + return false; + + document->functions.document_free = pdf_document_free; + document->functions.document_index_generate = pdf_document_index_generate;; + document->functions.document_save_as = pdf_document_save_as; + document->functions.document_attachments_get = pdf_document_attachments_get; + document->functions.page_get = pdf_page_get; + document->functions.page_search_text = pdf_page_search_text; + document->functions.page_links_get = pdf_page_links_get; + document->functions.page_form_fields_get = pdf_page_form_fields_get; + document->functions.page_render = pdf_page_render; + document->functions.page_free = pdf_page_free; + return true; } + +bool +pdf_document_free(zathura_document_t* document) +{ + return false; +} + +zathura_list_t* +pdf_document_index_generate(zathura_document_t* document) +{ + return NULL; +} + +bool +pdf_document_save_as(zathura_document_t* document, const char* path) +{ + return false; +} + +zathura_list_t* +pdf_document_attachments_get(zathura_document_t* document) +{ + return NULL; +} + +zathura_page_t* +pdf_page_get(zathura_document_t* document, unsigned int page) +{ + return NULL; +} + +zathura_list_t* +pdf_page_search_text(zathura_page_t* page, const char* text) +{ + return NULL; +} + +zathura_list_t* +pdf_page_links_get(zathura_page_t* page) +{ + return NULL; +} + +zathura_list_t* +pdf_page_form_fields_get(zathura_page_t* page) +{ + return NULL; +} + +cairo_surface_t* +pdf_page_render(zathura_page_t* page) +{ + return NULL; +} + +bool +pdf_page_free(zathura_page_t* page) +{ + return false; +} diff --git a/ft/pdf/pdf.h b/ft/pdf/pdf.h index e207dd2..1d7563d 100644 --- a/ft/pdf/pdf.h +++ b/ft/pdf/pdf.h @@ -1,7 +1,22 @@ /* See LICENSE file for license and copyright information */ +#ifndef PDF_H +#define PDF_H + #include #include "../document.h" bool pdf_document_open(zathura_document_t* document); +bool pdf_document_free(zathura_document_t* document); +zathura_list_t* pdf_document_index_generate(zathura_document_t* document); +bool pdf_document_save_as(zathura_document_t* document, const char* path); +zathura_list_t* pdf_document_attachments_get(zathura_document_t* document); +zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); +zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); +zathura_list_t* pdf_page_links_get(zathura_page_t* page); +zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); +cairo_surface_t* pdf_page_render(zathura_page_t* page); +bool pdf_page_free(zathura_page_t* page); + +#endif // PDF_H diff --git a/utils.c b/utils.c index 47d1690..9938900 100644 --- a/utils.c +++ b/utils.c @@ -1,6 +1,7 @@ /* See LICENSE file for license and copyright information */ #include +#include #include #include "utils.h" @@ -18,5 +19,22 @@ file_exists(const char* path) const char* file_get_extension(const char* path) { - return NULL; + if(!path) { + return NULL; + } + + unsigned int i = strlen(path); + for(; i > 0; i--) + { + if(*(path + i) != '.') + continue; + else + break; + } + + if(!i) { + return NULL; + } + + return path + i + 1; }