Fixing the issue of the 'best-fit' zoom being way too low if one page is larger that the rest. The zoom was trying to accomodate for the large page, but it should instead accomodate for the most frequent size. This is still not ideal, since as it is now Zathura crops the larger pages to the size of the most frequent size, but this typically only affects things like larger first pages in scans. I am building this on thop of the Ailrk-fork, since that version already implemented a way how to estimate the most frequent page size, from the first 32 pages.

This commit is contained in:
Viktor Walter 2021-11-29 19:12:45 +01:00
parent 5ea8b4462e
commit 6d66bc88af
3 changed files with 30 additions and 7 deletions

View File

@ -427,6 +427,7 @@ void zathura_document_set_zoom(zathura_document_t *document, double zoom) {
return;
}
/* fprintf(stderr, "orig_zoom: %f\t new_zoom: %f\n", document->zoom, zoom); */
document->zoom = zoom;
}
@ -603,6 +604,14 @@ void zathura_document_get_document_size(zathura_document_t *document,
*height = nrow * cell_height + (nrow - 1) * pad;
}
void zathura_document_set_cell_size(zathura_document_t *document,
unsigned int cell_height,
unsigned int cell_width) {
document->cell_width = cell_width;
document->cell_height = cell_height;
}
void zathura_document_set_page_layout(zathura_document_t *document,
unsigned int page_padding,
unsigned int pages_per_row,

View File

@ -328,6 +328,18 @@ ZATHURA_PLUGIN_API void zathura_document_get_cell_size(zathura_document_t* docum
ZATHURA_PLUGIN_API void zathura_document_get_document_size(zathura_document_t* document,
unsigned int* height, unsigned int* width);
/**
* Sets the cell height and width of the document
*
* @param[in] document The document instance
* @param[in] cell_height The desired cell height
* @param[in] cell_width The desired cell width
*/
ZATHURA_PLUGIN_API void zathura_document_set_cell_size(zathura_document_t *document,
unsigned int cell_height,
unsigned int cell_width);
/**
* Sets the layout of the pages in the document
*

View File

@ -931,11 +931,6 @@ static void document_open_page_most_frequent_size(zathura_document_t *document,
unsigned int number_of_pages = zathura_document_get_number_of_pages(document);
unsigned int last_sample = (number_of_pages > 32) ? 32 : number_of_pages;
for (int i = 0; i < 32; ++i) {
fprintf(stderr, "i: %d, w: %f, h: %f, freq: %d\n", i, samples[i].h,
samples[i].w, samples[i].freq);
}
for (unsigned int page_id = 0; page_id < last_sample; page_id++) {
zathura_page_t *page = zathura_document_get_page(document, page_id);
double w = zathura_page_get_width(page), h = zathura_page_get_height(page);
@ -956,8 +951,8 @@ static void document_open_page_most_frequent_size(zathura_document_t *document,
qsort((void *)samples, 32, sizeof(sample_t), document_page_size_comp);
for (int i = 0; i < 32; ++i) {
fprintf(stderr, "i: %d, w: %f, h: %f, freq: %d\n", i, samples[i].h,
samples[i].w, samples[i].freq);
/* fprintf(stderr, "i: %d, w: %f, h: %f, freq: %d\n", i, samples[i].h,
samples[i].w, samples[i].freq); */
}
*width = samples[31].w;
@ -1189,6 +1184,10 @@ bool document_open(zathura_t *zathura, const char *path, const char *uri,
goto error_free;
}
unsigned int cell_height = 0, cell_width = 0;
zathura_document_get_cell_size(document, &cell_height, &cell_width);
/* fprintf(stderr, "new_cell_height: %d \t new_cell_width: %d\n", most_freq_height, most_freq_width); */
zathura_document_set_cell_size(document, most_freq_height, most_freq_width);
zathura_page_set_width(page, most_freq_width);
zathura_page_set_height(page, most_freq_height);
@ -1741,6 +1740,9 @@ bool adjust_view(zathura_t *zathura) {
double zoom = zathura_document_get_zoom(zathura->document);
double newzoom = zoom;
/* fprintf(stderr, "cell_height: %d \t cell_width: %d \t page_ratio: %f\n", cell_height, cell_width, page_ratio); */
/* fprintf(stderr, "view_height: %d \t view_width: %d \t view_ratio: %f\n", view_height, view_width, view_ratio); */
if (adjust_mode == ZATHURA_ADJUST_WIDTH ||
(adjust_mode == ZATHURA_ADJUST_BESTFIT && page_ratio < view_ratio)) {
newzoom *= (double)view_width / (double)document_width;