Add option for right-to-left layout (fixes #754)

This commit is contained in:
Naohiro Aota 2018-09-11 11:01:20 +02:00 committed by Sebastian Ramacher
parent 3d12dbc51f
commit 2df776b329
6 changed files with 28 additions and 4 deletions

View File

@ -329,7 +329,10 @@ cb_page_layout_value_changed(girara_session_t* session, const char* name, girara
unsigned int page_padding = 1; unsigned int page_padding = 1;
girara_setting_get(zathura->ui.session, "page-padding", &page_padding); girara_setting_get(zathura->ui.session, "page-padding", &page_padding);
page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column); bool page_right_to_left = false;
girara_setting_get(zathura->ui.session, "page-right-to-left", &page_right_to_left);
page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column, page_right_to_left);
zathura_document_set_page_layout(zathura->document, page_padding, pages_per_row, first_page_column); zathura_document_set_page_layout(zathura->document, page_padding, pages_per_row, first_page_column);
} }

View File

@ -191,6 +191,8 @@ config_load_default(zathura_t* zathura)
girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, _("Number of pages per row"), cb_page_layout_value_changed, NULL); girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, _("Number of pages per row"), cb_page_layout_value_changed, NULL);
int_value = 1; int_value = 1;
girara_setting_add(gsession, "first-page-column", "1:2", STRING, false, _("Column of the first page"), cb_page_layout_value_changed, NULL); girara_setting_add(gsession, "first-page-column", "1:2", STRING, false, _("Column of the first page"), cb_page_layout_value_changed, NULL);
bool_value = false;
girara_setting_add(gsession, "page-right-to-left", &bool_value, BOOLEAN, false, _("Render pages from right to left"), cb_page_layout_value_changed, NULL);
float_value = 40; float_value = 40;
girara_setting_add(gsession, "scroll-step", &float_value, FLOAT, false, _("Scroll step"), NULL, NULL); girara_setting_add(gsession, "scroll-step", &float_value, FLOAT, false, _("Scroll step"), NULL, NULL);
float_value = 40; float_value = 40;

View File

@ -27,6 +27,7 @@
#define KEY_ZOOM "zoom" #define KEY_ZOOM "zoom"
#define KEY_ROTATE "rotate" #define KEY_ROTATE "rotate"
#define KEY_PAGES_PER_ROW "pages-per-row" #define KEY_PAGES_PER_ROW "pages-per-row"
#define KEY_PAGE_RIGHT_TO_LEFT "page-right-to-left"
#define KEY_FIRST_PAGE_COLUMN "first-page-column" #define KEY_FIRST_PAGE_COLUMN "first-page-column"
#define KEY_POSITION_X "position-x" #define KEY_POSITION_X "position-x"
#define KEY_POSITION_Y "position-y" #define KEY_POSITION_Y "position-y"
@ -560,6 +561,7 @@ plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
g_key_file_set_integer(priv->history, name, KEY_ROTATE, file_info->rotation); g_key_file_set_integer(priv->history, name, KEY_ROTATE, file_info->rotation);
g_key_file_set_integer(priv->history, name, KEY_PAGES_PER_ROW, file_info->pages_per_row); g_key_file_set_integer(priv->history, name, KEY_PAGES_PER_ROW, file_info->pages_per_row);
g_key_file_set_string(priv->history, name, KEY_FIRST_PAGE_COLUMN, file_info->first_page_column_list); g_key_file_set_string(priv->history, name, KEY_FIRST_PAGE_COLUMN, file_info->first_page_column_list);
g_key_file_set_boolean(priv->history, name, KEY_PAGE_RIGHT_TO_LEFT,file_info->page_right_to_left);
g_key_file_set_double (priv->history, name, KEY_POSITION_X, file_info->position_x); g_key_file_set_double (priv->history, name, KEY_POSITION_X, file_info->position_x);
g_key_file_set_double (priv->history, name, KEY_POSITION_Y, file_info->position_y); g_key_file_set_double (priv->history, name, KEY_POSITION_Y, file_info->position_y);
g_key_file_set_integer(priv->history, name, KEY_TIME, time(NULL)); g_key_file_set_integer(priv->history, name, KEY_TIME, time(NULL));
@ -603,6 +605,9 @@ plain_get_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
if (g_key_file_has_key(priv->history, name, KEY_FIRST_PAGE_COLUMN, NULL) == TRUE) { if (g_key_file_has_key(priv->history, name, KEY_FIRST_PAGE_COLUMN, NULL) == TRUE) {
file_info->first_page_column_list = g_key_file_get_string(priv->history, name, KEY_FIRST_PAGE_COLUMN, NULL); file_info->first_page_column_list = g_key_file_get_string(priv->history, name, KEY_FIRST_PAGE_COLUMN, NULL);
} }
if (g_key_file_has_key(priv->history, name, KEY_PAGE_RIGHT_TO_LEFT, NULL) == TRUE) {
file_info->page_right_to_left = g_key_file_get_boolean(priv->history, name, KEY_PAGE_RIGHT_TO_LEFT, NULL);
}
if (g_key_file_has_key(priv->history, name, KEY_POSITION_X, NULL) == TRUE) { if (g_key_file_has_key(priv->history, name, KEY_POSITION_X, NULL) == TRUE) {
file_info->position_x = g_key_file_get_double(priv->history, name, KEY_POSITION_X, NULL); file_info->position_x = g_key_file_get_double(priv->history, name, KEY_POSITION_X, NULL);
} }

