Replace GtkWidget with zathura_image_buffer_t

This commit is contained in:
Moritz Lipp 2011-03-18 13:27:21 +01:00
parent 58c2ee7dd3
commit 7d18faa452
9 changed files with 78 additions and 52 deletions

View file

@ -469,7 +469,7 @@ zathura_page_form_fields_free(zathura_list_t* list)
return false; return false;
} }
GtkWidget* zathura_image_buffer_t*
zathura_page_render(zathura_page_t* page) zathura_page_render(zathura_page_t* page)
{ {
if (!page || !page->document) { if (!page || !page->document) {
@ -481,13 +481,13 @@ zathura_page_render(zathura_page_t* page)
return NULL; return NULL;
} }
GtkWidget* widget = page->document->functions.page_render(page); zathura_image_buffer_t* buffer = page->document->functions.page_render(page);
if (widget) { if (buffer) {
page->rendered = true; page->rendered = true;
} }
return widget; return buffer;
} }
zathura_index_element_t* zathura_index_element_t*
@ -523,3 +523,35 @@ zathura_index_element_free(zathura_index_element_t* index)
g_free(index); g_free(index);
} }
zathura_image_buffer_t*
zathura_image_buffer_create(unsigned int width, unsigned int height)
{
zathura_image_buffer_t* image_buffer = malloc(sizeof(zathura_image_buffer_t));
if (image_buffer == NULL) {
return NULL;
}
image_buffer->data = calloc(width * height * 3, sizeof(unsigned char));
if (image_buffer->data == NULL) {
free(image_buffer);
return NULL;
}
image_buffer->width = width;
image_buffer->height = height;
return image_buffer;
}
void
zathura_image_buffer_free(zathura_image_buffer_t* image_buffer)
{
if (image_buffer == NULL) {
return;
}
free(image_buffer->data);
}

View file

