diff --git a/render.c b/render.c index 7a2f470..7e07b76 100644 --- a/render.c +++ b/render.c @@ -12,6 +12,18 @@ void* render_job(void* data); bool render(zathura_t* zathura, zathura_page_t* page); +static void +page_calc_height_width(zathura_page_t* page, unsigned int* page_height, unsigned int* page_width) +{ + if (page->document->rotate == 0 || page->document->rotate == 180) { + *page_width = page->width * page->document->scale; + *page_height = page->height * page->document->scale; + } else { + *page_width = page->height * page->document->scale; + *page_height = page->width * page->document->scale; + } +} + void* render_job(void* data) { @@ -153,14 +165,7 @@ render(zathura_t* zathura, zathura_page_t* page) /* create cairo surface */ unsigned int page_width = 0; unsigned int page_height = 0; - - if (page->document->rotate == 0 || page->document->rotate == 180) { - page_width = page->width * zathura->document->scale; - page_height = page->height * zathura->document->scale; - } else { - page_width = page->height * zathura->document->scale; - page_height = page->width * zathura->document->scale; - } + page_calc_height_width(page, &page_height, &page_width); cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, page_width, page_height); @@ -255,7 +260,6 @@ render(zathura_t* zathura, zathura_page_t* page) /* draw to gtk widget */ page->surface = surface; - gtk_widget_set_size_request(page->drawing_area, page_width, page_height); gtk_widget_queue_draw(page->drawing_area); g_static_mutex_unlock(&(page->lock)); @@ -273,13 +277,16 @@ render_all(zathura_t* zathura) /* unmark all pages */ for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) { - cairo_surface_destroy(zathura->document->pages[page_id]->surface); - zathura->document->pages[page_id]->surface = NULL; - } + zathura_page_t* page = zathura->document->pages[page_id]; + cairo_surface_destroy(page->surface); + page->surface = NULL; - /* redraw current page */ - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - cb_view_vadjustment_value_changed(view_vadjustment, zathura); + unsigned int page_height = 0, page_width = 0; + page_calc_height_width(page, &page_height, &page_width); + + gtk_widget_set_size_request(page->drawing_area, page_width, page_height); + gtk_widget_queue_resize(page->drawing_area); + } } gboolean diff --git a/utils.c b/utils.c index e10dab6..4c36d5a 100644 --- a/utils.c +++ b/utils.c @@ -178,65 +178,6 @@ document_index_build(GtkTreeModel* model, GtkTreeIter* parent, GIRARA_LIST_FOREACH_END(list, gchar*, iter, name); } -char* -string_concat(const char* string1, ...) -{ - if(!string1) { - return NULL; - } - - va_list args; - char* s; - int l = strlen(string1) + 1; - - /* calculate length */ - va_start(args, string1); - - s = va_arg(args, char*); - - while(s) { - l += strlen(s); - s = va_arg(args, char*); - } - - va_end(args); - - /* prepare */ - char* c = malloc(sizeof(char) * l); - char* p = c; - - /* copy */ - char* d = p; - char* x = (char*) string1; - - do { - *d++ = *x; - } while (*x++ != '\0'); - - p = d - 1; - - va_start(args, string1); - - s = va_arg(args, char*); - - while(s) { - d = p; - x = s; - - do { - *d++ = *x; - } while (*x++ != '\0'); - - p = d - 1; - s = va_arg(args, char*); - } - - va_end(args); - - return c; -} - - page_offset_t* page_calculate_offset(zathura_page_t* page) { diff --git a/utils.h b/utils.h index d04e75f..499e654 100644 --- a/utils.h +++ b/utils.h @@ -62,16 +62,6 @@ bool execute_command(char* const argv[], char** output); */ void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree); -/** - * This function is used to concatenate multiple strings. Argument list has to - * be ended with NULL. Returned string has to be freed with free(). - * - * @param string1 First string - * @param ... Additional strings - * @return Concatenated string or NULL if an error occured - */ -char* string_concat(const char* string1, ...); - /** * Calculates the offset of the page to the top of the viewing area as * well as to the left side of it. The result has to be freed. diff --git a/zathura.c b/zathura.c index ed13cd4..2199539 100644 --- a/zathura.c +++ b/zathura.c @@ -591,7 +591,7 @@ page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { int x = i % pages_per_row; int y = i / pages_per_row; - gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_EXPAND, GTK_EXPAND, 0, 0); + gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_SHRINK, GTK_SHRINK, 0, 0); } gtk_widget_show_all(zathura->ui.page_view);