View File

@ -15,6 +15,7 @@ typedef struct zathura_fileinfo_s {
double zoom; double zoom;
unsigned int rotation; unsigned int rotation;
unsigned int pages_per_row; unsigned int pages_per_row;
bool page_right_to_left;
char* first_page_column_list; char* first_page_column_list;
double position_x; double position_x;
double position_y; double position_y;

View File

@ -980,6 +980,7 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char*
.rotation = 0, .rotation = 0,
.pages_per_row = 0, .pages_per_row = 0,
.first_page_column_list = NULL, .first_page_column_list = NULL,
.page_right_to_left = false,
.position_x = 0, .position_x = 0,
.position_y = 0 .position_y = 0
}; };
@ -1152,6 +1153,7 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char*
unsigned int pages_per_row = 1; unsigned int pages_per_row = 1;
char* first_page_column_list = NULL; char* first_page_column_list = NULL;
unsigned int page_padding = 1; unsigned int page_padding = 1;
bool page_right_to_left = false;
girara_setting_get(zathura->ui.session, "page-padding", &page_padding); girara_setting_get(zathura->ui.session, "page-padding", &page_padding);
@ -1177,7 +1179,9 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char*
g_free(file_info.first_page_column_list); g_free(file_info.first_page_column_list);
g_free(first_page_column_list); g_free(first_page_column_list);
page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column); page_right_to_left = file_info.page_right_to_left;
page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column, page_right_to_left);
zathura_document_set_page_layout(zathura->document, page_padding, pages_per_row, first_page_column); zathura_document_set_page_layout(zathura->document, page_padding, pages_per_row, first_page_column);
girara_set_view(zathura->ui.session, zathura->ui.page_widget); girara_set_view(zathura->ui.session, zathura->ui.page_widget);
@ -1341,6 +1345,7 @@ save_fileinfo_to_db(zathura_t* zathura)
.rotation = zathura_document_get_rotation(zathura->document), .rotation = zathura_document_get_rotation(zathura->document),
.pages_per_row = 1, .pages_per_row = 1,
.first_page_column_list = "1:2", .first_page_column_list = "1:2",
.page_right_to_left = false,
.position_x = zathura_document_get_position_x(zathura->document), .position_x = zathura_document_get_position_x(zathura->document),
.position_y = zathura_document_get_position_y(zathura->document) .position_y = zathura_document_get_position_y(zathura->document)
}; };
@ -1349,6 +1354,8 @@ save_fileinfo_to_db(zathura_t* zathura)
&(file_info.pages_per_row)); &(file_info.pages_per_row));
girara_setting_get(zathura->ui.session, "first-page-column", girara_setting_get(zathura->ui.session, "first-page-column",
&(file_info.first_page_column_list)); &(file_info.first_page_column_list));
girara_setting_get(zathura->ui.session, "page-right-to-left",
&(file_info.page_right_to_left));
/* save file info */ /* save file info */
zathura_db_set_fileinfo(zathura->database, path, &file_info); zathura_db_set_fileinfo(zathura->database, path, &file_info);
@ -1509,7 +1516,8 @@ statusbar_page_number_update(zathura_t* zathura)
void void
page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, page_widget_set_mode(zathura_t* zathura, unsigned int page_padding,
unsigned int pages_per_row, unsigned int first_page_column) unsigned int pages_per_row, unsigned int first_page_column,
bool page_right_to_left)
{ {
/* show at least one page */ /* show at least one page */
if (pages_per_row == 0) { if (pages_per_row == 0) {
@ -1540,6 +1548,9 @@ page_widget_set_mode(zathura_t* zathura, unsigned int page_padding,
int y = (i + first_page_column - 1) / pages_per_row; int y = (i + first_page_column - 1) / pages_per_row;
GtkWidget* page_widget = zathura->pages[i]; GtkWidget* page_widget = zathura->pages[i];
if (page_right_to_left) {
x = pages_per_row - 1 - x;
}
gtk_grid_attach(GTK_GRID(zathura->ui.page_widget), page_widget, x, y, 1, 1); gtk_grid_attach(GTK_GRID(zathura->ui.page_widget), page_widget, x, y, 1, 1);
} }

View File

@ -404,9 +404,11 @@ bool adjust_view(zathura_t* zathura);
* @param page_padding padding in pixels between pages * @param page_padding padding in pixels between pages
* @param pages_per_row Number of shown pages per row * @param pages_per_row Number of shown pages per row
* @param first_page_column Column on which first page start * @param first_page_column Column on which first page start
* @param page_right_to_left Render pages right to left
*/ */
void page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, void page_widget_set_mode(zathura_t* zathura, unsigned int page_padding,
unsigned int pages_per_row, unsigned int first_page_column); unsigned int pages_per_row, unsigned int first_page_column,
bool page_right_to_left);
/** /**
* Updates the page number in the statusbar. Note that 1 will be added to the * Updates the page number in the statusbar. Note that 1 will be added to the