mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 21:16:00 +01:00
Refactor
This commit is contained in:
parent
2899daa838
commit
abb76d8dfe
1 changed files with 75 additions and 69 deletions
144
zathura/links.c
144
zathura/links.c
|
@ -117,6 +117,79 @@ zathura_link_get_target(zathura_link_t* link)
|
||||||
return link->target;
|
return link->target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
link_goto_dest(zathura_t* zathura, const zathura_link_t* link)
|
||||||
|
{
|
||||||
|
if (link->target.destination_type == ZATHURA_LINK_DESTINATION_UNKNOWN) {
|
||||||
|
girara_warning("link destination type unknown");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool link_zoom = true;
|
||||||
|
girara_setting_get(zathura->ui.session, "link-zoom", &link_zoom);
|
||||||
|
|
||||||
|
if (link->target.zoom >= DBL_EPSILON && link_zoom == true) {
|
||||||
|
zathura_document_set_zoom(zathura->document,
|
||||||
|
zathura_correct_zoom_value(zathura->ui.session, link->target.zoom));
|
||||||
|
render_all(zathura);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get page */
|
||||||
|
zathura_page_t* page = zathura_document_get_page(zathura->document,
|
||||||
|
link->target.page_number);
|
||||||
|
if (page == NULL) {
|
||||||
|
girara_warning("link to non-existing page %u", link->target.page_number);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* compute the position with the page aligned to the top and left
|
||||||
|
of the viewport */
|
||||||
|
double pos_x = 0;
|
||||||
|
double pos_y = 0;
|
||||||
|
page_number_to_position(zathura->document, link->target.page_number,
|
||||||
|
0.0, 0.0, &pos_x, &pos_y);
|
||||||
|
|
||||||
|
/* correct to place the target position at the top of the viewport */
|
||||||
|
/* NOTE: link->target is in page units, needs to be scaled and rotated */
|
||||||
|
unsigned int cell_height = 0;
|
||||||
|
unsigned int cell_width = 0;
|
||||||
|
zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width);
|
||||||
|
|
||||||
|
unsigned int doc_height = 0;
|
||||||
|
unsigned int doc_width = 0;
|
||||||
|
zathura_document_get_document_size(zathura->document, &doc_height, &doc_width);
|
||||||
|
|
||||||
|
bool link_hadjust = true;
|
||||||
|
girara_setting_get(zathura->ui.session, "link-hadjust", &link_hadjust);
|
||||||
|
|
||||||
|
/* scale and rotate */
|
||||||
|
double scale = zathura_document_get_scale(zathura->document);
|
||||||
|
double shiftx = link->target.left * scale / (double)cell_width;
|
||||||
|
double shifty = link->target.top * scale / (double)cell_height;
|
||||||
|
page_calc_position(zathura->document, shiftx, shifty, &shiftx, &shifty);
|
||||||
|
|
||||||
|
/* shift the position or set to auto */
|
||||||
|
if (link->target.destination_type == ZATHURA_LINK_DESTINATION_XYZ &&
|
||||||
|
link->target.left != -1 && link_hadjust == true) {
|
||||||
|
pos_x += shiftx / (double)doc_width;
|
||||||
|
} else {
|
||||||
|
pos_x = -1; /* -1 means automatic */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (link->target.destination_type == ZATHURA_LINK_DESTINATION_XYZ &&
|
||||||
|
link->target.top != -1) {
|
||||||
|
pos_y += shifty / (double)doc_height;
|
||||||
|
} else {
|
||||||
|
pos_y = -1; /* -1 means automatic */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* move to position */
|
||||||
|
zathura_jumplist_add(zathura);
|
||||||
|
zathura_document_set_current_page_number(zathura->document, link->target.page_number);
|
||||||
|
position_set(zathura, pos_x, pos_y);
|
||||||
|
zathura_jumplist_add(zathura);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
link_remote(zathura_t* zathura, const char* file)
|
link_remote(zathura_t* zathura, const char* file)
|
||||||
{
|
{
|
||||||
|
@ -145,12 +218,8 @@ link_remote(zathura_t* zathura, const char* file)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
link_launch(zathura_t* zathura, zathura_link_t* link)
|
link_launch(zathura_t* zathura, const zathura_link_t* link)
|
||||||
{
|
{
|
||||||
if (zathura == NULL || link == NULL || zathura->document == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get file path */
|
/* get file path */
|
||||||
if (link->target.value == NULL) {
|
if (link->target.value == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -180,72 +249,9 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool link_zoom = true;
|
|
||||||
girara_setting_get(zathura->ui.session, "link-zoom", &link_zoom);
|
|
||||||
|
|
||||||
switch (link->type) {
|
switch (link->type) {
|
||||||
case ZATHURA_LINK_GOTO_DEST:
|
case ZATHURA_LINK_GOTO_DEST:
|
||||||
if (link->target.destination_type != ZATHURA_LINK_DESTINATION_UNKNOWN) {
|
link_goto_dest(zathura, link);
|
||||||
if (link->target.zoom >= DBL_EPSILON && link_zoom) {
|
|
||||||
zathura_document_set_zoom(zathura->document,
|
|
||||||
zathura_correct_zoom_value(zathura->ui.session, link->target.zoom));
|
|
||||||
render_all(zathura);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get page */
|
|
||||||
zathura_page_t* page = zathura_document_get_page(zathura->document,
|
|
||||||
link->target.page_number);
|
|
||||||
if (page == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* compute the position with the page aligned to the top and left
|
|
||||||
of the viewport */
|
|
||||||
double pos_x = 0;
|
|
||||||
double pos_y = 0;
|
|
||||||
page_number_to_position(zathura->document, link->target.page_number,
|
|
||||||
0.0, 0.0, &pos_x, &pos_y);
|
|
||||||
|
|
||||||
/* correct to place the target position at the top of the viewport */
|
|
||||||
/* NOTE: link->target is in page units, needs to be scaled and rotated */
|
|
||||||
unsigned int cell_height = 0;
|
|
||||||
unsigned int cell_width = 0;
|
|
||||||
zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width);
|
|
||||||
|
|
||||||
unsigned int doc_height = 0;
|
|
||||||
unsigned int doc_width = 0;
|
|
||||||
zathura_document_get_document_size(zathura->document, &doc_height, &doc_width);
|
|
||||||
|
|
||||||
bool link_hadjust = true;
|
|
||||||
girara_setting_get(zathura->ui.session, "link-hadjust", &link_hadjust);
|
|
||||||
|
|
||||||
/* scale and rotate */
|
|
||||||
double scale = zathura_document_get_scale(zathura->document);
|
|
||||||
double shiftx = link->target.left * scale / (double)cell_width;
|
|
||||||
double shifty = link->target.top * scale / (double)cell_height;
|
|
||||||
page_calc_position(zathura->document, shiftx, shifty, &shiftx, &shifty);
|
|
||||||
|
|
||||||
/* shift the position or set to auto */
|
|
||||||
if (link->target.destination_type == ZATHURA_LINK_DESTINATION_XYZ &&
|
|
||||||
link->target.left != -1 && link_hadjust == true) {
|
|
||||||
pos_x += shiftx / (double)doc_width;
|
|
||||||
} else {
|
|
||||||
pos_x = -1; /* -1 means automatic */
|
|
||||||
}
|
|
||||||
|
|
||||||
if (link->target.destination_type == ZATHURA_LINK_DESTINATION_XYZ &&
|
|
||||||
link->target.top != -1) {
|
|
||||||
pos_y += shifty / (double)doc_height;
|
|
||||||
} else {
|
|
||||||
pos_y = -1; /* -1 means automatic */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* move to position */
|
|
||||||
zathura_jumplist_add(zathura);
|
|
||||||
zathura_document_set_current_page_number(zathura->document, link->target.page_number);
|
|
||||||
position_set(zathura, pos_x, pos_y);
|
|
||||||
zathura_jumplist_add(zathura);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ZATHURA_LINK_GOTO_REMOTE:
|
case ZATHURA_LINK_GOTO_REMOTE:
|
||||||
link_remote(zathura, link->target.value);
|
link_remote(zathura, link->target.value);
|
||||||
|
|
Loading…
Reference in a new issue