@ -43,6 +43,32 @@ struct zathura_list_s
struct zathura_list_s* next; /**> Next element in the list */ struct zathura_list_s* next; /**> Next element in the list */
}; };
/**
* Image buffer
*/
typedef struct zathura_image_buffer_s
{
unsigned char* data; /**> Image buffer data */
unsigned int height; /**> Height of the image */
unsigned int width; /**> Width of the image */
} zathura_image_buffer_t;
/**
* Creates an image buffer
*
* @param width Width of the image stored in the buffer
* @param height Height of the image stored in the buffer
* @return Image buffer or NULL if an error occured
*/
zathura_image_buffer_t* zathura_image_buffer_create(unsigned int width, unsigned int height);
/**
* Frees the image buffer
*
* @param zathura_image_buffer_t
*/
void zathura_image_buffer_free(zathura_image_buffer_t*);
/** /**
* Rectangle structure * Rectangle structure
*/ */
@ -141,83 +167,51 @@ struct zathura_document_s
{ {
/** /**
* Frees the document * Frees the document
*
* @param document The document
*/ */
bool (*document_free)(zathura_document_t* document); bool (*document_free)(zathura_document_t* document);
/** /**
* Generates the document index * Generates the document index
*
* @param document The document
* @return NULL if an error occured or no index exists
*/ */
girara_tree_node_t* (*document_index_generate)(zathura_document_t* document); girara_tree_node_t* (*document_index_generate)(zathura_document_t* document);
/** /**
* Save the document * Save the document
*
* @param document The document
* @param path The new path
* @return true if no error occured
*/ */
bool (*document_save_as)(zathura_document_t* document, const char* path); bool (*document_save_as)(zathura_document_t* document, const char* path);
/** /**
* Get list of attachments * Get list of attachments
*
* @param document The document
* @return NULL if an error occured, otherwise the attachment list
*/ */
zathura_list_t* (*document_attachments_get)(zathura_document_t* document); zathura_list_t* (*document_attachments_get)(zathura_document_t* document);
/** /**
* Gets the page object * Gets the page object
*
* @param document The document
* @param page_id Number of the page
* @return The page object or NULL, if an error occured
*/ */
zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id); zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id);
/** /**
* Search text * Search text
*
* @param page The page
* @param text Search item
* @return List of results
*/ */
zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text); zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text);
/** /**
* Get links on a page * Get links on a page
*
* @param page
* @return List of links
*/ */
zathura_list_t* (*page_links_get)(zathura_page_t* page); zathura_list_t* (*page_links_get)(zathura_page_t* page);
/** /**
* Get form fields * Get form fields
*
* @param page
* @return List of form fields
*/ */
zathura_list_t* (*page_form_fields_get)(zathura_page_t* page); zathura_list_t* (*page_form_fields_get)(zathura_page_t* page);
/** /**
* Renders the page * Renders the page
*
* @param page
* @return Rendered page
*/ */
GtkWidget* (*page_render)(zathura_page_t* page); zathura_image_buffer_t* (*page_render)(zathura_page_t* page);
/** /**
* Free page * Free page
*
* @param page
* @return true if no error occured, otherwise false
*/ */
bool (*page_free)(zathura_page_t* page); bool (*page_free)(zathura_page_t* page);
} functions; } functions;
@ -356,9 +350,9 @@ bool zathura_page_form_fields_free(zathura_list_t* list);
* Render page * Render page
* *
* @param page The page object * @param page The page object
* @return Rendered page * @return Image buffer or NULL if an error occured
*/ */
GtkWidget* zathura_page_render(zathura_page_t* page); zathura_image_buffer_t* zathura_page_render(zathura_page_t* page);
/** /**
* Create new index element * Create new index element

View file

@ -215,7 +215,7 @@ djvu_page_form_fields_get(zathura_page_t* page)
return NULL; return NULL;
} }
GtkWidget* zathura_image_buffer_t*
djvu_page_render(zathura_page_t* page) djvu_page_render(zathura_page_t* page)
{ {
if (!Zathura.document || !page || !page->document) { if (!Zathura.document || !page || !page->document) {

View file

@ -24,7 +24,7 @@ zathura_page_t* djvu_page_get(zathura_document_t* document, unsigned int page);
zathura_list_t* djvu_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* djvu_page_search_text(zathura_page_t* page, const char* text);
zathura_list_t* djvu_page_links_get(zathura_page_t* page); zathura_list_t* djvu_page_links_get(zathura_page_t* page);
zathura_list_t* djvu_page_form_fields_get(zathura_page_t* page); zathura_list_t* djvu_page_form_fields_get(zathura_page_t* page);
GtkWidget* djvu_page_render(zathura_page_t* page); zathura_image_buffer_t* djvu_page_render(zathura_page_t* page);
bool djvu_page_free(zathura_page_t* page); bool djvu_page_free(zathura_page_t* page);
#endif // DJVU_H #endif // DJVU_H

View file

@ -173,7 +173,7 @@ pdf_page_form_fields_get(zathura_page_t* page)
return NULL; return NULL;
} }
GtkWidget* zathura_image_buffer_t*
pdf_page_render(zathura_page_t* page) pdf_page_render(zathura_page_t* page)
{ {
if (!Zathura.document || !page || !page->data || !page->document) { if (!Zathura.document || !page || !page->data || !page->document) {

View file

@ -27,7 +27,7 @@ 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_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_links_get(zathura_page_t* page);
zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page);
GtkWidget* pdf_page_render(zathura_page_t* page); zathura_image_buffer_t* pdf_page_render(zathura_page_t* page);
bool pdf_page_free(zathura_page_t* page); bool pdf_page_free(zathura_page_t* page);
#endif // PDF_H #endif // PDF_H

View file

@ -250,7 +250,7 @@ pdf_page_form_fields_get(zathura_page_t* page)
return NULL; return NULL;
} }
GtkWidget* zathura_image_buffer_t*
pdf_page_render(zathura_page_t* page) pdf_page_render(zathura_page_t* page)
{ {
if (!Zathura.document || !page || !page->data || !page->document) { if (!Zathura.document || !page || !page->data || !page->document) {

View file

@ -22,7 +22,7 @@ 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_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_links_get(zathura_page_t* page);
zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page);
GtkWidget* pdf_page_render(zathura_page_t* page); zathura_image_buffer_t* pdf_page_render(zathura_page_t* page);
bool pdf_page_free(zathura_page_t* page); bool pdf_page_free(zathura_page_t* page);
#endif // PDF_H #endif // PDF_H

View file

@ -132,9 +132,9 @@ bool
render(zathura_page_t* page) render(zathura_page_t* page)
{ {
g_static_mutex_lock(&(page->lock)); g_static_mutex_lock(&(page->lock));
GtkWidget* image = zathura_page_render(page); zathura_image_buffer_t* buffer = zathura_page_render(page);
if (!image) { if (!buffer) {
g_static_mutex_unlock(&(page->lock)); g_static_mutex_unlock(&(page->lock));
printf("error: rendering failed\n"); printf("error: rendering failed\n");
return false; return false;
@ -148,7 +148,7 @@ render(zathura_page_t* page)
if (!widget) { if (!widget) {
g_static_mutex_unlock(&(page->lock)); g_static_mutex_unlock(&(page->lock));
printf("error: page container does not exist\n"); printf("error: page container does not exist\n");
g_object_unref(image); // TODO: zathura_image_buffer_free(image);
return false; return false;
} }
@ -164,13 +164,13 @@ render(zathura_page_t* page)
gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget); gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget);
/* add new widget */ /* add new widget */
gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); // TODO: gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0);
/* set old packaging values */ /* set old packaging values */
gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); // TODO: gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type);
/* reorder child */ /* reorder child */
gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); // TODO: gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number);
g_static_mutex_unlock(&(page->lock)); g_static_mutex_unlock(&(page->lock));
return true; return true;