PDF function definitions

This commit is contained in:
Moritz Lipp 2010-11-18 03:15:32 +01:00
parent 4857d62fde
commit cd7fda37cf
5 changed files with 127 additions and 6 deletions

View file

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "document.h" #include "document.h"
#include "../utils.h" #include "../utils.h"
@ -43,6 +44,7 @@ zathura_document_open(const char* path, const char* password)
document->number_of_pages = 0; document->number_of_pages = 0;
document->scale = 100; document->scale = 100;
document->rotate = 0; document->rotate = 0;
document->data = NULL;
document->functions.document_free = NULL; document->functions.document_free = NULL;
document->functions.document_index_generate = 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 */ /* init plugin with associated file type */
for(unsigned int i = 0; i < LENGTH(zathura_document_plugins); i++) 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; return NULL;
} }
@ -68,12 +78,13 @@ bool
zathura_document_free(zathura_document_t* document) zathura_document_free(zathura_document_t* document)
{ {
if(!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__); fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
return NULL; free(document);
return true;
} }
bool r = document->functions.document_free(document); bool r = document->functions.document_free(document);

View file

@ -13,7 +13,7 @@ typedef bool (*zathura_document_open_t)(zathura_document_t* document);
typedef struct zathura_document_plugin_s typedef struct zathura_document_plugin_s
{ {
const char* file_type; const char* file_extension;
zathura_document_open_t open_function; zathura_document_open_t open_function;
} zathura_document_plugin_t; } zathura_document_plugin_t;
@ -76,6 +76,7 @@ struct zathura_document_s
unsigned int number_of_pages; unsigned int number_of_pages;
int scale; int scale;
int rotate; int rotate;
void* data;
struct struct
{ {

View file

@ -1,9 +1,85 @@
/* See LICENSE file for license and copyright information */ /* See LICENSE file for license and copyright information */
#include <stdlib.h>
#include "pdf.h" #include "pdf.h"
bool bool
pdf_document_open(zathura_document_t* document) 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; 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;
}

View file

@ -1,7 +1,22 @@
/* See LICENSE file for license and copyright information */ /* See LICENSE file for license and copyright information */
#ifndef PDF_H
#define PDF_H
#include <stdbool.h> #include <stdbool.h>
#include "../document.h" #include "../document.h"
bool pdf_document_open(zathura_document_t* document); 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

20
utils.c
View file

@ -1,6 +1,7 @@
/* See LICENSE file for license and copyright information */ /* See LICENSE file for license and copyright information */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "utils.h" #include "utils.h"
@ -18,5 +19,22 @@ file_exists(const char* path)
const char* const char*
file_get_extension(const char* path) 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;
} }