Commit cd7fda37 authored by Moritz Lipp's avatar Moritz Lipp
Browse files

PDF function definitions

parent 4857d62f
......@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#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);
......
......@@ -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
{
......
/* See LICENSE file for license and copyright information */
#include <stdlib.h>
#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;
}
/* See LICENSE file for license and copyright information */
#ifndef PDF_H
#define PDF_H
#include <stdbool.h>
#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
/* See LICENSE file for license and copyright information */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#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;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment