bool sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; g_return_val_if_fail(argument != NULL, false); g_return_val_if_fail(zathura->document != NULL, false); zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_NONE); /* retreive zoom step value */ int value = 1; girara_setting_get(zathura->ui.session, "zoom-step", &value); int nt = (t == 0) ? 1 : t; float zoom_step = value / 100.0f * nt; float old_zoom = zathura_document_get_scale(zathura->document); /* specify new zoom value */ if (argument->n == ZOOM_IN) { zathura_document_set_scale(zathura->document, old_zoom + zoom_step); } else if (argument->n == ZOOM_OUT) { zathura_document_set_scale(zathura->document, old_zoom - zoom_step); } else if (argument->n == ZOOM_SPECIFIC) { if (t == 0) { zathura_document_set_scale(zathura->document, 1.0f); } else { zathura_document_set_scale(zathura->document, t / 100.0f); } } else { zathura_document_set_scale(zathura->document, 1.0f); } /* zoom limitations */ int zoom_min_int = 10; int zoom_max_int = 1000; girara_setting_get(session, "zoom-min", &zoom_min_int); girara_setting_get(session, "zoom-max", &zoom_max_int); float zoom_min = zoom_min_int * 0.01f; float zoom_max = zoom_max_int * 0.01f; float scale = zathura_document_get_scale(zathura->document); if (scale < zoom_min) { zathura_document_set_scale(zathura->document, zoom_min); } else if (scale > zoom_max) { zathura_document_set_scale(zathura->document, zoom_max); } /* keep position */ readjust_view_after_zooming(zathura, old_zoom, true); render_all(zathura); return false; }
void mark_evaluate(zathura_t* zathura, int key) { if (zathura == NULL || zathura->global.marks == NULL) { return; } /* search for existing mark */ GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark) if (mark != NULL && mark->key == key) { double old_scale = zathura_document_get_scale(zathura->document); zathura_document_set_scale(zathura->document, mark->scale); readjust_view_after_zooming(zathura, old_scale, true); render_all(zathura); position_set_delayed(zathura, mark->position_x, mark->position_y); cb_view_vadjustment_value_changed(NULL, zathura); zathura->global.update_page_number = true; return; } GIRARA_LIST_FOREACH_END(zathura->global.marks, zathura_mark_t*, iter, mark); }
bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; g_return_val_if_fail(argument != NULL, false); unsigned int pages_per_row = 1; girara_setting_get(session, "pages-per-row", &pages_per_row); unsigned int first_page_column = 1; girara_setting_get(session, "first-page-column", &first_page_column); int padding = 1; girara_setting_get(zathura->ui.session, "page-padding", &padding); if (zathura->ui.page_widget == NULL || zathura->document == NULL) { goto error_ret; } float old_zoom = zathura_document_get_scale(zathura->document); zathura_document_set_adjust_mode(zathura->document, argument->n); if (argument->n == ZATHURA_ADJUST_NONE) { /* there is nothing todo */ goto error_ret; } /* get window size */ GtkAllocation allocation; gtk_widget_get_allocation(session->gtk.view, &allocation); unsigned int width = allocation.width; unsigned int height = allocation.height; /* scrollbar spacing */ gint spacing; gtk_widget_style_get(session->gtk.view, "scrollbar_spacing", &spacing, NULL); width -= spacing; /* correct view size */ if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)) == true) { gtk_widget_get_allocation(session->gtk.inputbar, &allocation); height += allocation.height; } double scale = 1.0; unsigned int cell_height = 0, cell_width = 0; unsigned int document_height = 0, document_width = 0; zathura_document_set_scale(zathura->document, scale); zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width); zathura_get_document_size(zathura, cell_height, cell_width, &document_height, &document_width); double page_ratio = (double)cell_height / (double)document_width; double window_ratio = (double)height / (double)width; if (argument->n == ZATHURA_ADJUST_WIDTH || (argument->n == ZATHURA_ADJUST_BESTFIT && page_ratio < window_ratio)) { scale = (double)(width - (pages_per_row - 1) * padding) / (double)(pages_per_row * cell_width); zathura_document_set_scale(zathura->document, scale); bool show_scrollbars = false; girara_setting_get(session, "show-scrollbars", &show_scrollbars); if (show_scrollbars) { /* If the document is taller than the view, there's a vertical * scrollbar; we need to substract its width from the view's width. */ zathura_get_document_size(zathura, cell_height, cell_width, &document_height, &document_width); if (height < document_height) { GtkWidget* vscrollbar = gtk_scrolled_window_get_vscrollbar( GTK_SCROLLED_WINDOW(session->gtk.view)); if (vscrollbar != NULL) { GtkRequisition requisition; gtk_widget_get_requisition(vscrollbar, &requisition); if (0 < requisition.width && (unsigned)requisition.width < width) { width -= requisition.width; scale = (double)(width - (pages_per_row - 1) * padding) / (double)(pages_per_row * cell_width); zathura_document_set_scale(zathura->document, scale); } } } } } else if (argument->n == ZATHURA_ADJUST_BESTFIT) { scale = (double)height / (double)cell_height; zathura_document_set_scale(zathura->document, scale); } else { goto error_ret; } /* keep position */ readjust_view_after_zooming(zathura, old_zoom, false); /* re-render all pages */ render_all(zathura); error_ret: return false; }