Added page labels

With this commit it is possible to show and use the labels of a page,
which makes it possible to use a page offset. E.g.: Sometimes the page
numbers written on the page in the document differ from the order in the
file, which can be annoying by e.g. trying to go to the page number >20<
that is instead page number >24< in the document.
This commit is contained in:
neldoreth 2010-05-05 12:36:04 +02:00
parent 4aad8d8720
commit 9c0eea2d2a
2 changed files with 26 additions and 17 deletions

View file

@ -55,6 +55,7 @@ static const char DEFAULT_TEXT[] = "[No Name]";
#define SHOW_SCROLLBARS 0 #define SHOW_SCROLLBARS 0
#define ADJUST_OPEN ADJUST_BESTFIT #define ADJUST_OPEN ADJUST_BESTFIT
#define RECOLOR_OPEN 0 #define RECOLOR_OPEN 0
#define ENABLE_LABELS 1
/* shortcuts */ /* shortcuts */
Shortcut shortcuts[] = { Shortcut shortcuts[] = {
@ -159,4 +160,5 @@ Setting settings[] = {
/* name, variable, type, render, description */ /* name, variable, type, render, description */
{"recolor", &(Zathura.Global.recolor), 'b', TRUE, "Invert the image"}, {"recolor", &(Zathura.Global.recolor), 'b', TRUE, "Invert the image"},
{"password", &(Zathura.PDF.password), 's', FALSE, "The password of the document"}, {"password", &(Zathura.PDF.password), 's', FALSE, "The password of the document"},
{"labels", &(Zathura.Global.enable_labels), 'b', FALSE, "Use labels for pages"},
}; };

View file

@ -112,6 +112,8 @@ typedef struct
typedef struct typedef struct
{ {
PopplerPage *page; PopplerPage *page;
int id;
char *label;
} Page; } Page;
typedef struct typedef struct
@ -184,6 +186,7 @@ struct
int mode; int mode;
int viewing_mode; int viewing_mode;
gboolean recolor; gboolean recolor;
gboolean enable_labels;
GtkLabel *status_text; GtkLabel *status_text;
GtkLabel *status_buffer; GtkLabel *status_buffer;
GtkLabel *status_state; GtkLabel *status_state;
@ -409,6 +412,7 @@ init_zathura()
Zathura.Global.viewing_mode = NORMAL; Zathura.Global.viewing_mode = NORMAL;
Zathura.Global.recolor = RECOLOR_OPEN; Zathura.Global.recolor = RECOLOR_OPEN;
Zathura.Global.adjust_mode = ADJUST_OPEN; Zathura.Global.adjust_mode = ADJUST_OPEN;
Zathura.Global.enable_labels = ENABLE_LABELS;
Zathura.State.filename = (char*) DEFAULT_TEXT; Zathura.State.filename = (char*) DEFAULT_TEXT;
Zathura.State.pages = ""; Zathura.State.pages = "";
@ -850,7 +854,9 @@ open_file(char* path, char* password)
for(i = 0; i < Zathura.PDF.number_of_pages; i++) for(i = 0; i < Zathura.PDF.number_of_pages; i++)
{ {
Zathura.PDF.pages[i] = malloc(sizeof(Page)); Zathura.PDF.pages[i] = malloc(sizeof(Page));
Zathura.PDF.pages[i]->id = i + 1;
Zathura.PDF.pages[i]->page = poppler_document_get_page(Zathura.PDF.document, i); Zathura.PDF.pages[i]->page = poppler_document_get_page(Zathura.PDF.document, i);
g_object_get(G_OBJECT(Zathura.PDF.pages[i]->page), "label", &(Zathura.PDF.pages[i]->label), NULL);
} }
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
@ -906,9 +912,20 @@ update_status()
/* update text */ /* update text */
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_text, Zathura.State.filename); gtk_label_set_markup((GtkLabel*) Zathura.Global.status_text, Zathura.State.filename);
/* update pages */
if( Zathura.PDF.document && Zathura.PDF.pages )
{
int page = Zathura.PDF.page_number;
if(Zathura.Global.enable_labels && Zathura.PDF.pages[page]->label)
Zathura.State.pages = g_strdup_printf("[%s/%i]",
Zathura.PDF.pages[page]->label, Zathura.PDF.number_of_pages);
else
Zathura.State.pages = g_strdup_printf("[%i/%i]", page + 1, Zathura.PDF.number_of_pages);
}
/* update state */ /* update state */
char* zoom_level = (Zathura.PDF.scale != 0) ? g_strdup_printf("%d%%", Zathura.PDF.scale) : ""; char* zoom_level = (Zathura.PDF.scale != 0) ? g_strdup_printf("%d%%", Zathura.PDF.scale) : "";
char* status_text = g_strdup_printf("%s %d%% %s", zoom_level, Zathura.State.scroll_percentage, Zathura.State.pages); char* status_text = g_strdup_printf("%s %s", zoom_level, Zathura.State.pages);
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_state, status_text); gtk_label_set_markup((GtkLabel*) Zathura.Global.status_state, status_text);
} }
@ -1048,7 +1065,6 @@ set_page(int page)
} }
Zathura.PDF.page_number = page; Zathura.PDF.page_number = page;
Zathura.State.pages = g_strdup_printf("[%i/%i]", page + 1, Zathura.PDF.number_of_pages);
Argument argument; Argument argument;
argument.n = TOP; argument.n = TOP;
@ -1145,10 +1161,6 @@ search(void* parameter)
gdk_threads_leave(); gdk_threads_leave();
} }
else
{
printf("Nothing found for %s\n", search_item);
}
g_static_mutex_lock(&(Zathura.Lock.search_lock)); g_static_mutex_lock(&(Zathura.Lock.search_lock));
Zathura.Thread.search_thread_running = FALSE; Zathura.Thread.search_thread_running = FALSE;
@ -1406,12 +1418,6 @@ sc_scroll(Argument* argument)
else else
gtk_adjustment_set_value(adjustment, (value + SCROLL_STEP) > max ? max : (value + SCROLL_STEP)); gtk_adjustment_set_value(adjustment, (value + SCROLL_STEP) > max ? max : (value + SCROLL_STEP));
int percentage = 100 * (value / max);
percentage = (percentage < 0) ? 0 : ((percentage > 100) ? 100 : percentage);
if( (argument->n != LEFT) && (argument->n != RIGHT) )
Zathura.State.scroll_percentage = percentage;
update_status(); update_status();
} }
@ -2402,9 +2408,9 @@ cmd_set(int argc, char** argv)
if(argv[1]) if(argv[1])
{ {
if(!strcmp(argv[1], "false") || !strcmp(argv[1], "0")) if(!strcmp(argv[1], "false") || !strcmp(argv[1], "0"))
*x = TRUE;
else
*x = FALSE; *x = FALSE;
else
*x = TRUE;
} }
} }
else if(settings[i].type == 'i') else if(settings[i].type == 'i')
@ -2446,6 +2452,7 @@ cmd_set(int argc, char** argv)
} }
} }
update_status();
return TRUE; return TRUE;
} }
@ -3181,11 +3188,11 @@ int main(int argc, char* argv[])
init_zathura(); init_zathura();
init_directories(); init_directories();
update_status();
if(argc >= 2) if(argc >= 2)
open_file(argv[1], (argc == 3) ? argv[2] : NULL); open_file(argv[1], (argc == 3) ? argv[2] : NULL);
update_status();
gtk_widget_show_all(GTK_WIDGET(Zathura.UI.window)); gtk_widget_show_all(GTK_WIDGET(Zathura.UI.window));
gdk_threads_enter(); gdk_threads_enter();