Commit 48183d67 authored by Moritz Lipp's avatar Moritz Lipp

Correct the given scale value

parent 42c1780a
......@@ -135,7 +135,8 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
case ZATHURA_LINK_GOTO_DEST:
if (link->target.destination_type != ZATHURA_LINK_DESTINATION_UNKNOWN) {
if (link->target.scale != 0 && link_zoom) {
zathura_document_set_scale(zathura->document, link->target.scale);
zathura_document_set_scale(zathura->document,
zathura_correct_scale_value(zathura->ui.session, link->target.scale));
render_all(zathura);
}
......
......@@ -239,7 +239,8 @@ mark_evaluate(zathura_t* zathura, int key)
/* search for existing mark */
GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark)
if (mark != NULL && mark->key == key) {
zathura_document_set_scale(zathura->document, mark->scale);
zathura_document_set_scale(zathura->document,
zathura_correct_scale_value(zathura->ui.session, mark->scale));
render_all(zathura);
zathura_jumplist_add(zathura);
......
......@@ -1390,20 +1390,8 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t*
}
/* 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);
const double zoom_min = zoom_min_int * 0.01;
const double zoom_max = zoom_max_int * 0.01;
const double 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);
}
zathura_document_set_scale(zathura->document, zathura_correct_scale_value(session, scale));
const double new_zoom = zathura_document_get_scale(zathura->document);
if (fabs(new_zoom - old_zoom) <= DBL_EPSILON) {
......
......@@ -23,6 +23,35 @@
#include "plugin.h"
#include "content-type.h"
double
zathura_correct_scale_value(girara_session_t* session, const double scale)
{
if (scale <= FLT_EPSILON) {
return 1;
}
if (session == NULL) {
return scale;
}
/* 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);
const double zoom_min = zoom_min_int * 0.01;
const double zoom_max = zoom_max_int * 0.01;
if (scale < zoom_min) {
return zoom_min;
} else if (scale > zoom_max) {
return zoom_max;
} else {
return scale;
}
}
bool
file_valid_extension(zathura_t* zathura, const char* path)
{
......
......@@ -95,4 +95,16 @@ char* zathura_get_version_string(zathura_t* zathura, bool markup);
*/
GdkAtom* get_selection(zathura_t* zathura);
/**
* Returns the valid scale value which needs to lie in the interval of zoom_min
* and zoom_max specified in the girara session
*
* @param[in] session The session
* @param[in] scale The proposed scale value
*
* @return The corrected scale value
*/
double zathura_correct_scale_value(girara_session_t* session, const double
scale);
#endif // UTILS_H
......@@ -607,12 +607,8 @@ document_open(zathura_t* zathura, const char* path, const char* password,
zathura_document_set_page_offset(document, file_info.page_offset);
/* check for valid scale value */
if (file_info.scale <= FLT_EPSILON) {
girara_warning("document info: '%s' has non positive scale", file_path);
zathura_document_set_scale(document, 1);
} else {
zathura_document_set_scale(document, file_info.scale);
}
zathura_document_set_scale(document,
zathura_correct_scale_value(zathura->ui.session, file_info.scale));
/* check current page number */
/* if it wasn't specified on the command-line, get it from file_info */
......
Markdown is supported
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